Fix a bigInt cmp bug

pull/1836/head
Rongjian Lan 5 years ago
parent 0c01b58f8a
commit 3106c87bb5
  1. 7
      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 {

Loading…
Cancel
Save