Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.3"
version = "7.4.4"
edition = "2021"

[lib]
Expand Down
9 changes: 9 additions & 0 deletions apps/fortuna/src/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
keeper::commitment::update_commitments_loop,
keeper::fee::adjust_fee_wrapper,
keeper::fee::withdraw_fees_wrapper,
keeper::track::track_accrued_pyth_fees,
keeper::track::track_balance,
keeper::track::track_provider,
},
Expand Down Expand Up @@ -208,6 +209,14 @@ pub async fn run_keeper_threads(
)
.in_current_span(),
);
spawn(
track_accrued_pyth_fees(
chain_id.clone(),
contract.clone(),
keeper_metrics.clone(),
)
.in_current_span(),
);

time::sleep(TRACK_INTERVAL).await;
}
Expand Down
23 changes: 23 additions & 0 deletions apps/fortuna/src/keeper/keeper_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ pub struct AccountLabel {
pub address: String,
}

#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
pub struct ChainIdLabel {
pub chain_id: String,
}

pub struct KeeperMetrics {
pub current_sequence_number: Family<AccountLabel, Gauge>,
pub end_sequence_number: Family<AccountLabel, Gauge>,
Expand All @@ -36,6 +41,7 @@ pub struct KeeperMetrics {
pub final_gas_multiplier: Family<AccountLabel, Histogram>,
pub final_fee_multiplier: Family<AccountLabel, Histogram>,
pub gas_price_estimate: Family<AccountLabel, Gauge<f64, AtomicU64>>,
pub accrued_pyth_fees: Family<ChainIdLabel, Gauge<f64, AtomicU64>>,
}

impl Default for KeeperMetrics {
Expand Down Expand Up @@ -76,6 +82,7 @@ impl Default for KeeperMetrics {
Histogram::new(vec![100.0, 110.0, 120.0, 140.0, 160.0, 180.0, 200.0].into_iter())
}),
gas_price_estimate: Family::default(),
accrued_pyth_fees: Family::default(),
}
}
}
Expand Down Expand Up @@ -202,9 +209,25 @@ impl KeeperMetrics {
keeper_metrics.gas_price_estimate.clone(),
);

writable_registry.register(
"accrued_pyth_fees",
"Accrued Pyth fees on the contract",
keeper_metrics.accrued_pyth_fees.clone(),
);

// *Important*: When adding a new metric:
// 1. Register it above using `writable_registry.register(...)`
// 2. Add a get_or_create call in the loop below to initialize it for each chain/provider pair

// Initialize accrued_pyth_fees for each chain_id
for (chain_id, _) in chain_labels.iter() {
let _ = keeper_metrics
.accrued_pyth_fees
.get_or_create(&ChainIdLabel {
chain_id: chain_id.clone(),
});
}

for (chain_id, provider_address) in chain_labels {
let account_label = AccountLabel {
chain_id,
Expand Down
30 changes: 29 additions & 1 deletion apps/fortuna/src/keeper/track.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::keeper_metrics::{AccountLabel, KeeperMetrics},
super::keeper_metrics::{AccountLabel, ChainIdLabel, KeeperMetrics},
crate::{
api::ChainId, chain::ethereum::InstrumentedPythContract,
eth_utils::traced_client::TracedClient,
Expand Down Expand Up @@ -100,3 +100,31 @@ pub async fn track_provider(
})
.set(end_sequence_number as i64);
}

/// tracks the accrued pyth fees on the given chain
/// if there is an error the function will just return
#[tracing::instrument(skip_all)]
pub async fn track_accrued_pyth_fees(
chain_id: ChainId,
contract: InstrumentedPythContract,
metrics: Arc<KeeperMetrics>,
) {
let accrued_pyth_fees = match contract.get_accrued_pyth_fees().call().await {
Ok(fees) => fees,
Err(e) => {
tracing::error!("Error while getting accrued pyth fees. error: {:?}", e);
return;
}
};

// The f64 conversion is made to be able to serve metrics with the constraints of Prometheus.
// The fee is in wei, so we divide by 1e18 to convert it to eth.
let accrued_pyth_fees = accrued_pyth_fees as f64 / 1e18;

metrics
.accrued_pyth_fees
.get_or_create(&ChainIdLabel {
chain_id: chain_id.clone(),
})
.set(accrued_pyth_fees);
}
Loading