|
|
@ -287,7 +287,7 @@ func AccumulateRewardsAndCountSigs( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reader, err := distributeRewardAfterAggregateEpoch(bc, state, header, beaconChain, defaultReward) |
|
|
|
_, reader, err := distributeRewardAfterAggregateEpoch(bc, state, header, beaconChain, defaultReward) |
|
|
|
return numeric.ZeroDec(), reader, err |
|
|
|
return numeric.ZeroDec(), reader, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -304,13 +304,17 @@ func waitForCommitSigs(sigsReady chan bool) error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func distributeRewardAfterAggregateEpoch( |
|
|
|
func distributeRewardAfterAggregateEpoch(bc engine.ChainReader, state *state.DB, header *block.Header, beaconChain engine.ChainReader, |
|
|
|
bc engine.ChainReader, |
|
|
|
rewardToDistribute numeric.Dec) (numeric.Dec, reward.Reader, error) { |
|
|
|
state *state.DB, |
|
|
|
epoch := header.Epoch() |
|
|
|
header *block.Header, |
|
|
|
defaultReward := rewardToDistribute |
|
|
|
beaconChain engine.ChainReader, |
|
|
|
remainingReward := numeric.ZeroDec() |
|
|
|
defaultReward numeric.Dec, |
|
|
|
if bc.Config().IsHIP30(epoch) { |
|
|
|
) (reward.Reader, error) { |
|
|
|
fractionToRecovery := shard.Schedule.InstanceForEpoch(epoch).HIP30EmissionFraction() |
|
|
|
|
|
|
|
fractionToValidators := numeric.OneDec().Sub(fractionToRecovery) |
|
|
|
|
|
|
|
defaultReward = rewardToDistribute.Mul(fractionToValidators) |
|
|
|
|
|
|
|
remainingReward = rewardToDistribute.Mul(fractionToRecovery) |
|
|
|
|
|
|
|
} |
|
|
|
newRewards, payouts := |
|
|
|
newRewards, payouts := |
|
|
|
big.NewInt(0), []reward.Payout{} |
|
|
|
big.NewInt(0), []reward.Payout{} |
|
|
|
|
|
|
|
|
|
|
@ -341,7 +345,7 @@ func distributeRewardAfterAggregateEpoch( |
|
|
|
if cxLinks := curHeader.CrossLinks(); len(cxLinks) > 0 { |
|
|
|
if cxLinks := curHeader.CrossLinks(); len(cxLinks) > 0 { |
|
|
|
crossLinks := types.CrossLinks{} |
|
|
|
crossLinks := types.CrossLinks{} |
|
|
|
if err := rlp.DecodeBytes(cxLinks, &crossLinks); err != nil { |
|
|
|
if err := rlp.DecodeBytes(cxLinks, &crossLinks); err != nil { |
|
|
|
return network.EmptyPayout, err |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
allCrossLinks = append(allCrossLinks, crossLinks...) |
|
|
|
allCrossLinks = append(allCrossLinks, crossLinks...) |
|
|
|
} |
|
|
|
} |
|
|
@ -356,7 +360,7 @@ func distributeRewardAfterAggregateEpoch( |
|
|
|
payables, _, err := processOneCrossLink(bc, state, cxLink, defaultReward, i) |
|
|
|
payables, _, err := processOneCrossLink(bc, state, cxLink, defaultReward, i) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return network.EmptyPayout, err |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
allPayables = append(allPayables, payables...) |
|
|
|
allPayables = append(allPayables, payables...) |
|
|
@ -395,14 +399,14 @@ func distributeRewardAfterAggregateEpoch( |
|
|
|
for _, addr := range allAddresses { |
|
|
|
for _, addr := range allAddresses { |
|
|
|
snapshot, err := bc.ReadValidatorSnapshot(addr) |
|
|
|
snapshot, err := bc.ReadValidatorSnapshot(addr) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return network.EmptyPayout, err |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
due := allValidatorPayable[addr] |
|
|
|
due := allValidatorPayable[addr] |
|
|
|
newRewards.Add(newRewards, due) |
|
|
|
newRewards.Add(newRewards, due) |
|
|
|
|
|
|
|
|
|
|
|
shares, err := lookupDelegatorShares(snapshot) |
|
|
|
shares, err := lookupDelegatorShares(snapshot) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return network.EmptyPayout, err |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
if err := state.AddReward( |
|
|
|
if err := state.AddReward( |
|
|
|
snapshot.Validator, |
|
|
|
snapshot.Validator, |
|
|
@ -415,7 +419,7 @@ func distributeRewardAfterAggregateEpoch( |
|
|
|
// and delegations pruned afterwards
|
|
|
|
// and delegations pruned afterwards
|
|
|
|
bc.Config().IsNoNilDelegations(header.Epoch()), |
|
|
|
bc.Config().IsNoNilDelegations(header.Epoch()), |
|
|
|
); err != nil { |
|
|
|
); err != nil { |
|
|
|
return network.EmptyPayout, err |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|