use of tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater in project teku by ConsenSys.
the class StoreVoteUpdaterTest method shouldIncludeUncommittedVotesInHighestVotedValidatorIndex.
@Test
void shouldIncludeUncommittedVotesInHighestVotedValidatorIndex() {
setVote(UInt64.ZERO, dataStructureUtil.randomVoteTracker());
setVote(UInt64.ONE, dataStructureUtil.randomVoteTracker());
final VoteUpdater voteUpdater = store.startVoteUpdate(voteUpdateChannel);
voteUpdater.putVote(UInt64.valueOf(2), dataStructureUtil.randomVoteTracker());
assertThat(voteUpdater.getHighestVotedValidatorIndex()).isEqualTo(UInt64.valueOf(2));
}
use of tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater in project teku by ConsenSys.
the class StoreVoteUpdaterTest method shouldSendUpdatesToStorageOnCommit.
@Test
void shouldSendUpdatesToStorageOnCommit() {
final VoteUpdater voteUpdater = store.startVoteUpdate(voteUpdateChannel);
final VoteTracker updatedVote = dataStructureUtil.randomVoteTracker();
voteUpdater.putVote(UInt64.ZERO, updatedVote);
verifyNoInteractions(voteUpdateChannel);
voteUpdater.commit();
verify(voteUpdateChannel).onVotesUpdated(Map.of(UInt64.ZERO, updatedVote));
}
use of tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater in project teku by ConsenSys.
the class ForkChoice method applyVotesFromBlock.
private void applyVotesFromBlock(final ForkChoiceStrategy forkChoiceStrategy, final UInt64 currentEpoch, final CapturingIndexedAttestationCache indexedAttestationProvider) {
final VoteUpdater voteUpdater = recentChainData.startVoteUpdate();
indexedAttestationProvider.getIndexedAttestations().stream().filter(attestation -> validateBlockAttestation(forkChoiceStrategy, currentEpoch, attestation)).forEach(attestation -> forkChoiceStrategy.onAttestation(voteUpdater, attestation));
voteUpdater.commit();
}
use of tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater in project teku by ConsenSys.
the class ForkChoice method onAttestation.
public SafeFuture<AttestationProcessingResult> onAttestation(final ValidateableAttestation attestation) {
return recentChainData.retrieveCheckpointState(attestation.getData().getTarget()).thenCompose(maybeTargetState -> {
final UpdatableStore store = recentChainData.getStore();
final AttestationProcessingResult validationResult = spec.validateAttestation(store, attestation, maybeTargetState);
if (!validationResult.isSuccessful()) {
return SafeFuture.completedFuture(validationResult);
}
return onForkChoiceThread(() -> {
final VoteUpdater transaction = recentChainData.startVoteUpdate();
getForkChoiceStrategy().onAttestation(transaction, getIndexedAttestation(attestation));
transaction.commit();
}).thenApply(__ -> validationResult);
}).exceptionallyCompose(error -> {
final Throwable rootCause = Throwables.getRootCause(error);
if (rootCause instanceof InvalidCheckpointException) {
return SafeFuture.completedFuture(AttestationProcessingResult.invalid(rootCause.getMessage()));
}
return SafeFuture.failedFuture(error);
});
}
use of tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater in project teku by ConsenSys.
the class StoreVoteUpdaterTest method setVote.
private void setVote(final UInt64 validatorIndex, final VoteTracker vote) {
final VoteUpdater voteUpdater = store.startVoteUpdate(voteUpdateChannel);
voteUpdater.putVote(validatorIndex, vote);
voteUpdater.commit();
}
Aggregations