Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
18747f11
Unverified
Commit
18747f11
authored
Apr 05, 2023
by
OptimismBot
Committed by
GitHub
Apr 05, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5322 from ethereum-optimism/jg/extended_metrics
txmgr: Add more metrics
parents
cb8fbc4c
3daf6e14
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
8 deletions
+86
-8
event.go
op-service/metrics/event.go
+1
-2
noop.go
op-service/txmgr/metrics/noop.go
+4
-1
tx_metrics.go
op-service/txmgr/metrics/tx_metrics.go
+61
-4
txmgr.go
op-service/txmgr/txmgr.go
+17
-1
txmgr_test.go
op-service/txmgr/txmgr_test.go
+3
-0
No files found.
op-service/metrics/event.go
View file @
18747f11
...
@@ -52,7 +52,6 @@ func NewEventVec(factory Factory, ns string, name string, displayName string, la
...
@@ -52,7 +52,6 @@ func NewEventVec(factory Factory, ns string, name string, displayName string, la
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"last_%s_unix"
,
name
),
Name
:
fmt
.
Sprintf
(
"last_%s_unix"
,
name
),
Help
:
fmt
.
Sprintf
(
"Timestamp of last %s event"
,
displayName
),
Help
:
fmt
.
Sprintf
(
"Timestamp of last %s event"
,
displayName
),
},
},
labelNames
),
labelNames
),
}
}
}
}
op-service/txmgr/metrics/noop.go
View file @
18747f11
...
@@ -4,6 +4,9 @@ import "github.com/ethereum/go-ethereum/core/types"
...
@@ -4,6 +4,9 @@ import "github.com/ethereum/go-ethereum/core/types"
type
NoopTxMetrics
struct
{}
type
NoopTxMetrics
struct
{}
func
(
*
NoopTxMetrics
)
Record
L1GasFee
(
*
types
.
Receipt
)
{}
func
(
*
NoopTxMetrics
)
Record
Nonce
(
uint64
)
{}
func
(
*
NoopTxMetrics
)
RecordGasBumpCount
(
int
)
{}
func
(
*
NoopTxMetrics
)
RecordGasBumpCount
(
int
)
{}
func
(
*
NoopTxMetrics
)
RecordTxConfirmationLatency
(
int64
)
{}
func
(
*
NoopTxMetrics
)
RecordTxConfirmationLatency
(
int64
)
{}
func
(
*
NoopTxMetrics
)
TxConfirmed
(
*
types
.
Receipt
)
{}
func
(
*
NoopTxMetrics
)
TxPublished
(
string
)
{}
func
(
*
NoopTxMetrics
)
RPCError
()
{}
op-service/txmgr/metrics/tx_metrics.go
View file @
18747f11
...
@@ -9,15 +9,34 @@ import (
...
@@ -9,15 +9,34 @@ import (
)
)
type
TxMetricer
interface
{
type
TxMetricer
interface
{
RecordL1GasFee
(
receipt
*
types
.
Receipt
)
RecordGasBumpCount
(
int
)
RecordGasBumpCount
(
times
int
)
RecordTxConfirmationLatency
(
int64
)
RecordTxConfirmationLatency
(
latency
int64
)
RecordNonce
(
uint64
)
TxConfirmed
(
*
types
.
Receipt
)
TxPublished
(
string
)
RPCError
()
}
}
type
TxMetrics
struct
{
type
TxMetrics
struct
{
TxL1GasFee
prometheus
.
Gauge
TxL1GasFee
prometheus
.
Gauge
TxGasBump
prometheus
.
Gauge
TxGasBump
prometheus
.
Gauge
LatencyConfirmedTx
prometheus
.
Gauge
LatencyConfirmedTx
prometheus
.
Gauge
currentNonce
prometheus
.
Gauge
txPublishError
*
prometheus
.
CounterVec
publishEvent
metrics
.
Event
confirmEvent
metrics
.
EventVec
rpcError
prometheus
.
Counter
}
func
receiptStatusString
(
receipt
*
types
.
Receipt
)
string
{
switch
receipt
.
Status
{
case
types
.
ReceiptStatusSuccessful
:
return
"success"
case
types
.
ReceiptStatusFailed
:
return
"failed"
default
:
return
"unknown_status"
}
}
}
var
_
TxMetricer
=
(
*
TxMetrics
)(
nil
)
var
_
TxMetricer
=
(
*
TxMetrics
)(
nil
)
...
@@ -42,10 +61,36 @@ func MakeTxMetrics(ns string, factory metrics.Factory) TxMetrics {
...
@@ -42,10 +61,36 @@ func MakeTxMetrics(ns string, factory metrics.Factory) TxMetrics {
Help
:
"Latency of a confirmed transaction in milliseconds"
,
Help
:
"Latency of a confirmed transaction in milliseconds"
,
Subsystem
:
"txmgr"
,
Subsystem
:
"txmgr"
,
}),
}),
currentNonce
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Name
:
"current_nonce"
,
Help
:
"Current nonce of the from address"
,
Subsystem
:
"txmgr"
,
}),
txPublishError
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Name
:
"tx_publish_error_count"
,
Help
:
"Count of publish errors. Labells are sanitized error strings"
,
Subsystem
:
"txmgr"
,
},
[]
string
{
"error"
}),
confirmEvent
:
metrics
.
NewEventVec
(
factory
,
ns
,
"confirm"
,
"tx confirm"
,
[]
string
{
"status"
}),
publishEvent
:
metrics
.
NewEvent
(
factory
,
ns
,
"publish"
,
"tx publish"
),
rpcError
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Name
:
"rpc_error_count"
,
Help
:
"Temporrary: Count of RPC errors (like timeouts) that have occurrred"
,
Subsystem
:
"txmgr"
,
}),
}
}
}
}
func
(
t
*
TxMetrics
)
RecordL1GasFee
(
receipt
*
types
.
Receipt
)
{
func
(
t
*
TxMetrics
)
RecordNonce
(
nonce
uint64
)
{
t
.
currentNonce
.
Set
(
float64
(
nonce
))
}
// TxConfirmed records lots of information about the confirmed transaction
func
(
t
*
TxMetrics
)
TxConfirmed
(
receipt
*
types
.
Receipt
)
{
t
.
confirmEvent
.
Record
(
receiptStatusString
(
receipt
))
t
.
TxL1GasFee
.
Set
(
float64
(
receipt
.
EffectiveGasPrice
.
Uint64
()
*
receipt
.
GasUsed
/
params
.
GWei
))
t
.
TxL1GasFee
.
Set
(
float64
(
receipt
.
EffectiveGasPrice
.
Uint64
()
*
receipt
.
GasUsed
/
params
.
GWei
))
}
}
...
@@ -56,3 +101,15 @@ func (t *TxMetrics) RecordGasBumpCount(times int) {
...
@@ -56,3 +101,15 @@ func (t *TxMetrics) RecordGasBumpCount(times int) {
func
(
t
*
TxMetrics
)
RecordTxConfirmationLatency
(
latency
int64
)
{
func
(
t
*
TxMetrics
)
RecordTxConfirmationLatency
(
latency
int64
)
{
t
.
LatencyConfirmedTx
.
Set
(
float64
(
latency
))
t
.
LatencyConfirmedTx
.
Set
(
float64
(
latency
))
}
}
func
(
t
*
TxMetrics
)
TxPublished
(
errString
string
)
{
if
errString
!=
""
{
t
.
txPublishError
.
WithLabelValues
(
errString
)
.
Inc
()
}
else
{
t
.
publishEvent
.
Record
()
}
}
func
(
t
*
TxMetrics
)
RPCError
()
{
t
.
rpcError
.
Inc
()
}
op-service/txmgr/txmgr.go
View file @
18747f11
...
@@ -148,6 +148,7 @@ func (m *SimpleTxManager) Send(ctx context.Context, candidate TxCandidate) (*typ
...
@@ -148,6 +148,7 @@ func (m *SimpleTxManager) Send(ctx context.Context, candidate TxCandidate) (*typ
func
(
m
*
SimpleTxManager
)
craftTx
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Transaction
,
error
)
{
func
(
m
*
SimpleTxManager
)
craftTx
(
ctx
context
.
Context
,
candidate
TxCandidate
)
(
*
types
.
Transaction
,
error
)
{
gasTipCap
,
basefee
,
err
:=
m
.
suggestGasPriceCaps
(
ctx
)
gasTipCap
,
basefee
,
err
:=
m
.
suggestGasPriceCaps
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
m
.
metr
.
RPCError
()
return
nil
,
fmt
.
Errorf
(
"failed to get gas price info: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get gas price info: %w"
,
err
)
}
}
gasFeeCap
:=
calcGasFeeCap
(
basefee
,
gasTipCap
)
gasFeeCap
:=
calcGasFeeCap
(
basefee
,
gasTipCap
)
...
@@ -157,8 +158,10 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
...
@@ -157,8 +158,10 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
defer
cancel
()
defer
cancel
()
nonce
,
err
:=
m
.
backend
.
NonceAt
(
childCtx
,
m
.
cfg
.
From
,
nil
)
nonce
,
err
:=
m
.
backend
.
NonceAt
(
childCtx
,
m
.
cfg
.
From
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
m
.
metr
.
RPCError
()
return
nil
,
fmt
.
Errorf
(
"failed to get nonce: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get nonce: %w"
,
err
)
}
}
m
.
metr
.
RecordNonce
(
nonce
)
rawTx
:=
&
types
.
DynamicFeeTx
{
rawTx
:=
&
types
.
DynamicFeeTx
{
ChainID
:
m
.
chainID
,
ChainID
:
m
.
chainID
,
...
@@ -240,6 +243,7 @@ func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*typ
...
@@ -240,6 +243,7 @@ func (m *SimpleTxManager) send(ctx context.Context, tx *types.Transaction) (*typ
case
receipt
:=
<-
receiptChan
:
case
receipt
:=
<-
receiptChan
:
m
.
metr
.
RecordGasBumpCount
(
bumpCounter
)
m
.
metr
.
RecordGasBumpCount
(
bumpCounter
)
m
.
metr
.
TxConfirmed
(
receipt
)
return
receipt
,
nil
return
receipt
,
nil
}
}
}
}
...
@@ -263,19 +267,28 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra
...
@@ -263,19 +267,28 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra
switch
{
switch
{
case
errStringMatch
(
err
,
core
.
ErrNonceTooLow
)
:
case
errStringMatch
(
err
,
core
.
ErrNonceTooLow
)
:
log
.
Warn
(
"nonce too low"
,
"err"
,
err
)
log
.
Warn
(
"nonce too low"
,
"err"
,
err
)
m
.
metr
.
TxPublished
(
"nonce_to_low"
)
case
errStringMatch
(
err
,
context
.
Canceled
)
:
case
errStringMatch
(
err
,
context
.
Canceled
)
:
m
.
metr
.
RPCError
()
log
.
Warn
(
"transaction send cancelled"
,
"err"
,
err
)
log
.
Warn
(
"transaction send cancelled"
,
"err"
,
err
)
m
.
metr
.
TxPublished
(
"context_cancelled"
)
case
errStringMatch
(
err
,
txpool
.
ErrAlreadyKnown
)
:
case
errStringMatch
(
err
,
txpool
.
ErrAlreadyKnown
)
:
log
.
Warn
(
"resubmitted already known transaction"
,
"err"
,
err
)
log
.
Warn
(
"resubmitted already known transaction"
,
"err"
,
err
)
m
.
metr
.
TxPublished
(
"tx_already_known"
)
case
errStringMatch
(
err
,
txpool
.
ErrReplaceUnderpriced
)
:
case
errStringMatch
(
err
,
txpool
.
ErrReplaceUnderpriced
)
:
log
.
Warn
(
"transaction replacement is underpriced"
,
"err"
,
err
)
log
.
Warn
(
"transaction replacement is underpriced"
,
"err"
,
err
)
m
.
metr
.
TxPublished
(
"tx_replacement_underpriced"
)
case
errStringMatch
(
err
,
txpool
.
ErrUnderpriced
)
:
case
errStringMatch
(
err
,
txpool
.
ErrUnderpriced
)
:
log
.
Warn
(
"transaction is underpriced"
,
"err"
,
err
)
log
.
Warn
(
"transaction is underpriced"
,
"err"
,
err
)
m
.
metr
.
TxPublished
(
"tx_underpriced"
)
default
:
default
:
m
.
metr
.
RPCError
()
log
.
Error
(
"unable to publish transaction"
,
"err"
,
err
)
log
.
Error
(
"unable to publish transaction"
,
"err"
,
err
)
m
.
metr
.
TxPublished
(
"unknown_error"
)
}
}
return
return
}
}
m
.
metr
.
TxPublished
(
""
)
log
.
Info
(
"Transaction successfully published"
)
log
.
Info
(
"Transaction successfully published"
)
// Poll for the transaction to be ready & then send the result to receiptChan
// Poll for the transaction to be ready & then send the result to receiptChan
...
@@ -287,7 +300,6 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra
...
@@ -287,7 +300,6 @@ func (m *SimpleTxManager) publishAndWaitForTx(ctx context.Context, tx *types.Tra
select
{
select
{
case
receiptChan
<-
receipt
:
case
receiptChan
<-
receipt
:
m
.
metr
.
RecordTxConfirmationLatency
(
time
.
Since
(
t
)
.
Milliseconds
())
m
.
metr
.
RecordTxConfirmationLatency
(
time
.
Since
(
t
)
.
Milliseconds
())
m
.
metr
.
RecordL1GasFee
(
receipt
)
default
:
default
:
}
}
}
}
...
@@ -319,9 +331,11 @@ func (m *SimpleTxManager) queryReceipt(ctx context.Context, txHash common.Hash,
...
@@ -319,9 +331,11 @@ func (m *SimpleTxManager) queryReceipt(ctx context.Context, txHash common.Hash,
m
.
l
.
Trace
(
"Transaction not yet mined"
,
"hash"
,
txHash
)
m
.
l
.
Trace
(
"Transaction not yet mined"
,
"hash"
,
txHash
)
return
nil
return
nil
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
m
.
metr
.
RPCError
()
m
.
l
.
Info
(
"Receipt retrieval failed"
,
"hash"
,
txHash
,
"err"
,
err
)
m
.
l
.
Info
(
"Receipt retrieval failed"
,
"hash"
,
txHash
,
"err"
,
err
)
return
nil
return
nil
}
else
if
receipt
==
nil
{
}
else
if
receipt
==
nil
{
m
.
metr
.
RPCError
()
m
.
l
.
Warn
(
"Receipt and error are both nil"
,
"hash"
,
txHash
)
m
.
l
.
Warn
(
"Receipt and error are both nil"
,
"hash"
,
txHash
)
return
nil
return
nil
}
}
...
@@ -405,6 +419,7 @@ func (m *SimpleTxManager) suggestGasPriceCaps(ctx context.Context) (*big.Int, *b
...
@@ -405,6 +419,7 @@ func (m *SimpleTxManager) suggestGasPriceCaps(ctx context.Context) (*big.Int, *b
defer
cancel
()
defer
cancel
()
tip
,
err
:=
m
.
backend
.
SuggestGasTipCap
(
cCtx
)
tip
,
err
:=
m
.
backend
.
SuggestGasTipCap
(
cCtx
)
if
err
!=
nil
{
if
err
!=
nil
{
m
.
metr
.
RPCError
()
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to fetch the suggested gas tip cap: %w"
,
err
)
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to fetch the suggested gas tip cap: %w"
,
err
)
}
else
if
tip
==
nil
{
}
else
if
tip
==
nil
{
return
nil
,
nil
,
errors
.
New
(
"the suggested tip was nil"
)
return
nil
,
nil
,
errors
.
New
(
"the suggested tip was nil"
)
...
@@ -413,6 +428,7 @@ func (m *SimpleTxManager) suggestGasPriceCaps(ctx context.Context) (*big.Int, *b
...
@@ -413,6 +428,7 @@ func (m *SimpleTxManager) suggestGasPriceCaps(ctx context.Context) (*big.Int, *b
defer
cancel
()
defer
cancel
()
head
,
err
:=
m
.
backend
.
HeaderByNumber
(
cCtx
,
nil
)
head
,
err
:=
m
.
backend
.
HeaderByNumber
(
cCtx
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
m
.
metr
.
RPCError
()
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to fetch the suggested basefee: %w"
,
err
)
return
nil
,
nil
,
fmt
.
Errorf
(
"failed to fetch the suggested basefee: %w"
,
err
)
}
else
if
head
.
BaseFee
==
nil
{
}
else
if
head
.
BaseFee
==
nil
{
return
nil
,
nil
,
errors
.
New
(
"txmgr does not support pre-london blocks that do not have a basefee"
)
return
nil
,
nil
,
errors
.
New
(
"txmgr does not support pre-london blocks that do not have a basefee"
)
...
...
op-service/txmgr/txmgr_test.go
View file @
18747f11
...
@@ -691,6 +691,7 @@ func TestWaitMinedReturnsReceiptAfterFailure(t *testing.T) {
...
@@ -691,6 +691,7 @@ func TestWaitMinedReturnsReceiptAfterFailure(t *testing.T) {
name
:
"TEST"
,
name
:
"TEST"
,
backend
:
&
borkedBackend
,
backend
:
&
borkedBackend
,
l
:
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
l
:
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
metr
:
&
metrics
.
NoopTxMetrics
{},
}
}
// Don't mine the tx with the default backend. The failingBackend will
// Don't mine the tx with the default backend. The failingBackend will
...
@@ -726,6 +727,7 @@ func doGasPriceIncrease(t *testing.T, txTipCap, txFeeCap, newTip, newBaseFee int
...
@@ -726,6 +727,7 @@ func doGasPriceIncrease(t *testing.T, txTipCap, txFeeCap, newTip, newBaseFee int
name
:
"TEST"
,
name
:
"TEST"
,
backend
:
&
borkedBackend
,
backend
:
&
borkedBackend
,
l
:
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
l
:
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
metr
:
&
metrics
.
NoopTxMetrics
{},
}
}
tx
:=
types
.
NewTx
(
&
types
.
DynamicFeeTx
{
tx
:=
types
.
NewTx
(
&
types
.
DynamicFeeTx
{
...
@@ -829,6 +831,7 @@ func TestIncreaseGasPriceNotExponential(t *testing.T) {
...
@@ -829,6 +831,7 @@ func TestIncreaseGasPriceNotExponential(t *testing.T) {
name
:
"TEST"
,
name
:
"TEST"
,
backend
:
&
borkedBackend
,
backend
:
&
borkedBackend
,
l
:
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
l
:
testlog
.
Logger
(
t
,
log
.
LvlCrit
),
metr
:
&
metrics
.
NoopTxMetrics
{},
}
}
tx
:=
types
.
NewTx
(
&
types
.
DynamicFeeTx
{
tx
:=
types
.
NewTx
(
&
types
.
DynamicFeeTx
{
GasTipCap
:
big
.
NewInt
(
10
),
GasTipCap
:
big
.
NewInt
(
10
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment