-
Notifications
You must be signed in to change notification settings - Fork 207
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
chore(forks): Handle MaxValidatorsPerWithdrawalsSweep based on planned fork upgrade #2194
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,10 +45,13 @@ type SpecData[ | |
|
||
// HysteresisQuotient is the quotient used in effective balance calculations | ||
HysteresisQuotient uint64 `mapstructure:"hysteresis-quotient"` | ||
// HysteresisDownwardMultiplier is the multiplier for downward balance adjustments. | ||
// HysteresisDownwardMultiplier is the multiplier for downward balance | ||
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. nit: we need to sync our linters XD |
||
// adjustments. | ||
HysteresisDownwardMultiplier uint64 `mapstructure:"hysteresis-downward-multiplier"` | ||
// HysteresisUpwardMultiplier is the multiplier for upward balance adjustments. | ||
// HysteresisUpwardMultiplier is the multiplier for upward balance | ||
// adjustments. | ||
HysteresisUpwardMultiplier uint64 `mapstructure:"hysteresis-upward-multiplier"` | ||
|
||
// Time parameters constants. | ||
// | ||
// SlotsPerEpoch is the number of slots per epoch. | ||
|
@@ -128,10 +131,15 @@ type SpecData[ | |
// MaxWithdrawalsPerPayload indicates the maximum number of withdrawal | ||
// operations allowed in a single payload. | ||
MaxWithdrawalsPerPayload uint64 `mapstructure:"max-withdrawals-per-payload"` | ||
// MaxValidatorsPerWithdrawalsSweep specifies the maximum number of | ||
// validator | ||
// withdrawals allowed per sweep. | ||
MaxValidatorsPerWithdrawalsSweep uint64 `mapstructure:"max-validators-per-withdrawals-sweep"` | ||
// MaxValidatorsPerWithdrawalsSweepPreUpgrade specifies the maximum number | ||
// of validator withdrawals allowed per sweep. Before the upgrade, this | ||
// value is consistent with ETH2.0 spec, set to 2^14. | ||
MaxValidatorsPerWithdrawalsSweepPreUpgrade uint64 `mapstructure:"max-validators-per-withdrawals-sweep-pre-upgrade"` | ||
// MaxValidatorsPerWithdrawalsSweepPostUpgrade specifies the maximum number | ||
// of validator withdrawals allowed per sweep. After the upgrade, this value | ||
// is set to the largest prime number smaller than the minimum possible | ||
// amount of total validators. | ||
MaxValidatorsPerWithdrawalsSweepPostUpgrade uint64 `mapstructure:"max-validators-per-withdrawals-sweep-post-upgrade"` | ||
Comment on lines
+134
to
+142
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. 🧹 Nitpick (assertive) Consider simplifying field names for readability The field names
|
||
|
||
// Deneb Values | ||
// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,10 +55,11 @@ func BaseSpec() chain.SpecData[ | |
any, | ||
]{ | ||
// Gwei value constants. | ||
MinDepositAmount: 1e9, | ||
MaxEffectiveBalance: 32e9, | ||
EjectionBalance: 16e9, | ||
EffectiveBalanceIncrement: 1e9, | ||
MinDepositAmount: 1e9, | ||
MaxEffectiveBalance: 32e9, | ||
EjectionBalance: 16e9, | ||
EffectiveBalanceIncrement: 1e9, | ||
|
||
HysteresisQuotient: 4, | ||
HysteresisDownwardMultiplier: 1, | ||
HysteresisUpwardMultiplier: 5, | ||
|
@@ -67,6 +68,7 @@ func BaseSpec() chain.SpecData[ | |
SlotsPerEpoch: 32, | ||
MinEpochsToInactivityPenalty: 4, | ||
SlotsPerHistoricalRoot: 8, | ||
|
||
// Signature domains. | ||
DomainTypeProposer: common.DomainType{ | ||
0x00, 0x00, 0x00, 0x00, | ||
|
@@ -92,35 +94,43 @@ func BaseSpec() chain.SpecData[ | |
DomainTypeApplicationMask: common.DomainType{ | ||
0x00, 0x00, 0x00, 0x01, | ||
}, | ||
|
||
// Eth1-related values. | ||
DepositContractAddress: common.NewExecutionAddressFromHex( | ||
DefaultDepositContractAddress, | ||
), | ||
DepositEth1ChainID: 1, | ||
Eth1FollowDistance: 1, | ||
TargetSecondsPerEth1Block: 3, | ||
|
||
// Fork-related values. | ||
DenebPlusForkEpoch: 9999999999999998, | ||
ElectraForkEpoch: 9999999999999999, | ||
|
||
calbera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// State list length constants. | ||
EpochsPerHistoricalVector: 8, | ||
EpochsPerSlashingsVector: 8, | ||
HistoricalRootsLimit: 8, | ||
ValidatorRegistryLimit: 1099511627776, | ||
|
||
// Max operations per block constants. | ||
MaxDepositsPerBlock: 16, | ||
|
||
// Slashing | ||
ProportionalSlashingMultiplier: 1, | ||
|
||
// Capella values. | ||
MaxWithdrawalsPerPayload: 16, | ||
MaxValidatorsPerWithdrawalsSweep: 1 << 14, | ||
MaxWithdrawalsPerPayload: 16, | ||
MaxValidatorsPerWithdrawalsSweepPreUpgrade: 1 << 14, | ||
|
||
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. Wait, are we changing this for every network? |
||
// Deneb values. | ||
MinEpochsForBlobsSidecarsRequest: 4096, | ||
MaxBlobCommitmentsPerBlock: 16, | ||
MaxBlobsPerBlock: 6, | ||
FieldElementsPerBlob: 4096, | ||
BytesPerBlob: 131072, | ||
KZGCommitmentInclusionProofDepth: 17, | ||
|
||
// Comet values. | ||
CometValues: cmtConsensusParams, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,7 +251,9 @@ func (s *StateDB[ | |
} | ||
|
||
bound := min( | ||
totalValidators, s.cs.MaxValidatorsPerWithdrawalsSweep(), | ||
totalValidators, s.cs.MaxValidatorsPerWithdrawalsSweep( | ||
IsPostUpgrade, s.cs.DepositEth1ChainID(), slot, | ||
), | ||
Comment on lines
+254
to
+256
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. Undefined variable The variable Apply this diff to define slot, err := s.GetSlot()
if err != nil {
return nil, err
}
+// Determine if the chain is post-upgrade based on the current slot
+IsPostUpgrade := s.IsPostUpgrade(slot)
bound := min(
totalValidators, s.cs.MaxValidatorsPerWithdrawalsSweep(
IsPostUpgrade, s.cs.DepositEth1ChainID(), slot,
),
)
|
||
) | ||
|
||
// Iterate through indices to find the next validators to withdraw. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// | ||
// Copyright (C) 2024, Berachain Foundation. All rights reserved. | ||
// Use of this software is governed by the Business Source License included | ||
// in the LICENSE file of this repository and at www.mariadb.com/bsl11. | ||
// | ||
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY | ||
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER | ||
// VERSIONS OF THE LICENSED WORK. | ||
// | ||
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF | ||
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF | ||
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). | ||
// | ||
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON | ||
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, | ||
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND | ||
// TITLE. | ||
|
||
package state | ||
|
||
import ( | ||
"github.com/berachain/beacon-kit/mod/config/pkg/spec" | ||
"github.com/berachain/beacon-kit/mod/primitives/pkg/math" | ||
) | ||
|
||
// IsPostUpgrade returns true if the chain is post-upgrade (Fork2 on Boonet). | ||
// | ||
// TODO: Jank. Refactor into better fork version management. | ||
calbera marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func IsPostUpgrade(chainID uint64, slot math.Slot) bool { | ||
switch chainID { | ||
case spec.BartioChainID: | ||
return false | ||
case spec.BoonetEth1ChainID: | ||
if slot < math.U64(spec.BoonetFork2Height) { | ||
return false | ||
} | ||
|
||
return true | ||
default: | ||
return true | ||
Comment on lines
+41
to
+42
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. default behaviour equals Boonet post fork. This is the general principle we are following, right? |
||
} | ||
} | ||
calbera marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -26,6 +26,7 @@ import ( | |||||||||||||
"github.com/berachain/beacon-kit/mod/config/pkg/spec" | ||||||||||||||
"github.com/berachain/beacon-kit/mod/errors" | ||||||||||||||
"github.com/berachain/beacon-kit/mod/primitives/pkg/math" | ||||||||||||||
"github.com/berachain/beacon-kit/mod/state-transition/pkg/core/state" | ||||||||||||||
"github.com/davecgh/go-spew/spew" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
|
@@ -93,6 +94,7 @@ func (sp *StateProcessor[ | |||||||||||||
st, | ||||||||||||||
expectedWithdrawals, | ||||||||||||||
payloadWithdrawals, | ||||||||||||||
slot, | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
case sp.cs.DepositEth1ChainID() == spec.BoonetEth1ChainID && | ||||||||||||||
|
@@ -116,13 +118,15 @@ func (sp *StateProcessor[ | |||||||||||||
st, | ||||||||||||||
expectedWithdrawals, | ||||||||||||||
payloadWithdrawals, | ||||||||||||||
slot, | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
default: | ||||||||||||||
return sp.processWithdrawalsDefault( | ||||||||||||||
st, | ||||||||||||||
expectedWithdrawals, | ||||||||||||||
payloadWithdrawals, | ||||||||||||||
slot, | ||||||||||||||
) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
@@ -134,6 +138,7 @@ func (sp *StateProcessor[ | |||||||||||||
st BeaconStateT, | ||||||||||||||
expectedWithdrawals []WithdrawalT, | ||||||||||||||
payloadWithdrawals []WithdrawalT, | ||||||||||||||
slot math.Slot, | ||||||||||||||
) error { | ||||||||||||||
for i, wd := range expectedWithdrawals { | ||||||||||||||
// Ensure the withdrawals match the local state. | ||||||||||||||
|
@@ -185,7 +190,9 @@ func (sp *StateProcessor[ | |||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
nextValidatorIndex += math.ValidatorIndex( | ||||||||||||||
sp.cs.MaxValidatorsPerWithdrawalsSweep()) | ||||||||||||||
sp.cs.MaxValidatorsPerWithdrawalsSweep( | ||||||||||||||
state.IsPostUpgrade, spec.BartioChainID, slot, | ||||||||||||||
)) | ||||||||||||||
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. Call 'state.IsPostUpgrade' function instead of passing it as a reference In lines 194-195, Apply this diff to fix the issue: nextValidatorIndex += math.ValidatorIndex(
- sp.cs.MaxValidatorsPerWithdrawalsSweep(
- state.IsPostUpgrade, spec.BartioChainID, slot,
+ sp.cs.MaxValidatorsPerWithdrawalsSweep(
+ state.IsPostUpgrade(spec.BartioChainID, slot),
+ spec.BartioChainID, slot,
)) This ensures that 📝 Committable suggestion
Suggested change
|
||||||||||||||
nextValidatorIndex %= math.ValidatorIndex(totalValidators) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
@@ -199,6 +206,7 @@ func (sp *StateProcessor[ | |||||||||||||
st BeaconStateT, | ||||||||||||||
expectedWithdrawals []WithdrawalT, | ||||||||||||||
payloadWithdrawals []WithdrawalT, | ||||||||||||||
slot math.Slot, | ||||||||||||||
) error { | ||||||||||||||
// Enforce that first withdrawal is EVM inflation | ||||||||||||||
if len(payloadWithdrawals) == 0 { | ||||||||||||||
|
@@ -259,7 +267,9 @@ func (sp *StateProcessor[ | |||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
nextValidatorIndex += math.ValidatorIndex( | ||||||||||||||
sp.cs.MaxValidatorsPerWithdrawalsSweep()) | ||||||||||||||
sp.cs.MaxValidatorsPerWithdrawalsSweep( | ||||||||||||||
state.IsPostUpgrade, sp.cs.DepositEth1ChainID(), slot, | ||||||||||||||
)) | ||||||||||||||
abi87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
nextValidatorIndex %= math.ValidatorIndex(totalValidators) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
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.
🧹 Nitpick (assertive)
Update method comment to reflect new parameters
The
MaxValidatorsPerWithdrawalsSweep
method now acceptsisPostUpgrade
,chainID
, andslot
as parameters, but the method comment has not been updated accordingly. To improve clarity and maintain accurate documentation, please update the comment to describe these parameters.Apply this change to the comment:
📝 Committable suggestion
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.
Fork choice should not be binary (pre/post) but I guess:
So fine with me
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.
@abi87, understood. Thank you.