cartesi / rollups-node

Reference implementation of the Cartesi Rollups Node
Apache License 2.0
23 stars 64 forks source link

Expose wallet balance via /metrics to authority-claimer #495

Open endersonmaia opened 4 months ago

endersonmaia commented 4 months ago

📚 Context

The cartesi-rollups-authority-claimer should expose the balance for the Authority Owner wallet as a metric in the /metrics endpoint.

As a rollups-node operator, it's important to keep track of the balance so that the validator node can keep making claims without problems.

For Sunodo, we must keep track of at least 8 different wallet balances, for all the chains we support.

✔️ Solution

Provide the balance of the Authority Onwer wallet as a metrics in trghe /metrics endpoint.

For ex,:

# HELP cartesi_rollups_authority_claimer_wallet_balance Show the current balance of the wallet
# TYPE cartesi_rollups_authority_claimer_wallet_balance gauge
cartesi_rollups_authority_claimer_wallet_balance{chain_id="11155420",authority_onwer="cartesi_rollups_authority_claimer_wallet_balance"} 123
# EOF

I don't know what should be the value since each chain has its own token. maybe we'd need a configuration to define the token or the precision for the value.

endersonmaia commented 3 months ago

This is a sample output of my own exporter that I'm using for sunodo.

# HELP sunodo_wallet_balance The balance for a given address as float64 from BigInt with loss of precision.
# TYPE sunodo_wallet_balance gauge
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="1",chain_name="mainnet"} 0
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="10",chain_name="optimism-mainnet"} 0
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="11155111",chain_name="sepolia"} 4.900563043998054e+16
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="11155420",chain_name="optimism-sepolia"} 1.0275045421842128e+17
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="42161",chain_name="arbitrum-mainnet"} 0
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="421614",chain_name="arbitrum-sepolia"} 4.99053544e+16
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="8453",chain_name="base-mainnet"} 0
sunodo_wallet_balance{address="0xd330c12e8dbd00570616d9406614106e2b3a1cf5",chain_id="84532",chain_name="base-sepolia"} 3.9783845731226925e+17

My version will hit the blockchain provider RPC every time a scrape is made to the /metrics endpoint.

Ideally, having this integrated into the rollups-node-authority-claimer, the metrics should be updated every time a transaction (claim) is made that can change the wallet balance.