Skip to content

Commit

Permalink
Funds reserve when low (ethereum#850)
Browse files Browse the repository at this point in the history
* Adds isReserveLow contract helper

* Checks if the reserve needs to be funded

Co-authored-by: jfoutts-celo <57463555+jfoutts-celo@users.noreply.github.com>
  • Loading branch information
Joshua Gutow and jfoutts-celo authored Mar 2, 2020
1 parent 9e2e8d5 commit d109453
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions consensus/istanbul/backend/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ func (sb *Backend) distributeCommunityRewards(header *types.Header, state *state
if err != nil {
return totalCommunityRewards, err
}
// TODO: replace 'false' with 'isReserveLow'
if false && reserveAddress != nil {
lowReserve, err := epoch_rewards.IsReserveLow(header, state)
if err != nil {
return totalCommunityRewards, err
}
if lowReserve && reserveAddress != nil {
state.AddBalance(*reserveAddress, communityReward)
totalCommunityRewards.Add(totalCommunityRewards, communityReward)
} else if governanceAddress != nil {
Expand Down
24 changes: 24 additions & 0 deletions contract_comm/epoch_rewards/epoch_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ const epochRewardsABIString string = `[
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isReserveLow",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
`
Expand All @@ -82,3 +96,13 @@ func CalculateTargetEpochRewards(header *types.Header, state vm.StateDB) (*big.I
}
return validatorEpochReward, totalVoterRewards, totalCommunityReward, nil
}

// Determines if the reserve is below it's critical threshold
func IsReserveLow(header *types.Header, state vm.StateDB) (bool, error) {
var isLow bool
_, err := contract_comm.MakeStaticCall(params.EpochRewardsRegistryId, epochRewardsABI, "isReserveLow", []interface{}{}, &isLow, params.MaxGasForIsReserveLow, header, state)
if err != nil {
return false, err
}
return isLow, nil
}
1 change: 1 addition & 0 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,5 @@ const (
MaxGasForUpdateValidatorScore uint64 = 1 * 1000000
MaxGasForTotalSupply uint64 = 50 * 1000
MaxGasToReadErc20Balance uint64 = 100000
MaxGasForIsReserveLow uint64 = 1000000
)

0 comments on commit d109453

Please sign in to comment.