miner: no need to lock the coinbase

This commit is contained in:
Marius van der Wijden 2024-03-06 13:07:18 +01:00
parent 81276b36ba
commit 4a11409cac
2 changed files with 5 additions and 12 deletions

View file

@ -65,7 +65,7 @@ var DefaultConfig = Config{
// Miner is the main object which takes care of submitting new work to consensus // Miner is the main object which takes care of submitting new work to consensus
// engine and gathering the sealing result. // engine and gathering the sealing result.
type Miner struct { type Miner struct {
confMu sync.RWMutex // The lock used to protect the config confMu sync.RWMutex // The lock used to protect the config fields: GasCeil, GasTip and Extradata
config *Config config *Config
chainConfig *params.ChainConfig chainConfig *params.ChainConfig
engine consensus.Engine engine consensus.Engine
@ -133,14 +133,10 @@ func (miner *Miner) BuildPayload(args *BuildPayloadArgs) (*Payload, error) {
// getPending retrieves the pending block based on the current head block. // getPending retrieves the pending block based on the current head block.
// The result might be nil if pending generation is failed. // The result might be nil if pending generation is failed.
func (miner *Miner) getPending() *newPayloadResult { func (miner *Miner) getPending() *newPayloadResult {
miner.confMu.RLock()
coinbase := miner.config.PendingFeeRecipient
miner.confMu.RUnlock()
header := miner.chain.CurrentHeader() header := miner.chain.CurrentHeader()
miner.pendingMu.Lock() miner.pendingMu.Lock()
defer miner.pendingMu.Unlock() defer miner.pendingMu.Unlock()
if cached := miner.pending.resolve(header.Hash(), coinbase); cached != nil { if cached := miner.pending.resolve(header.Hash()); cached != nil {
return cached return cached
} }
@ -155,7 +151,7 @@ func (miner *Miner) getPending() *newPayloadResult {
timestamp: timestamp, timestamp: timestamp,
forceTime: false, forceTime: false,
parentHash: header.Hash(), parentHash: header.Hash(),
coinbase: coinbase, coinbase: miner.config.PendingFeeRecipient,
random: common.Hash{}, random: common.Hash{},
withdrawals: withdrawal, withdrawals: withdrawal,
beaconRoot: nil, beaconRoot: nil,

View file

@ -37,10 +37,10 @@ type pending struct {
} }
// resolve retrieves the cached pending result if it's available. Nothing will be // resolve retrieves the cached pending result if it's available. Nothing will be
// returned if the parentHash/coinbase is not matched or the result is already too old. // returned if the parentHash is not matched or the result is already too old.
// //
// Note, don't modify the returned payload result. // Note, don't modify the returned payload result.
func (p *pending) resolve(parentHash common.Hash, coinbase common.Address) *newPayloadResult { func (p *pending) resolve(parentHash common.Hash) *newPayloadResult {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
@ -50,9 +50,6 @@ func (p *pending) resolve(parentHash common.Hash, coinbase common.Address) *newP
if parentHash != p.parentHash { if parentHash != p.parentHash {
return nil return nil
} }
if p.result.block.Coinbase() != coinbase {
return nil
}
if time.Since(p.created) > pendingTTL { if time.Since(p.created) > pendingTTL {
return nil return nil
} }