Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cache attester index during attestation validation #7260

Closed
wants to merge 1 commit into from

Conversation

nflaig
Copy link
Member

@nflaig nflaig commented Nov 28, 2024

Motivation

Currently we always try to get the validator index from attestationOrCache.attestation but it might be null if cached value is used leading to the following error:

Nov-28 13:33:21.898[network]         debug: Gossip batch validation beacon_attestation threw a non-AttestationError - Cannot read properties of null (reading 'attesterIndex')
TypeError: Cannot read properties of null (reading 'attesterIndex')
    at validateAttestationNoSignatureCheck (file:///usr/app/packages/beacon-node/src/chain/validation/attestation.ts:426:93)
    at validateGossipAttestationsSameAttData (file:///usr/app/packages/beacon-node/src/chain/validation/attestation.ts:119:43)
    at Object.beacon_attestation (file:///usr/app/packages/beacon-node/src/network/processor/gossipHandlers.ts:625:64)
    at NetworkProcessor.gossipValidatorBatchFn (file:///usr/app/packages/beacon-node/src/network/processor/gossipValidatorFn.ts:36:75)
    at NetworkProcessor.processPendingGossipsubMessage (file:///usr/app/packages/beacon-node/src/network/processor/index.ts:438:20)
    at NetworkProcessor.executeWork (file:///usr/app/packages/beacon-node/src/network/processor/index.ts:398:16)
    at NetworkProcessor.pushPendingGossipsubMessageToQueue (file:///usr/app/packages/beacon-node/src/network/processor/index.ts:310:10)
    at NetworkProcessor.onPendingGossipsubMessage (file:///usr/app/packages/beacon-node/src/network/processor/index.ts:298:10)
    at NetworkEventBus.emit (node:events:520:28)

Caching the attester index also has some benefits pre-electra as we can safe a getSingleTrueBit call (see #7209) if we retrieve the attestation from the cache.

Description

Cache attester index during attestation validation

@@ -11,8 +11,8 @@ type AttDataBase64 = string;
export type AttestationDataCacheEntry = {
// part of shuffling data, so this does not take memory
committeeValidatorIndices: Uint32Array;
// TODO: remove this? this is available in SingleAttestation
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twoeths I am not sure about this comment, seems simpler to keep the committee index in the cache as if in case of loading the attestation from cache we won't deserialize the SingleAttestation to get the committe index from there, and for pre-electra we would still need it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes let's keep it in the cache and remove "TODO"

@@ -498,6 +507,7 @@ async function validateAttestationNoSignatureCheck(
chain.seenAttestationDatas.add(attSlot, committeeIndex, attDataKey, {
committeeValidatorIndices,
committeeIndex,
attesterIndex: validatorIndex,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could consider renaming validatorIndex to attesterIndex (or vice versa)

@nflaig nflaig marked this pull request as ready for review November 28, 2024 17:01
@nflaig nflaig requested a review from a team as a code owner November 28, 2024 17:01
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Project coverage is 48.43%. Comparing base (cfe6c89) to head (59b3b1e).

Additional details and impacted files
@@             Coverage Diff              @@
##           devnet-5    #7260      +/-   ##
============================================
- Coverage     48.44%   48.43%   -0.01%     
============================================
  Files           602      602              
  Lines         40321    40328       +7     
  Branches       2057     2057              
============================================
  Hits          19532    19532              
- Misses        20751    20758       +7     
  Partials         38       38              

committeeIndex: CommitteeIndex;
attesterIndex: ValidatorIndex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not correct to have attesterIndex here, this is the common cache for the whole committee while this is specific information of a validator

should also remove aggregationBits below as it's specific to the validator

@nflaig
Copy link
Member Author

nflaig commented Nov 29, 2024

Closing as we need a different approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants