|
|
|
@ -48,12 +48,12 @@ var ( |
|
|
|
|
|
|
|
|
|
func expectedRewardPerYear( |
|
|
|
|
now, oneEpochAgo *block.Header, |
|
|
|
|
curValidator, snapshotLastEpoch *staking.ValidatorWrapper, |
|
|
|
|
wrapper, snapshot *staking.ValidatorWrapper, |
|
|
|
|
) (*big.Int, error) { |
|
|
|
|
timeNow, oneTAgo := now.Time(), oneEpochAgo.Time() |
|
|
|
|
diffTime, diffReward := |
|
|
|
|
new(big.Int).Sub(timeNow, oneTAgo), |
|
|
|
|
new(big.Int).Sub(curValidator.BlockReward, snapshotLastEpoch.BlockReward) |
|
|
|
|
new(big.Int).Sub(wrapper.BlockReward, snapshot.BlockReward) |
|
|
|
|
|
|
|
|
|
// impossibility but keep sane
|
|
|
|
|
if diffTime.Sign() == -1 { |
|
|
|
@ -66,7 +66,7 @@ func expectedRewardPerYear( |
|
|
|
|
// TODO some more sanity checks of some sort?
|
|
|
|
|
expectedValue := new(big.Int).Div(diffReward, diffTime) |
|
|
|
|
expectedPerYear := new(big.Int).Mul(expectedValue, oneYear) |
|
|
|
|
utils.Logger().Info().Interface("now", curValidator).Interface("before", snapshotLastEpoch). |
|
|
|
|
utils.Logger().Info().Interface("now", wrapper).Interface("before", snapshot). |
|
|
|
|
Uint64("diff-reward", diffReward.Uint64()). |
|
|
|
|
Uint64("diff-time", diffTime.Uint64()). |
|
|
|
|
Interface("expected-value", expectedValue). |
|
|
|
@ -79,7 +79,7 @@ func expectedRewardPerYear( |
|
|
|
|
func ComputeForValidator( |
|
|
|
|
bc Reader, |
|
|
|
|
block *types.Block, |
|
|
|
|
validatorNow *staking.ValidatorWrapper, |
|
|
|
|
wrapper *staking.ValidatorWrapper, |
|
|
|
|
) (*numeric.Dec, error) { |
|
|
|
|
oneEpochAgo, zero := |
|
|
|
|
new(big.Int).Sub(block.Epoch(), common.Big1), |
|
|
|
@ -90,9 +90,9 @@ func ComputeForValidator( |
|
|
|
|
Uint64("one-epoch-ago", oneEpochAgo.Uint64()). |
|
|
|
|
Msg("apr - begin compute for validator ") |
|
|
|
|
|
|
|
|
|
oneSnapshotAgo, err := bc.ReadValidatorSnapshotAtEpoch( |
|
|
|
|
oneEpochAgo, |
|
|
|
|
validatorNow.Address, |
|
|
|
|
snapshot, err := bc.ReadValidatorSnapshotAtEpoch( |
|
|
|
|
block.Epoch(), |
|
|
|
|
wrapper.Address, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
@ -123,7 +123,7 @@ func ComputeForValidator( |
|
|
|
|
|
|
|
|
|
estimatedRewardPerYear, err := expectedRewardPerYear( |
|
|
|
|
block.Header(), headerOneEpochAgo, |
|
|
|
|
validatorNow, oneSnapshotAgo.Validator, |
|
|
|
|
wrapper, snapshot.Validator, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
@ -134,7 +134,7 @@ func ComputeForValidator( |
|
|
|
|
return &zero, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
total := numeric.NewDecFromBigInt(oneSnapshotAgo.Validator.TotalDelegation()) |
|
|
|
|
total := numeric.NewDecFromBigInt(snapshot.Validator.TotalDelegation()) |
|
|
|
|
if total.IsZero() { |
|
|
|
|
return nil, errors.Wrapf( |
|
|
|
|
ErrZeroStakeOneEpochAgo, |
|
|
|
|