Skip to content

Commit

Permalink
fix: remove needless coinbase setting
Browse files Browse the repository at this point in the history
  • Loading branch information
egonspace committed May 21, 2024
1 parent fe76fa8 commit 1fd5ec7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
}
state.AddBalance(header.Coinbase, reward)
} else {
_, rewards, err := wemixminer.CalculateRewards(
rewards, err := wemixminer.CalculateRewards(
config, header.Number, header.Fees,
func(addr common.Address, amt *big.Int) {
state.AddBalance(addr, amt)
Expand Down
13 changes: 3 additions & 10 deletions wemix/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ func distributeRewards(height *big.Int, rp *rewardParameters, blockReward *big.I
return rewards, nil
}

func calculateRewardsWithParams(config *params.ChainConfig, rp *rewardParameters, num, fees *big.Int, addBalance func(common.Address, *big.Int)) (coinbase *common.Address, rewards []byte, err error) {
func calculateRewardsWithParams(config *params.ChainConfig, rp *rewardParameters, num, fees *big.Int, addBalance func(common.Address, *big.Int)) (rewards []byte, err error) {
if (rp.staker == nil && rp.ecoSystem == nil && rp.maintenance == nil) || len(rp.members) == 0 {
// handle testnet block 94 rewards
if rewards94 := handleBlock94Rewards(num, rp, fees); rewards94 != nil {
Expand All @@ -1163,13 +1163,6 @@ func calculateRewardsWithParams(config *params.ChainConfig, rp *rewardParameters
return
}

// determine coinbase
if len(rp.members) > 0 {
mix := int(num.Int64()/rp.blocksPer) % len(rp.members)
coinbase = &common.Address{}
coinbase.SetBytes(rp.members[mix].Reward.Bytes())
}

var blockReward *big.Int
if config.IsBrioche(num) {
blockReward = config.Brioche.GetBriocheBlockReward(defaultBriocheBlockReward, num)
Expand Down Expand Up @@ -1200,15 +1193,15 @@ func calculateRewardsWithParams(config *params.ChainConfig, rp *rewardParameters
return
}

func calculateRewards(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) (*common.Address, []byte, error) {
func calculateRewards(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) ([]byte, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

rp, err := admin.getRewardParams(ctx, big.NewInt(num.Int64()-1))
if err != nil {
// all goes to the coinbase
err = wemixminer.ErrNotInitialized
return nil, nil, err
return nil, err
}

return calculateRewardsWithParams(config, rp, num, fees, addBalance)
Expand Down
6 changes: 3 additions & 3 deletions wemix/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
AmPartnerFunc func() bool
IsPartnerFunc func(string) bool
AmHubFunc func(string) int
CalculateRewardsFunc func(*params.ChainConfig, *big.Int, *big.Int, func(common.Address, *big.Int)) (*common.Address, []byte, error)
CalculateRewardsFunc func(*params.ChainConfig, *big.Int, *big.Int, func(common.Address, *big.Int)) ([]byte, error)
VerifyRewardsFunc func(*big.Int, string) error
GetCoinbaseFunc func(height *big.Int) (coinbase common.Address, err error)
SignBlockFunc func(height *big.Int, hash common.Hash) (coinbase common.Address, sig []byte, err error)
Expand Down Expand Up @@ -79,9 +79,9 @@ func IsPoW() bool {
return params.ConsensusMethod == params.ConsensusPoW
}

func CalculateRewards(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) (*common.Address, []byte, error) {
func CalculateRewards(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) ([]byte, error) {
if CalculateRewardsFunc == nil {
return nil, nil, ErrNotInitialized
return nil, ErrNotInitialized
} else {
return CalculateRewardsFunc(config, num, fees, addBalance)
}
Expand Down
4 changes: 2 additions & 2 deletions wemix/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func TestDistributeRewards(t *testing.T) {
}
}

func makeCalculateRewardFunc(rp *rewardParameters) func(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) (*common.Address, []byte, error) {
return func(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) (*common.Address, []byte, error) {
func makeCalculateRewardFunc(rp *rewardParameters) func(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) ([]byte, error) {
return func(config *params.ChainConfig, num, fees *big.Int, addBalance func(common.Address, *big.Int)) ([]byte, error) {
return calculateRewardsWithParams(config, rp, num, fees, addBalance)
}
}
Expand Down

0 comments on commit 1fd5ec7

Please sign in to comment.