Search in sources :

Example 1 with AttestationManager

use of tech.pegasys.teku.statetransition.attestation.AttestationManager in project teku by ConsenSys.

the class ValidatorApiHandlerTest method sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates.

@Test
void sendAggregateAndProofs_shouldProcessMixOfValidAndInvalidAggregates() {
    final SignedAggregateAndProof invalidAggregate = dataStructureUtil.randomSignedAggregateAndProof();
    final SignedAggregateAndProof validAggregate = dataStructureUtil.randomSignedAggregateAndProof();
    when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, invalidAggregate))).thenReturn(completedFuture(AttestationProcessingResult.invalid("Bad juju")));
    when(attestationManager.onAttestation(ValidateableAttestation.aggregateFromValidator(spec, validAggregate))).thenReturn(completedFuture(SUCCESSFUL));
    final SafeFuture<List<SubmitDataError>> result = validatorApiHandler.sendAggregateAndProofs(List.of(invalidAggregate, validAggregate));
    assertThat(result).isCompletedWithValue(List.of(new SubmitDataError(ZERO, "Bad juju")));
    // Should send both to the attestation manager.
    verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(validAggregate)));
    verify(attestationManager).onAttestation(argThat(validatableAttestation -> validatableAttestation.getSignedAggregateAndProof().equals(invalidAggregate)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) SyncCommitteeSubscriptionManager(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) AggregatingAttestationPool(tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool) SUCCESSFUL(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult.SUCCESSFUL) ONE(tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) BlockImportChannel(tech.pegasys.teku.statetransition.block.BlockImportChannel) AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Map(java.util.Map) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) Bytes32(org.apache.tuweni.bytes.Bytes32) ChainDataProvider(tech.pegasys.teku.api.ChainDataProvider) SendSignedBlockResult(tech.pegasys.teku.validator.api.SendSignedBlockResult) DefaultPerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker) BLSSignature(tech.pegasys.teku.bls.BLSSignature) DOES_NOT_DESCEND_FROM_LATEST_FINALIZED(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason.DOES_NOT_DESCEND_FROM_LATEST_FINALIZED) Collections.emptyList(java.util.Collections.emptyList) ValidationResultCode(tech.pegasys.teku.statetransition.validation.ValidationResultCode) Test(org.junit.jupiter.api.Test) List(java.util.List) SyncCommitteeContributionPool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) Mockito.inOrder(org.mockito.Mockito.inOrder) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) ForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier) Optional(java.util.Optional) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BlockGossipChannel(tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) NodeSyncingException(tech.pegasys.teku.validator.api.NodeSyncingException) ForkChoiceTrigger(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) AttestationTopicSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber) SafeFuture.completedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) SyncCommitteeMessagePool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ZERO(tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) CommitteeSubscriptionRequest(tech.pegasys.teku.validator.api.CommitteeSubscriptionRequest) InOrder(org.mockito.InOrder) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) AttestationManager(tech.pegasys.teku.statetransition.attestation.AttestationManager) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Mockito.when(org.mockito.Mockito.when) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) IntList(it.unimi.dsi.fastutil.ints.IntList) SyncState(tech.pegasys.teku.beacon.sync.events.SyncState) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) SyncStateProvider(tech.pegasys.teku.beacon.sync.events.SyncStateProvider) IntSet(it.unimi.dsi.fastutil.ints.IntSet) CheckpointState(tech.pegasys.teku.spec.datastructures.state.CheckpointState) Comparator(java.util.Comparator) SszMutableList(tech.pegasys.teku.infrastructure.ssz.SszMutableList) SpecConfigAltair(tech.pegasys.teku.spec.config.SpecConfigAltair) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) IntList(it.unimi.dsi.fastutil.ints.IntList) SszMutableList(tech.pegasys.teku.infrastructure.ssz.SszMutableList) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Test(org.junit.jupiter.api.Test)

Example 2 with AttestationManager

use of tech.pegasys.teku.statetransition.attestation.AttestationManager in project teku by ConsenSys.

the class BeaconChainController method initAttestationManager.

protected void initAttestationManager() {
    final PendingPool<ValidateableAttestation> pendingAttestations = PendingPool.createForAttestations(spec);
    final FutureItems<ValidateableAttestation> futureAttestations = FutureItems.create(ValidateableAttestation::getEarliestSlotForForkChoiceProcessing, UInt64.valueOf(3));
    AttestationValidator attestationValidator = new AttestationValidator(spec, recentChainData, signatureVerificationService);
    AggregateAttestationValidator aggregateValidator = new AggregateAttestationValidator(spec, recentChainData, attestationValidator, signatureVerificationService);
    blockImporter.subscribeToVerifiedBlockAttestations((slot, attestations) -> attestations.forEach(attestation -> aggregateValidator.addSeenAggregate(ValidateableAttestation.from(spec, attestation))));
    attestationManager = AttestationManager.create(pendingAttestations, futureAttestations, forkChoice, attestationPool, attestationValidator, aggregateValidator, signatureVerificationService, eventChannels.getPublisher(ActiveValidatorChannel.class, beaconAsyncRunner));
    eventChannels.subscribe(SlotEventsChannel.class, attestationManager).subscribe(FinalizedCheckpointChannel.class, pendingAttestations).subscribe(BlockImportNotifications.class, attestationManager);
}
Also used : SyncCommitteePerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.SyncCommitteePerformanceTracker) SyncCommitteeSubscriptionManager(tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager) Eth2P2PNetwork(tech.pegasys.teku.networking.eth2.Eth2P2PNetwork) SyncCommitteeStateUtils(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeStateUtils) TimeProvider(tech.pegasys.teku.infrastructure.time.TimeProvider) VersionProvider(tech.pegasys.teku.infrastructure.version.VersionProvider) SyncServiceFactory(tech.pegasys.teku.beacon.sync.SyncServiceFactory) OperationPool(tech.pegasys.teku.statetransition.OperationPool) StableSubnetSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.StableSubnetSubscriber) AggregateAttestationValidator(tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator) BlockImportChannel(tech.pegasys.teku.statetransition.block.BlockImportChannel) EpochCachePrimer(tech.pegasys.teku.statetransition.EpochCachePrimer) Duration(java.time.Duration) Path(java.nio.file.Path) Service(tech.pegasys.teku.service.serviceutils.Service) SyncService(tech.pegasys.teku.beacon.sync.SyncService) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) OperationsReOrgManager(tech.pegasys.teku.statetransition.OperationsReOrgManager) ValidatorBasedStableSubnetSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.ValidatorBasedStableSubnetSubscriber) NoOpPerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.NoOpPerformanceTracker) SyncCommitteeMessageValidator(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessageValidator) TerminalPowBlockMonitor(tech.pegasys.teku.statetransition.forkchoice.TerminalPowBlockMonitor) ActiveValidatorTracker(tech.pegasys.teku.validator.coordinator.ActiveValidatorTracker) AttestationValidator(tech.pegasys.teku.statetransition.validation.AttestationValidator) Logger(org.apache.logging.log4j.Logger) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) BlockManager(tech.pegasys.teku.statetransition.block.BlockManager) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) Bytes(org.apache.tuweni.bytes.Bytes) EventChannels(tech.pegasys.teku.infrastructure.events.EventChannels) WeakSubjectivityValidator(tech.pegasys.teku.weaksubjectivity.WeakSubjectivityValidator) FileKeyValueStore(tech.pegasys.teku.storage.store.FileKeyValueStore) SyncCommitteeMessagePool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignatureVerificationService(tech.pegasys.teku.statetransition.validation.signatures.SignatureVerificationService) ZERO(tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) FinalizedCheckpointChannel(tech.pegasys.teku.storage.api.FinalizedCheckpointChannel) ForkChoiceNotifierImpl(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifierImpl) AttestationManager(tech.pegasys.teku.statetransition.attestation.AttestationManager) DiscoveryConfig(tech.pegasys.teku.networking.p2p.discovery.DiscoveryConfig) Throwables(com.google.common.base.Throwables) InteropStartupUtil(tech.pegasys.teku.spec.datastructures.interop.InteropStartupUtil) StorageQueryChannel(tech.pegasys.teku.storage.api.StorageQueryChannel) ServiceConfig(tech.pegasys.teku.service.serviceutils.ServiceConfig) PerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.PerformanceTracker) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) CoalescingChainHeadChannel(tech.pegasys.teku.beacon.sync.events.CoalescingChainHeadChannel) STATUS_LOG(tech.pegasys.teku.infrastructure.logging.StatusLogger.STATUS_LOG) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) CombinedChainDataClient(tech.pegasys.teku.storage.client.CombinedChainDataClient) StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) StorageBackedRecentChainData(tech.pegasys.teku.storage.client.StorageBackedRecentChainData) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException) ValidatorPerformanceTrackingMode(tech.pegasys.teku.validator.api.ValidatorPerformanceTrackingMode) Random(java.util.Random) AggregatingAttestationPool(tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool) Eth1VotingPeriod(tech.pegasys.teku.validator.coordinator.Eth1VotingPeriod) P2PConfig(tech.pegasys.teku.networking.eth2.P2PConfig) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) ProposerSlashingValidator(tech.pegasys.teku.statetransition.validation.ProposerSlashingValidator) BeaconBlockBodySchema(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkBuilder) ChainDataProvider(tech.pegasys.teku.api.ChainDataProvider) ActiveValidatorChannel(tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorChannel) Eth1DataCache(tech.pegasys.teku.validator.coordinator.Eth1DataCache) DefaultPerformanceTracker(tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker) BlockFactory(tech.pegasys.teku.validator.coordinator.BlockFactory) ValidatorApiHandler(tech.pegasys.teku.validator.coordinator.ValidatorApiHandler) DepositProvider(tech.pegasys.teku.validator.coordinator.DepositProvider) TimeTickChannel(tech.pegasys.teku.services.timer.TimeTickChannel) ExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel) OperationAcceptedFilter(tech.pegasys.teku.statetransition.OperationAcceptedFilter) BlockValidator(tech.pegasys.teku.statetransition.validation.BlockValidator) FutureItems(tech.pegasys.teku.statetransition.util.FutureItems) AttesterSlashingValidator(tech.pegasys.teku.statetransition.validation.AttesterSlashingValidator) BlockOperationSelectorFactory(tech.pegasys.teku.validator.coordinator.BlockOperationSelectorFactory) SyncCommitteeContributionPool(tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool) AsyncRunnerFactory(tech.pegasys.teku.infrastructure.async.AsyncRunnerFactory) ForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier) Optional(java.util.Optional) PortAvailability(tech.pegasys.teku.infrastructure.io.PortAvailability) VoteUpdateChannel(tech.pegasys.teku.storage.api.VoteUpdateChannel) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) ActiveValidatorCache(tech.pegasys.teku.statetransition.validatorcache.ActiveValidatorCache) SignedContributionAndProofValidator(tech.pegasys.teku.statetransition.synccommittee.SignedContributionAndProofValidator) BlockGossipChannel(tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel) ChainHeadChannel(tech.pegasys.teku.storage.api.ChainHeadChannel) ReexecutingExecutionPayloadBlockManager(tech.pegasys.teku.statetransition.block.ReexecutingExecutionPayloadBlockManager) ForkChoiceTrigger(tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger) AttestationTopicSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber) BindException(java.net.BindException) DutyMetrics(tech.pegasys.teku.validator.coordinator.DutyMetrics) Function(java.util.function.Function) NoOpEth2P2PNetwork(tech.pegasys.teku.networking.eth2.mock.NoOpEth2P2PNetwork) ValidatorPerformanceMetrics(tech.pegasys.teku.validator.coordinator.performance.ValidatorPerformanceMetrics) KeyValueStore(tech.pegasys.teku.storage.store.KeyValueStore) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) PendingPool(tech.pegasys.teku.statetransition.util.PendingPool) Bytes20(tech.pegasys.teku.infrastructure.bytes.Bytes20) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) Spec(tech.pegasys.teku.spec.Spec) AggregatingSignatureVerificationService(tech.pegasys.teku.statetransition.validation.signatures.AggregatingSignatureVerificationService) SlotEventsChannel(tech.pegasys.teku.ethereum.events.SlotEventsChannel) VoluntaryExitValidator(tech.pegasys.teku.statetransition.validation.VoluntaryExitValidator) EVENT_LOG(tech.pegasys.teku.infrastructure.logging.EventLogger.EVENT_LOG) StorageUpdateChannel(tech.pegasys.teku.storage.api.StorageUpdateChannel) AllSubnetsSubscriber(tech.pegasys.teku.networking.eth2.gossip.subnets.AllSubnetsSubscriber) BeaconRestApi(tech.pegasys.teku.beaconrestapi.BeaconRestApi) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) GenesisHandler(tech.pegasys.teku.statetransition.genesis.GenesisHandler) Comparator(java.util.Comparator) LogManager(org.apache.logging.log4j.LogManager) DataProvider(tech.pegasys.teku.api.DataProvider) AllSyncCommitteeSubscriptions(tech.pegasys.teku.networking.eth2.gossip.subnets.AllSyncCommitteeSubscriptions) Eth1EventsChannel(tech.pegasys.teku.pow.api.Eth1EventsChannel) InteropConfig(tech.pegasys.teku.validator.api.InteropConfig) AsyncRunnerEventThread(tech.pegasys.teku.infrastructure.async.eventthread.AsyncRunnerEventThread) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) FinalizedCheckpointChannel(tech.pegasys.teku.storage.api.FinalizedCheckpointChannel) AggregateAttestationValidator(tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator) AttestationValidator(tech.pegasys.teku.statetransition.validation.AttestationValidator) AggregateAttestationValidator(tech.pegasys.teku.statetransition.validation.AggregateAttestationValidator) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)

Aggregations

Comparator (java.util.Comparator)2 Optional (java.util.Optional)2 ChainDataProvider (tech.pegasys.teku.api.ChainDataProvider)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 ZERO (tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO)2 BlockGossipChannel (tech.pegasys.teku.networking.eth2.gossip.BlockGossipChannel)2 AttestationTopicSubscriber (tech.pegasys.teku.networking.eth2.gossip.subnets.AttestationTopicSubscriber)2 SyncCommitteeSubscriptionManager (tech.pegasys.teku.networking.eth2.gossip.subnets.SyncCommitteeSubscriptionManager)2 Spec (tech.pegasys.teku.spec.Spec)2 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 AggregatingAttestationPool (tech.pegasys.teku.statetransition.attestation.AggregatingAttestationPool)2 AttestationManager (tech.pegasys.teku.statetransition.attestation.AttestationManager)2 BlockImportChannel (tech.pegasys.teku.statetransition.block.BlockImportChannel)2 ForkChoiceNotifier (tech.pegasys.teku.statetransition.forkchoice.ForkChoiceNotifier)2 ForkChoiceTrigger (tech.pegasys.teku.statetransition.forkchoice.ForkChoiceTrigger)2 SyncCommitteeContributionPool (tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeContributionPool)2 SyncCommitteeMessagePool (tech.pegasys.teku.statetransition.synccommittee.SyncCommitteeMessagePool)2