Skip to content

Commit

Permalink
feat(fortuna): Track amount spent on tx fees (#2245)
Browse files Browse the repository at this point in the history
* track amount spent on tx fees

* comment

* bump version
  • Loading branch information
jayantk authored Jan 13, 2025
1 parent 3ea2ac7 commit 5fc0f0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/fortuna/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/fortuna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fortuna"
version = "7.0.0"
version = "7.1.0"
edition = "2021"

[dependencies]
Expand Down
45 changes: 26 additions & 19 deletions apps/fortuna/src/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct KeeperMetrics {
pub collected_fee: Family<AccountLabel, Gauge<f64, AtomicU64>>,
pub current_fee: Family<AccountLabel, Gauge<f64, AtomicU64>>,
pub total_gas_spent: Family<AccountLabel, Gauge<f64, AtomicU64>>,
pub total_gas_fee_spent: Family<AccountLabel, Gauge<f64, AtomicU64>>,
pub requests: Family<AccountLabel, Counter>,
pub requests_processed: Family<AccountLabel, Counter>,
pub requests_processed_success: Family<AccountLabel, Counter>,
Expand All @@ -88,6 +89,7 @@ impl Default for KeeperMetrics {
collected_fee: Family::default(),
current_fee: Family::default(),
total_gas_spent: Family::default(),
total_gas_fee_spent: Family::default(),
requests: Family::default(),
requests_processed: Family::default(),
requests_processed_success: Family::default(),
Expand Down Expand Up @@ -178,6 +180,12 @@ impl KeeperMetrics {
keeper_metrics.total_gas_spent.clone(),
);

writable_registry.register(
"total_gas_fee_spent",
"Total amount of ETH spent on gas for revealing requests",
keeper_metrics.total_gas_fee_spent.clone(),
);

writable_registry.register(
"requests_reprocessed",
"Number of requests reprocessed",
Expand Down Expand Up @@ -476,6 +484,7 @@ pub async fn process_event_with_backoff(
.contract
.get_request(event.provider_address, event.sequence_number)
.await;

tracing::error!("Failed to process event: {:?}. Request: {:?}", e, req);

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

let account_label = AccountLabel {
chain_id: chain_config.id.clone(),
address: chain_config.provider_address.to_string(),
};

if let Some(gas_used) = receipt.gas_used {
let gas_used = gas_used.as_u128() as f64 / 1e18;
let gas_used_float = gas_used.as_u128() as f64 / 1e18;
metrics
.total_gas_spent
.get_or_create(&AccountLabel {
chain_id: chain_config.id.clone(),
address: client
.inner()
.inner()
.inner()
.signer()
.address()
.to_string(),
})
.inc_by(gas_used);
.get_or_create(&account_label)
.inc_by(gas_used_float);

if let Some(gas_price) = receipt.effective_gas_price {
let gas_fee = (gas_used * gas_price).as_u128() as f64 / 1e18;
metrics
.total_gas_fee_spent
.get_or_create(&account_label)
.inc_by(gas_fee);
}
}

metrics
.reveals
.get_or_create(&AccountLabel {
chain_id: chain_config.id.clone(),
address: chain_config.provider_address.to_string(),
})
.inc();
metrics.reveals.get_or_create(&account_label).inc();

Ok(())
}
Expand Down

0 comments on commit 5fc0f0d

Please sign in to comment.