Search in sources :

Example 1 with BeaconBlockBody

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

the class BlockProposalUtil method createNewUnsignedBlock.

public BeaconBlockAndState createNewUnsignedBlock(final UInt64 newSlot, final int proposerIndex, final BeaconState blockSlotState, final Bytes32 parentBlockSigningRoot, final Consumer<BeaconBlockBodyBuilder> bodyBuilder) throws StateTransitionException {
    checkArgument(blockSlotState.getSlot().equals(newSlot), "Block slot state from incorrect slot. Expected %s but got %s", newSlot, blockSlotState.getSlot());
    // Create block body
    final BeaconBlockBody beaconBlockBody = schemaDefinitions.getBeaconBlockBodySchema().createBlockBody(bodyBuilder);
    // Create initial block with some stubs
    final Bytes32 tmpStateRoot = Bytes32.ZERO;
    BeaconBlock newBlock = schemaDefinitions.getBeaconBlockSchema().create(newSlot, UInt64.valueOf(proposerIndex), parentBlockSigningRoot, tmpStateRoot, beaconBlockBody);
    // Skip verifying signatures as all operations are coming from our own pools.
    try {
        final BeaconState newState = blockProcessor.processUnsignedBlock(blockSlotState, newBlock, IndexedAttestationCache.NOOP, BLSSignatureVerifier.NO_OP, OptimisticExecutionPayloadExecutor.NOOP);
        Bytes32 stateRoot = newState.hashTreeRoot();
        BeaconBlock newCompleteBlock = newBlock.withStateRoot(stateRoot);
        return new BeaconBlockAndState(newCompleteBlock, newState);
    } catch (final BlockProcessingException e) {
        throw new StateTransitionException(e);
    }
}
Also used : BlockProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) BeaconBlockBody(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody) BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)

Example 2 with BeaconBlockBody

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

the class DataStructureUtil method randomBlockAndState.

private BeaconBlockAndState randomBlockAndState(final UInt64 slot, final BeaconState state, final Bytes32 parentRoot) {
    final BeaconBlockBody body = randomBeaconBlockBody();
    final UInt64 proposer_index = randomUInt64();
    final BeaconBlockHeader latestHeader = new BeaconBlockHeader(slot, proposer_index, parentRoot, Bytes32.ZERO, body.hashTreeRoot());
    final BeaconState matchingState = state.updated(s -> s.setLatest_block_header(latestHeader));
    final BeaconBlock block = new BeaconBlock(spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockSchema(), slot, proposer_index, parentRoot, matchingState.hashTreeRoot(), body);
    return new BeaconBlockAndState(block, matchingState);
}
Also used : BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconBlockBody(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody) BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader) SignedBeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 3 with BeaconBlockBody

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

the class BlockProposalTestUtil method createNewBlockSkippingStateTransition.

public SignedBlockAndState createNewBlockSkippingStateTransition(final Signer signer, final UInt64 newSlot, final BeaconState state, final Bytes32 parentBlockSigningRoot, final Eth1Data eth1Data, final SszList<Attestation> attestations, final SszList<ProposerSlashing> slashings, final SszList<Deposit> deposits, final SszList<SignedVoluntaryExit> exits, final Optional<List<Bytes>> transactions, final Optional<Bytes32> terminalBlock, final Optional<ExecutionPayload> executionPayload) throws EpochProcessingException, SlotProcessingException {
    final UInt64 newEpoch = spec.computeEpochAtSlot(newSlot);
    final BLSSignature randaoReveal = signer.createRandaoReveal(newEpoch, state.getForkInfo()).join();
    final BeaconState blockSlotState = spec.processSlots(state, newSlot);
    // Sign block and set block signature
    final BeaconBlockBody blockBody = spec.atSlot(newSlot).getSchemaDefinitions().getBeaconBlockBodySchema().createBlockBody(builder -> builder.randaoReveal(randaoReveal).eth1Data(eth1Data).graffiti(Bytes32.ZERO).attestations(attestations).proposerSlashings(slashings).attesterSlashings(blockBodyLists.createAttesterSlashings()).deposits(deposits).voluntaryExits(exits).syncAggregate(() -> dataStructureUtil.emptySyncAggregateIfRequiredByState(blockSlotState)).executionPayload(() -> executionPayload.orElseGet(() -> createExecutionPayload(newSlot, state, transactions, terminalBlock))));
    final BeaconBlock block = spec.atSlot(newSlot).getSchemaDefinitions().getBeaconBlockSchema().create(newSlot, UInt64.valueOf(spec.getBeaconProposerIndex(blockSlotState, newSlot)), parentBlockSigningRoot, blockSlotState.hashTreeRoot(), blockBody);
    // Sign block and set block signature
    BLSSignature blockSignature = signer.signBlock(block, state.getForkInfo()).join();
    final SignedBeaconBlock signedBlock = SignedBeaconBlock.create(spec, block, blockSignature);
    return new SignedBlockAndState(signedBlock, blockSlotState);
}
Also used : BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconBlockBody(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BLSSignature(tech.pegasys.teku.bls.BLSSignature) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 4 with BeaconBlockBody

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

the class AbstractBlockProcessor method verifyBlockSignatures.

@CheckReturnValue
private BlockValidationResult verifyBlockSignatures(final BeaconState preState, final SignedBeaconBlock block, final IndexedAttestationCache indexedAttestationCache, final BLSSignatureVerifier signatureVerifier) {
    BeaconBlock blockMessage = block.getMessage();
    BeaconBlockBody blockBody = blockMessage.getBody();
    return BlockValidationResult.allOf(() -> verifyBlockSignature(preState, block, signatureVerifier), () -> verifyAttestationSignatures(preState, blockBody.getAttestations(), signatureVerifier, indexedAttestationCache), () -> verifyRandao(preState, blockMessage, signatureVerifier), () -> verifyProposerSlashings(preState, blockBody.getProposerSlashings(), signatureVerifier), () -> verifyVoluntaryExits(preState, blockBody.getVoluntaryExits(), signatureVerifier));
}
Also used : BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconBlockBody(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody) CheckReturnValue(javax.annotation.CheckReturnValue)

Example 5 with BeaconBlockBody

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

the class AbstractBeaconBlockBodyTest method roundTripsViaSsz.

@Test
void roundTripsViaSsz() {
    BeaconBlockBody newBeaconBlockBody = getBlockBodySchema().sszDeserialize(defaultBlockBody.sszSerialize());
    assertEquals(defaultBlockBody, newBeaconBlockBody);
}
Also used : BeaconBlockBody(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody) Test(org.junit.jupiter.api.Test)

Aggregations

BeaconBlockBody (tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody)14 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)10 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)7 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)6 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 Collection (java.util.Collection)2 NavigableMap (java.util.NavigableMap)2 Optional (java.util.Optional)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Test (org.junit.jupiter.api.Test)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)2 BeaconBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState)2 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)2 AttesterSlashing (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing)2 ProposerSlashing (tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing)2 SignedVoluntaryExit (tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit)2 AggregatingAttestationPool (tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool)2