-
-
Notifications
You must be signed in to change notification settings - Fork 348
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: duplicated block attestations #7455
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
243bc80
Use map to store consolidations in getAttestationsForBlockElectra
ensi321 57a8565
add comment
ensi321 95c7074
Update aggregatedAttestationPool.test.ts
ensi321 e4562f0
Update packages/beacon-node/src/chain/opPools/aggregatedAttestationPo…
ensi321 8de5c80
lint
ensi321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,7 +50,6 @@ export type AttestationsConsolidation = { | |||||
byCommittee: Map<CommitteeIndex, AttestationNonParticipant>; | ||||||
attData: phase0.AttestationData; | ||||||
totalNotSeenCount: number; | ||||||
score: number; | ||||||
}; | ||||||
|
||||||
/** | ||||||
|
@@ -307,7 +306,8 @@ export class AggregatedAttestationPool { | |||||
const validateAttestationDataFn = getValidateAttestationDataFn(forkChoice, state); | ||||||
|
||||||
const slots = Array.from(this.attestationGroupByIndexByDataHexBySlot.keys()).sort((a, b) => b - a); | ||||||
const consolidations: AttestationsConsolidation[] = []; | ||||||
// Track score of each `AttestationsConsolidation` | ||||||
const consolidations = new Map<AttestationsConsolidation, number>(); | ||||||
let minScore = Number.MAX_SAFE_INTEGER; | ||||||
let slotCount = 0; | ||||||
slot: for (const slot of slots) { | ||||||
|
@@ -344,7 +344,7 @@ export class AggregatedAttestationPool { | |||||
|
||||||
if ( | ||||||
slotCount > 2 && | ||||||
consolidations.length >= MAX_ATTESTATIONS_ELECTRA && | ||||||
consolidations.size >= MAX_ATTESTATIONS_ELECTRA && | ||||||
notSeenAttestingIndices.size / slotDelta < minScore | ||||||
) { | ||||||
// after 2 slots, there are a good chance that we have 2 * MAX_ATTESTATIONS_ELECTRA attestations and break the for loop early | ||||||
|
@@ -373,8 +373,6 @@ export class AggregatedAttestationPool { | |||||
byCommittee: new Map(), | ||||||
attData: attestationNonParticipation.attestation.data, | ||||||
totalNotSeenCount: 0, | ||||||
// only update score after we have full data | ||||||
score: 0, | ||||||
}; | ||||||
} | ||||||
sameAttDataCons[i].byCommittee.set(committeeIndex, attestationNonParticipation); | ||||||
|
@@ -385,19 +383,22 @@ export class AggregatedAttestationPool { | |||||
if (score < minScore) { | ||||||
minScore = score; | ||||||
} | ||||||
consolidations.push({...consolidation, score}); | ||||||
|
||||||
consolidations.set(consolidation, score); | ||||||
|
||||||
// Stop accumulating attestations there are enough that may have good scoring | ||||||
if (consolidations.length >= MAX_ATTESTATIONS_ELECTRA * 2) { | ||||||
if (consolidations.size >= MAX_ATTESTATIONS_ELECTRA * 2) { | ||||||
break slot; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
const sortedConsolidationsByScore = consolidations | ||||||
.sort((a, b) => b.score - a.score) | ||||||
const sortedConsolidationsByScore = [...consolidations.entries()] | ||||||
ensi321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
.sort((a, b) => b[1] - a[1]) | ||||||
.map(([consolidation, _]) => consolidation) | ||||||
.slice(0, MAX_ATTESTATIONS_ELECTRA); | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed we are not cloning here lodestar/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts Lines 288 to 289 in e45e0eb
but might be fine due to |
||||||
// on chain aggregation is expensive, only do it after all | ||||||
return sortedConsolidationsByScore.map(aggregateConsolidation); | ||||||
} | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this would override the record? might be better to just continue if it already exists.
But why do we have duplicates in
sameAttDataCons
shouldn't this be aggregated earlier into a single one?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the whole point. The current implementation would insert the same consolidation with different score into
consolidations
, hence the duplication.The aggregation earlier only aggregates the
SignedAggregateAndProof
s from the same committee. Notice how they are stored by committee index andMatchingDataAttestationGroup
only store aggregated attestations from the same committee.