From a84068091cd04b10f6f379a9c09fb888b20eb0b8 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Sun, 12 Jan 2025 21:27:28 -0800 Subject: [PATCH 1/3] track amount spent on tx fees --- apps/fortuna/src/keeper.rs | 45 ++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index 2c47dd9fa4..07f1b6f5fe 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -71,6 +71,7 @@ pub struct KeeperMetrics { pub collected_fee: Family>, pub current_fee: Family>, pub total_gas_spent: Family>, + pub total_gas_fee_spent: Family>, pub requests: Family, pub requests_processed: Family, pub requests_processed_success: Family, @@ -89,6 +90,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(), @@ -179,6 +181,12 @@ impl KeeperMetrics { keeper_metrics.total_gas_spent.clone(), ); + writable_registry.register( + "total_gas_fee_spent", + "Total amount of wei spent on gas for revealing requests", + keeper_metrics.total_gas_fee_spent.clone(), + ); + writable_registry.register( "requests_reprocessed", "Number of requests reprocessed", @@ -471,6 +479,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. @@ -618,30 +627,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(()) } From 1d4db65696fc7a307625f243f9886f4fcc23e7ec Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Sun, 12 Jan 2025 21:28:20 -0800 Subject: [PATCH 2/3] comment --- apps/fortuna/src/keeper.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index 07f1b6f5fe..506c10a4d5 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -183,7 +183,7 @@ impl KeeperMetrics { writable_registry.register( "total_gas_fee_spent", - "Total amount of wei spent on gas for revealing requests", + "Total amount of ETH spent on gas for revealing requests", keeper_metrics.total_gas_fee_spent.clone(), ); From 82ca2909fec2580002ca6ed2a68adecd2b23cfc6 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Mon, 13 Jan 2025 09:20:35 -0800 Subject: [PATCH 3/3] bump version --- apps/fortuna/Cargo.lock | 2 +- apps/fortuna/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/fortuna/Cargo.lock b/apps/fortuna/Cargo.lock index 02e0ad04a4..9da01ca493 100644 --- a/apps/fortuna/Cargo.lock +++ b/apps/fortuna/Cargo.lock @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "fortuna" -version = "7.0.0" +version = "7.1.0" dependencies = [ "anyhow", "axum", diff --git a/apps/fortuna/Cargo.toml b/apps/fortuna/Cargo.toml index 454156d64c..eb7cf2dedf 100644 --- a/apps/fortuna/Cargo.toml +++ b/apps/fortuna/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fortuna" -version = "7.0.0" +version = "7.1.0" edition = "2021" [dependencies]