-
Notifications
You must be signed in to change notification settings - Fork 125
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
feature(state-processor): send only validators set diffs to consensus #2143
base: complete-validator-set-updates
Are you sure you want to change the base?
feature(state-processor): send only validators set diffs to consensus #2143
Conversation
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## complete-validator-set-updates #2143 +/- ##
==================================================================
+ Coverage 26.51% 26.59% +0.07%
==================================================================
Files 360 360
Lines 16244 16276 +32
Branches 12 12
==================================================================
+ Hits 4307 4328 +21
- Misses 11658 11667 +9
- Partials 279 281 +2
|
// prevEpochValidators tracks the set of validators active during | ||
// previous epoch. This is useful at the turn of the epoch to send to | ||
// consensus only the diffs rather than the full updated validator set. | ||
prevEpochValidators []*transition.ValidatorUpdate |
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.
note that we only keep active validators here, i.e. those whose effective balance is larger than ejection one.
I do not expect this list to be beefy, although we should probably track its size and decide whether this is the best way to calculate diffs.
A less memory consuming approach is to track chances wherever we do them (e.g. when updating effective balances, or creating validators or removing it). I prefer current approach is it is more easily verifiable for correctness for me, but we should measure how much of a performance improvement these two alternatives bring
@@ -166,5 +166,5 @@ func (sp *StateProcessor[ | |||
return nil, err | |||
} | |||
|
|||
return sp.processSyncCommitteeUpdates(st) |
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.
processSyncCommitteeUpdates
does not really make sense to me.
It seems to me we're trying to squeeze a pure BeaconKit operation (updating CometBFT val set) into an Eth 2.0 one
for i := range len(genDeposits) - 1 { | ||
require.Equal(t, genVals[i], newEpochVals[i], fmt.Sprintf("idx: %d", i)) | ||
} | ||
require.Len(t, newEpochVals, 1) // just topped up one validator |
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.
only send diffs
for i := range len(genDeposits) { | ||
require.Equal(t, genVals[i], newEpochVals[i], fmt.Sprintf("idx: %d", i)) | ||
} | ||
require.Len(t, newEpochVals, 1) // just added 1 validator |
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.
only send diff.
6d61cc7
to
c6b5586
Compare
var ( | ||
emptyAddress = common.ExecutionAddress{} | ||
emptyCredentials = types.NewCredentialsFromExecutionAddress( | ||
emptyAddress, | ||
) | ||
|
||
dummyExecutionPayload = &types.ExecutionPayload{ | ||
Timestamp: 0, | ||
ExtraData: []byte("testing"), | ||
Transactions: [][]byte{}, | ||
Withdrawals: []*engineprimitives.Withdrawal{}, | ||
BaseFeePerGas: math.NewU256(0), | ||
} | ||
) |
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.
minor UT consolidation
…tes-optimizations
// prevValsSet now contains all evicted validators (and only those) | ||
for pkBytes := range prevValsSet { | ||
//#nosec:G703 // bytes comes from a pk | ||
pk, _ := bytes.ToBytes48([]byte(pkBytes)) | ||
res = append(res, &transition.ValidatorUpdate{ | ||
Pubkey: pk, | ||
EffectiveBalance: 0, // signal val eviction to consensus | ||
}) | ||
} |
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.
we do not evict validators yet, so this should not really happen. Still added for completeness
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.
logically makes sense, agree with trying to optimize this in future
…tes-optimizations
…tes-optimizations
Whenever we turn the epoch, we must inform consensus of the changes in the validator set composition.
It's best to send only diffs of the validator set wrt previous epoch, rather than sending the whole new validator set.
This is what this PR does.