Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions multinode/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ require (
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/smartcontractkit/chainlink-framework/metrics => ../metrics

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bump metrics module version instead of local replace

Adding replace github.com/smartcontractkit/chainlink-framework/metrics => ../metrics makes local tests pass, but consumers of github.com/smartcontractkit/chainlink-framework/multinode do not apply replace directives from dependency modules, so they will resolve the pinned required metrics version (v0.0.0-20250717121125-2350c82883e2) instead. That version does not contain the new metrics.RPCClientMetrics API used by multinode/rpc_client_base.go, causing downstream builds to fail once they import this commit.

Useful? React with 👍 / 👎.

2 changes: 0 additions & 2 deletions multinode/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ github.com/smartcontractkit/chainlink-common v0.10.1-0.20260305114348-b8bbac30bf
github.com/smartcontractkit/chainlink-common v0.10.1-0.20260305114348-b8bbac30bfc7/go.mod h1:0ghbAr7tRO0tT5ZqBXhOyzgUO37tNNe33Yn0hskauVM=
github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.10 h1:FJAFgXS9oqASnkS03RE1HQwYQQxrO4l46O5JSzxqLgg=
github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.10/go.mod h1:oiDa54M0FwxevWwyAX773lwdWvFYYlYHHQV1LQ5HpWY=
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250717121125-2350c82883e2 h1:ysZjKH+BpWlQhF93kr/Lc668UlCvT9NjfcsGdZT19I8=
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250717121125-2350c82883e2/go.mod h1:jo+cUqNcHwN8IF7SInQNXDZ8qzBsyMpnLdYbDswviFc=
github.com/smartcontractkit/freeport v0.1.3-0.20250716200817-cb5dfd0e369e h1:Hv9Mww35LrufCdM9wtS9yVi/rEWGI1UnjHbcKKU0nVY=
github.com/smartcontractkit/freeport v0.1.3-0.20250716200817-cb5dfd0e369e/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
github.com/smartcontractkit/libocr v0.0.0-20250912173940-f3ab0246e23d h1:LokA9PoCNb8mm8mDT52c3RECPMRsGz1eCQORq+J3n74=
Expand Down
38 changes: 32 additions & 6 deletions multinode/rpc_client_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-framework/metrics"
)

type RPCClientBaseConfig interface {
Expand All @@ -33,6 +34,9 @@ type RPCClientBase[HEAD Head] struct {
latestBlock func(ctx context.Context) (HEAD, error)
latestFinalizedBlock func(ctx context.Context) (HEAD, error)

// rpcMetrics is optional; when non-nil, LatestBlock and LatestFinalizedBlock record latency and errors.
rpcMetrics metrics.RPCClientMetrics

// lifeCycleCh can be closed to immediately cancel all in-flight requests on
// this RPC. Closing and replacing should be serialized through
// lifeCycleMu since it can happen on state transitions as well as RPCClientBase Close.
Expand All @@ -52,13 +56,15 @@ func NewRPCClientBase[HEAD Head](
cfg RPCClientBaseConfig, ctxTimeout time.Duration, log logger.Logger,
latestBlock func(ctx context.Context) (HEAD, error),
latestFinalizedBlock func(ctx context.Context) (HEAD, error),
rpcMetrics metrics.RPCClientMetrics,
) *RPCClientBase[HEAD] {
return &RPCClientBase[HEAD]{
cfg: cfg,
log: log,
ctxTimeout: ctxTimeout,
latestBlock: latestBlock,
latestFinalizedBlock: latestFinalizedBlock,
rpcMetrics: rpcMetrics,
subs: make(map[Subscription]struct{}),
lifeCycleCh: make(chan struct{}),
}
Expand Down Expand Up @@ -156,15 +162,25 @@ func (m *RPCClientBase[HEAD]) LatestBlock(ctx context.Context) (HEAD, error) {
ctx, cancel, lifeCycleCh := m.AcquireQueryCtx(ctx, m.ctxTimeout)
defer cancel()

start := time.Now()
head, err := m.latestBlock(ctx)
latencyMs := float64(time.Since(start).Milliseconds())
if err != nil {
if m.rpcMetrics != nil {
m.rpcMetrics.RecordRequest(ctx, "latest_block", latencyMs, err)
}
return head, err
}

if !head.IsValid() {
return head, errors.New("invalid head")
err := errors.New("invalid head")
if m.rpcMetrics != nil {
m.rpcMetrics.RecordRequest(ctx, "latest_block", latencyMs, err)
}
return head, err
}
if m.rpcMetrics != nil {
m.rpcMetrics.RecordRequest(ctx, "latest_block", latencyMs, nil)
}

m.OnNewHead(ctx, lifeCycleCh, head)
return head, nil
}
Expand All @@ -173,15 +189,25 @@ func (m *RPCClientBase[HEAD]) LatestFinalizedBlock(ctx context.Context) (HEAD, e
ctx, cancel, lifeCycleCh := m.AcquireQueryCtx(ctx, m.ctxTimeout)
defer cancel()

start := time.Now()
head, err := m.latestFinalizedBlock(ctx)
latencyMs := float64(time.Since(start).Milliseconds())
if err != nil {
if m.rpcMetrics != nil {
m.rpcMetrics.RecordRequest(ctx, "latest_finalized_block", latencyMs, err)
}
return head, err
}

if !head.IsValid() {
return head, errors.New("invalid head")
err := errors.New("invalid head")
if m.rpcMetrics != nil {
m.rpcMetrics.RecordRequest(ctx, "latest_finalized_block", latencyMs, err)
}
return head, err
}
if m.rpcMetrics != nil {
m.rpcMetrics.RecordRequest(ctx, "latest_finalized_block", latencyMs, nil)
}

m.OnNewFinalizedHead(ctx, lifeCycleCh, head)
return head, nil
}
Expand Down
2 changes: 1 addition & 1 deletion multinode/rpc_client_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func newTestRPC(t *testing.T) *testRPC {
}

rpc := &testRPC{}
rpc.RPCClientBase = NewRPCClientBase[*testHead](cfg, requestTimeout, lggr, rpc.latestBlock, rpc.latestBlock)
rpc.RPCClientBase = NewRPCClientBase[*testHead](cfg, requestTimeout, lggr, rpc.latestBlock, rpc.latestBlock, nil)
t.Cleanup(rpc.Close)
return rpc
}
Expand Down
Loading