Fix max churn bug (#2121)

This commit is contained in:
Preston Van Loon 2019-03-31 11:47:38 -05:00 committed by Nishant Das
parent 02f9a56513
commit 6b3df2f776
2 changed files with 6 additions and 5 deletions

View File

@ -529,7 +529,7 @@ func allValidatorsIndices(state *pb.BeaconState) []uint64 {
// MAX_DEPOSIT_AMOUNT,
// total_balance // (2 * MAX_BALANCE_CHURN_QUOTIENT))
func maxBalanceChurn(totalBalance uint64) uint64 {
maxBalanceChurn := totalBalance / 2 * params.BeaconConfig().MaxBalanceChurnQuotient
maxBalanceChurn := totalBalance / (2 * params.BeaconConfig().MaxBalanceChurnQuotient)
if maxBalanceChurn > params.BeaconConfig().MaxDepositAmount {
return maxBalanceChurn
}

View File

@ -586,14 +586,15 @@ func TestUpdateRegistry_Exits(t *testing.T) {
}
func TestMaxBalanceChurn_OK(t *testing.T) {
maxDepositAmount := params.BeaconConfig().MaxDepositAmount
tests := []struct {
totalBalance uint64
maxBalanceChurn uint64
}{
{totalBalance: 1e9, maxBalanceChurn: params.BeaconConfig().MaxDepositAmount},
{totalBalance: params.BeaconConfig().MaxDepositAmount, maxBalanceChurn: 512 * 1e9},
{totalBalance: params.BeaconConfig().MaxDepositAmount * 10, maxBalanceChurn: 512 * 1e10},
{totalBalance: params.BeaconConfig().MaxDepositAmount * 1000, maxBalanceChurn: 512 * 1e12},
{totalBalance: 1e9, maxBalanceChurn: maxDepositAmount},
{totalBalance: maxDepositAmount, maxBalanceChurn: maxDepositAmount},
{totalBalance: maxDepositAmount * 10, maxBalanceChurn: maxDepositAmount},
{totalBalance: params.BeaconConfig().MaxDepositAmount * 1000, maxBalanceChurn: 5 * 1e11},
}
for _, tt := range tests {