Skip to content

Commit

Permalink
feat: add metrics in L1 message iterator (#527)
Browse files Browse the repository at this point in the history
* feat: add metrics in L1 message iterator

* add L1 message size metric
  • Loading branch information
Thegaram authored Oct 1, 2023
1 parent fe8232a commit 751dbda
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions core/rawdb/accessors_l1_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions core/rawdb/accessors_skipped_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit 751dbda

Please sign in to comment.