Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if epoch rewards are frozen and avoid putting errors in the logs #839

Merged
merged 16 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ func (sb *Backend) Finalize(chain consensus.ChainReader, header *types.Header, s
snapshot = state.Snapshot()
err = sb.distributeEpochRewards(header, state)
if err != nil {
sb.logger.Error("Failed to distribute epoch rewards", "blockNumber", header.Number, "err", err)
state.RevertToSnapshot(snapshot)
}
}
Expand Down
15 changes: 13 additions & 2 deletions consensus/istanbul/backend/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ import (
func (sb *Backend) distributeEpochRewards(header *types.Header, state *state.StateDB) error {
start := time.Now()
defer sb.rewardDistributionTimer.UpdateSince(start)
logger := sb.logger.New("func", "Backend.distributeEpochPaymentsAndRewards", "blocknum", header.Number.Uint64())

// Check if reward distribution has been frozen and return early without error if it is.
if frozen, err := epoch_rewards.EpochRewardsIsFrozen(header, state); err != nil {
logger.Warn("Failed to determine if epoch rewards are frozen", "err", err)
} else if frozen {
logger.Debug("Epoch rewards are frozen, skipping distribution")
return nil
}

err := epoch_rewards.UpdateTargetVotingYield(header, state)
if err != nil {
Expand All @@ -50,14 +59,16 @@ func (sb *Backend) distributeEpochRewards(header *types.Header, state *state.Sta
if err != nil {
return err
}
log.Debug("Calculated target rewards", "validatorReward", validatorReward, "totalVoterRewards", totalVoterRewards, "communityReward", communityReward)

logger.Debug("Calculated target rewards", "validatorReward", validatorReward, "totalVoterRewards", totalVoterRewards, "communityReward", communityReward)

// The validator set that signs off on the last block of the epoch is the one that we need to
// iterate over.
valSet := sb.GetValidators(big.NewInt(header.Number.Int64()-1), header.ParentHash)
if len(valSet) == 0 {

err := errors.New("Unable to fetch validator set to update scores and distribute rewards")
sb.logger.Error(err.Error())
logger.Error(err.Error())
return err
}

Expand Down
23 changes: 23 additions & 0 deletions contract_comm/epoch_rewards/epoch_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ const epochRewardsABIString string = `[
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "frozen",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
`
Expand Down Expand Up @@ -135,3 +149,12 @@ func GetCarbonOffsettingPartnerAddress(header *types.Header, state vm.StateDB) (
}
return carbonOffsettingPartner, nil
}

func EpochRewardsIsFrozen(header *types.Header, state vm.StateDB) (bool, error) {
var frozen bool
_, err := contract_comm.MakeStaticCall(params.EpochRewardsRegistryId, epochRewardsABI, "frozen", []interface{}{}, &[]interface{}{&frozen}, params.MaxGasForIsFrozen, header, state)
if err != nil {
return false, err
}
return frozen, nil
}