Skip to content

Commit f3f95f9

Browse files
committed
Update OperatorBalance metric to only require the balance as an argument
1 parent dd10cb6 commit f3f95f9

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

metrics/collector.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"time"
66

7-
"github.com/onflow/flow-go-sdk"
87
"github.com/prometheus/client_golang/prometheus"
98
"github.com/rs/zerolog"
109
)
@@ -113,7 +112,7 @@ type Collector interface {
113112
EVMTransactionIndexed(count int)
114113
EVMAccountInteraction(address string)
115114
MeasureRequestDuration(start time.Time, method string)
116-
OperatorBalance(account *flow.Account)
115+
OperatorBalance(balance uint64)
117116
AvailableSigningKeys(count int)
118117
GasEstimationIterations(count int)
119118
BlockIngestionTime(blockCreation time.Time)
@@ -208,8 +207,8 @@ func (c *DefaultCollector) EVMAccountInteraction(address string) {
208207
c.evmAccountCallCounters.With(prometheus.Labels{"address": address}).Inc()
209208
}
210209

211-
func (c *DefaultCollector) OperatorBalance(account *flow.Account) {
212-
c.operatorBalance.Set(float64(account.Balance))
210+
func (c *DefaultCollector) OperatorBalance(balance uint64) {
211+
c.operatorBalance.Set(float64(balance))
213212
}
214213

215214
func (c *DefaultCollector) MeasureRequestDuration(start time.Time, method string) {

metrics/nop.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package metrics
22

33
import (
44
"time"
5-
6-
"github.com/onflow/flow-go-sdk"
75
)
86

97
type nopCollector struct{}
@@ -19,7 +17,7 @@ func (c *nopCollector) EVMHeightIndexed(uint64) {}
1917
func (c *nopCollector) EVMTransactionIndexed(int) {}
2018
func (c *nopCollector) EVMAccountInteraction(string) {}
2119
func (c *nopCollector) MeasureRequestDuration(time.Time, string) {}
22-
func (c *nopCollector) OperatorBalance(*flow.Account) {}
20+
func (c *nopCollector) OperatorBalance(balance uint64) {}
2321
func (c *nopCollector) AvailableSigningKeys(count int) {}
2422
func (c *nopCollector) GasEstimationIterations(count int) {}
2523
func (c *nopCollector) BlockIngestionTime(blockCreation time.Time) {}

services/requester/requester.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func NewEVM(
118118

119119
if !config.IndexOnly {
120120
address := config.COAAddress
121-
acc, err := client.GetAccount(context.Background(), address)
121+
accBalance, err := client.GetAccountBalanceAtLatestBlock(context.Background(), address)
122122
if err != nil {
123123
return nil, fmt.Errorf(
124124
"could not fetch the configured COA account: %s make sure it exists: %w",
@@ -127,13 +127,13 @@ func NewEVM(
127127
)
128128
}
129129
// initialize the operator balance metric since it is only updated when sending a tx
130-
collector.OperatorBalance(acc)
130+
collector.OperatorBalance(accBalance)
131131

132-
if acc.Balance < minFlowBalance {
132+
if accBalance < minFlowBalance {
133133
return nil, fmt.Errorf(
134134
"COA account must be funded with at least %d Flow, but has balance of: %d",
135135
minFlowBalance,
136-
acc.Balance,
136+
accBalance,
137137
)
138138
}
139139
}

0 commit comments

Comments
 (0)