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
9fc86361
Commit
9fc86361
authored
Nov 08, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(chain-mon): monitor safe nonce as a metric
parent
97cfa03b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
16 deletions
+53
-16
service.ts
packages/chain-mon/src/balance-mon/service.ts
+53
-16
No files found.
packages/chain-mon/src/balance-mon/service.ts
View file @
9fc86361
...
...
@@ -6,7 +6,7 @@ import {
validators
,
}
from
'
@eth-optimism/common-ts
'
import
{
Provider
}
from
'
@ethersproject/abstract-provider
'
import
{
ethers
}
from
'
ethers
'
import
{
BigNumber
,
ethers
}
from
'
ethers
'
import
{
version
}
from
'
../../package.json
'
...
...
@@ -17,11 +17,12 @@ type BalanceMonOptions = {
type
BalanceMonMetrics
=
{
balances
:
Gauge
safeNonces
:
Gauge
unexpectedRpcErrors
:
Counter
}
type
BalanceMonState
=
{
accounts
:
Array
<
{
address
:
string
;
nickname
:
string
}
>
accounts
:
Array
<
{
address
:
string
;
nickname
:
string
;
safe
:
boolean
}
>
}
export
class
BalanceMonService
extends
BaseServiceV2
<
...
...
@@ -45,7 +46,7 @@ export class BalanceMonService extends BaseServiceV2<
},
accounts
:
{
validator
:
validators
.
str
,
desc
:
'
JSON array of [{ address, nickname
}] to monitor bala
nces of
'
,
desc
:
'
JSON array of [{ address, nickname
, safe }] to monitor balances and no
nces of
'
,
public
:
true
,
},
},
...
...
@@ -55,6 +56,11 @@ export class BalanceMonService extends BaseServiceV2<
desc
:
'
Balances of addresses
'
,
labels
:
[
'
address
'
,
'
nickname
'
],
},
safeNonces
:
{
type
:
Gauge
,
desc
:
'
Safe nonce
'
,
labels
:
[
'
address
'
,
'
nickname
'
],
},
unexpectedRpcErrors
:
{
type
:
Counter
,
desc
:
'
Number of unexpected RPC errors
'
,
...
...
@@ -73,6 +79,19 @@ export class BalanceMonService extends BaseServiceV2<
let
balance
:
ethers
.
BigNumber
try
{
balance
=
await
this
.
options
.
rpc
.
getBalance
(
account
.
address
)
this
.
logger
.
info
(
`got balance`
,
{
address
:
account
.
address
,
nickname
:
account
.
nickname
,
balance
:
balance
.
toString
(),
})
// Parse the balance as an integer instead of via toNumber() to avoid ethers throwing an
// an error. We might get rounding errors but we don't need perfect precision here, just a
// generally accurate sense for what the current balance is.
this
.
metrics
.
balances
.
set
(
{
address
:
account
.
address
,
nickname
:
account
.
nickname
},
parseInt
(
balance
.
toString
(),
10
)
)
}
catch
(
err
)
{
this
.
logger
.
info
(
`got unexpected RPC error`
,
{
section
:
'
balances
'
,
...
...
@@ -83,22 +102,40 @@ export class BalanceMonService extends BaseServiceV2<
section
:
'
balances
'
,
name
:
'
getBalance
'
,
})
continue
}
this
.
logger
.
info
(
`got balance`
,
{
address
:
account
.
address
,
nickname
:
account
.
nickname
,
balance
:
balance
.
toString
(),
})
// Get the safe nonce to report
if
(
account
.
safe
)
{
let
safeNonce
:
ethers
.
BigNumber
try
{
safeNonce
=
BigNumber
.
from
(
await
this
.
options
.
rpc
.
call
({
to
:
account
.
address
,
data
:
'
0xaffed0e0
'
,
// call the nonce() function in the safe contract
})
)
this
.
logger
.
info
(
`got nonce`
,
{
address
:
account
.
address
,
nickname
:
account
.
nickname
,
nonce
:
safeNonce
.
toString
(),
})
// Parse the balance as an integer instead of via toNumber() to avoid ethers throwing an
// an error. We might get rounding errors but we don't need perfect precision here, just a
// generally accurate sense for what the current balance is.
this
.
metrics
.
balances
.
set
(
{
address
:
account
.
address
,
nickname
:
account
.
nickname
},
parseInt
(
balance
.
toString
(),
10
)
)
this
.
metrics
.
safeNonces
.
set
(
{
address
:
account
.
address
,
nickname
:
account
.
nickname
},
parseInt
(
safeNonce
.
toString
(),
10
)
)
}
catch
(
err
)
{
this
.
logger
.
info
(
`got unexpected RPC error`
,
{
section
:
'
safeNonce
'
,
name
:
'
getSafeNonce
'
,
err
,
})
this
.
metrics
.
unexpectedRpcErrors
.
inc
({
section
:
'
safeNonce
'
,
name
:
'
getSafeNonce
'
,
})
}
}
}
}
}
...
...
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