Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve relayer metrics #105

Merged
merged 3 commits into from
Aug 20, 2024
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
31 changes: 11 additions & 20 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions relayer/src/ethereum_checkpoints/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ impl_metered_service! {
pub struct Updates {
pub fetched_sync_update_slot: IntGauge,
pub total_fetched_finality_updates: IntCounter,
pub total_fetched_committee_updates: IntCounter,
pub processed_finality_updates: IntCounter,
pub processed_committee_updates: IntCounter,
pub account_total_balance: IntGauge,
}
}

Expand All @@ -26,10 +26,6 @@ impl Updates {
"checkpoints_relayer_total_fetched_finality_updates",
"Total amount of fetched finality updates",
)?,
total_fetched_committee_updates: IntCounter::new(
"checkpoints_relayer_total_fetched_committee_updates",
"Total amount of fetched committee updates",
)?,
processed_finality_updates: IntCounter::new(
"checkpoints_relayer_processed_finality_updates",
"Amount of processed finality updates",
Expand All @@ -38,6 +34,10 @@ impl Updates {
"checkpoints_relayer_processed_committee_updates",
"Amount of processed committee updates",
)?,
account_total_balance: IntGauge::new(
"checkpoints_relayer_account_total_balance",
"The total balance of the account used to send messages",
)?,
})
}
}
28 changes: 23 additions & 5 deletions relayer/src/ethereum_checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ mod sync_update;
mod utils;

const SIZE_CHANNEL: usize = 100_000;
const SIZE_BATCH: u64 = 40 * SLOTS_PER_EPOCH;
const SIZE_BATCH: u64 = 30 * SLOTS_PER_EPOCH;
const COUNT_FAILURE: usize = 3;
const DELAY_SECS_UPDATE_REQUEST: u64 = 30;
// The constant is intentionally duplicated since vara-runtime is too heavy dependency.
const UNITS: u128 = 1_000_000_000_000;

pub async fn relay(args: RelayCheckpointsArgs) {
log::info!("Started");
Expand Down Expand Up @@ -123,6 +125,8 @@ pub async fn relay(args: RelayCheckpointsArgs) {

log::info!("Metrics service spawned");

update_total_balance(&client, &update_metrics).await;

loop {
let future_interrupt = signal_interrupt.recv();
pin_mut!(future_interrupt);
Expand All @@ -148,22 +152,22 @@ pub async fn relay(args: RelayCheckpointsArgs) {
.fetched_sync_update_slot
.set(i64::from_le_bytes(slot.to_le_bytes()));

if slot == slot_last {
let committee_update = sync_update.sync_committee_next_pub_keys.is_some();
if !committee_update {
update_metrics.total_fetched_finality_updates.inc();
}

if slot == slot_last {
continue;
}

let committee_update = sync_update.sync_committee_next_pub_keys.is_some();
match sync_update::try_to_apply(&client, program_id, sync_update, gas_limit).await {
Ok(Ok(_)) => {
slot_last = slot;

if committee_update {
update_metrics.total_fetched_committee_updates.inc();
update_metrics.processed_committee_updates.inc();
} else {
update_metrics.total_fetched_finality_updates.inc();
update_metrics.processed_finality_updates.inc();
}
}
Expand All @@ -182,5 +186,19 @@ pub async fn relay(args: RelayCheckpointsArgs) {
return;
}
}

update_total_balance(&client, &update_metrics).await;
}
}

async fn update_total_balance(client: &GearApi, update_metrics: &metrics::Updates) {
match client.total_balance(client.account_id()).await {
Ok(total_balance) => {
let total_balance = total_balance / UNITS;
let total_balance: i64 = total_balance.try_into().unwrap_or(i64::MAX);

update_metrics.account_total_balance.set(total_balance);
}
Err(e) => log::error!("Unable to get total balance: {e:?}"),
}
}
Loading