use snapshot total delegation instead of current total delegation

pull/3054/head
Ganesha Upadhyaya 5 years ago committed by Leo Chen
parent 9663128d0a
commit c0d84f7a30
  1. 13
      staking/apr/compute.go

@ -20,6 +20,8 @@ var (
ErrInsufficientEpoch = errors.New("insufficient past epochs to compute apr") ErrInsufficientEpoch = errors.New("insufficient past epochs to compute apr")
// ErrCouldNotRetreiveHeaderByNumber is returned when fail to retrieve header by number // ErrCouldNotRetreiveHeaderByNumber is returned when fail to retrieve header by number
ErrCouldNotRetreiveHeaderByNumber = errors.New("could not retrieve header by number") ErrCouldNotRetreiveHeaderByNumber = errors.New("could not retrieve header by number")
// ErrZeroStakeOneEpochAgo is returned when total delegation is zero for one epoch ago
ErrZeroStakeOneEpochAgo = errors.New("zero total delegation one epoch ago")
) )
// Reader .. // Reader ..
@ -132,7 +134,16 @@ func ComputeForValidator(
return &zero, nil return &zero, nil
} }
total := numeric.NewDecFromBigInt(validatorNow.TotalDelegation()) total := numeric.NewDecFromBigInt(oneSnapshotAgo.Validator.TotalDelegation())
if total.IsZero() {
return nil, errors.Wrapf(
ErrZeroStakeOneEpochAgo,
"current epoch %d, one-epoch-ago %d",
block.Epoch().Uint64(),
oneEpochAgo.Uint64(),
)
}
result := numeric.NewDecFromBigInt(estimatedRewardPerYear).Quo( result := numeric.NewDecFromBigInt(estimatedRewardPerYear).Quo(
total, total,
) )

Loading…
Cancel
Save