From 8d1718edf93379271531a09967bf452a259b6d48 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Wed, 12 Dec 2018 23:46:44 -0800 Subject: [PATCH] Helper Functions to Retrieve Total Validator Balances (#1087) * helper functions to get active validator total balances * forgot to * params.BeaconConfig().Gwei * tests * GetEffectiveBalance comments & MaxDepositInGwei in config * format --- .../chaintest/backend/simulated_backend.go | 2 +- beacon-chain/core/state/state_transition.go | 6 +- .../core/state/state_transition_test.go | 4 +- beacon-chain/core/validators/validator.go | 76 ++++++++++-- .../core/validators/validator_test.go | 109 ++++++++++++++---- shared/params/config.go | 9 +- 6 files changed, 164 insertions(+), 42 deletions(-) diff --git a/beacon-chain/chaintest/backend/simulated_backend.go b/beacon-chain/chaintest/backend/simulated_backend.go index 2ae5c6ae1..fc0611d00 100644 --- a/beacon-chain/chaintest/backend/simulated_backend.go +++ b/beacon-chain/chaintest/backend/simulated_backend.go @@ -70,7 +70,7 @@ func (sb *SimulatedBackend) RunChainTest(testCase *ChainTestCase) error { for i := uint64(0); i < testCase.Config.ValidatorCount; i++ { validators[i] = &pb.ValidatorRecord{ Status: pb.ValidatorRecord_ACTIVE, - Balance: c.DepositSize * c.Gwei, + Balance: c.MaxDeposit * c.Gwei, Pubkey: []byte{}, RandaoCommitmentHash32: randaoReveal[:], } diff --git a/beacon-chain/core/state/state_transition.go b/beacon-chain/core/state/state_transition.go index 3e0f4aabf..d14c370d3 100644 --- a/beacon-chain/core/state/state_transition.go +++ b/beacon-chain/core/state/state_transition.go @@ -67,7 +67,7 @@ func NewStateTransition( blockVoteCache, newState.ValidatorRegistry(), v.ActiveValidatorIndices(newState.ValidatorRegistry()), - v.TotalActiveValidatorDeposit(newState.ValidatorRegistry()), + v.TotalActiveValidatorBalance(newState.ValidatorRegistry()), timeSinceFinality, ) @@ -79,7 +79,7 @@ func NewStateTransition( finalizedSlot, justifiedStreak, blockVoteBalance, - v.TotalActiveValidatorDeposit(st.ValidatorRegistry()), + v.TotalActiveValidatorBalance(st.ValidatorRegistry()), ) } @@ -159,7 +159,7 @@ func crossLinkCalculations( indices, attestation, st.ValidatorRegistry(), - v.TotalActiveValidatorDeposit(st.ValidatorRegistry()), + v.TotalActiveValidatorBalance(st.ValidatorRegistry()), totalBalance, voteBalance, ) diff --git a/beacon-chain/core/state/state_transition_test.go b/beacon-chain/core/state/state_transition_test.go index ab5a03119..7255c2e55 100644 --- a/beacon-chain/core/state/state_transition_test.go +++ b/beacon-chain/core/state/state_transition_test.go @@ -75,11 +75,11 @@ func TestNextDeriveSlot(t *testing.T) { } beaconState.SetValidatorRegistry([]*pb.ValidatorRecord{ - {Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei), + {Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei), Status: pb.ValidatorRecord_ACTIVE}, }) - totalDeposits := v.TotalActiveValidatorDeposit(beaconState.ValidatorRegistry()) + totalDeposits := v.TotalActiveValidatorBalance(beaconState.ValidatorRegistry()) recentShardBlockHashes := make([][]byte, 3*params.BeaconConfig().CycleLength) for i := 0; i < int(params.BeaconConfig().CycleLength); i++ { shardBlockHash := [32]byte{} diff --git a/beacon-chain/core/validators/validator.go b/beacon-chain/core/validators/validator.go index 144937818..07be74997 100644 --- a/beacon-chain/core/validators/validator.go +++ b/beacon-chain/core/validators/validator.go @@ -28,7 +28,7 @@ func InitialValidatorRegistry() []*pb.ValidatorRecord { for i := uint64(0); i < config.BootstrappedValidatorsCount; i++ { validators[i] = &pb.ValidatorRecord{ Status: pb.ValidatorRecord_ACTIVE, - Balance: config.DepositSize * config.Gwei, + Balance: config.MaxDeposit * config.Gwei, Pubkey: []byte{}, RandaoCommitmentHash32: randaoReveal[:], } @@ -38,10 +38,17 @@ func InitialValidatorRegistry() []*pb.ValidatorRecord { // ActiveValidatorIndices filters out active validators based on validator status // and returns their indices in a list. +// +// Spec pseudocode definition: +// def get_active_validator_indices(validators: [ValidatorRecord]) -> List[int]: +// """ +// Gets indices of active validators from ``validators``. +// """ +// return [i for i, v in enumerate(validators) if is_active_validator(v)] func ActiveValidatorIndices(validators []*pb.ValidatorRecord) []uint32 { indices := make([]uint32, 0, len(validators)) for i, v := range validators { - if v.Status == pb.ValidatorRecord_ACTIVE { + if isActiveValidator(v) { indices = append(indices, uint32(i)) } @@ -49,6 +56,18 @@ func ActiveValidatorIndices(validators []*pb.ValidatorRecord) []uint32 { return indices } +// ActiveValidator returns the active validator records in a list. +// +// Spec pseudocode definition: +// [state.validator_registry[i] for i in get_active_validator_indices(state.validator_registry)] +func ActiveValidator(state *pb.BeaconState, validatorIndices []uint32) []*pb.ValidatorRecord { + activeValidators := make([]*pb.ValidatorRecord, 0, len(validatorIndices)) + for _, validatorIndex := range validatorIndices { + activeValidators = append(activeValidators, state.ValidatorRegistry[validatorIndex]) + } + return activeValidators +} + // ShardAndCommitteesAtSlot returns the shard and committee list for a given // slot within the range of 2 * epoch length within the same 2 epoch slot // window as the state slot. @@ -214,20 +233,22 @@ func ValidatorSlotAndRole(pubKey []byte, validators []*pb.ValidatorRecord, shard return 0, pbrpc.ValidatorRole_UNKNOWN, fmt.Errorf("can't find slot number for validator with public key %#x", pubKey) } -// TotalActiveValidatorDeposit returns the total deposited amount in Gwei for all active validators. -func TotalActiveValidatorDeposit(validators []*pb.ValidatorRecord) uint64 { +// TotalActiveValidatorBalance returns the total deposited amount in Gwei for all active validators. +// +// Spec pseudocode definition: +// sum([get_effective_balance(v) for v in active_validators]) +func TotalActiveValidatorBalance(activeValidators []*pb.ValidatorRecord) uint64 { var totalDeposit uint64 - indices := ActiveValidatorIndices(validators) - for _, index := range indices { - totalDeposit += validators[index].GetBalance() + for _, v := range activeValidators { + totalDeposit += EffectiveBalance(v) } return totalDeposit } // TotalActiveValidatorDepositInEth returns the total deposited amount in ETH for all active validators. func TotalActiveValidatorDepositInEth(validators []*pb.ValidatorRecord) uint64 { - totalDeposit := TotalActiveValidatorDeposit(validators) + totalDeposit := TotalActiveValidatorBalance(validators) depositInEth := totalDeposit / params.BeaconConfig().Gwei return depositInEth @@ -269,7 +290,7 @@ func AddPendingValidator( newValidatorRecord := &pb.ValidatorRecord{ Pubkey: pubKey, RandaoCommitmentHash32: randaoCommitment, - Balance: params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei, + Balance: params.BeaconConfig().MaxDepositInGwei, Status: status, } @@ -301,9 +322,9 @@ func ExitValidator( // ChangeValidatorRegistry updates the validator set during state transition. func ChangeValidatorRegistry(currentSlot uint64, totalPenalties uint64, validators []*pb.ValidatorRecord) []*pb.ValidatorRecord { - maxAllowableChange := 2 * params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei + maxAllowableChange := 2 * params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei - totalBalance := TotalActiveValidatorDeposit(validators) + totalBalance := TotalActiveValidatorBalance(validators) // Determine the max total wei that can deposit and withdraw. if totalBalance > maxAllowableChange { @@ -314,7 +335,7 @@ func ChangeValidatorRegistry(currentSlot uint64, totalPenalties uint64, validato for i := 0; i < len(validators); i++ { if validators[i].Status == pb.ValidatorRecord_PENDING_ACTIVATION { validators[i].Status = pb.ValidatorRecord_ACTIVE - totalChanged += params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei + totalChanged += params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei // TODO(#614): Add validator set change. } @@ -383,6 +404,23 @@ func CheckValidatorMinDeposit(validatorSet []*pb.ValidatorRecord, currentSlot ui return validatorSet } +// EffectiveBalance returns the balance at stake for the validator. +// Beacon chain allows validators to top off their balance above MAX_DEPOSIT, +// but they can be slashed at most MAX_DEPOSIT at any time. +// +// Spec pseudocode definition: +// def get_effective_balance(validator: ValidatorRecord) -> int: +// """ +// Returns the effective balance (also known as "balance at stake") for the ``validator``. +// """ +// return min(validator.balance, MAX_DEPOSIT) +func EffectiveBalance(validator *pb.ValidatorRecord) uint64 { + if validator.Balance > params.BeaconConfig().MaxDeposit*params.BeaconConfig().Gwei { + return params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei + } + return validator.Balance +} + // minEmptyValidator returns the lowest validator index which the status is withdrawn. func minEmptyValidator(validators []*pb.ValidatorRecord) int { for i := 0; i < len(validators); i++ { @@ -392,3 +430,17 @@ func minEmptyValidator(validators []*pb.ValidatorRecord) int { } return -1 } + +// isActiveValidator returns the boolean value on whether the validator +// is active or not. +// +// Spec pseudocode definition: +// def is_active_validator(validator: ValidatorRecord) -> bool: +// """ +// Returns the ``ShardCommittee`` for the ``slot``. +// """ +// return validator.status in [ACTIVE, ACTIVE_PENDING_EXIT] +func isActiveValidator(validator *pb.ValidatorRecord) bool { + return validator.Status == pb.ValidatorRecord_ACTIVE_PENDING_EXIT || + validator.Status == pb.ValidatorRecord_ACTIVE +} diff --git a/beacon-chain/core/validators/validator_test.go b/beacon-chain/core/validators/validator_test.go index 9f3bf956c..1bba6381e 100644 --- a/beacon-chain/core/validators/validator_test.go +++ b/beacon-chain/core/validators/validator_test.go @@ -3,6 +3,7 @@ package validators import ( "bytes" "math/big" + "reflect" "testing" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" @@ -50,7 +51,7 @@ func TestHasVoted(t *testing.T) { func TestInitialValidatorRegistry(t *testing.T) { validators := InitialValidatorRegistry() for _, validator := range validators { - if validator.GetBalance() != params.BeaconConfig().DepositSize*params.BeaconConfig().Gwei { + if validator.GetBalance() != params.BeaconConfig().MaxDeposit*params.BeaconConfig().Gwei { t.Fatalf("deposit size of validator is not expected %d", validator.GetBalance()) } if validator.GetStatus() != pb.ValidatorRecord_ACTIVE { @@ -244,7 +245,7 @@ func TestTotalActiveValidatorDeposit(t *testing.T) { expectedTotalDeposit := new(big.Int) expectedTotalDeposit.SetString("10000000000", 10) - totalDeposit := TotalActiveValidatorDeposit(validators) + totalDeposit := TotalActiveValidatorBalance(validators) if expectedTotalDeposit.Cmp(new(big.Int).SetUint64(totalDeposit)) != 0 { t.Fatalf("incorrect total deposit calculated %d", totalDeposit) } @@ -321,7 +322,7 @@ func TestAddValidatorRegistry(t *testing.T) { if validators[10].Status != pb.ValidatorRecord_PENDING_ACTIVATION { t.Errorf("Newly added validator should be pending") } - if validators[10].Balance != uint64(params.BeaconConfig().DepositSize*params.BeaconConfig().Gwei) { + if validators[10].Balance != uint64(params.BeaconConfig().MaxDeposit*params.BeaconConfig().Gwei) { t.Errorf("Incorrect deposit size") } @@ -333,27 +334,27 @@ func TestAddValidatorRegistry(t *testing.T) { if validators[5].Status != pb.ValidatorRecord_PENDING_ACTIVATION { t.Errorf("Newly added validator should be pending") } - if validators[5].Balance != uint64(params.BeaconConfig().DepositSize*params.BeaconConfig().Gwei) { + if validators[5].Balance != uint64(params.BeaconConfig().MaxDeposit*params.BeaconConfig().Gwei) { t.Errorf("Incorrect deposit size") } } func TestChangeValidatorRegistry(t *testing.T) { existingValidatorRegistry := []*pb.ValidatorRecord{ - {Pubkey: []byte{1}, Status: pb.ValidatorRecord_PENDING_ACTIVATION, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, - {Pubkey: []byte{2}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, - {Pubkey: []byte{3}, Status: pb.ValidatorRecord_PENDING_ACTIVATION, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, - {Pubkey: []byte{4}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, - {Pubkey: []byte{5}, Status: pb.ValidatorRecord_PENDING_ACTIVATION, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, - {Pubkey: []byte{6}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, - {Pubkey: []byte{7}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, - {Pubkey: []byte{8}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, - {Pubkey: []byte{9}, Status: pb.ValidatorRecord_EXITED_WITH_PENALTY, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, - {Pubkey: []byte{10}, Status: pb.ValidatorRecord_EXITED_WITH_PENALTY, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, - {Pubkey: []byte{11}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, - {Pubkey: []byte{12}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, - {Pubkey: []byte{13}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, - {Pubkey: []byte{14}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().DepositSize * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{1}, Status: pb.ValidatorRecord_PENDING_ACTIVATION, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, + {Pubkey: []byte{2}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, + {Pubkey: []byte{3}, Status: pb.ValidatorRecord_PENDING_ACTIVATION, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, + {Pubkey: []byte{4}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, + {Pubkey: []byte{5}, Status: pb.ValidatorRecord_PENDING_ACTIVATION, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, + {Pubkey: []byte{6}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei), LatestStatusChangeSlot: params.BeaconConfig().MinWithdrawalPeriod}, + {Pubkey: []byte{7}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{8}, Status: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{9}, Status: pb.ValidatorRecord_EXITED_WITH_PENALTY, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{10}, Status: pb.ValidatorRecord_EXITED_WITH_PENALTY, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{11}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{12}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{13}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, + {Pubkey: []byte{14}, Status: pb.ValidatorRecord_ACTIVE, Balance: uint64(params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei)}, } validators := ChangeValidatorRegistry(params.BeaconConfig().MinWithdrawalPeriod+1, 50*10e9, existingValidatorRegistry) @@ -361,7 +362,7 @@ func TestChangeValidatorRegistry(t *testing.T) { if validators[0].Status != pb.ValidatorRecord_ACTIVE { t.Errorf("Wanted status Active. Got: %d", validators[0].Status) } - if validators[0].Balance != uint64(params.BeaconConfig().DepositSize*params.BeaconConfig().Gwei) { + if validators[0].Balance != uint64(params.BeaconConfig().MaxDeposit*params.BeaconConfig().Gwei) { t.Error("Failed to set validator balance") } if validators[1].Status != pb.ValidatorRecord_ACTIVE_PENDING_EXIT { @@ -373,7 +374,7 @@ func TestChangeValidatorRegistry(t *testing.T) { if validators[2].Status != pb.ValidatorRecord_ACTIVE { t.Errorf("Wanted status Active. Got: %d", validators[2].Status) } - if validators[2].Balance != uint64(params.BeaconConfig().DepositSize*params.BeaconConfig().Gwei) { + if validators[2].Balance != uint64(params.BeaconConfig().MaxDeposit*params.BeaconConfig().Gwei) { t.Error("Failed to set validator balance") } if validators[3].Status != pb.ValidatorRecord_ACTIVE_PENDING_EXIT { @@ -386,7 +387,7 @@ func TestChangeValidatorRegistry(t *testing.T) { if validators[5].Status != pb.ValidatorRecord_ACTIVE_PENDING_EXIT { t.Errorf("Wanted status PendingExit. Got: %d", validators[5].Status) } - if validators[7].Status != pb.ValidatorRecord_EXITED_WITHOUT_PENALTY { + if validators[7].Status != pb.ValidatorRecord_ACTIVE_PENDING_EXIT { t.Errorf("Wanted status Withdrawn. Got: %d", validators[7].Status) } if validators[8].Status != pb.ValidatorRecord_EXITED_WITHOUT_PENALTY { @@ -579,3 +580,69 @@ func TestShardAndCommitteesAtSlot_OutOfBounds(t *testing.T) { } } + +func TestEffectiveBalance(t *testing.T) { + defaultBalance := params.BeaconConfig().MaxDeposit * params.BeaconConfig().Gwei + + tests := []struct { + a uint64 + b uint64 + }{ + {a: 0, b: 0}, + {a: defaultBalance - 1, b: defaultBalance - 1}, + {a: defaultBalance, b: defaultBalance}, + {a: defaultBalance + 1, b: defaultBalance}, + {a: defaultBalance * 100, b: defaultBalance}, + } + for _, test := range tests { + validator := &pb.ValidatorRecord{Balance: test.a} + if EffectiveBalance(validator) != test.b { + t.Errorf("EffectiveBalance(%d) = %d, want = %d", validator.Balance, EffectiveBalance(validator), test.b) + } + } +} + +func TestIsActiveValidator(t *testing.T) { + + tests := []struct { + a pb.ValidatorRecord_StatusCodes + b bool + }{ + {a: pb.ValidatorRecord_PENDING_ACTIVATION, b: false}, + {a: pb.ValidatorRecord_ACTIVE, b: true}, + {a: pb.ValidatorRecord_ACTIVE_PENDING_EXIT, b: true}, + {a: pb.ValidatorRecord_EXITED_WITHOUT_PENALTY + 1, b: false}, + {a: pb.ValidatorRecord_EXITED_WITH_PENALTY * 100, b: false}, + } + for _, test := range tests { + validator := &pb.ValidatorRecord{Status: test.a} + if isActiveValidator(validator) != test.b { + t.Errorf("isActiveValidator(%d) = %v, want = %v", validator.Status, isActiveValidator(validator), test.b) + } + } +} + +func TestGetActiveValidatorRecord(t *testing.T) { + inputValidators := []*pb.ValidatorRecord{ + {ExitCount: 0}, + {ExitCount: 1}, + {ExitCount: 2}, + {ExitCount: 3}, + {ExitCount: 4}, + } + + outputValidators := []*pb.ValidatorRecord{ + {ExitCount: 1}, + {ExitCount: 3}, + } + + state := &pb.BeaconState{ + ValidatorRegistry: inputValidators, + } + + validators := ActiveValidator(state, []uint32{1, 3}) + + if !reflect.DeepEqual(outputValidators, validators) { + t.Errorf("Active validators don't match. Wanted: %v, Got: %v", outputValidators, validators) + } +} diff --git a/shared/params/config.go b/shared/params/config.go index 1480fd020..01fe12f31 100644 --- a/shared/params/config.go +++ b/shared/params/config.go @@ -21,10 +21,11 @@ type ValidatorSetDeltaFlags int type BeaconChainConfig struct { MaxProposerSlashings uint64 // MaxProposerSlashing defines the maximum number of slashings of proposers possible in a block. ShardCount uint64 // ShardCount is the fixed number of shards in Ethereum 2.0. - DepositSize uint64 // DepositSize is how much a validator has deposited in Eth. + MaxDeposit uint64 // MaxDeposit is the max balance a validator can have at stake. MinTopUpSize uint64 // MinTopUpSize is the minimal amount of Ether a validator can top up. MinOnlineDepositSize uint64 // MinOnlineDepositSize is the minimal amount of Ether a validator needs to participate. Gwei uint64 // Gwei is the denomination of Gwei in Ether. + MaxDepositInGwei uint64 // MaxDepositInGwei is the max balance in Gwei a validator can have at stake. DepositContractAddress common.Address // DepositContractAddress is the address of validator registration contract in PoW chain. DepositsForChainStart uint64 // DepositsForChainStart defines how many deposits needed to start off beacon chain. TargetCommitteeSize uint64 // TargetCommitteeSize is the minimal number of validator needs to be in a committee. @@ -64,10 +65,11 @@ type ShardChainConfig struct { var defaultBeaconConfig = &BeaconChainConfig{ MaxProposerSlashings: 16, ShardCount: 1024, - DepositSize: 32, + MaxDeposit: 32, MinTopUpSize: 1, MinOnlineDepositSize: 16, Gwei: 1e9, + MaxDepositInGwei: 32 * 1e9, DepositsForChainStart: 16384, TargetCommitteeSize: uint64(256), SlotDuration: uint64(16), @@ -92,10 +94,11 @@ var defaultBeaconConfig = &BeaconChainConfig{ var demoBeaconConfig = &BeaconChainConfig{ MaxProposerSlashings: 16, ShardCount: 5, - DepositSize: 32, + MaxDeposit: 32, MinTopUpSize: 1, MinOnlineDepositSize: 16, Gwei: 1e9, + MaxDepositInGwei: 32 * 1e9, DepositsForChainStart: 16384, TargetCommitteeSize: uint64(3), SlotDuration: uint64(2),