Search in sources :

Example 1 with BeaconBlockBodyLists

use of tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists in project teku by ConsenSys.

the class AbstractBeaconBlockBodyTest method setUpBaseClass.

protected void setUpBaseClass(final SpecMilestone milestone, Runnable additionalSetup) {
    spec = TestSpecFactory.createMinimal(milestone);
    dataStructureUtil = new DataStructureUtil(spec);
    BeaconBlockBodyLists blockBodyLists = BeaconBlockBodyLists.ofSpec(spec);
    voluntaryExits = blockBodyLists.createVoluntaryExits(dataStructureUtil.randomSignedVoluntaryExit(), dataStructureUtil.randomSignedVoluntaryExit(), dataStructureUtil.randomSignedVoluntaryExit());
    deposits = blockBodyLists.createDeposits(dataStructureUtil.randomDeposits(2).toArray(new Deposit[0]));
    attestations = blockBodyLists.createAttestations(dataStructureUtil.randomAttestation(), dataStructureUtil.randomAttestation(), dataStructureUtil.randomAttestation());
    attesterSlashings = blockBodyLists.createAttesterSlashings(dataStructureUtil.randomAttesterSlashing());
    proposerSlashings = blockBodyLists.createProposerSlashings(dataStructureUtil.randomProposerSlashing(), dataStructureUtil.randomProposerSlashing(), dataStructureUtil.randomProposerSlashing());
    graffiti = dataStructureUtil.randomBytes32();
    eth1Data = dataStructureUtil.randomEth1Data();
    randaoReveal = dataStructureUtil.randomSignature();
    additionalSetup.run();
    defaultBlockBody = createDefaultBlockBody();
    blockBodySchema = defaultBlockBody.getSchema();
}
Also used : BeaconBlockBodyLists(tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 2 with BeaconBlockBodyLists

use of tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists in project teku by ConsenSys.

the class BlockFactoryTest method assertBlockCreated.

private BeaconBlock assertBlockCreated(final int blockSlot, final Spec spec) throws EpochProcessingException, SlotProcessingException, StateTransitionException {
    final UInt64 newSlot = UInt64.valueOf(blockSlot);
    final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
    final BeaconBlockBodyLists blockBodyLists = BeaconBlockBodyLists.ofSpec(spec);
    final RecentChainData recentChainData = MemoryOnlyRecentChainData.create(spec);
    final BeaconChainUtil beaconChainUtil = BeaconChainUtil.create(spec, 1, recentChainData);
    final SszList<Deposit> deposits = blockBodyLists.createDeposits();
    final SszList<Attestation> attestations = blockBodyLists.createAttestations();
    final SszList<AttesterSlashing> attesterSlashings = blockBodyLists.createAttesterSlashings();
    final SszList<ProposerSlashing> proposerSlashings = blockBodyLists.createProposerSlashings();
    final SszList<SignedVoluntaryExit> voluntaryExits = blockBodyLists.createVoluntaryExits();
    if (spec.getGenesisSpec().getMilestone().isGreaterThanOrEqualTo(SpecMilestone.BELLATRIX)) {
        executionPayload = SchemaDefinitionsBellatrix.required(spec.getGenesisSpec().getSchemaDefinitions()).getExecutionPayloadSchema().getDefault();
    } else {
        executionPayload = null;
    }
    final Bytes32 graffiti = dataStructureUtil.randomBytes32();
    final BlockFactory blockFactory = new BlockFactory(spec, new BlockOperationSelectorFactory(spec, attestationsPool, attesterSlashingPool, proposerSlashingPool, voluntaryExitPool, syncCommitteeContributionPool, depositProvider, eth1DataCache, graffiti, forkChoiceNotifier, executionEngine));
    when(depositProvider.getDeposits(any(), any())).thenReturn(deposits);
    when(attestationsPool.getAttestationsForBlock(any(), any(), any())).thenReturn(attestations);
    when(attesterSlashingPool.getItemsForBlock(any(), any(), any())).thenReturn(attesterSlashings);
    when(proposerSlashingPool.getItemsForBlock(any(), any(), any())).thenReturn(proposerSlashings);
    when(voluntaryExitPool.getItemsForBlock(any(), any(), any())).thenReturn(voluntaryExits);
    when(eth1DataCache.getEth1Vote(any())).thenReturn(ETH1_DATA);
    when(forkChoiceNotifier.getPayloadId(any(), any())).thenReturn(SafeFuture.completedFuture(Optional.of(Bytes8.fromHexStringLenient("0x0"))));
    when(executionEngine.getPayload(any(), any())).thenReturn(SafeFuture.completedFuture(executionPayload));
    beaconChainUtil.initializeStorage();
    final BLSSignature randaoReveal = dataStructureUtil.randomSignature();
    final Bytes32 bestBlockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    final BeaconState blockSlotState = recentChainData.retrieveStateAtSlot(new SlotAndBlockRoot(UInt64.valueOf(blockSlot), bestBlockRoot)).join().orElseThrow();
    when(syncCommitteeContributionPool.createSyncAggregateForBlock(newSlot, bestBlockRoot)).thenAnswer(invocation -> createEmptySyncAggregate(spec));
    final BeaconBlock block = blockFactory.createUnsignedBlock(blockSlotState, newSlot, randaoReveal, Optional.empty());
    assertThat(block).isNotNull();
    assertThat(block.getSlot()).isEqualTo(newSlot);
    assertThat(block.getBody().getRandaoReveal()).isEqualTo(randaoReveal);
    assertThat(block.getBody().getEth1Data()).isEqualTo(ETH1_DATA);
    assertThat(block.getBody().getDeposits()).isEqualTo(deposits);
    assertThat(block.getBody().getAttestations()).isEqualTo(attestations);
    assertThat(block.getBody().getAttesterSlashings()).isEqualTo(attesterSlashings);
    assertThat(block.getBody().getProposerSlashings()).isEqualTo(proposerSlashings);
    assertThat(block.getBody().getVoluntaryExits()).isEqualTo(voluntaryExits);
    assertThat(block.getBody().getGraffiti()).isEqualTo(graffiti);
    return block;
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) BeaconBlockBodyLists(tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSSignature(tech.pegasys.teku.bls.BLSSignature) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Aggregations

BeaconBlockBodyLists (tech.pegasys.teku.spec.datastructures.util.BeaconBlockBodyLists)2 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)1 SlotAndBlockRoot (tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot)1 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)1 AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)1 Deposit (tech.pegasys.teku.spec.datastructures.operations.Deposit)1 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)1 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)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