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