Skip to content

Commit 5fc0f0d

Browse files
authored
feat(fortuna): Track amount spent on tx fees (#2245)
* track amount spent on tx fees * comment * bump version
1 parent 3ea2ac7 commit 5fc0f0d

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

apps/fortuna/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "7.0.0"
3+
version = "7.1.0"
44
edition = "2021"
55

66
[dependencies]

apps/fortuna/src/keeper.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub struct KeeperMetrics {
7070
pub collected_fee: Family<AccountLabel, Gauge<f64, AtomicU64>>,
7171
pub current_fee: Family<AccountLabel, Gauge<f64, AtomicU64>>,
7272
pub total_gas_spent: Family<AccountLabel, Gauge<f64, AtomicU64>>,
73+
pub total_gas_fee_spent: Family<AccountLabel, Gauge<f64, AtomicU64>>,
7374
pub requests: Family<AccountLabel, Counter>,
7475
pub requests_processed: Family<AccountLabel, Counter>,
7576
pub requests_processed_success: Family<AccountLabel, Counter>,
@@ -88,6 +89,7 @@ impl Default for KeeperMetrics {
8889
collected_fee: Family::default(),
8990
current_fee: Family::default(),
9091
total_gas_spent: Family::default(),
92+
total_gas_fee_spent: Family::default(),
9193
requests: Family::default(),
9294
requests_processed: Family::default(),
9395
requests_processed_success: Family::default(),
@@ -178,6 +180,12 @@ impl KeeperMetrics {
178180
keeper_metrics.total_gas_spent.clone(),
179181
);
180182

183+
writable_registry.register(
184+
"total_gas_fee_spent",
185+
"Total amount of ETH spent on gas for revealing requests",
186+
keeper_metrics.total_gas_fee_spent.clone(),
187+
);
188+
181189
writable_registry.register(
182190
"requests_reprocessed",
183191
"Number of requests reprocessed",
@@ -476,6 +484,7 @@ pub async fn process_event_with_backoff(
476484
.contract
477485
.get_request(event.provider_address, event.sequence_number)
478486
.await;
487+
479488
tracing::error!("Failed to process event: {:?}. Request: {:?}", e, req);
480489

481490
// We only count failures for cases where we are completely certain that the callback failed.
@@ -635,30 +644,28 @@ pub async fn process_event(
635644
receipt
636645
);
637646

647+
let account_label = AccountLabel {
648+
chain_id: chain_config.id.clone(),
649+
address: chain_config.provider_address.to_string(),
650+
};
651+
638652
if let Some(gas_used) = receipt.gas_used {
639-
let gas_used = gas_used.as_u128() as f64 / 1e18;
653+
let gas_used_float = gas_used.as_u128() as f64 / 1e18;
640654
metrics
641655
.total_gas_spent
642-
.get_or_create(&AccountLabel {
643-
chain_id: chain_config.id.clone(),
644-
address: client
645-
.inner()
646-
.inner()
647-
.inner()
648-
.signer()
649-
.address()
650-
.to_string(),
651-
})
652-
.inc_by(gas_used);
656+
.get_or_create(&account_label)
657+
.inc_by(gas_used_float);
658+
659+
if let Some(gas_price) = receipt.effective_gas_price {
660+
let gas_fee = (gas_used * gas_price).as_u128() as f64 / 1e18;
661+
metrics
662+
.total_gas_fee_spent
663+
.get_or_create(&account_label)
664+
.inc_by(gas_fee);
665+
}
653666
}
654667

655-
metrics
656-
.reveals
657-
.get_or_create(&AccountLabel {
658-
chain_id: chain_config.id.clone(),
659-
address: chain_config.provider_address.to_string(),
660-
})
661-
.inc();
668+
metrics.reveals.get_or_create(&account_label).inc();
662669

663670
Ok(())
664671
}

0 commit comments

Comments
 (0)