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!");
}
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));
}
}
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;
}
}
}
}
}
}
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);
}
Aggregations