Repository navigation
feat: cache builder deposit signatures for gloas fork transition #9727
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aa035b0
feat: cache builder deposit signatures for gloas fork transition
twoeths 457e9cd
fix: handle error thrown per verify()
twoeths cb473cf
fix: simplify metric buckets
twoeths 2d90027
chore: add upgradeStateToGloasCacheHit.test.ts unit test
twoeths 6d249a7
fix: linting
twoeths 9489a34
Merge branch 'unstable' into te/gloas_onboard_builders_at_fork
nflaig a37f5d3
feat: time box preverify step
twoeths b352417
feat: preverify validator deposits with same builder pubkey
twoeths 625fe33
fix: specrefs
twoeths ea2360e
fix: only pre-verify validator deposits until a valid signature found
twoeths a6297dd
Merge branch 'unstable' into te/gloas_onboard_builders_at_fork
nflaig 221a4ff
Merge branch 'unstable' into te/gloas_onboard_builders_at_fork
nflaig 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
81 changes: 81 additions & 0 deletions
81
packages/state-transition/src/cache/builderDepositSignatureCache.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,81 @@ | ||
| import {PubkeyHex, electra} from "@lodestar/types"; | ||
|
|
||
| /** | ||
| * Caches deposit signature-verification results — passes (`true`) and failures (`false`) — so the | ||
| * Fulu → Gloas fork transition can skip the bulk verification cost AND skip re-verifying deposits | ||
| * already proven invalid. Covers both builder-prefix deposits (onboarding) and validator deposits | ||
| * that share a pubkey with a builder deposit (the ones `hasPendingValidator` checks at the fork). | ||
| * | ||
| * Keyed by the deposit's struct **value object** — `electra.PendingDeposit` is a | ||
| * `ContainerNodeStructType`, so its `node.value` is a stable object reused across | ||
| * prepareNextSlot-derived states and carried by reference through the gloas pendingDeposits | ||
| * migration. No merkle-root computation, no slot bucketing. | ||
| * | ||
| * Also tracks builder pubkeys seen so the scanner knows which validator deposits to pre-verify (only | ||
| * those sharing a pubkey with a builder deposit ever reach `hasPendingValidator`). The mapped boolean | ||
| * records whether a *valid* validator deposit for that pubkey has been found: once true, the scanner | ||
| * stops pre-verifying further validator deposits for it — `hasPendingValidator` short-circuits on the | ||
| * first valid signature at the fork, so the rest would never be read. | ||
| * | ||
| * Lifecycle owned by `prepareNextSlot`: filled during the pre-fork window, then `clear()`ed once the | ||
| * Gloas fork is finalized. `onboardBuildersFromPendingDeposits()` only reads it. A plain `Map` (not a | ||
| * `WeakMap`) is used so the drop is deterministic and the contents are inspectable for logging. | ||
| * | ||
| * Single instance across the application (created in `EpochCache.createFromState`, shared | ||
| * by-reference through `clone()`). | ||
| */ | ||
| export class BuilderDepositSignatureCache { | ||
| private validityByDeposit = new Map<electra.PendingDeposit, boolean>(); | ||
| /** builder pubkey → whether a valid validator deposit sharing it has already been pre-verified. */ | ||
| private builderPubkeys = new Map<PubkeyHex, boolean>(); | ||
|
|
||
| setSignatureValidity(deposit: electra.PendingDeposit, isValid: boolean): void { | ||
| this.validityByDeposit.set(deposit, isValid); | ||
| } | ||
|
|
||
| getSignatureValidity(deposit: electra.PendingDeposit): boolean | null { | ||
| return this.validityByDeposit.get(deposit) ?? null; | ||
| } | ||
|
|
||
| isVerified(deposit: electra.PendingDeposit): boolean { | ||
| return this.validityByDeposit.has(deposit); | ||
| } | ||
|
|
||
| /** Record a builder deposit's pubkey so the scanner pre-verifies validator deposits for it. | ||
| * Idempotent; never downgrades a pubkey already marked as having a valid validator deposit. */ | ||
| addBuilderPubkey(pubkeyHex: PubkeyHex): void { | ||
| if (!this.builderPubkeys.has(pubkeyHex)) { | ||
| this.builderPubkeys.set(pubkeyHex, false); | ||
| } | ||
| } | ||
|
|
||
| isBuilderPubkey(pubkeyHex: PubkeyHex): boolean { | ||
| return this.builderPubkeys.has(pubkeyHex); | ||
| } | ||
|
|
||
| /** True once a valid validator deposit sharing this builder pubkey has been pre-verified — the | ||
| * scanner then skips this pubkey's remaining validator deposits (as `hasPendingValidator` would). */ | ||
| hasValidValidatorDeposit(pubkeyHex: PubkeyHex): boolean { | ||
| return this.builderPubkeys.get(pubkeyHex) === true; | ||
| } | ||
|
|
||
| /** Mark that a valid validator deposit sharing this builder pubkey was found. */ | ||
| setValidValidatorDeposit(pubkeyHex: PubkeyHex): void { | ||
| this.builderPubkeys.set(pubkeyHex, true); | ||
| } | ||
|
|
||
| /** Cumulative deposits verified & cached this window (pass + fail). */ | ||
| get cachedDepositCount(): number { | ||
| return this.validityByDeposit.size; | ||
| } | ||
|
|
||
| /** Distinct builder pubkeys tracked this window. */ | ||
| get builderPubkeyCount(): number { | ||
| return this.builderPubkeys.size; | ||
| } | ||
|
|
||
| clear(): void { | ||
| this.validityByDeposit.clear(); | ||
| this.builderPubkeys.clear(); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
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.
I wonder if there can be attackers that submit a bunch of deposits with invalid signature that force us to fall back to verify one by one which makes lodestar hard to keep up.
They only need 1 bad deposit per batch (32 deposits) to nullify all the optimizations here
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.
this is a valid concern but also the attacker would burn the eth, so it's basically a trade-off here, we want the batch sizes to be large enough to get benefits from batching but not too large so an invalid signature can't waste too much time/compute