Skip to content

Commit 03ca37b

Browse files
eth/catalyst: add getBlobs metrics
1 parent f62d01c commit 03ca37b

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,17 +1332,19 @@ func (p *BlobPool) GetBlobs(vhashes []common.Hash) []*types.BlobTxSidecar {
13321332
return sidecars
13331333
}
13341334

1335-
func (p *BlobPool) HasBlobs(vhashes []common.Hash) bool {
1335+
// AvailableBlobs returns the number of blobs that are available in the subpool.
1336+
func (p *BlobPool) AvailableBlobs(vhashes []common.Hash) int {
1337+
available := 0
13361338
for _, vhash := range vhashes {
13371339
// Retrieve the datastore item (in a short lock)
13381340
p.lock.RLock()
13391341
_, exists := p.lookup.storeidOfBlob(vhash)
13401342
p.lock.RUnlock()
1341-
if !exists {
1342-
return false
1343+
if exists {
1344+
available++
13431345
}
13441346
}
1345-
return true
1347+
return available
13461348
}
13471349

13481350
// Add inserts a set of blob transactions into the pool if they pass validation (both

core/txpool/legacypool/legacypool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,10 @@ func (pool *LegacyPool) GetBlobs(vhashes []common.Hash) []*types.BlobTxSidecar {
10681068
return nil
10691069
}
10701070

1071-
// HasBlobs is not supported by the legacy transaction pool, it is just here to
1071+
// AvailableBlobs is not supported by the legacy transaction pool, it is just here to
10721072
// implement the txpool.SubPool interface.
1073-
func (pool *LegacyPool) HasBlobs(vhashes []common.Hash) bool {
1074-
return false
1073+
func (pool *LegacyPool) AvailableBlobs(vhashes []common.Hash) int {
1074+
return 0
10751075
}
10761076

10771077
// Has returns an indicator whether txpool has a transaction cached with the

core/txpool/subpool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ type SubPool interface {
137137
// retrieve blobs from the pools directly instead of the network.
138138
GetBlobs(vhashes []common.Hash) []*types.BlobTxSidecar
139139

140-
// HasBlobs returns true if all blobs corresponding to the versioned hashes
141-
// are in the sub pool.
142-
HasBlobs(vhashes []common.Hash) bool
140+
// AvailableBlobs returns number of blobs corresponding to the versioned hashes
141+
// that are available in the sub pool.
142+
AvailableBlobs(vhashes []common.Hash) int
143143

144144
// ValidateTxBasics checks whether a transaction is valid according to the consensus
145145
// rules, but does not check state-dependent validation such as sufficient balance.

core/txpool/txpool.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,18 @@ func (p *TxPool) GetBlobs(vhashes []common.Hash) []*types.BlobTxSidecar {
323323
return nil
324324
}
325325

326-
// HasBlobs will return true if all the vhashes are available in the same subpool.
327-
func (p *TxPool) HasBlobs(vhashes []common.Hash) bool {
326+
// AvailableBlobs will return the number of vhashes that are available in the same subpool.
327+
func (p *TxPool) AvailableBlobs(vhashes []common.Hash) int {
328328
for _, subpool := range p.subpools {
329329
// It's an ugly to assume that only one pool will be capable of returning
330330
// anything meaningful for this call, but anything else requires merging
331331
// partial responses and that's too annoying to do until we get a second
332332
// blobpool (probably never).
333-
if subpool.HasBlobs(vhashes) {
334-
return true
333+
if count := subpool.AvailableBlobs(vhashes); count != 0 {
334+
return count
335335
}
336336
}
337-
return false
337+
return 0
338338
}
339339

340340
// Add enqueues a batch of transactions into the pool if they are valid. Due

eth/catalyst/api.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/eth/ethconfig"
3737
"github.com/ethereum/go-ethereum/internal/version"
3838
"github.com/ethereum/go-ethereum/log"
39+
"github.com/ethereum/go-ethereum/metrics"
3940
"github.com/ethereum/go-ethereum/miner"
4041
"github.com/ethereum/go-ethereum/node"
4142
"github.com/ethereum/go-ethereum/params"
@@ -116,6 +117,17 @@ var caps = []string{
116117
"engine_getClientVersionV1",
117118
}
118119

120+
var (
121+
// Number of blobs requested via getBlobsV2
122+
getBlobsRequestedCounter = metrics.NewRegisteredCounter("engine/getblobs/requested", nil)
123+
// Number of blobs requested via getBlobsV2 that are present in the blobpool
124+
getBlobsAvailableCounter = metrics.NewRegisteredCounter("engine/getblobs/available", nil)
125+
// Number of times getBlobsV2 responded with “hit”
126+
getBlobsV2RequestHit = metrics.NewRegisteredCounter("engine/getblobs/hit", nil)
127+
// Number of times getBlobsV2 responded with “miss”
128+
getBlobsV2RequestMiss = metrics.NewRegisteredCounter("engine/getblobs/miss", nil)
129+
)
130+
119131
type ConsensusAPI struct {
120132
eth *eth.Ethereum
121133

@@ -510,10 +522,15 @@ func (api *ConsensusAPI) GetBlobsV2(hashes []common.Hash) ([]*engine.BlobAndProo
510522
return nil, engine.TooLargeRequest.With(fmt.Errorf("requested blob count too large: %v", len(hashes)))
511523
}
512524

525+
available := api.eth.TxPool().AvailableBlobs(hashes)
526+
getBlobsRequestedCounter.Inc(int64(len(hashes)))
527+
getBlobsAvailableCounter.Inc(int64(available))
513528
// Optimization: check first if all blobs are available, if not, return empty response
514-
if !api.eth.TxPool().HasBlobs(hashes) {
529+
if available != len(hashes) {
530+
getBlobsV2RequestMiss.Inc(1)
515531
return nil, nil
516532
}
533+
getBlobsV2RequestMiss.Inc(1)
517534

518535
// pull up the blob hashes
519536
var (

0 commit comments

Comments
 (0)