mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
feat: add metrics in L1 message iterator (#527)
* feat: add metrics in L1 message iterator * add L1 message size metric
This commit is contained in:
parent
fe8232a40f
commit
751dbda234
3 changed files with 28 additions and 4 deletions
|
|
@ -4,14 +4,26 @@ import (
|
|||
"bytes"
|
||||
"encoding/binary"
|
||||
"math/big"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/scroll-tech/go-ethereum/common"
|
||||
"github.com/scroll-tech/go-ethereum/core/types"
|
||||
"github.com/scroll-tech/go-ethereum/ethdb"
|
||||
"github.com/scroll-tech/go-ethereum/log"
|
||||
"github.com/scroll-tech/go-ethereum/metrics"
|
||||
"github.com/scroll-tech/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
var (
|
||||
// L1 message iterator metrics
|
||||
iteratorNextCalledCounter = metrics.NewRegisteredCounter("rawdb/l1_message/iterator/next_called", nil)
|
||||
iteratorInnerNextCalledCounter = metrics.NewRegisteredCounter("rawdb/l1_message/iterator/inner_next_called", nil)
|
||||
iteratorLengthMismatchCounter = metrics.NewRegisteredCounter("rawdb/l1_message/iterator/length_mismatch", nil)
|
||||
iteratorNextDurationTimer = metrics.NewRegisteredTimer("rawdb/l1_message/iterator/next_time", nil)
|
||||
iteratorL1MessageSizeGauge = metrics.NewRegisteredGauge("rawdb/l1_message/size", nil)
|
||||
)
|
||||
|
||||
// WriteSyncedL1BlockNumber writes the highest synced L1 block number to the database.
|
||||
func WriteSyncedL1BlockNumber(db ethdb.KeyValueWriter, L1BlockNumber uint64) {
|
||||
value := big.NewInt(0).SetUint64(L1BlockNumber).Bytes()
|
||||
|
|
@ -148,10 +160,20 @@ func IterateL1MessagesFrom(db ethdb.Database, fromQueueIndex uint64) L1MessageIt
|
|||
// It returns false when the iterator is exhausted.
|
||||
// TODO: Consider reading items in batches.
|
||||
func (it *L1MessageIterator) Next() bool {
|
||||
iteratorNextCalledCounter.Inc(1)
|
||||
|
||||
defer func(t0 time.Time) {
|
||||
iteratorNextDurationTimer.Update(time.Since(t0))
|
||||
}(time.Now())
|
||||
|
||||
for it.inner.Next() {
|
||||
iteratorInnerNextCalledCounter.Inc(1)
|
||||
|
||||
key := it.inner.Key()
|
||||
if len(key) == it.keyLength {
|
||||
return true
|
||||
} else {
|
||||
iteratorLengthMismatchCounter.Inc(1)
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
|
@ -207,6 +229,8 @@ func ReadL1MessagesFrom(db ethdb.Database, startIndex, maxCount uint64) []types.
|
|||
index += 1
|
||||
count -= 1
|
||||
|
||||
iteratorL1MessageSizeGauge.Update(int64(unsafe.Sizeof(msg) + uintptr(cap(msg.Data))))
|
||||
|
||||
if msg.QueueIndex == it.maxQueueIndex {
|
||||
break
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,9 +189,9 @@ func WriteSkippedTransaction(db ethdb.Database, tx *types.Transaction, traces *t
|
|||
|
||||
// update in a batch
|
||||
batch := db.NewBatch()
|
||||
writeSkippedTransaction(db, tx, traces, reason, blockNumber, blockHash)
|
||||
writeSkippedTransactionHash(db, index, tx.Hash())
|
||||
writeNumSkippedTransactions(db, index+1)
|
||||
writeSkippedTransaction(batch, tx, traces, reason, blockNumber, blockHash)
|
||||
writeSkippedTransactionHash(batch, index, tx.Hash())
|
||||
writeNumSkippedTransactions(batch, index+1)
|
||||
|
||||
// write to DB
|
||||
if err := batch.Write(); err != nil {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
const (
|
||||
VersionMajor = 4 // Major version component of the current release
|
||||
VersionMinor = 4 // Minor version component of the current release
|
||||
VersionPatch = 14 // Patch version component of the current release
|
||||
VersionPatch = 15 // Patch version component of the current release
|
||||
VersionMeta = "sepolia" // Version metadata to append to the version string
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue