Search in sources :

Example 1 with StateAndBlockSummary

use of tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary 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)

Example 2 with StateAndBlockSummary

use of tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary in project teku by ConsenSys.

the class BlockImporterTest method importBlock_validAttestations.

@Test
public void importBlock_validAttestations() throws Exception {
    UInt64 currentSlot = UInt64.ONE;
    SignedBeaconBlock block1 = localChain.createAndImportBlockAtSlot(currentSlot);
    currentSlot = currentSlot.plus(UInt64.ONE);
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    final StateAndBlockSummary stateAndBlock = recentChainData.getStore().retrieveStateAndBlockSummary(block1.getRoot()).join().orElseThrow();
    List<Attestation> attestations = attestationGenerator.getAttestationsForSlot(stateAndBlock, currentSlot);
    List<Attestation> aggregatedAttestations = AttestationGenerator.groupAndAggregateAttestations(attestations);
    currentSlot = currentSlot.plus(UInt64.ONE);
    localChain.createAndImportBlockAtSlotWithAttestations(currentSlot, aggregatedAttestations);
}
Also used : StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Test(org.junit.jupiter.api.Test)

Example 3 with StateAndBlockSummary

use of tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary in project teku by ConsenSys.

the class BlockImporterTest method importBlock_attestationWithInvalidSignature.

@Test
public void importBlock_attestationWithInvalidSignature() throws Exception {
    UInt64 currentSlot = UInt64.ONE;
    SignedBeaconBlock block1 = localChain.createAndImportBlockAtSlot(currentSlot);
    currentSlot = currentSlot.plus(UInt64.ONE);
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    final StateAndBlockSummary stateAndBlock = recentChainData.getStore().retrieveStateAndBlockSummary(block1.getRoot()).join().orElseThrow();
    List<Attestation> attestations = attestationGenerator.getAttestationsForSlot(stateAndBlock, currentSlot);
    List<Attestation> aggregatedAttestations = AttestationGenerator.groupAndAggregateAttestations(attestations);
    // make one attestation signature invalid
    int invalidAttIdx = aggregatedAttestations.size() / 2;
    Attestation att = aggregatedAttestations.get(invalidAttIdx);
    Attestation invalidAtt = attestationSchema.create(att.getAggregationBits(), att.getData(), BLSTestUtil.randomSignature(1));
    aggregatedAttestations.set(invalidAttIdx, invalidAtt);
    UInt64 currentSlotFinal = currentSlot.plus(UInt64.ONE);
    assertThatCode(() -> {
        localChain.createAndImportBlockAtSlotWithAttestations(currentSlotFinal, aggregatedAttestations);
    }).hasMessageContaining("signature");
}
Also used : StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 4 with StateAndBlockSummary

use of tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary in project teku by ConsenSys.

the class BlockImporterTest method importBlock_wrongChain.

@Test
public void importBlock_wrongChain() throws Exception {
    UInt64 currentSlot = recentChainData.getHeadSlot();
    for (int i = 0; i < 3; i++) {
        currentSlot = currentSlot.plus(UInt64.ONE);
        localChain.createAndImportBlockAtSlot(currentSlot);
    }
    // Update finalized epoch
    final StoreTransaction tx = recentChainData.startStoreTransaction();
    final Bytes32 finalizedRoot = recentChainData.getBestBlockRoot().orElseThrow();
    final UInt64 finalizedEpoch = UInt64.ONE;
    final Checkpoint finalized = new Checkpoint(finalizedEpoch, finalizedRoot);
    tx.setFinalizedCheckpoint(finalized);
    tx.commit().join();
    // Now create a new block that is not descendant from the finalized block
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    final StateAndBlockSummary blockAndState = safeJoin(otherStorage.getChainHead().orElseThrow().asStateAndBlockSummary());
    final Attestation attestation = attestationGenerator.validAttestation(blockAndState);
    final SignedBeaconBlock block = otherChain.createAndImportBlockAtSlotWithAttestations(currentSlot, List.of(attestation));
    final BlockImportResult result = blockImporter.importBlock(block).get();
    assertImportFailed(result, FailureReason.UNKNOWN_PARENT);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) Test(org.junit.jupiter.api.Test)

Example 5 with StateAndBlockSummary

use of tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary in project teku by ConsenSys.

the class AggregateAttestationValidatorTest method shouldReturnValidForValidAggregate.

@Test
public void shouldReturnValidForValidAggregate() {
    final StateAndBlockSummary chainHead = storageSystem.getChainHead();
    final SignedAggregateAndProof aggregate = generator.validAggregateAndProof(chainHead);
    whenAttestationIsValid(aggregate);
    assertThat(validator.validate(ValidateableAttestation.aggregateFromValidator(spec, aggregate))).isCompletedWithValue(InternalValidationResult.ACCEPT);
}
Also used : StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Test(org.junit.jupiter.api.Test)

Aggregations

StateAndBlockSummary (tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary)34 Test (org.junit.jupiter.api.Test)30 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)18 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)17 AttestationGenerator (tech.pegasys.teku.core.AttestationGenerator)12 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)12 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)12 SignedAggregateAndProof (tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof)7 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)7 InternalValidationResult (tech.pegasys.teku.statetransition.validation.InternalValidationResult)7 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 Bytes (org.apache.tuweni.bytes.Bytes)5 Spec (tech.pegasys.teku.spec.Spec)5 ValidationResult (io.libp2p.core.pubsub.ValidationResult)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Set (java.util.Set)4 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)4 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)4 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)4