Search in sources :

Example 1 with BlockImportNotifications

use of tech.pegasys.teku.statetransition.block.BlockImportNotifications in project teku by ConsenSys.

the class EpochTransitionBenchmark method init.

@Setup(Level.Trial)
public void init() throws Exception {
    AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
    String blocksFile = "/blocks/blocks_epoch_" + spec.getSlotsPerEpoch(UInt64.ZERO) + "_validators_" + validatorsCount + ".ssz.gz";
    String keysFile = "/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz";
    System.out.println("Generating keypairs from " + keysFile);
    List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource(keysFile).readAll(validatorsCount);
    final BlockImportNotifications blockImportNotifications = mock(BlockImportNotifications.class);
    spec = TestSpecFactory.createMainnetPhase0();
    epochProcessor = spec.getGenesisSpec().getEpochProcessor();
    wsValidator = WeakSubjectivityFactory.lenientValidator();
    recentChainData = MemoryOnlyRecentChainData.create(spec);
    final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
    ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
    localChain = BeaconChainUtil.create(spec, recentChainData, validatorKeys, false);
    localChain.initializeStorage();
    blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, wsValidator, ExecutionEngineChannel.NOOP);
    blockIterator = BlockIO.createResourceReader(spec, blocksFile).iterator();
    System.out.println("Importing 63 blocks from " + blocksFile);
    for (int i = 0; i < 63; i++) {
        SignedBeaconBlock block = blockIterator.next();
        localChain.setSlot(block.getSlot());
        lastResult = blockImporter.importBlock(block).join();
    }
    preEpochTransitionState = safeJoin(recentChainData.getBestState().orElseThrow());
    validatorStatuses = spec.getGenesisSpec().getValidatorStatusFactory().createValidatorStatuses(preEpochTransitionState);
    preEpochTransitionState.updated(mbs -> preEpochTransitionMutableState = mbs);
    attestationDeltas = epochProcessor.getRewardAndPenaltyDeltas(preEpochTransitionState, validatorStatuses);
    System.out.println("Done!");
}
Also used : MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with BlockImportNotifications

use of tech.pegasys.teku.statetransition.block.BlockImportNotifications 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 3 with BlockImportNotifications

use of tech.pegasys.teku.statetransition.block.BlockImportNotifications 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)

Example 4 with BlockImportNotifications

use of tech.pegasys.teku.statetransition.block.BlockImportNotifications in project teku by ConsenSys.

the class TransitionBenchmark method init.

@Setup(Level.Trial)
public void init() throws Exception {
    AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
    String blocksFile = "/blocks/blocks_epoch_" + spec.getSlotsPerEpoch(UInt64.ZERO) + "_validators_" + validatorsCount + ".ssz.gz";
    String keysFile = "/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz";
    System.out.println("Generating keypairs from " + keysFile);
    List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource(keysFile).readAll(validatorsCount);
    final BlockImportNotifications blockImportNotifications = mock(BlockImportNotifications.class);
    spec = TestSpecFactory.createMainnetAltair();
    wsValidator = WeakSubjectivityFactory.lenientValidator();
    recentChainData = MemoryOnlyRecentChainData.create(spec);
    final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
    ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
    localChain = BeaconChainUtil.create(spec, recentChainData, validatorKeys, false);
    localChain.initializeStorage();
    blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, wsValidator, ExecutionEngineChannel.NOOP);
    blockIterator = BlockIO.createResourceReader(spec, blocksFile).iterator();
    System.out.println("Importing blocks from " + blocksFile);
}
Also used : MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)4 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)4 BlockImportNotifications (tech.pegasys.teku.statetransition.block.BlockImportNotifications)4 BlockImporter (tech.pegasys.teku.statetransition.block.BlockImporter)4 ForkChoice (tech.pegasys.teku.statetransition.forkchoice.ForkChoice)4 MergeTransitionBlockValidator (tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator)4 StubForkChoiceNotifier (tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 Disabled (org.junit.jupiter.api.Disabled)2 Test (org.junit.jupiter.api.Test)2 Setup (org.openjdk.jmh.annotations.Setup)2 Reader (tech.pegasys.teku.benchmarks.gen.BlockIO.Reader)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)2 BeaconChainUtil (tech.pegasys.teku.statetransition.BeaconChainUtil)2 MemoryOnlyRecentChainData (tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData)2 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)2 WeakSubjectivityValidator (tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator)2