From 08fb1aade6f8053f7b929d154db2a3c824779ac5 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 3 Nov 2022 22:18:28 +0800 Subject: [PATCH] miner: display change in fees, change recommit period (#26097) * miner: add logs for displaying fees change * miner: simplify feesInEther calculation * miner: fix lock * miner: change to default recommit to 2 seconds --- miner/miner.go | 11 ++++++++--- miner/payload_building.go | 20 +++++++++++++------- miner/worker.go | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/miner/miner.go b/miner/miner.go index c2a9e07d04..5102cb523c 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -60,9 +60,14 @@ type Config struct { // DefaultConfig contains default settings for miner. var DefaultConfig = Config{ - GasCeil: 30000000, - GasPrice: big.NewInt(params.GWei), - Recommit: 3 * time.Second, + GasCeil: 30000000, + GasPrice: big.NewInt(params.GWei), + + // The default recommit time is chosen as two seconds since + // consensus-layer usually will wait a half slot of time(6s) + // for payload generation. It should be enough for Geth to + // run 3 rounds. + Recommit: 2 * time.Second, NewPayloadTimeout: 2 * time.Second, } diff --git a/miner/payload_building.go b/miner/payload_building.go index 18a74ceae3..cdea6a3cc3 100644 --- a/miner/payload_building.go +++ b/miner/payload_building.go @@ -24,6 +24,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/beacon" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" ) // BuildPayloadArgs contains the provided parameters for building payload. @@ -46,23 +48,22 @@ type Payload struct { full *types.Block fullFees *big.Int stop chan struct{} - lock *sync.Mutex + lock sync.Mutex cond *sync.Cond } // newPayload initializes the payload object. func newPayload(empty *types.Block) *Payload { - lock := new(sync.Mutex) - return &Payload{ + payload := &Payload{ empty: empty, stop: make(chan struct{}), - lock: lock, - cond: sync.NewCond(lock), } + payload.cond = sync.NewCond(&payload.lock) + return payload } // update updates the full-block with latest built version. -func (payload *Payload) update(block *types.Block, fees *big.Int) { +func (payload *Payload) update(block *types.Block, fees *big.Int, elapsed time.Duration) { payload.lock.Lock() defer payload.lock.Unlock() @@ -77,6 +78,10 @@ func (payload *Payload) update(block *types.Block, fees *big.Int) { if payload.full == nil || fees.Cmp(payload.fullFees) > 0 { payload.full = block payload.fullFees = fees + + feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether)) + log.Info("Updated payload", "number", block.NumberU64(), "hash", block.Hash(), + "txs", len(block.Transactions()), "gas", block.GasUsed(), "fees", feesInEther, "elapsed", common.PrettyDuration(elapsed)) } payload.cond.Broadcast() // fire signal for notifying full block } @@ -152,9 +157,10 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) { for { select { case <-timer.C: + start := time.Now() block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, false) if err == nil { - payload.update(block, fees) + payload.update(block, fees, time.Since(start)) } timer.Reset(w.recommit) case <-payload.stop: diff --git a/miner/worker.go b/miner/worker.go index 720613cb2e..5e3c3f22b5 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1196,7 +1196,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti w.unconfirmed.Shift(block.NumberU64() - 1) fees := totalFees(block, env.receipts) - feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), new(big.Float).SetInt(big.NewInt(params.Ether))) + feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether)) log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()), "uncles", len(env.uncles), "txs", env.tcount, "gas", block.GasUsed(), "fees", feesInEther,