From 3106c87bb5920e9b675ae15aac7beb67ec750ad5 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Tue, 19 Nov 2019 12:15:58 -0800 Subject: [PATCH] Fix a bigInt cmp bug --- staking/types/delegation.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/staking/types/delegation.go b/staking/types/delegation.go index 6fc8c5668..04ddb602a 100644 --- a/staking/types/delegation.go +++ b/staking/types/delegation.go @@ -13,6 +13,11 @@ var ( errInvalidAmount = errors.New("Invalid amount, must be positive") ) +const ( + // The number of epochs a undelegated token needs to be before it's released to the delegator's balance + LockPeriodInEpoch = 14 +) + // Delegation represents the bond with tokens held by an account. It is // owned by one delegator, and is associated with the voting power of one // validator. @@ -99,7 +104,7 @@ func (d *Delegation) RemoveUnlockedUndelegations(curEpoch *big.Int) *big.Int { totalWithdraw := big.NewInt(0) count := 0 for j := range d.Entries { - if curEpoch.Cmp(d.Entries[j].Epoch) > 14 { // need to wait at least 14 epochs to withdraw; + if big.NewInt(0).Sub(curEpoch, d.Entries[j].Epoch).Int64() > LockPeriodInEpoch { // need to wait at least 14 epochs to withdraw; totalWithdraw.Add(totalWithdraw, d.Entries[j].Amount) count++ } else {