@@ -16,7 +16,9 @@ import (
1616 "github.com/ethereum/go-ethereum/accounts/abi/bind"
1717 "github.com/ethereum/go-ethereum/common"
1818 "github.com/ethereum/go-ethereum/log"
19+ "github.com/ethereum/go-ethereum/metrics"
1920 "github.com/ethereum/go-ethereum/node"
21+ "github.com/ethereum/go-ethereum/params"
2022 "github.com/ethereum/go-ethereum/rpc"
2123
2224 protocol "github.com/offchainlabs/bold/chain-abstraction"
@@ -31,11 +33,17 @@ import (
3133 "github.com/offchainlabs/nitro/arbutil"
3234 "github.com/offchainlabs/nitro/staker"
3335 legacystaker "github.com/offchainlabs/nitro/staker/legacy"
36+ "github.com/offchainlabs/nitro/util/arbmath"
3437 "github.com/offchainlabs/nitro/util/headerreader"
3538 "github.com/offchainlabs/nitro/util/stopwaiter"
3639 "github.com/offchainlabs/nitro/validator"
3740)
3841
42+ var (
43+ boldStakerBalanceGauge = metrics .NewRegisteredGaugeFloat64 ("arb/staker/balance" , nil )
44+ boldStakerAmountStakedGauge = metrics .NewRegisteredGauge ("arb/staker/amount_staked" , nil )
45+ )
46+
3947var assertionCreatedId common.Hash
4048
4149func init () {
@@ -195,7 +203,7 @@ type BOLDStaker struct {
195203 blockValidator * staker.BlockValidator
196204 rollupAddress common.Address
197205 l1Reader * headerreader.HeaderReader
198- client protocol. ChainBackend
206+ client * util. BackendWrapper
199207 callOpts bind.CallOpts
200208 wallet legacystaker.ValidatorWalletInterface
201209 stakedNotifiers []legacystaker.LatestStakedNotifier
@@ -327,10 +335,43 @@ func (b *BOLDStaker) Start(ctxIn context.Context) {
327335 notifier .UpdateLatestConfirmed (confirmedMsgCount , * confirmedGlobalState )
328336 }
329337 }
338+ err = b .updateStakerBalanceMetric (ctx )
339+ if err != nil {
340+ log .Warn ("error updating staker balance metric" , "err" , err )
341+ }
330342 return b .config .AssertionPostingInterval
331343 })
332344}
333345
346+ func (b * BOLDStaker ) updateStakerBalanceMetric (ctx context.Context ) error {
347+ walletAddressOrZero := b .wallet .AddressOrZero ()
348+ if walletAddressOrZero != (common.Address {}) {
349+ rollupUserLogic , err := boldrollup .NewRollupUserLogic (b .rollupAddress , b .client )
350+ if err != nil {
351+ return fmt .Errorf ("error creating rollup user logic: %w" , err )
352+ }
353+ amountStaked , err := rollupUserLogic .AmountStaked (& bind.CallOpts {Context : ctx }, walletAddressOrZero )
354+ if err != nil {
355+ return fmt .Errorf ("error getting amount staked: %w" , err )
356+ }
357+ boldStakerAmountStakedGauge .Update (arbmath .BigDivByUint (amountStaked , params .Ether ).Int64 ())
358+ } else {
359+ boldStakerAmountStakedGauge .Update (0 )
360+ }
361+
362+ txSenderAddress := b .wallet .TxSenderAddress ()
363+ if txSenderAddress != nil {
364+ balance , err := b .client .BalanceAt (ctx , * txSenderAddress , nil )
365+ if err != nil {
366+ return fmt .Errorf ("error getting balance for %v: %w" , txSenderAddress , err )
367+ }
368+ boldStakerBalanceGauge .Update (arbmath .BalancePerEther (balance ))
369+ } else {
370+ boldStakerBalanceGauge .Update (0 )
371+ }
372+ return nil
373+ }
374+
334375func (b * BOLDStaker ) getLatestState (ctx context.Context , confirmed bool ) (arbutil.MessageIndex , * validator.GoGlobalState , error ) {
335376 var globalState protocol.GoGlobalState
336377 var err error
0 commit comments