mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-01 20:48:38 +00:00
core/txpool/blobpool: add metrics for blob buffer
This commit is contained in:
parent
1a7e0397bb
commit
7aa045c60c
1 changed files with 34 additions and 1 deletions
|
|
@ -26,6 +26,14 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
blobBufferTxFirstCounter = metrics.NewRegisteredCounter("blobpool/buffer/txfirst", nil)
|
||||||
|
blobBufferCellsFirstCounter = metrics.NewRegisteredCounter("blobpool/buffer/cellsfirst", nil)
|
||||||
|
blobBufferTotalTx = metrics.NewRegisteredGauge("blobpool/buffer/txcount", nil)
|
||||||
|
blobBufferTotalCells = metrics.NewRegisteredGauge("blobpool/buffer/cellcount", nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -70,6 +78,9 @@ func NewBlobBuffer(addToPool func(*PooledBlobTx) error, dropPeer func(string)) *
|
||||||
// AddTx buffers a blob transaction (without blobs) from an ETH/72 peer.
|
// AddTx buffers a blob transaction (without blobs) from an ETH/72 peer.
|
||||||
// If cells are already buffered, verification and pool insertion are attempted.
|
// If cells are already buffered, verification and pool insertion are attempted.
|
||||||
func (b *BlobBuffer) AddTx(tx *types.Transaction, peer string) error {
|
func (b *BlobBuffer) AddTx(tx *types.Transaction, peer string) error {
|
||||||
|
defer b.updateMetrics()()
|
||||||
|
|
||||||
|
// First remove any timed-out entries.
|
||||||
b.evict()
|
b.evict()
|
||||||
|
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
|
|
@ -98,6 +109,7 @@ func (b *BlobBuffer) AddTx(tx *types.Transaction, peer string) error {
|
||||||
if entry, ok := b.cells[hash]; ok {
|
if entry, ok := b.cells[hash]; ok {
|
||||||
return b.add(hash, tx, entry)
|
return b.add(hash, tx, entry)
|
||||||
}
|
}
|
||||||
|
blobBufferTxFirstCounter.Inc(1)
|
||||||
b.txs[hash] = &txEntry{tx: tx, peer: peer, added: time.Now()}
|
b.txs[hash] = &txEntry{tx: tx, peer: peer, added: time.Now()}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -105,16 +117,20 @@ func (b *BlobBuffer) AddTx(tx *types.Transaction, peer string) error {
|
||||||
// AddCells buffers per-peer cell deliveries from the blob fetcher.
|
// AddCells buffers per-peer cell deliveries from the blob fetcher.
|
||||||
// If the transaction is already buffered, verification and pool insertion are attempted.
|
// If the transaction is already buffered, verification and pool insertion are attempted.
|
||||||
func (b *BlobBuffer) AddCells(hash common.Hash, deliveries map[string]*PeerDelivery, custody *types.CustodyBitmap) error {
|
func (b *BlobBuffer) AddCells(hash common.Hash, deliveries map[string]*PeerDelivery, custody *types.CustodyBitmap) error {
|
||||||
|
defer b.updateMetrics()()
|
||||||
|
|
||||||
|
// First remove any timed-out entries.
|
||||||
b.evict()
|
b.evict()
|
||||||
|
|
||||||
b.cells[hash] = &cellEntry{
|
b.cells[hash] = &cellEntry{
|
||||||
deliveries: deliveries,
|
deliveries: deliveries,
|
||||||
custody: custody,
|
custody: custody,
|
||||||
added: time.Now(),
|
added: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if txe, ok := b.txs[hash]; ok {
|
if txe, ok := b.txs[hash]; ok {
|
||||||
return b.add(hash, txe.tx, b.cells[hash])
|
return b.add(hash, txe.tx, b.cells[hash])
|
||||||
}
|
}
|
||||||
|
blobBufferCellsFirstCounter.Inc(1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,6 +200,23 @@ func (b *BlobBuffer) evict() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateMetrics updates the metrics gauges.
|
||||||
|
// This should be called at the start of any operation that changes the buffer
|
||||||
|
// content. The returned function is to be called at the end of the operation,
|
||||||
|
// usually with defer.
|
||||||
|
func (b *BlobBuffer) updateMetrics() func() {
|
||||||
|
preTxCount := len(b.txs)
|
||||||
|
preCellsCount := len(b.cells)
|
||||||
|
return func() {
|
||||||
|
if len(b.txs) != preTxCount {
|
||||||
|
blobBufferTotalTx.Update(int64(len(b.txs)))
|
||||||
|
}
|
||||||
|
if len(b.cells) != preCellsCount {
|
||||||
|
blobBufferTotalCells.Update(int64(len(b.cells)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// verifyCells verifies each peer's cells against the sidecar.
|
// verifyCells verifies each peer's cells against the sidecar.
|
||||||
// Returns the list of peers whose cells failed verification.
|
// Returns the list of peers whose cells failed verification.
|
||||||
func (b *BlobBuffer) verifyCells(entry *cellEntry, sidecar *types.BlobTxSidecar) []string {
|
func (b *BlobBuffer) verifyCells(entry *cellEntry, sidecar *types.BlobTxSidecar) []string {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue