use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.
the class HistoricalBatchFetcher method batchVerifyHistoricalBlockSignature.
private SafeFuture<Void> batchVerifyHistoricalBlockSignature(final Collection<SignedBeaconBlock> blocks, final BeaconState bestState) {
List<BLSSignature> signatures = new ArrayList<>();
List<Bytes> signingRoots = new ArrayList<>();
List<List<BLSPublicKey>> proposerPublicKeys = new ArrayList<>();
final Bytes32 genesisValidatorsRoot = bestState.getForkInfo().getGenesisValidatorsRoot();
blocks.forEach(signedBlock -> {
final BeaconBlock block = signedBlock.getMessage();
if (block.getSlot().isGreaterThan(SpecConfig.GENESIS_SLOT)) {
final UInt64 epoch = spec.computeEpochAtSlot(block.getSlot());
final Fork fork = spec.fork(epoch);
final Bytes32 domain = spec.getDomain(Domain.BEACON_PROPOSER, epoch, fork, genesisValidatorsRoot);
signatures.add(signedBlock.getSignature());
signingRoots.add(spec.computeSigningRoot(block, domain));
BLSPublicKey proposerPublicKey = spec.getValidatorPubKey(bestState, block.getProposerIndex()).orElseThrow(() -> new IllegalStateException("Proposer has to be in the state since state is more recent than the block proposed"));
proposerPublicKeys.add(List.of(proposerPublicKey));
}
});
return signatureVerificationService.verify(proposerPublicKeys, signingRoots, signatures).thenAccept(signaturesValid -> {
if (!signaturesValid) {
throw new IllegalArgumentException("Batch signature verification failed");
}
});
}
use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.
the class BellatrixStateUpgrade method upgrade.
@Override
public BeaconStateBellatrix upgrade(final BeaconState preState) {
final UInt64 epoch = beaconStateAccessors.getCurrentEpoch(preState);
BeaconStateAltair preStateAltair = BeaconStateAltair.required(preState);
return schemaDefinitions.getBeaconStateSchema().createEmpty().updatedBellatrix(state -> {
BeaconStateFields.copyCommonFieldsFromSource(state, preState);
state.setCurrentEpochParticipation(preStateAltair.getCurrentEpochParticipation());
state.setPreviousEpochParticipation(preStateAltair.getPreviousEpochParticipation());
state.setCurrentSyncCommittee(preStateAltair.getCurrentSyncCommittee());
state.setNextSyncCommittee(preStateAltair.getNextSyncCommittee());
state.setInactivityScores(preStateAltair.getInactivityScores());
state.setFork(new Fork(preState.getFork().getCurrent_version(), specConfig.getBellatrixForkVersion(), epoch));
state.setLatestExecutionPayloadHeader(schemaDefinitions.getExecutionPayloadHeaderSchema().getDefault());
});
}
use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.
the class BlockProcessorTest method createBeaconState.
private BeaconState createBeaconState(boolean addToList, UInt64 amount, Validator knownValidator) {
return spec.getGenesisSpec().getSchemaDefinitions().getBeaconStateSchema().createEmpty().updated(beaconState -> {
beaconState.setSlot(dataStructureUtil.randomUInt64());
beaconState.setFork(new Fork(specConfig.getGenesisForkVersion(), specConfig.getGenesisForkVersion(), SpecConfig.GENESIS_EPOCH));
List<Validator> validatorList = new ArrayList<>(List.of(dataStructureUtil.randomValidator(), dataStructureUtil.randomValidator(), dataStructureUtil.randomValidator()));
List<UInt64> balanceList = new ArrayList<>(List.of(dataStructureUtil.randomUInt64(), dataStructureUtil.randomUInt64(), dataStructureUtil.randomUInt64()));
if (addToList) {
validatorList.add(knownValidator);
balanceList.add(amount);
}
beaconState.getValidators().appendAll(validatorList);
beaconState.getBalances().appendAllElements(balanceList);
});
}
use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.
the class GossipForkSubscriptionsPhase0 method startGossip.
@Override
public final void startGossip(final Bytes32 genesisValidatorsRoot, final boolean isOptimisticHead) {
if (gossipManagers.isEmpty()) {
final ForkInfo forkInfo = new ForkInfo(fork, genesisValidatorsRoot);
addGossipManagers(forkInfo);
}
gossipManagers.stream().filter(manager -> manager.isEnabledDuringOptimisticSync() || !isOptimisticHead).forEach(GossipManager::subscribe);
}
use of tech.pegasys.teku.spec.datastructures.state.Fork in project teku by ConsenSys.
the class ForkScheduleTest method getFork_withTransition.
@Test
public void getFork_withTransition() {
final ForkSchedule forkSchedule = buildForkSchedule(TRANSITION_CONFIG);
final Fork phase0Fork = getPhase0Fork(TRANSITION_CONFIG);
for (UInt64 epoch = UInt64.ZERO; epoch.isLessThan(FORK_EPOCH_ALTAIR); epoch = epoch.increment()) {
assertThat(forkSchedule.getFork(epoch)).isEqualTo(phase0Fork);
}
final Fork altairFork = getAltairFork(TRANSITION_CONFIG);
for (UInt64 epoch = FORK_EPOCH_ALTAIR; epoch.isLessThan(FORK_EPOCH_ALTAIR.times(2)); epoch = epoch.increment()) {
assertThat(forkSchedule.getFork(epoch)).isEqualTo(altairFork);
}
}
Aggregations