Skip to content
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

Eip6110 queue deposit requests #14430

Merged
merged 64 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
2cc1ff3
wip
james-prysm Aug 8, 2024
b008a3b
updating types and wip on functions
james-prysm Aug 9, 2024
8d0d444
fixing conficts and merging develop
james-prysm Sep 6, 2024
4a87609
Merge branch 'develop' into eip6110-queue
james-prysm Sep 6, 2024
a0bef32
renaming to MAX_PENDING_DEPOSITS_PER_EPOCH
james-prysm Sep 6, 2024
46e88f0
fixing linting and conversions
james-prysm Sep 6, 2024
6cf54bc
adding queue deposit changes
james-prysm Sep 6, 2024
5334144
Merge branch 'develop' into eip6110-queue
james-prysm Sep 6, 2024
3c25797
fixing test and cloning
james-prysm Sep 6, 2024
330cfa3
removing unneeded test based on update
james-prysm Sep 6, 2024
3566543
gaz
james-prysm Sep 6, 2024
41ba44b
Merge branch 'develop' into eip6110-queue
james-prysm Sep 9, 2024
0690e44
Merge branch 'develop' into eip6110-queue
james-prysm Sep 10, 2024
f697f65
wip apply pending deposit
james-prysm Sep 10, 2024
792a4f7
fixing replay test and adding apply pending deposit
james-prysm Sep 10, 2024
af3f8d0
Merge branch 'develop' into eip6110-queue
james-prysm Sep 12, 2024
8bb1fcc
fixing setters test
james-prysm Sep 11, 2024
5dda6df
updating transition test
james-prysm Sep 11, 2024
1e4e826
changelog
james-prysm Sep 12, 2024
29cf448
Merge branch 'develop' into eip6110-queue
james-prysm Sep 16, 2024
f1a2dca
updating pending deposits
james-prysm Sep 12, 2024
944afd1
fixing ProcessPendingDeposit unit tests
james-prysm Sep 16, 2024
5fb1e10
gaz
james-prysm Sep 16, 2024
1a55937
fixing cyclic dependencies
james-prysm Sep 16, 2024
fe2598d
fix visiblity
james-prysm Sep 17, 2024
26216ef
missed adding the right signature verification
james-prysm Sep 17, 2024
582444c
adding point to infinity topup test
james-prysm Sep 18, 2024
8776421
adding apply pending deposit test
james-prysm Sep 18, 2024
f6e06d7
making changes based on eip6110 changes
james-prysm Sep 19, 2024
9110135
fixing ineffassign
james-prysm Sep 19, 2024
9abebd7
gaz
james-prysm Sep 19, 2024
41f1406
Merge branch 'develop' into eip6110-queue
james-prysm Sep 20, 2024
f95f87c
adding batched verifications sigs
james-prysm Sep 23, 2024
377f5a6
Merge branch 'develop' into eip6110-queue
james-prysm Sep 23, 2024
134fe8c
Merge branch 'develop' into eip6110-queue
james-prysm Sep 24, 2024
fe5c942
Merge branch 'develop' into eip6110-queue
james-prysm Sep 26, 2024
b5d2d90
fixing broken type
james-prysm Sep 26, 2024
446cba2
fixing proto
james-prysm Sep 27, 2024
c3fb312
Merge branch 'develop' into eip6110-queue
james-prysm Sep 27, 2024
7a5ff1a
Merge branch 'develop' into eip6110-queue
james-prysm Oct 7, 2024
f976c26
updated consensus spec tests and fixed consensus bug tests
james-prysm Oct 8, 2024
c2e6686
Merge branch 'develop' into eip6110-queue
james-prysm Oct 8, 2024
abd0e1e
testing readability improvement by avoiding ApplyPendingDeposit
james-prysm Oct 8, 2024
5b40a23
removing the boolean from apply pending deposit
james-prysm Oct 8, 2024
64545de
improve naming
james-prysm Oct 8, 2024
c37cd17
review comments and fixing a small bug using wrong variable
james-prysm Oct 8, 2024
de43591
fixing tests and skipping a test
james-prysm Oct 8, 2024
dc38cf9
Merge branch 'develop' into eip6110-queue
james-prysm Oct 8, 2024
7abdd5d
adding some test skips
james-prysm Oct 8, 2024
6677634
fixing bugs terence found
james-prysm Oct 8, 2024
4e310e7
Merge branch 'develop' into eip6110-queue
james-prysm Oct 8, 2024
d52d819
adding test for batchProcessNewPendingDeposits
james-prysm Oct 8, 2024
c66c2e9
gaz
james-prysm Oct 8, 2024
44a41c4
adding churn test
james-prysm Oct 9, 2024
197163b
updating spec tests to alpha.8
james-prysm Oct 9, 2024
1c0d70e
Merge branch 'develop' into eip6110-queue
james-prysm Oct 9, 2024
0eb8e79
adding pr to changelog
james-prysm Oct 9, 2024
c48a58b
addressing terence's comments
james-prysm Oct 10, 2024
cc3e941
Update beacon-chain/core/electra/validator.go
james-prysm Oct 10, 2024
a637027
adding tests for batch verify and rename some variables
james-prysm Oct 10, 2024
fa23924
Merge branch 'develop' into eip6110-queue
james-prysm Oct 10, 2024
cd39461
skipping tests , add them back in later
james-prysm Oct 10, 2024
9b96fa6
skipping one more test
james-prysm Oct 10, 2024
d786dc5
Merge branch 'develop' into eip6110-queue
james-prysm Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Light client support: Implement `ComputeFieldRootsForBlockBody`.
- Light client support: Add light client database changes.
- Light client support: Implement capella and deneb changes.
- Electra EIP6110: Queue deposit
- Light client support: Implement `BlockToLightClientHeaderXXX` functions upto Deneb

### Changed
Expand All @@ -31,6 +32,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- `grpc-gateway-corsdomain` is renamed to http-cors-domain. The old name can still be used as an alias.
- `api-timeout` is changed from int flag to duration flag, default value updated.
- Light client support: abstracted out the light client headers with different versions.
- Electra EIP6110: Queue deposit requests changes from consensus spec pr #3818
- `ApplyToEveryValidator` has been changed to prevent misuse bugs, it takes a closure that takes a `ReadOnlyValidator` and returns a raw pointer to a `Validator`.
- Removed gorilla mux library and replaced it with net/http updates in go 1.22.
- Clean up `ProposeBlock` for validator client to reduce cognitive scoring and enable further changes.
Expand Down
13 changes: 8 additions & 5 deletions api/server/structs/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,12 +1475,15 @@ func DepositSnapshotFromConsensus(ds *eth.DepositSnapshot) *DepositSnapshot {
}
}

func PendingBalanceDepositsFromConsensus(ds []*eth.PendingBalanceDeposit) []*PendingBalanceDeposit {
deposits := make([]*PendingBalanceDeposit, len(ds))
func PendingDepositsFromConsensus(ds []*eth.PendingDeposit) []*PendingDeposit {
deposits := make([]*PendingDeposit, len(ds))
for i, d := range ds {
deposits[i] = &PendingBalanceDeposit{
Index: fmt.Sprintf("%d", d.Index),
Amount: fmt.Sprintf("%d", d.Amount),
deposits[i] = &PendingDeposit{
Pubkey: hexutil.Encode(d.PublicKey),
WithdrawalCredentials: hexutil.Encode(d.WithdrawalCredentials),
Amount: fmt.Sprintf("%d", d.Amount),
Signature: hexutil.Encode(d.Signature),
Slot: fmt.Sprintf("%d", d.Slot),
}
}
return deposits
Expand Down
4 changes: 2 additions & 2 deletions api/server/structs/conversions_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func BeaconStateElectraFromConsensus(st beaconState.BeaconState) (*BeaconStateEl
if err != nil {
return nil, err
}
pbd, err := st.PendingBalanceDeposits()
pbd, err := st.PendingDeposits()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -770,7 +770,7 @@ func BeaconStateElectraFromConsensus(st beaconState.BeaconState) (*BeaconStateEl
EarliestExitEpoch: fmt.Sprintf("%d", eee),
ConsolidationBalanceToConsume: fmt.Sprintf("%d", cbtc),
EarliestConsolidationEpoch: fmt.Sprintf("%d", ece),
PendingBalanceDeposits: PendingBalanceDepositsFromConsensus(pbd),
PendingDeposits: PendingDepositsFromConsensus(pbd),
PendingPartialWithdrawals: PendingPartialWithdrawalsFromConsensus(ppw),
PendingConsolidations: PendingConsolidationsFromConsensus(pc),
}, nil
Expand Down
9 changes: 6 additions & 3 deletions api/server/structs/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@ type ConsolidationRequest struct {
TargetPubkey string `json:"target_pubkey"`
}

type PendingBalanceDeposit struct {
Index string `json:"index"`
Amount string `json:"amount"`
type PendingDeposit struct {
Pubkey string `json:"pubkey"`
WithdrawalCredentials string `json:"withdrawal_credentials"`
Amount string `json:"amount"`
Signature string `json:"signature"`
Slot string `json:"slot"`
}

type PendingPartialWithdrawal struct {
Expand Down
2 changes: 1 addition & 1 deletion api/server/structs/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type BeaconStateElectra struct {
EarliestExitEpoch string `json:"earliest_exit_epoch"`
ConsolidationBalanceToConsume string `json:"consolidation_balance_to_consume"`
EarliestConsolidationEpoch string `json:"earliest_consolidation_epoch"`
PendingBalanceDeposits []*PendingBalanceDeposit `json:"pending_balance_deposits"`
PendingDeposits []*PendingDeposit `json:"pending_deposits"`
PendingPartialWithdrawals []*PendingPartialWithdrawal `json:"pending_partial_withdrawals"`
PendingConsolidations []*PendingConsolidation `json:"pending_consolidations"`
}
73 changes: 1 addition & 72 deletions beacon-chain/core/altair/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

// ProcessPreGenesisDeposits processes a deposit for the beacon state before chainstart.
Expand Down Expand Up @@ -130,7 +128,7 @@ func ApplyDeposit(beaconState state.BeaconState, data *ethpb.Deposit_Data, verif
return beaconState, nil
}
}
if err := AddValidatorToRegistry(beaconState, pubKey, withdrawalCredentials, amount); err != nil {
if err := blocks.AddValidatorToRegistry(beaconState, pubKey, withdrawalCredentials, amount); err != nil {
return nil, err
}
} else {
Expand All @@ -140,72 +138,3 @@ func ApplyDeposit(beaconState state.BeaconState, data *ethpb.Deposit_Data, verif
}
return beaconState, nil
}

// AddValidatorToRegistry updates the beacon state with validator information
// def add_validator_to_registry(state: BeaconState,
//
// pubkey: BLSPubkey,
// withdrawal_credentials: Bytes32,
// amount: uint64) -> None:
// index = get_index_for_new_validator(state)
// validator = get_validator_from_deposit(pubkey, withdrawal_credentials)
// set_or_append_list(state.validators, index, validator)
// set_or_append_list(state.balances, index, 0)
// set_or_append_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000)) // New in Altair
// set_or_append_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000)) // New in Altair
// set_or_append_list(state.inactivity_scores, index, uint64(0)) // New in Altair
func AddValidatorToRegistry(beaconState state.BeaconState, pubKey []byte, withdrawalCredentials []byte, amount uint64) error {
val := GetValidatorFromDeposit(pubKey, withdrawalCredentials, amount)
if err := beaconState.AppendValidator(val); err != nil {
return err
}
if err := beaconState.AppendBalance(amount); err != nil {
return err
}

// only active in altair and only when it's a new validator (after append balance)
if beaconState.Version() >= version.Altair {
if err := beaconState.AppendInactivityScore(0); err != nil {
return err
}
if err := beaconState.AppendPreviousParticipationBits(0); err != nil {
return err
}
if err := beaconState.AppendCurrentParticipationBits(0); err != nil {
return err
}
}
return nil
}

// GetValidatorFromDeposit gets a new validator object with provided parameters
//
// def get_validator_from_deposit(pubkey: BLSPubkey, withdrawal_credentials: Bytes32, amount: uint64) -> Validator:
//
// effective_balance = min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
//
// return Validator(
// pubkey=pubkey,
// withdrawal_credentials=withdrawal_credentials,
// activation_eligibility_epoch=FAR_FUTURE_EPOCH,
// activation_epoch=FAR_FUTURE_EPOCH,
// exit_epoch=FAR_FUTURE_EPOCH,
// withdrawable_epoch=FAR_FUTURE_EPOCH,
// effective_balance=effective_balance,
// )
func GetValidatorFromDeposit(pubKey []byte, withdrawalCredentials []byte, amount uint64) *ethpb.Validator {
effectiveBalance := amount - (amount % params.BeaconConfig().EffectiveBalanceIncrement)
if params.BeaconConfig().MaxEffectiveBalance < effectiveBalance {
effectiveBalance = params.BeaconConfig().MaxEffectiveBalance
}

return &ethpb.Validator{
PublicKey: pubKey,
WithdrawalCredentials: withdrawalCredentials,
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: effectiveBalance,
}
}
70 changes: 70 additions & 0 deletions beacon-chain/core/blocks/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,78 @@ import (
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/math"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

// AddValidatorToRegistry updates the beacon state with validator information
// def add_validator_to_registry(state: BeaconState,
//
// pubkey: BLSPubkey,
// withdrawal_credentials: Bytes32,
// amount: uint64) -> None:
// index = get_index_for_new_validator(state)
// validator = get_validator_from_deposit(pubkey, withdrawal_credentials)
// set_or_append_list(state.validators, index, validator)
// set_or_append_list(state.balances, index, 0)
// set_or_append_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000)) // New in Altair
// set_or_append_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000)) // New in Altair
// set_or_append_list(state.inactivity_scores, index, uint64(0)) // New in Altair
func AddValidatorToRegistry(beaconState state.BeaconState, pubKey []byte, withdrawalCredentials []byte, amount uint64) error {
val := GetValidatorFromDeposit(pubKey, withdrawalCredentials, amount)
if err := beaconState.AppendValidator(val); err != nil {
return err
}
if err := beaconState.AppendBalance(amount); err != nil {
return err
}

// only active in altair and only when it's a new validator (after append balance)
if beaconState.Version() >= version.Altair {
if err := beaconState.AppendInactivityScore(0); err != nil {
return err
}
if err := beaconState.AppendPreviousParticipationBits(0); err != nil {
return err
}
if err := beaconState.AppendCurrentParticipationBits(0); err != nil {
return err
}
}
return nil
}

// GetValidatorFromDeposit gets a new validator object with provided parameters
//
// def get_validator_from_deposit(pubkey: BLSPubkey, withdrawal_credentials: Bytes32, amount: uint64) -> Validator:
//
// effective_balance = min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
//
// return Validator(
// pubkey=pubkey,
// withdrawal_credentials=withdrawal_credentials,
// activation_eligibility_epoch=FAR_FUTURE_EPOCH,
// activation_epoch=FAR_FUTURE_EPOCH,
// exit_epoch=FAR_FUTURE_EPOCH,
// withdrawable_epoch=FAR_FUTURE_EPOCH,
// effective_balance=effective_balance,
// )
func GetValidatorFromDeposit(pubKey []byte, withdrawalCredentials []byte, amount uint64) *ethpb.Validator {
effectiveBalance := amount - (amount % params.BeaconConfig().EffectiveBalanceIncrement)
if params.BeaconConfig().MaxEffectiveBalance < effectiveBalance {
effectiveBalance = params.BeaconConfig().MaxEffectiveBalance
}

return &ethpb.Validator{
PublicKey: pubKey,
WithdrawalCredentials: withdrawalCredentials,
ActivationEligibilityEpoch: params.BeaconConfig().FarFutureEpoch,
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: effectiveBalance,
}
}

// ActivateValidatorWithEffectiveBalance updates validator's effective balance, and if it's above MaxEffectiveBalance, validator becomes active in genesis.
func ActivateValidatorWithEffectiveBalance(beaconState state.BeaconState, deposits []*ethpb.Deposit) (state.BeaconState, error) {
for _, d := range deposits {
Expand Down
2 changes: 2 additions & 0 deletions beacon-chain/core/electra/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_library(
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//contracts/deposit:go_default_library",
"//crypto/bls/common:go_default_library",
"//encoding/bytesutil:go_default_library",
"//math:go_default_library",
"//monitoring/tracing/trace:go_default_library",
Expand Down Expand Up @@ -65,6 +66,7 @@ go_test(
"//beacon-chain/core/time:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/state-native:go_default_library",
"//beacon-chain/state/testing:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
Expand Down
32 changes: 0 additions & 32 deletions beacon-chain/core/electra/consolidations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,6 @@ func TestProcessPendingConsolidations(t *testing.T) {
}
}

func stateWithActiveBalanceETH(t *testing.T, balETH uint64) state.BeaconState {
gwei := balETH * 1_000_000_000
balPerVal := params.BeaconConfig().MinActivationBalance
numVals := gwei / balPerVal

vals := make([]*eth.Validator, numVals)
bals := make([]uint64, numVals)
for i := uint64(0); i < numVals; i++ {
wc := make([]byte, 32)
wc[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte
wc[31] = byte(i)
vals[i] = &eth.Validator{
ActivationEpoch: 0,
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
EffectiveBalance: balPerVal,
WithdrawalCredentials: wc,
}
bals[i] = balPerVal
}
st, err := state_native.InitializeFromProtoUnsafeElectra(&eth.BeaconStateElectra{
Slot: 10 * params.BeaconConfig().SlotsPerEpoch,
Validators: vals,
Balances: bals,
Fork: &eth.Fork{
CurrentVersion: params.BeaconConfig().ElectraForkVersion,
},
})
require.NoError(t, err)

return st
}

func TestProcessConsolidationRequests(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading
Loading