|
|
@ -270,7 +270,8 @@ func AccumulateRewardsAndCountSigs( |
|
|
|
|
|
|
|
|
|
|
|
// Handle rewards on pre-aggregated rewards era.
|
|
|
|
// Handle rewards on pre-aggregated rewards era.
|
|
|
|
if !bc.Config().IsAggregatedRewardEpoch(header.Epoch()) { |
|
|
|
if !bc.Config().IsAggregatedRewardEpoch(header.Epoch()) { |
|
|
|
return distributeRewardBeforeAggregateEpoch(bc, state, header, beaconChain, defaultReward, sigsReady) |
|
|
|
reader, err := distributeRewardBeforeAggregateEpoch(bc, state, header, beaconChain, defaultReward, sigsReady) |
|
|
|
|
|
|
|
return numeric.ZeroDec(), reader, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Aggregated Rewards Era: Rewards are aggregated every 64 blocks.
|
|
|
|
// Aggregated Rewards Era: Rewards are aggregated every 64 blocks.
|
|
|
@ -285,7 +286,8 @@ func AccumulateRewardsAndCountSigs( |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, nil |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return distributeRewardAfterAggregateEpoch(bc, state, header, beaconChain, defaultReward) |
|
|
|
_, reader, err := distributeRewardAfterAggregateEpoch(bc, state, header, beaconChain, defaultReward) |
|
|
|
|
|
|
|
return numeric.ZeroDec(), reader, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func waitForCommitSigs(sigsReady chan bool) error { |
|
|
|
func waitForCommitSigs(sigsReady chan bool) error { |
|
|
@ -405,21 +407,39 @@ func distributeRewardAfterAggregateEpoch(bc engine.ChainReader, state *state.DB, |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
if err := state.AddReward(snapshot.Validator, due, shares); err != nil { |
|
|
|
if err := state.AddReward( |
|
|
|
|
|
|
|
snapshot.Validator, |
|
|
|
|
|
|
|
due, |
|
|
|
|
|
|
|
shares, |
|
|
|
|
|
|
|
// epoch prior to no nil delegations
|
|
|
|
|
|
|
|
// block 32767 -> snapshot saved, rewards paid
|
|
|
|
|
|
|
|
// in no nil delegations epoch
|
|
|
|
|
|
|
|
// block 1 -> rewards not paid (unless schedule changes),
|
|
|
|
|
|
|
|
// and delegations pruned afterwards
|
|
|
|
|
|
|
|
bc.Config().IsNoNilDelegations(header.Epoch()), |
|
|
|
|
|
|
|
); err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTimeLocal).Milliseconds()).Msg("After Chain Reward (AddReward)") |
|
|
|
|
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("After Chain Reward") |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Since(startTimeLocal).Milliseconds()).Msg("After Chain Reward (AddReward)") |
|
|
|
|
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Since(startTime).Milliseconds()).Msg("After Chain Reward") |
|
|
|
|
|
|
|
|
|
|
|
// remainingReward needs to be multipled with the number of crosslinks across all shards
|
|
|
|
// remainingReward needs to be multipled with the number of crosslinks across all shards
|
|
|
|
|
|
|
|
|
|
|
|
return remainingReward.MulInt(big.NewInt(int64(len(allCrossLinks)))), network.NewStakingEraRewardForRound( |
|
|
|
return remainingReward.MulInt(big.NewInt(int64(len(allCrossLinks)))), network.NewStakingEraRewardForRound( |
|
|
|
newRewards, payouts, |
|
|
|
newRewards, payouts, |
|
|
|
), nil |
|
|
|
), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB, header *block.Header, beaconChain engine.ChainReader, |
|
|
|
func distributeRewardBeforeAggregateEpoch( |
|
|
|
defaultReward numeric.Dec, sigsReady chan bool) (numeric.Dec, reward.Reader, error) { |
|
|
|
bc engine.ChainReader, |
|
|
|
|
|
|
|
state *state.DB, |
|
|
|
|
|
|
|
header *block.Header, |
|
|
|
|
|
|
|
beaconChain engine.ChainReader, |
|
|
|
|
|
|
|
defaultReward numeric.Dec, |
|
|
|
|
|
|
|
sigsReady chan bool, |
|
|
|
|
|
|
|
) (reward.Reader, error) { |
|
|
|
newRewards, payouts := |
|
|
|
newRewards, payouts := |
|
|
|
big.NewInt(0), []reward.Payout{} |
|
|
|
big.NewInt(0), []reward.Payout{} |
|
|
|
|
|
|
|
|
|
|
@ -429,9 +449,9 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
startTime := time.Now() |
|
|
|
startTime := time.Now() |
|
|
|
crossLinks := types.CrossLinks{} |
|
|
|
crossLinks := types.CrossLinks{} |
|
|
|
if err := rlp.DecodeBytes(cxLinks, &crossLinks); err != nil { |
|
|
|
if err := rlp.DecodeBytes(cxLinks, &crossLinks); err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("Decode Cross Links") |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Since(startTime).Milliseconds()).Msg("Decode Cross Links") |
|
|
|
|
|
|
|
|
|
|
|
startTime = time.Now() |
|
|
|
startTime = time.Now() |
|
|
|
for i := range crossLinks { |
|
|
|
for i := range crossLinks { |
|
|
@ -439,7 +459,7 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
payables, _, err := processOneCrossLink(bc, state, cxLink, defaultReward, i) |
|
|
|
payables, _, err := processOneCrossLink(bc, state, cxLink, defaultReward, i) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
allPayables = append(allPayables, payables...) |
|
|
|
allPayables = append(allPayables, payables...) |
|
|
@ -473,17 +493,17 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
payable.EcdsaAddress, |
|
|
|
payable.EcdsaAddress, |
|
|
|
) |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
due := resultsHandle[bucket][payThem].payout |
|
|
|
due := resultsHandle[bucket][payThem].payout |
|
|
|
newRewards.Add(newRewards, due) |
|
|
|
newRewards.Add(newRewards, due) |
|
|
|
|
|
|
|
|
|
|
|
shares, err := lookupDelegatorShares(snapshot) |
|
|
|
shares, err := lookupDelegatorShares(snapshot) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
if err := state.AddReward(snapshot.Validator, due, shares); err != nil { |
|
|
|
if err := state.AddReward(snapshot.Validator, due, shares, bc.Config().IsNoNilDelegations(header.Epoch())); err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
payouts = append(payouts, reward.Payout{ |
|
|
|
payouts = append(payouts, reward.Payout{ |
|
|
|
Addr: payable.EcdsaAddress, |
|
|
|
Addr: payable.EcdsaAddress, |
|
|
@ -492,21 +512,21 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTimeLocal).Milliseconds()).Msg("Shard Chain Reward (AddReward)") |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Since(startTimeLocal).Milliseconds()).Msg("Shard Chain Reward (AddReward)") |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("Shard Chain Reward") |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Since(startTime).Milliseconds()).Msg("Shard Chain Reward") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Block here until the commit sigs are ready or timeout.
|
|
|
|
// Block here until the commit sigs are ready or timeout.
|
|
|
|
// sigsReady signal indicates that the commit sigs are already populated in the header object.
|
|
|
|
// sigsReady signal indicates that the commit sigs are already populated in the header object.
|
|
|
|
if err := waitForCommitSigs(sigsReady); err != nil { |
|
|
|
if err := waitForCommitSigs(sigsReady); err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
startTime := time.Now() |
|
|
|
startTime := time.Now() |
|
|
|
// Take care of my own beacon chain committee, _ is missing, for slashing
|
|
|
|
// Take care of my own beacon chain committee, _ is missing, for slashing
|
|
|
|
parentE, members, payable, missing, err := ballotResultBeaconchain(beaconChain, header) |
|
|
|
parentE, members, payable, missing, err := ballotResultBeaconchain(beaconChain, header) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, errors.Wrapf(err, "shard 0 block %d reward error with bitmap %x", header.Number(), header.LastCommitBitmap()) |
|
|
|
return network.EmptyPayout, errors.Wrapf(err, "shard 0 block %d reward error with bitmap %x", header.Number(), header.LastCommitBitmap()) |
|
|
|
} |
|
|
|
} |
|
|
|
subComm := shard.Committee{ShardID: shard.BeaconChainShardID, Slots: members} |
|
|
|
subComm := shard.Committee{ShardID: shard.BeaconChainShardID, Slots: members} |
|
|
|
|
|
|
|
|
|
|
@ -517,13 +537,13 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
payable, |
|
|
|
payable, |
|
|
|
missing, |
|
|
|
missing, |
|
|
|
); err != nil { |
|
|
|
); err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
votingPower, err := lookupVotingPower( |
|
|
|
votingPower, err := lookupVotingPower( |
|
|
|
parentE, &subComm, |
|
|
|
parentE, &subComm, |
|
|
|
) |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
allSignersShare := numeric.ZeroDec() |
|
|
|
allSignersShare := numeric.ZeroDec() |
|
|
@ -540,7 +560,7 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
if !voter.IsHarmonyNode { |
|
|
|
if !voter.IsHarmonyNode { |
|
|
|
snapshot, err := bc.ReadValidatorSnapshot(voter.EarningAccount) |
|
|
|
snapshot, err := bc.ReadValidatorSnapshot(voter.EarningAccount) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
due := defaultReward.Mul( |
|
|
|
due := defaultReward.Mul( |
|
|
|
voter.OverallPercent.Quo(allSignersShare), |
|
|
|
voter.OverallPercent.Quo(allSignersShare), |
|
|
@ -549,10 +569,10 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
|
|
|
|
|
|
|
|
shares, err := lookupDelegatorShares(snapshot) |
|
|
|
shares, err := lookupDelegatorShares(snapshot) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
if err := state.AddReward(snapshot.Validator, due, shares); err != nil { |
|
|
|
if err := state.AddReward(snapshot.Validator, due, shares, bc.Config().IsNoNilDelegations(header.Epoch())); err != nil { |
|
|
|
return numeric.ZeroDec(), network.EmptyPayout, err |
|
|
|
return network.EmptyPayout, err |
|
|
|
} |
|
|
|
} |
|
|
|
payouts = append(payouts, reward.Payout{ |
|
|
|
payouts = append(payouts, reward.Payout{ |
|
|
|
Addr: voter.EarningAccount, |
|
|
|
Addr: voter.EarningAccount, |
|
|
@ -561,9 +581,9 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("Beacon Chain Reward") |
|
|
|
utils.Logger().Debug().Int64("elapsed time", time.Since(startTime).Milliseconds()).Msg("Beacon Chain Reward") |
|
|
|
|
|
|
|
|
|
|
|
return numeric.ZeroDec(), network.NewStakingEraRewardForRound( |
|
|
|
return network.NewStakingEraRewardForRound( |
|
|
|
newRewards, payouts, |
|
|
|
newRewards, payouts, |
|
|
|
), nil |
|
|
|
), nil |
|
|
|
} |
|
|
|
} |
|
|
|