Search in sources :

Example 1 with BeaconBlockAndState

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

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

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

the class AnchorPointTest method create_withCheckpointPriorToState.

@Test
public void create_withCheckpointPriorToState() {
    final UInt64 epoch = UInt64.valueOf(10);
    final UInt64 epochStartSlot = spec.computeStartSlotAtEpoch(epoch);
    final BeaconBlockAndState blockAndState = dataStructureUtil.randomBlockAndState(epochStartSlot.plus(1));
    final Checkpoint checkpoint = new Checkpoint(epoch, blockAndState.getRoot());
    assertThatThrownBy(() -> AnchorPoint.create(spec, checkpoint, blockAndState.getState(), Optional.empty())).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Block must be at or prior to the start of the checkpoint epoch");
}
Also used : BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 4 with BeaconBlockAndState

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

the class BlockProposalTestUtil method createNewBlock.

public SignedBlockAndState createNewBlock(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 StateTransitionException, EpochProcessingException, SlotProcessingException {
    final UInt64 newEpoch = spec.computeEpochAtSlot(newSlot);
    final BLSSignature randaoReveal = signer.createRandaoReveal(newEpoch, state.getForkInfo()).join();
    final BeaconState blockSlotState = spec.processSlots(state, newSlot);
    final BeaconBlockAndState newBlockAndState = spec.createNewUnsignedBlock(newSlot, spec.getBeaconProposerIndex(blockSlotState, newSlot), blockSlotState, parentBlockSigningRoot, 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))));
    // Sign block and set block signature
    final BeaconBlock block = newBlockAndState.getBlock();
    BLSSignature blockSignature = signer.signBlock(block, state.getForkInfo()).join();
    final SignedBeaconBlock signedBlock = SignedBeaconBlock.create(spec, block, blockSignature);
    return new SignedBlockAndState(signedBlock, newBlockAndState.getState());
}
Also used : BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) 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 5 with BeaconBlockAndState

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

the class DatabaseMigraterTest method shouldCopyColumnData.

@Test
void shouldCopyColumnData(@TempDir Path tmpDir) throws IOException, DatabaseMigraterError {
    final DataDirLayout dataDirLayout = prepareTempDir(tmpDir, "5");
    DatabaseMigrater migrater = getDatabaseMigrater(dataDirLayout);
    final BeaconBlockAndState blockAndState = dataStructureUtil.randomBlockAndState(1_000_000);
    migrater.openDatabases(DatabaseVersion.V5, DatabaseVersion.LEVELDB2);
    TestKvStoreDatabase originalDb = new TestKvStoreDatabase(migrater.getOriginalDatabase());
    try (KvStoreHotDao.HotUpdater updater = originalDb.getHotDao().hotUpdater()) {
        updater.addHotState(blockAndState.getBlock().getRoot(), blockAndState.getState());
        updater.commit();
    }
    migrater.migrateData();
    TestKvStoreDatabase newDb = new TestKvStoreDatabase(migrater.getNewDatabase());
    assertThat(newDb.getHotDao().getHotState(blockAndState.getRoot())).contains(blockAndState.getState());
    migrater.closeDatabases();
}
Also used : KvStoreHotDao(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreHotDao) TestKvStoreDatabase(tech.pegasys.teku.storage.server.kvstore.TestKvStoreDatabase) BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Test(org.junit.jupiter.api.Test)

Aggregations

BeaconBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState)9 Test (org.junit.jupiter.api.Test)5 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 BeaconBlockBody (tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody)2 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)2 SignedAggregateAndProof (tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)1 BeaconBlockHeader (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader)1 SignedBeaconBlockHeader (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader)1 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1 CommitteeAssignment (tech.pegasys.teku.spec.datastructures.state.CommitteeAssignment)1 BlockProcessingException (tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException)1 StateTransitionException (tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException)1