From 1fd5ec7dd4dc2436b85dc6d7ab64c331e84baeb7 Mon Sep 17 00:00:00 2001 From: egonspace Date: Tue, 21 May 2024 09:54:27 +0900 Subject: [PATCH] fix: remove needless coinbase setting --- consensus/ethash/consensus.go | 2 +- wemix/admin.go | 13 +++---------- wemix/miner/miner.go | 6 +++--- wemix/rewards_test.go | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 72a25ff51c42..535d5b6c344e 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -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) diff --git a/wemix/admin.go b/wemix/admin.go index b3b0a92e1191..b2a3b0b9e52c 100644 --- a/wemix/admin.go +++ b/wemix/admin.go @@ -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 { @@ -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) @@ -1200,7 +1193,7 @@ 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() @@ -1208,7 +1201,7 @@ func calculateRewards(config *params.ChainConfig, num, fees *big.Int, addBalance 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) diff --git a/wemix/miner/miner.go b/wemix/miner/miner.go index 0b369b3b063c..339cb9f0e57c 100644 --- a/wemix/miner/miner.go +++ b/wemix/miner/miner.go @@ -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) @@ -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) } diff --git a/wemix/rewards_test.go b/wemix/rewards_test.go index b26279d507ad..d989116e79ab 100644 --- a/wemix/rewards_test.go +++ b/wemix/rewards_test.go @@ -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) } }