Skip to content

Commit 1c781f0

Browse files
committed
Add goroutine to collect the operator's balance metric every minute
1 parent d25d4ff commit 1c781f0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

bootstrap/bootstrap.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ func (b *Bootstrap) Run(
694694
// mark ready
695695
ready()
696696

697+
go b.trackOperatorBalance(ctx)
698+
697699
return nil
698700
}
699701

@@ -707,6 +709,26 @@ func (b *Bootstrap) Stop() {
707709
b.StopDB()
708710
}
709711

712+
func (b *Bootstrap) trackOperatorBalance(ctx context.Context) {
713+
ticker := time.NewTicker(1 * time.Minute)
714+
defer ticker.Stop()
715+
716+
for {
717+
select {
718+
case <-ctx.Done():
719+
return
720+
case <-ticker.C:
721+
accBalance, err := b.client.GetAccountBalanceAtLatestBlock(ctx, b.config.COAAddress)
722+
if err != nil {
723+
b.logger.Warn().Err(err).Msg(
724+
"failed to collect operator's balance metric",
725+
)
726+
}
727+
b.collector.OperatorBalance(accBalance)
728+
}
729+
}
730+
}
731+
710732
// Run will run complete bootstrap of the EVM gateway with all the engines.
711733
// Run is a blocking call, but it does signal readiness of the service
712734
// through a channel provided as an argument.

0 commit comments

Comments
 (0)