diff --git a/Cargo.lock b/Cargo.lock index 81441365..19a5d3d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5199,7 +5199,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core 0.52.0", + "windows-core", ] [[package]] @@ -10525,7 +10525,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -10564,7 +10564,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "proc-macro2", "quote", @@ -10585,7 +10585,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "environmental", "parity-scale-codec", @@ -10740,7 +10740,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -10771,7 +10771,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "Inflector", "expander", @@ -10869,7 +10869,7 @@ source = "git+https://github.com/gear-tech/polkadot-sdk.git?branch=gear-v1.4.0#0 [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" [[package]] name = "sp-storage" @@ -10887,7 +10887,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "impl-serde", "parity-scale-codec", @@ -10924,7 +10924,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "parity-scale-codec", "tracing", @@ -11002,7 +11002,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#149c70938f2b29f8d92ba1cc952aeb63d4084e27" +source = "git+https://github.com/paritytech/polkadot-sdk#a4b51593dbe9b9390fa64f5040a9230b5d33b898" dependencies = [ "impl-trait-for-tuples", "log", @@ -12938,7 +12938,7 @@ version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" dependencies = [ - "windows-core 0.51.1", + "windows-core", "windows-targets 0.48.5", ] @@ -12951,15 +12951,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-sys" version = "0.33.0" diff --git a/relayer/src/ethereum_checkpoints/metrics.rs b/relayer/src/ethereum_checkpoints/metrics.rs index 714d9c47..e9de5177 100644 --- a/relayer/src/ethereum_checkpoints/metrics.rs +++ b/relayer/src/ethereum_checkpoints/metrics.rs @@ -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, } } @@ -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", @@ -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", + )?, }) } } diff --git a/relayer/src/ethereum_checkpoints/mod.rs b/relayer/src/ethereum_checkpoints/mod.rs index 09cd2de3..2cbb96de 100644 --- a/relayer/src/ethereum_checkpoints/mod.rs +++ b/relayer/src/ethereum_checkpoints/mod.rs @@ -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"); @@ -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); @@ -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(); } } @@ -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:?}"), } }