Search in sources :

Example 6 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class BlockProposalTestUtil method createExecutionPayload.

private ExecutionPayload createExecutionPayload(final UInt64 newSlot, final BeaconState state, final Optional<List<Bytes>> transactions, final Optional<Bytes32> terminalBlock) {
    final SpecVersion specVersion = spec.atSlot(newSlot);
    final ExecutionPayloadSchema schema = SchemaDefinitionsBellatrix.required(specVersion.getSchemaDefinitions()).getExecutionPayloadSchema();
    if (terminalBlock.isEmpty() && !isMergeTransitionComplete(state)) {
        return schema.getDefault();
    }
    Bytes32 currentExecutionPayloadBlockHash = BeaconStateBellatrix.required(state).getLatestExecutionPayloadHeader().getBlockHash();
    if (!currentExecutionPayloadBlockHash.isZero() && terminalBlock.isPresent()) {
        throw new IllegalArgumentException("Merge already happened, cannot set terminal block hash");
    }
    Bytes32 parentHash = terminalBlock.orElse(currentExecutionPayloadBlockHash);
    UInt64 currentEpoch = specVersion.beaconStateAccessors().getCurrentEpoch(state);
    return schema.create(parentHash, Bytes20.ZERO, dataStructureUtil.randomBytes32(), dataStructureUtil.randomBytes32(), dataStructureUtil.randomBytes256(), specVersion.beaconStateAccessors().getRandaoMix(state, currentEpoch), newSlot, UInt64.valueOf(30_000_000L), UInt64.valueOf(30_000_000L), specVersion.miscHelpers().computeTimeAtSlot(state, newSlot), dataStructureUtil.randomBytes32(), UInt256.ONE, dataStructureUtil.randomBytes32(), transactions.orElse(Collections.emptyList()));
}
Also used : SpecVersion(tech.pegasys.teku.spec.SpecVersion) ExecutionPayloadSchema(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 7 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class StateTransition method processSlots.

public BeaconState processSlots(BeaconState preState, UInt64 slot) throws SlotProcessingException, EpochProcessingException {
    try {
        checkArgument(preState.getSlot().compareTo(slot) < 0, "process_slots: State slot %s higher than given slot %s", preState.getSlot(), slot);
        BeaconState state = preState;
        SpecVersion currentSpec = specProvider.getSpec(state.getSlot());
        while (state.getSlot().compareTo(slot) < 0) {
            // Transition from current to new slot (advance by 1)
            final UInt64 currentSlot = state.getSlot();
            final UInt64 newSlot = currentSlot.plus(1);
            final boolean isEpochTransition = newSlot.mod(currentSpec.getSlotsPerEpoch()).equals(UInt64.ZERO);
            state = processSlot(currentSpec, state);
            // Process epoch on the start slot of the next epoch
            if (isEpochTransition) {
                state = currentSpec.getEpochProcessor().processEpoch(state);
            }
            state = state.updated(s -> s.setSlot(newSlot));
            // Update spec, perform state upgrades on epoch boundaries
            if (isEpochTransition) {
                final SpecVersion newSpec = specProvider.getSpec(newSlot);
                if (!newSpec.getMilestone().equals(currentSpec.getMilestone())) {
                    // We've just transition to a new milestone - upgrade the state if necessary
                    final BeaconState prevMilestoneState = state;
                    state = newSpec.getStateUpgrade().map(u -> (BeaconState) u.upgrade(prevMilestoneState)).orElse(prevMilestoneState);
                    // Update spec
                    currentSpec = newSpec;
                }
            }
        }
        return state;
    } catch (IllegalArgumentException e) {
        LOG.warn(e.getMessage(), e);
        throw new SlotProcessingException(e);
    }
}
Also used : Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Logger(org.apache.logging.log4j.Logger) SlotProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.SlotProcessingException) EpochProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.EpochProcessingException) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) LogManager(org.apache.logging.log4j.LogManager) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader) SpecVersion(tech.pegasys.teku.spec.SpecVersion) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) SpecVersion(tech.pegasys.teku.spec.SpecVersion) SlotProcessingException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.SlotProcessingException) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 8 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class DiscoveryNetworkTest method setForkInfoAtInitialization.

@Test
public void setForkInfoAtInitialization() {
    final SpecVersion genesisSpec = spec.getGenesisSpec();
    final Bytes4 genesisForkVersion = genesisSpec.getConfig().getGenesisForkVersion();
    final EnrForkId enrForkId = new EnrForkId(genesisSpec.miscHelpers().computeForkDigest(genesisForkVersion, Bytes32.ZERO), genesisForkVersion, SpecConfig.FAR_FUTURE_EPOCH);
    verify(discoveryService).updateCustomENRField("eth2", enrForkId.sszSerialize());
}
Also used : SpecVersion(tech.pegasys.teku.spec.SpecVersion) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) Test(org.junit.jupiter.api.Test)

Example 9 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class DiscoveryNetwork method setPreGenesisForkInfo.

public void setPreGenesisForkInfo() {
    final SpecVersion genesisSpec = spec.getGenesisSpec();
    final Bytes4 genesisForkVersion = genesisSpec.getConfig().getGenesisForkVersion();
    final EnrForkId enrForkId = new EnrForkId(genesisSpec.miscHelpers().computeForkDigest(genesisForkVersion, Bytes32.ZERO), genesisForkVersion, SpecConfig.FAR_FUTURE_EPOCH);
    discoveryService.updateCustomENRField(ETH2_ENR_FIELD, enrForkId.sszSerialize());
    this.enrForkId = Optional.of(enrForkId);
}
Also used : SpecVersion(tech.pegasys.teku.spec.SpecVersion) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId)

Example 10 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class DepositProviderTest method checkThatDepositProofIsValid.

private void checkThatDepositProofIsValid(SszList<Deposit> deposits) {
    final SpecVersion genesisSpec = spec.getGenesisSpec();
    deposits.forEach(deposit -> assertThat(genesisSpec.predicates().isValidMerkleBranch(deposit.getData().hashTreeRoot(), deposit.getProof(), genesisSpec.getConfig().getDepositContractTreeDepth() + 1, ((DepositWithIndex) deposit).getIndex().intValue(), depositMerkleTree.getRoot())).isTrue());
}
Also used : SpecVersion(tech.pegasys.teku.spec.SpecVersion)

Aggregations

SpecVersion (tech.pegasys.teku.spec.SpecVersion)23 Bytes32 (org.apache.tuweni.bytes.Bytes32)12 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)7 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)4 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 ValidatorStatusFactory (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatusFactory)3 Optional (java.util.Optional)2 Bytes (org.apache.tuweni.bytes.Bytes)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 Spec (tech.pegasys.teku.spec.Spec)2 EnrForkId (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId)2 ValidatorStatuses (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatuses)2 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1