use of tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator in project teku by ConsenSys.
the class BlockImporterTest method importBlock_weakSubjectivityFailure_wrongAncestor.
@Test
public void importBlock_weakSubjectivityFailure_wrongAncestor() throws Exception {
final UInt64 wsEpoch = UInt64.valueOf(10);
final UInt64 wsEpochSlot = this.spec.computeStartSlotAtEpoch(wsEpoch);
final SignedBeaconBlock wsBlock = localChain.createBlockAtSlot(wsEpochSlot);
final SignedBeaconBlock otherBlock = otherChain.createBlockAtSlot(wsEpochSlot.plus(1));
final Spec spec = TestSpecFactory.createMinimalPhase0();
final Checkpoint wsCheckpoint = new Checkpoint(wsEpoch, wsBlock.getRoot());
final WeakSubjectivityConfig wsConfig = WeakSubjectivityConfig.builder().specProvider(spec).weakSubjectivityCheckpoint(wsCheckpoint).build();
final WeakSubjectivityValidator weakSubjectivityValidator = WeakSubjectivityValidator.lenient(wsConfig);
final BlockImporter blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, weakSubjectivityValidator, ExecutionEngineChannel.NOOP);
final BlockImportResult result = blockImporter.importBlock(otherBlock).get();
assertImportFailed(result, FailureReason.FAILED_WEAK_SUBJECTIVITY_CHECKS);
}
use of tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator in project teku by ConsenSys.
the class BlockImporterTest method importBlock_weakSubjectivityChecksPass.
@Test
public void importBlock_weakSubjectivityChecksPass() throws Exception {
final UInt64 wsEpoch = UInt64.valueOf(10);
final UInt64 wsEpochSlot = this.spec.computeStartSlotAtEpoch(wsEpoch);
final SignedBeaconBlock wsBlock = localChain.createBlockAtSlot(wsEpochSlot);
final SignedBeaconBlock nextBlock = localChain.createAndImportBlockAtSlot(wsEpochSlot.plus(1));
localChain.setSlot(wsEpochSlot.plus(1));
final Spec spec = TestSpecFactory.createMinimalPhase0();
final Checkpoint wsCheckpoint = new Checkpoint(wsEpoch, wsBlock.getRoot());
final WeakSubjectivityConfig wsConfig = WeakSubjectivityConfig.builder().specProvider(spec).weakSubjectivityCheckpoint(wsCheckpoint).build();
final WeakSubjectivityValidator weakSubjectivityValidator = WeakSubjectivityValidator.lenient(wsConfig);
final BlockImporter blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, weakSubjectivityValidator, ExecutionEngineChannel.NOOP);
// Import wsBlock
final BlockImportResult result = blockImporter.importBlock(wsBlock).get();
assertSuccessfulResult(result);
// Import next valid block
final BlockImportResult result2 = blockImporter.importBlock(nextBlock).get();
assertSuccessfulResult(result2);
}
use of tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator in project teku by ConsenSys.
the class ProfilingRun method importBlocks.
@Disabled
@Test
public void importBlocks() throws Exception {
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
int validatorsCount = 32 * 1024;
int iterationBlockLimit = 1024;
String blocksFile = "/blocks/blocks_epoch_" + spec.getSlotsPerEpoch(UInt64.ZERO) + "_validators_" + validatorsCount + ".ssz.gz";
System.out.println("Generating keypairs...");
List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource("/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz").readAll(validatorsCount);
BeaconState initialState = InteropStartupUtil.createMockedStartInitialBeaconState(spec, 0, validatorKeys, false);
final WeakSubjectivityValidator wsValidator = WeakSubjectivityFactory.lenientValidator();
while (true) {
final BlockImportNotifications blockImportNotifications = mock(BlockImportNotifications.class);
RecentChainData recentChainData = MemoryOnlyRecentChainData.create(spec);
recentChainData.initializeFromGenesis(initialState, UInt64.ZERO);
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
BeaconChainUtil localChain = BeaconChainUtil.create(spec, recentChainData, validatorKeys, false);
BlockImporter blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, wsValidator, ExecutionEngineChannel.NOOP);
System.out.println("Start blocks import from " + blocksFile);
int blockCount = 0;
int measuredBlockCount = 0;
long totalS = 0;
try (Reader blockReader = BlockIO.createResourceReader(spec, blocksFile)) {
for (SignedBeaconBlock block : blockReader) {
if (block.getSlot().intValue() == 65) {
totalS = System.currentTimeMillis();
measuredBlockCount = 0;
}
long s = System.currentTimeMillis();
localChain.setSlot(block.getSlot());
BlockImportResult result = blockImporter.importBlock(block).join();
System.out.println("Imported block at #" + block.getSlot() + " in " + (System.currentTimeMillis() - s) + " ms: " + result);
blockCount++;
measuredBlockCount++;
if (blockCount > iterationBlockLimit)
break;
}
}
long totalT = System.currentTimeMillis() - totalS;
System.out.printf("############# Total: %f.2 blocks/sec\n", measuredBlockCount / (totalT / 1000.0));
}
}
use of tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator in project teku by ConsenSys.
the class ProfilingRun method importBlocksMemProfiling.
@Disabled
@Test
public void importBlocksMemProfiling() throws Exception {
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
int validatorsCount = 32 * 1024;
String blocksFile = "/blocks/blocks_epoch_" + spec.getSlotsPerEpoch(UInt64.ZERO) + "_validators_" + validatorsCount + ".ssz.gz";
System.out.println("Generating keypairs...");
List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource("/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz").readAll(validatorsCount);
BeaconState initialState = InteropStartupUtil.createMockedStartInitialBeaconState(spec, 0, validatorKeys, false);
final WeakSubjectivityValidator wsValidator = WeakSubjectivityFactory.lenientValidator();
while (true) {
final BlockImportNotifications blockImportNotifications = mock(BlockImportNotifications.class);
RecentChainData recentChainData = MemoryOnlyRecentChainData.create();
BeaconChainUtil localChain = BeaconChainUtil.create(recentChainData, validatorKeys, false);
recentChainData.initializeFromGenesis(initialState, UInt64.ZERO);
initialState = null;
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
BlockImporter blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, wsValidator, ExecutionEngineChannel.NOOP);
System.out.println("Start blocks import from " + blocksFile);
int counter = 1;
try (Reader blockReader = BlockIO.createResourceReader(spec, blocksFile)) {
for (SignedBeaconBlock block : blockReader) {
long s = System.currentTimeMillis();
localChain.setSlot(block.getSlot());
BlockImportResult result = blockImporter.importBlock(block).join();
System.out.println("Imported block at #" + block.getSlot() + " in " + (System.currentTimeMillis() - s) + " ms: " + result);
if (--counter == 0) {
// recreate View validator caches for older state
// traverseViewHierarchy(statesList.get(statesList.size() - 2), v ->
// blackHole.accept(v));
System.out.println("Press enter: ");
String line = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)).readLine();
try {
counter = Integer.parseInt(line);
} catch (NumberFormatException e) {
counter = 1;
}
}
}
}
}
}
Aggregations