Repository navigation
fix: ptc gossip to dedup by slot not by epoch #9396
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
102 changes: 102 additions & 0 deletions
102
packages/beacon-node/test/unit/chain/seenCache/payloadAttesters.test.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import {describe, expect, it} from "vitest"; | ||
| import {SLOTS_PER_EPOCH} from "@lodestar/params"; | ||
| import {SeenPayloadAttesters} from "../../../../src/chain/seenCache/index.js"; | ||
|
|
||
| const MAX_SLOTS_IN_CACHE = 3; | ||
| const EPOCH_LOOKBACK_LIMIT = 2; | ||
|
|
||
| describe("chain / seenCache / SeenPayloadAttesters", () => { | ||
| const validatorIndex = 100; | ||
| const otherValidator = 101; | ||
| // Use a slot late in an epoch so we can test "same epoch, different slot" within one epoch. | ||
| const slot = SLOTS_PER_EPOCH * 10 + 1; | ||
| const epoch = Math.floor(slot / SLOTS_PER_EPOCH); | ||
|
|
||
| it("dedups by (slot, validatorIndex)", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| expect(cache.isKnown(slot, validatorIndex)).toBe(false); | ||
| cache.add(slot, validatorIndex); | ||
| expect(cache.isKnown(slot, validatorIndex)).toBe(true); | ||
| // Different validator at same slot is independent. | ||
| expect(cache.isKnown(slot, otherValidator)).toBe(false); | ||
| }); | ||
|
|
||
| it("accepts the same validator at different slots in the same epoch", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| const slot1 = slot; | ||
| const slot2 = slot + 1; | ||
| expect(Math.floor(slot1 / SLOTS_PER_EPOCH)).toBe(Math.floor(slot2 / SLOTS_PER_EPOCH)); | ||
|
|
||
| cache.add(slot1, validatorIndex); | ||
| expect(cache.isKnown(slot1, validatorIndex)).toBe(true); | ||
| // Same validator, different slot in the same epoch: must NOT be deduped. | ||
| expect(cache.isKnown(slot2, validatorIndex)).toBe(false); | ||
|
|
||
| cache.add(slot2, validatorIndex); | ||
| expect(cache.isKnown(slot2, validatorIndex)).toBe(true); | ||
| }); | ||
|
|
||
| it("populates the epoch liveness map when add() is called", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(false); | ||
| cache.add(slot, validatorIndex); | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(true); | ||
| expect(cache.isKnownAtEpoch(epoch + 1, validatorIndex)).toBe(false); | ||
| }); | ||
|
|
||
| it("prune(slot) evicts old slot entries but preserves epoch liveness", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| cache.add(slot, validatorIndex); | ||
| expect(cache.isKnown(slot, validatorIndex)).toBe(true); | ||
|
|
||
| cache.prune(slot + MAX_SLOTS_IN_CACHE + 1); | ||
| // Slot map evicted. | ||
| expect(cache.isKnown(slot, validatorIndex)).toBe(false); | ||
| // Epoch map outlives the slot map. | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(true); | ||
| }); | ||
|
|
||
| it("prune(slot) keeps slot entries within the lookback window", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| for (let i = 0; i < MAX_SLOTS_IN_CACHE; i++) { | ||
| cache.add(slot + i, validatorIndex); | ||
| } | ||
| // prune at the highest slot in the window: oldest (`slot`) should still be retained | ||
| // because the prune condition is `slot < clockSlot - MAX_SLOTS_IN_CACHE`. | ||
| cache.prune(slot + MAX_SLOTS_IN_CACHE); | ||
| expect(cache.isKnown(slot, validatorIndex)).toBe(true); | ||
| expect(cache.isKnown(slot + MAX_SLOTS_IN_CACHE - 1, validatorIndex)).toBe(true); | ||
| }); | ||
|
|
||
| it("pruneEpoch(epoch) evicts epoch entries outside the lookback window", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| cache.add(slot, validatorIndex); | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(true); | ||
|
|
||
| cache.pruneEpoch(epoch + EPOCH_LOOKBACK_LIMIT + 1); | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(false); | ||
| }); | ||
|
|
||
| it("pruneEpoch(epoch) keeps epoch entries within the lookback window", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| cache.add(slot, validatorIndex); | ||
|
|
||
| cache.pruneEpoch(epoch + EPOCH_LOOKBACK_LIMIT); | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(true); | ||
| }); | ||
|
|
||
| it("prune and pruneEpoch operate on independent maps", () => { | ||
| const cache = new SeenPayloadAttesters(); | ||
| cache.add(slot, validatorIndex); | ||
|
|
||
| // Heavy slot prune does not touch epoch liveness. | ||
| cache.prune(slot + MAX_SLOTS_IN_CACHE + 100); | ||
| expect(cache.isKnown(slot, validatorIndex)).toBe(false); | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(true); | ||
|
|
||
| // Epoch prune does not resurrect slot entries. | ||
| cache.pruneEpoch(epoch + EPOCH_LOOKBACK_LIMIT + 1); | ||
| expect(cache.isKnown(slot, validatorIndex)).toBe(false); | ||
| expect(cache.isKnownAtEpoch(epoch, validatorIndex)).toBe(false); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.