Search in sources :

Example 1 with WeakSubjectivityValidator

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);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Spec(tech.pegasys.teku.spec.Spec) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Test(org.junit.jupiter.api.Test)

Example 2 with WeakSubjectivityValidator

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);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) WeakSubjectivityConfig(tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Spec(tech.pegasys.teku.spec.Spec) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Test(org.junit.jupiter.api.Test)

Example 3 with WeakSubjectivityValidator

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));
    }
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) InputStreamReader(java.io.InputStreamReader) Reader(tech.pegasys.teku.benchmarks.gen.BlockIO.Reader) BufferedReader(java.io.BufferedReader) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with WeakSubjectivityValidator

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;
                    }
                }
            }
        }
    }
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) InputStreamReader(java.io.InputStreamReader) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) InputStreamReader(java.io.InputStreamReader) Reader(tech.pegasys.teku.benchmarks.gen.BlockIO.Reader) BufferedReader(java.io.BufferedReader) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) BufferedReader(java.io.BufferedReader) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Test (org.junit.jupiter.api.Test)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)4 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)4 WeakSubjectivityValidator (tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator)4 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 Disabled (org.junit.jupiter.api.Disabled)2 Reader (tech.pegasys.teku.benchmarks.gen.BlockIO.Reader)2 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)2 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 Spec (tech.pegasys.teku.spec.Spec)2 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 BeaconChainUtil (tech.pegasys.teku.statetransition.BeaconChainUtil)2 BlockImportNotifications (tech.pegasys.teku.statetransition.block.BlockImportNotifications)2 BlockImporter (tech.pegasys.teku.statetransition.block.BlockImporter)2 ForkChoice (tech.pegasys.teku.statetransition.forkchoice.ForkChoice)2 MergeTransitionBlockValidator (tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator)2 StubForkChoiceNotifier (tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier)2