Search in sources :

Example 1 with VoteUpdater

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));
}
Also used : VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) Test(org.junit.jupiter.api.Test)

Example 2 with VoteUpdater

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));
}
Also used : VoteTracker(tech.pegasys.teku.spec.datastructures.forkchoice.VoteTracker) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) Test(org.junit.jupiter.api.Test)

Example 3 with VoteUpdater

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();
}
Also used : StateRootCollector.addParentStateRoots(tech.pegasys.teku.statetransition.forkchoice.StateRootCollector.addParentStateRoots) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) FailureReason(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason) ExceptionThrowingRunnable(tech.pegasys.teku.infrastructure.async.ExceptionThrowingRunnable) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) IndexedAttestation(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) CapturingIndexedAttestationCache(tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache) ForkChoiceUtil(tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil) Subscribers(tech.pegasys.teku.infrastructure.subscribers.Subscribers) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) InvalidCheckpointException(tech.pegasys.teku.spec.datastructures.forkchoice.InvalidCheckpointException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ExecutionPayloadStatus(tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) Bytes32(org.apache.tuweni.bytes.Bytes32) FatalServiceFailureException(tech.pegasys.teku.infrastructure.exceptions.FatalServiceFailureException) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) EventThread(tech.pegasys.teku.infrastructure.async.eventthread.EventThread) Throwables(com.google.common.base.Throwables) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) INTERVALS_PER_SLOT(tech.pegasys.teku.spec.constants.NetworkConstants.INTERVALS_PER_SLOT) P2P_LOG(tech.pegasys.teku.infrastructure.logging.P2PLogger.P2P_LOG) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException) List(java.util.List) ForkChoiceStrategy(tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy) ExceptionUtil(tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil) Logger(org.apache.logging.log4j.Logger) IndexedAttestationCache(tech.pegasys.teku.spec.cache.IndexedAttestationCache) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Optional(java.util.Optional) ExceptionThrowingSupplier(tech.pegasys.teku.infrastructure.async.ExceptionThrowingSupplier) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater)

Example 4 with VoteUpdater

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);
    });
}
Also used : StateRootCollector.addParentStateRoots(tech.pegasys.teku.statetransition.forkchoice.StateRootCollector.addParentStateRoots) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) FailureReason(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason) ExceptionThrowingRunnable(tech.pegasys.teku.infrastructure.async.ExceptionThrowingRunnable) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) IndexedAttestation(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) CapturingIndexedAttestationCache(tech.pegasys.teku.spec.cache.CapturingIndexedAttestationCache) ForkChoiceUtil(tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil) Subscribers(tech.pegasys.teku.infrastructure.subscribers.Subscribers) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) InvalidCheckpointException(tech.pegasys.teku.spec.datastructures.forkchoice.InvalidCheckpointException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ExecutionPayloadStatus(tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) Bytes32(org.apache.tuweni.bytes.Bytes32) FatalServiceFailureException(tech.pegasys.teku.infrastructure.exceptions.FatalServiceFailureException) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) EventThread(tech.pegasys.teku.infrastructure.async.eventthread.EventThread) Throwables(com.google.common.base.Throwables) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) INTERVALS_PER_SLOT(tech.pegasys.teku.spec.constants.NetworkConstants.INTERVALS_PER_SLOT) P2P_LOG(tech.pegasys.teku.infrastructure.logging.P2PLogger.P2P_LOG) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StateTransitionException(tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException) List(java.util.List) ForkChoiceStrategy(tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy) ExceptionUtil(tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil) Logger(org.apache.logging.log4j.Logger) IndexedAttestationCache(tech.pegasys.teku.spec.cache.IndexedAttestationCache) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Optional(java.util.Optional) ExceptionThrowingSupplier(tech.pegasys.teku.infrastructure.async.ExceptionThrowingSupplier) LogManager(org.apache.logging.log4j.LogManager) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater) InvalidCheckpointException(tech.pegasys.teku.spec.datastructures.forkchoice.InvalidCheckpointException)

Example 5 with VoteUpdater

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();
}
Also used : VoteUpdater(tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater)

Aggregations

VoteUpdater (tech.pegasys.teku.spec.datastructures.forkchoice.VoteUpdater)7 Test (org.junit.jupiter.api.Test)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 ReadOnlyForkChoiceStrategy (tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy)3 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Throwables (com.google.common.base.Throwables)2 List (java.util.List)2 Optional (java.util.Optional)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 ForkChoiceStrategy (tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy)2 ExceptionThrowingRunnable (tech.pegasys.teku.infrastructure.async.ExceptionThrowingRunnable)2 ExceptionThrowingSupplier (tech.pegasys.teku.infrastructure.async.ExceptionThrowingSupplier)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 EventThread (tech.pegasys.teku.infrastructure.async.eventthread.EventThread)2 ExceptionUtil (tech.pegasys.teku.infrastructure.exceptions.ExceptionUtil)2 FatalServiceFailureException (tech.pegasys.teku.infrastructure.exceptions.FatalServiceFailureException)2