diff --git a/solver/app/app.go b/solver/app/app.go index 2c33f9bd6..fbc40060d 100644 --- a/solver/app/app.go +++ b/solver/app/app.go @@ -205,7 +205,7 @@ func startEventStreams( outboxContracts := make(map[uint64]*bindings.SolveOutbox) for _, chain := range outboxChains { name := network.ChainName(chain) - log.Debug(ctx, "Using outbox contract", "chain", name, "address", addrs.SolveInbox.Hex()) + log.Debug(ctx, "Using outbox contract", "chain", name, "address", addrs.SolveOutbox.Hex()) backend, err := backends.Backend(chain) if err != nil { @@ -232,6 +232,7 @@ func startEventStreams( Fulfill: newFulfiller(network.ID, outboxContracts, backends, solverAddr, addrs.SolveOutbox), Claim: newClaimer(inboxContracts, backends, solverAddr), SetCursor: cursorSetter, + ChainName: network.ChainName, } for _, chain := range inboxChains { diff --git a/solver/app/helpers.go b/solver/app/helpers.go index 29f25e248..96a6106bb 100644 --- a/solver/app/helpers.go +++ b/solver/app/helpers.go @@ -2,7 +2,7 @@ package app import ( "context" - "encoding/hex" + "encoding/binary" "github.com/omni-network/omni/lib/errors" "github.com/omni-network/omni/lib/ethclient/ethbackend" @@ -33,8 +33,7 @@ func detectContractChains(ctx context.Context, network netconf.Network, backends return resp, nil } -// fmtReqID returns the least-significant 7 hex chars of the provided request ID. -// ReqIDs are monotonically incrementing numbers, not hashes. -func fmtReqID(reqID [32]byte) string { - return hex.EncodeToString(reqID[:])[64-7:] +// reqIDOffset returns the req ID as a uint64 offset (monotonically incrementing number). +func reqIDOffset(reqID [32]byte) uint64 { + return binary.BigEndian.Uint64(reqID[32-8:]) } diff --git a/solver/app/metrics.go b/solver/app/metrics.go new file mode 100644 index 000000000..24e06c1f0 --- /dev/null +++ b/solver/app/metrics.go @@ -0,0 +1,15 @@ +package app + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +var ( + statusOffset = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "solver", + Subsystem: "processor", + Name: "status_offset", + Help: "Last inbox offset processed by chain and status", + }, []string{"chain", "status"}) +) diff --git a/solver/app/procdeps.go b/solver/app/procdeps.go index c63a17c05..05e3cd28a 100644 --- a/solver/app/procdeps.go +++ b/solver/app/procdeps.go @@ -29,6 +29,8 @@ type procDeps struct { Reject func(ctx context.Context, chainID uint64, req bindings.SolveRequest, reason rejectReason) error Fulfill func(ctx context.Context, chainID uint64, req bindings.SolveRequest) error Claim func(ctx context.Context, chainID uint64, req bindings.SolveRequest) error + + ChainName func(chainID uint64) string } func newClaimer( diff --git a/solver/app/processor.go b/solver/app/processor.go index 72a37ab0f..24599de20 100644 --- a/solver/app/processor.go +++ b/solver/app/processor.go @@ -25,8 +25,9 @@ func newEventProcessor(deps procDeps, chainID uint64) xchain.EventLogsCallback { return errors.Wrap(err, "parse id") } - ctx := log.WithCtx(ctx, "status", statusString(event.Status), "req_id", fmtReqID(reqID)) - + offset := reqIDOffset(reqID) + statusOffset.WithLabelValues(deps.ChainName(chainID), statusString(event.Status)).Set(float64(offset)) + ctx := log.WithCtx(ctx, "status", statusString(event.Status), "req_id", offset) log.Debug(ctx, "Processing event") req, _, err := deps.GetRequest(ctx, chainID, reqID) diff --git a/solver/app/processor_internal_test.go b/solver/app/processor_internal_test.go index d167e00e8..8aacce89c 100644 --- a/solver/app/processor_internal_test.go +++ b/solver/app/processor_internal_test.go @@ -145,6 +145,7 @@ func TestEventProcessor(t *testing.T) { return nil }, + ChainName: func(uint64) string { return "" }, } processor := newEventProcessor(deps, chainID)