Search in sources :

Example 1 with Writer

use of tech.pegasys.teku.benchmarks.gen.BlockIO.Writer in project teku by ConsenSys.

the class Generator method generateBlocks.

@Disabled
@Test
public void generateBlocks() throws Exception {
    final Spec spec = TestSpecFactory.createMainnetAltair();
    AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
    System.out.println("Generating keypairs...");
    int validatorsCount = 32 * 1024;
    List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource("/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz").readAll(validatorsCount);
    System.out.println("Keypairs done.");
    RecentChainData localStorage = MemoryOnlyRecentChainData.create(spec);
    BeaconChainUtil localChain = BeaconChainUtil.builder().specProvider(spec).recentChainData(localStorage).validatorKeys(validatorKeys).signDeposits(false).build();
    localChain.initializeStorage();
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    UInt64 currentSlot = localStorage.getHeadSlot();
    List<Attestation> attestations = Collections.emptyList();
    final int slotsPerEpoch = spec.getGenesisSpecConfig().getSlotsPerEpoch();
    String blocksFile = "blocks_epoch_" + slotsPerEpoch + "_validators_" + validatorsCount + ".ssz.gz";
    try (Writer writer = BlockIO.createFileWriter(blocksFile)) {
        for (int j = 0; j < 50; j++) {
            for (int i = 0; i < slotsPerEpoch; i++) {
                long s = System.currentTimeMillis();
                currentSlot = currentSlot.plus(UInt64.ONE);
                final SignedBeaconBlock block = localChain.createAndImportBlockAtSlotWithAttestations(currentSlot, AttestationGenerator.groupAndAggregateAttestations(attestations));
                writer.accept(block);
                final StateAndBlockSummary postState = localStorage.getStore().retrieveStateAndBlockSummary(block.getMessage().hashTreeRoot()).join().orElseThrow();
                attestations = UInt64.ONE.equals(currentSlot) ? Collections.emptyList() : attestationGenerator.getAttestationsForSlot(postState, currentSlot);
                System.out.println("Processed: " + currentSlot + ", " + getCommittees(spec, postState.getState()) + ", " + (System.currentTimeMillis() - s) + " ms");
            }
            Optional<BeaconState> bestState = localStorage.retrieveBlockState(localStorage.getBestBlockRoot().orElse(null)).join();
            System.out.println("Epoch done: " + bestState);
        }
    }
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) Spec(tech.pegasys.teku.spec.Spec) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Writer(tech.pegasys.teku.benchmarks.gen.BlockIO.Writer) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1 Writer (tech.pegasys.teku.benchmarks.gen.BlockIO.Writer)1 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)1 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 Spec (tech.pegasys.teku.spec.Spec)1 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)1 StateAndBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary)1 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)1 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)1 BeaconChainUtil (tech.pegasys.teku.statetransition.BeaconChainUtil)1 MemoryOnlyRecentChainData (tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData)1 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)1