• Joshua Gutow's avatar
    op-node: Metrics in the channel bank · c37e68fa
    Joshua Gutow authored
    This adds 3 new metrics to channel bank:
    1. New Head Channel Event
    2. Channel Timed Out Event
    3. Frame Added Event
    
    The new channel head event is the most complex. It indicates that there is new
    channel in the ready position of the channel bank. It does not indicate if the
    channel is ready to be read from. It is complicated to implement because we
    have several ways of removing channels which would mean that a new channel becomes
    the head channel.
    
    The channel timeout & frame added events are much simpler.
    
    The intention is to make it easier to determine if the head channel in the channel
    bank is not progressing.
    c37e68fa
metrics.go 1.65 KB
package testutils

import (
	"github.com/ethereum-optimism/optimism/op-service/eth"
)

// TestDerivationMetrics implements the metrics used in the derivation pipeline as no-op operations.
// Optionally a test may hook into the metrics
type TestDerivationMetrics struct {
	FnRecordL1ReorgDepth      func(d uint64)
	FnRecordL1Ref             func(name string, ref eth.L1BlockRef)
	FnRecordL2Ref             func(name string, ref eth.L2BlockRef)
	FnRecordUnsafePayloads    func(length uint64, memSize uint64, next eth.BlockID)
	FnRecordChannelInputBytes func(inputCompressedBytes int)
}

func (t *TestDerivationMetrics) RecordL1ReorgDepth(d uint64) {
	if t.FnRecordL1ReorgDepth != nil {
		t.FnRecordL1ReorgDepth(d)
	}
}

func (t *TestDerivationMetrics) RecordL1Ref(name string, ref eth.L1BlockRef) {
	if t.FnRecordL1Ref != nil {
		t.FnRecordL1Ref(name, ref)
	}
}

func (t *TestDerivationMetrics) RecordL2Ref(name string, ref eth.L2BlockRef) {
	if t.FnRecordL2Ref != nil {
		t.FnRecordL2Ref(name, ref)
	}
}

func (t *TestDerivationMetrics) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) {
	if t.FnRecordUnsafePayloads != nil {
		t.FnRecordUnsafePayloads(length, memSize, next)
	}
}

func (t *TestDerivationMetrics) RecordChannelInputBytes(inputCompressedBytes int) {
	if t.FnRecordChannelInputBytes != nil {
		t.FnRecordChannelInputBytes(inputCompressedBytes)
	}
}

func (t *TestDerivationMetrics) RecordHeadChannelOpened() {
}

func (t *TestDerivationMetrics) RecordChannelTimedOut() {
}

func (t *TestDerivationMetrics) RecordFrame() {
}

type TestRPCMetrics struct{}

func (n *TestRPCMetrics) RecordRPCServerRequest(method string) func() {
	return func() {}
}