mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Add Excess Deposit Flag to allow Validator Balances more than 32 ETH (#2625)
* add flags and code * adding tests * gaz * Update shared/featureconfig/config.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
parent
08288f0958
commit
25ce3a3676
@ -9,6 +9,7 @@ go_library(
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
@ -24,6 +25,7 @@ go_test(
|
||||
"//beacon-chain/core/state/stateutils:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/bitutil:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -137,7 +138,12 @@ func ProcessDeposit(
|
||||
withdrawalCredentials,
|
||||
)
|
||||
}
|
||||
state.ValidatorBalances[existingValidatorIdx] += amount
|
||||
newBalance := state.ValidatorBalances[existingValidatorIdx] + amount
|
||||
state.ValidatorBalances[existingValidatorIdx] = newBalance
|
||||
|
||||
if !featureconfig.FeatureConfig().EnableExcessDeposits && newBalance > params.BeaconConfig().MaxDepositAmount {
|
||||
state.ValidatorBalances[existingValidatorIdx] = params.BeaconConfig().MaxDepositAmount
|
||||
}
|
||||
}
|
||||
state.DepositIndex++
|
||||
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state/stateutils"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bitutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
@ -362,6 +363,90 @@ func TestProcessDeposit_PublicKeyDoesNotExistAndEmptyValidator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessDepositFlag_NotEnabled(t *testing.T) {
|
||||
registry := []*pb.Validator{
|
||||
{
|
||||
Pubkey: []byte{1, 2, 3},
|
||||
WithdrawalCredentialsHash32: []byte{2},
|
||||
},
|
||||
{
|
||||
Pubkey: []byte{4, 5, 6},
|
||||
WithdrawalCredentialsHash32: []byte{1},
|
||||
},
|
||||
}
|
||||
balances := []uint64{0, 32e9}
|
||||
beaconState := &pb.BeaconState{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
ValidatorBalances: balances,
|
||||
ValidatorRegistry: registry,
|
||||
}
|
||||
pubkey := []byte{4, 5, 6}
|
||||
deposit := uint64(32e9)
|
||||
proofOfPossession := []byte{}
|
||||
withdrawalCredentials := []byte{1}
|
||||
|
||||
newState, err := ProcessDeposit(
|
||||
beaconState,
|
||||
stateutils.ValidatorIndexMap(beaconState),
|
||||
pubkey,
|
||||
deposit,
|
||||
proofOfPossession,
|
||||
withdrawalCredentials,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Process deposit failed: %v", err)
|
||||
}
|
||||
if newState.ValidatorBalances[1] != 32e9 {
|
||||
t.Errorf("Balances have been updated despite flag being not applied: %d", newState.ValidatorBalances[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessDepositFlag_Enabled(t *testing.T) {
|
||||
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{
|
||||
EnableExcessDeposits: true,
|
||||
})
|
||||
|
||||
registry := []*pb.Validator{
|
||||
{
|
||||
Pubkey: []byte{1, 2, 3},
|
||||
WithdrawalCredentialsHash32: []byte{2},
|
||||
},
|
||||
{
|
||||
Pubkey: []byte{4, 5, 6},
|
||||
WithdrawalCredentialsHash32: []byte{1},
|
||||
},
|
||||
}
|
||||
balances := []uint64{0, 32e9}
|
||||
beaconState := &pb.BeaconState{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
ValidatorBalances: balances,
|
||||
ValidatorRegistry: registry,
|
||||
}
|
||||
pubkey := []byte{4, 5, 6}
|
||||
deposit := uint64(32e9)
|
||||
proofOfPossession := []byte{}
|
||||
withdrawalCredentials := []byte{1}
|
||||
|
||||
newState, err := ProcessDeposit(
|
||||
beaconState,
|
||||
stateutils.ValidatorIndexMap(beaconState),
|
||||
pubkey,
|
||||
deposit,
|
||||
proofOfPossession,
|
||||
withdrawalCredentials,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Process deposit failed: %v", err)
|
||||
}
|
||||
if newState.ValidatorBalances[1] != 64e9 {
|
||||
t.Errorf("Balances have been updated despite flag being not applied: %d", newState.ValidatorBalances[1])
|
||||
}
|
||||
// Un-setting flag
|
||||
featureconfig.InitFeatureConfig(&featureconfig.FeatureFlagConfig{
|
||||
EnableExcessDeposits: false,
|
||||
})
|
||||
}
|
||||
|
||||
func TestActivateValidatorGenesis_OK(t *testing.T) {
|
||||
state := &pb.BeaconState{
|
||||
ValidatorRegistry: []*pb.Validator{
|
||||
|
@ -33,6 +33,7 @@ type FeatureFlagConfig struct {
|
||||
DisableGossipSub bool // DisableGossipSub in p2p messaging.
|
||||
EnableCommitteesCache bool // EnableCommitteesCache for state transition.
|
||||
CacheTreeHash bool // CacheTreeHash determent whether tree hashes will be cached.
|
||||
EnableExcessDeposits bool // EnableExcessDeposits in validator balances.
|
||||
}
|
||||
|
||||
var featureConfig *FeatureFlagConfig
|
||||
@ -82,6 +83,10 @@ func ConfigureBeaconFeatures(ctx *cli.Context) {
|
||||
log.Info("Disabled gossipsub, using floodsub")
|
||||
cfg.DisableGossipSub = true
|
||||
}
|
||||
if ctx.GlobalBool(EnableExcessDepositsFlag.Name) {
|
||||
log.Info("Enabled excess deposits")
|
||||
cfg.EnableExcessDeposits = true
|
||||
}
|
||||
InitFeatureConfig(cfg)
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,12 @@ var (
|
||||
Name: "disable-gossip-sub",
|
||||
Usage: "Disable gossip sub messaging and use floodsub messaging",
|
||||
}
|
||||
// EnableExcessDepositsFlag enables a validator to have total amount deposited as more than the
|
||||
// max deposit amount.
|
||||
EnableExcessDepositsFlag = cli.BoolFlag{
|
||||
Name: "enables-excess-deposit",
|
||||
Usage: "Enables balances more than max deposit amount for a validator",
|
||||
}
|
||||
)
|
||||
|
||||
// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
|
||||
@ -60,4 +66,5 @@ var BeaconChainFlags = []cli.Flag{
|
||||
DisableHistoricalStatePruningFlag,
|
||||
DisableGossipSubFlag,
|
||||
CacheTreeHashFlag,
|
||||
EnableExcessDepositsFlag,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user