Sanitize non-utf8 spec IDs
This commit is contained in:
parent
75173da73b
commit
7a831a9a04
|
@ -79,7 +79,7 @@ func (a *AggregatorMonitor) HandleNewBlock(height uint64) {
|
|||
if delta > 15 {
|
||||
zap.L().Info("job fulfillment slot missed", zap.Uint64("height", n.Raw.BlockNumber),
|
||||
zap.String("requester", n.Requester.String()), zap.Binary("request_id", n.RequestId[:]),
|
||||
zap.ByteString("spec_id", n.SpecId[:]))
|
||||
zap.String("spec_id", sanitizeSpecID(n.SpecId)))
|
||||
delete(a.pendingJobs, reqID)
|
||||
a.monitor.HandleMiss(n)
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func (a *AggregatorMonitor) handleRequest(res *abi.OracleOracleRequest) {
|
|||
if _, exists := a.seenRequestIDs[requestIDString]; exists {
|
||||
zap.L().Info("request dropped; already seen same reqID", zap.Uint64("height", res.Raw.BlockNumber),
|
||||
zap.String("requester", res.Requester.String()), zap.Binary("request_id", res.RequestId[:]),
|
||||
zap.ByteString("spec_id", res.SpecId[:]), zap.Uint64("request_height", res.Raw.BlockNumber))
|
||||
zap.String("spec_id", sanitizeSpecID(res.SpecId)), zap.Uint64("request_height", res.Raw.BlockNumber))
|
||||
return
|
||||
} else {
|
||||
a.seenRequestIDs[requestIDString] = true
|
||||
|
@ -109,7 +109,7 @@ func (a *AggregatorMonitor) handleFulfillment(res *abi.AggregatorChainlinkFulfil
|
|||
if job, ok := a.pendingJobs[hex.EncodeToString(res.Id[:])]; ok {
|
||||
zap.L().Info("job fulfilled", zap.Uint64("height", res.Raw.BlockNumber),
|
||||
zap.String("requester", job.Requester.String()), zap.Binary("request_id", job.RequestId[:]),
|
||||
zap.ByteString("spec_id", job.SpecId[:]), zap.Uint64("request_height", job.Raw.BlockNumber))
|
||||
zap.String("spec_id", sanitizeSpecID(job.SpecId)), zap.Uint64("request_height", job.Raw.BlockNumber))
|
||||
delete(a.pendingJobs, hex.EncodeToString(res.Id[:]))
|
||||
|
||||
a.monitor.HandleFulfillment(res, job)
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"chainlink_exporter/abi"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
@ -15,6 +16,7 @@ import (
|
|||
"math/big"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -291,7 +293,7 @@ func (m *Monitor) requestRoutine() {
|
|||
func (m *Monitor) handleRequest(req *abi.OracleOracleRequest) error {
|
||||
logger := zap.L().With(zap.Uint64("height", req.Raw.BlockNumber),
|
||||
zap.String("requester", req.Requester.String()), zap.Binary("request_id", req.RequestId[:]),
|
||||
zap.ByteString("spec_id", req.SpecId[:]))
|
||||
zap.String("spec_id", sanitizeSpecID(req.SpecId)))
|
||||
logger.Info("received request")
|
||||
|
||||
if old := m.lastReqTime.Load(); old < req.Raw.BlockNumber {
|
||||
|
@ -334,13 +336,25 @@ func (m *Monitor) HandleFulfillment(res *abi.AggregatorChainlinkFulfilled, req *
|
|||
}
|
||||
|
||||
deltaBlocks := res.Raw.BlockNumber - req.Raw.BlockNumber
|
||||
m.responseTimeHistogram.WithLabelValues(string(req.SpecId[:])).Observe(float64(deltaBlocks))
|
||||
|
||||
m.fulfillmentCounter.WithLabelValues(string(req.SpecId[:]), req.Requester.String()).Inc()
|
||||
m.revenueCounter.WithLabelValues(string(req.SpecId[:]), req.Requester.String(), "fulfilled").Add(float64(req.Payment.Uint64()) / params.Ether)
|
||||
sanitizedSpecID := sanitizeSpecID(req.SpecId)
|
||||
m.responseTimeHistogram.WithLabelValues(sanitizedSpecID).Observe(float64(deltaBlocks))
|
||||
|
||||
m.fulfillmentCounter.WithLabelValues(sanitizedSpecID, req.Requester.String()).Inc()
|
||||
m.revenueCounter.WithLabelValues(sanitizedSpecID, req.Requester.String(), "fulfilled").Add(float64(req.Payment.Uint64()) / params.Ether)
|
||||
}
|
||||
|
||||
func (m *Monitor) HandleMiss(req *abi.OracleOracleRequest) {
|
||||
m.missCounter.WithLabelValues(string(req.SpecId[:]), req.Requester.String()).Inc()
|
||||
m.revenueCounter.WithLabelValues(string(req.SpecId[:]), req.Requester.String(), "missed").Add(float64(req.Payment.Uint64()) / params.Ether)
|
||||
sanitizedSpecID := sanitizeSpecID(req.SpecId)
|
||||
|
||||
m.missCounter.WithLabelValues(sanitizedSpecID, req.Requester.String()).Inc()
|
||||
m.revenueCounter.WithLabelValues(sanitizedSpecID, req.Requester.String(), "missed").Add(float64(req.Payment.Uint64()) / params.Ether)
|
||||
}
|
||||
|
||||
func sanitizeSpecID(specID [32]byte) string {
|
||||
if !utf8.Valid(specID[:]) {
|
||||
return hex.EncodeToString(specID[:])
|
||||
} else {
|
||||
return string(specID[:])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue