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