From c4e48f80665cd6f26fba281d7076d4cdcf96b8eb Mon Sep 17 00:00:00 2001 From: GalaIO Date: Fri, 26 Apr 2024 17:08:15 +0800 Subject: [PATCH] chore: add metric & log for blobTx; --- core/blockchain_insert.go | 8 +++++++- core/data_availability.go | 10 ++++++++++ miner/worker.go | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go index fafe684aa1..4b3c0af023 100644 --- a/core/blockchain_insert.go +++ b/core/blockchain_insert.go @@ -52,12 +52,18 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn for _, block := range chain[st.lastIndex : index+1] { txs += len(block.Transactions()) } + var blobs int + for _, block := range chain[st.lastIndex : index+1] { + for _, sidecar := range block.Sidecars() { + blobs += len(sidecar.Blobs) + } + } end := chain[index] // Assemble the log context and send it to the logger context := []interface{}{ "number", end.Number(), "hash", end.Hash(), "miner", end.Coinbase(), - "blocks", st.processed, "txs", txs, "mgas", float64(st.usedGas) / 1000000, + "blocks", st.processed, "txs", txs, "blobs", blobs, "mgas", float64(st.usedGas) / 1000000, "elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed), } if timestamp := time.Unix(int64(end.Time()), 0); time.Since(timestamp) > time.Minute { diff --git a/core/data_availability.go b/core/data_availability.go index cd8e58a147..09b2898e28 100644 --- a/core/data_availability.go +++ b/core/data_availability.go @@ -4,7 +4,9 @@ import ( "crypto/sha256" "errors" "fmt" + "github.com/ethereum/go-ethereum/metrics" "sync" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/gopool" @@ -14,6 +16,10 @@ import ( "github.com/ethereum/go-ethereum/params" ) +var ( + daCheckTimer = metrics.NewRegisteredTimer("chain/dacheck", nil) +) + // validateBlobSidecar it is same as validateBlobSidecar in core/txpool/validation.go func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobSidecar) error { if len(sidecar.Blobs) != len(hashes) { @@ -46,6 +52,10 @@ func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobSidecar) error // IsDataAvailable it checks that the blobTx block has available blob data func IsDataAvailable(chain consensus.ChainHeaderReader, block *types.Block) (err error) { + defer func(start time.Time) { + daCheckTimer.Update(time.Since(start)) + }(time.Now()) + // refer logic in ValidateBody if !chain.Config().IsCancun(block.Number(), block.Time()) { if block.Sidecars() != nil { diff --git a/miner/worker.go b/miner/worker.go index 2cc2ff00ab..43b08622e9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -115,6 +115,7 @@ func (env *environment) copy() *environment { if env.sidecars != nil { cpy.sidecars = make(types.BlobSidecars, len(env.sidecars)) copy(cpy.sidecars, env.sidecars) + cpy.blobs = env.blobs } return cpy @@ -1420,7 +1421,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti select { case w.taskCh <- &task{receipts: receipts, state: env.state, block: block, createdAt: time.Now()}: log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()), - "txs", env.tcount, "gas", block.GasUsed(), "fees", feesInEther, "elapsed", common.PrettyDuration(time.Since(start))) + "txs", env.tcount, "blobs", env.blobs, "gas", block.GasUsed(), "fees", feesInEther, "elapsed", common.PrettyDuration(time.Since(start))) case <-w.exitCh: log.Info("Worker has exited")