chain_metrics.go 821 Bytes
package source

import (
	"math/big"

	"github.com/ethereum-optimism/optimism/op-service/sources/caching"
)

// chainMetrics is an adapter between the metrics API expected by clients that assume there's only a single chain
// and the actual metrics implementation which requires a chain ID to identify the source chain.
type chainMetrics struct {
	chainID  *big.Int
	delegate Metrics
}

func newChainMetrics(chainID *big.Int, delegate Metrics) *chainMetrics {
	return &chainMetrics{
		chainID:  chainID,
		delegate: delegate,
	}
}

func (c *chainMetrics) CacheAdd(label string, cacheSize int, evicted bool) {
	c.delegate.CacheAdd(c.chainID, label, cacheSize, evicted)
}

func (c *chainMetrics) CacheGet(label string, hit bool) {
	c.delegate.CacheGet(c.chainID, label, hit)
}

var _ caching.Metrics = (*chainMetrics)(nil)