From 1d8c5e5dbf66d7532b223937e8a2edf6d5fccc83 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 13:46:12 +0000 Subject: [PATCH 01/41] stop logging the whole adapter response --- canister/src/heartbeat.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index ba82688a..7df99756 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -68,8 +68,6 @@ async fn maybe_fetch_blocks() -> bool { let response: Result<(GetSuccessorsResponse,), _> = call_get_successors(with_state(|s| s.blocks_source), request).await; - print(&format!("Received response: {:?}", response)); - // Save the response. with_state_mut(|s| { let response = match response { @@ -85,6 +83,11 @@ async fn maybe_fetch_blocks() -> bool { match response { GetSuccessorsResponse::Complete(response) => { // Received complete response. + print(&format!( + "Received complete response with {} blocks of size {} bytes.", + response.blocks.len(), + response.blocks.iter().map(|b| b.len()).sum::() + )); assert!( s.syncing_state.response_to_process.is_none(), "Received complete response before processing previous response." @@ -93,6 +96,11 @@ async fn maybe_fetch_blocks() -> bool { } GetSuccessorsResponse::Partial(partial_response) => { // Received partial response. + print(&format!( + "Received partial response with a partial block of {} bytes with remaining follow ups: {}.", + partial_response.partial_block.len(), + partial_response.remaining_follow_ups, + )); assert!( s.syncing_state.response_to_process.is_none(), "Received partial response before processing previous response." @@ -104,6 +112,10 @@ async fn maybe_fetch_blocks() -> bool { // Received a follow-up response. // A follow-up response is only expected, and only makes sense, when there's // a partial response to process. + print(&format!( + "Received follow-up response with a block of size {} bytes.", + block_bytes.len() + )); let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { Some(ResponseToProcess::Partial(res, pages)) => (res, pages), From 191533c521c78291d31e17f62c054c79ae9d4e8e Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 14:20:09 +0000 Subject: [PATCH 02/41] . --- canister/src/heartbeat.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 7df99756..aded04fd 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -83,28 +83,28 @@ async fn maybe_fetch_blocks() -> bool { match response { GetSuccessorsResponse::Complete(response) => { // Received complete response. + assert!( + s.syncing_state.response_to_process.is_none(), + "Received complete response before processing previous response." + ); print(&format!( "Received complete response with {} blocks of size {} bytes.", response.blocks.len(), response.blocks.iter().map(|b| b.len()).sum::() )); - assert!( - s.syncing_state.response_to_process.is_none(), - "Received complete response before processing previous response." - ); s.syncing_state.response_to_process = Some(ResponseToProcess::Complete(response)); } GetSuccessorsResponse::Partial(partial_response) => { // Received partial response. - print(&format!( - "Received partial response with a partial block of {} bytes with remaining follow ups: {}.", - partial_response.partial_block.len(), - partial_response.remaining_follow_ups, - )); assert!( s.syncing_state.response_to_process.is_none(), "Received partial response before processing previous response." ); + println!( + "Received partial response with {} bytes and {} follow-ups remaining.", + partial_response.partial_block.len(), + partial_response.remaining_follow_ups, + ); s.syncing_state.response_to_process = Some(ResponseToProcess::Partial(partial_response, 0)); } From a54cab21302ae93e75ae0e5f49125955ae53580b Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 14:23:40 +0000 Subject: [PATCH 03/41] . --- canister/src/heartbeat.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index aded04fd..e13e3c28 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -87,11 +87,11 @@ async fn maybe_fetch_blocks() -> bool { s.syncing_state.response_to_process.is_none(), "Received complete response before processing previous response." ); - print(&format!( - "Received complete response with {} blocks of size {} bytes.", + println!( + "Complete response: {} blocks, total {} bytes.", response.blocks.len(), response.blocks.iter().map(|b| b.len()).sum::() - )); + ); s.syncing_state.response_to_process = Some(ResponseToProcess::Complete(response)); } GetSuccessorsResponse::Partial(partial_response) => { @@ -101,7 +101,7 @@ async fn maybe_fetch_blocks() -> bool { "Received partial response before processing previous response." ); println!( - "Received partial response with {} bytes and {} follow-ups remaining.", + "Partial response: {} bytes, {} follow-ups remaining.", partial_response.partial_block.len(), partial_response.remaining_follow_ups, ); @@ -112,10 +112,7 @@ async fn maybe_fetch_blocks() -> bool { // Received a follow-up response. // A follow-up response is only expected, and only makes sense, when there's // a partial response to process. - print(&format!( - "Received follow-up response with a block of size {} bytes.", - block_bytes.len() - )); + println!("Follow-up response: {} bytes.", block_bytes.len()); let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { Some(ResponseToProcess::Partial(res, pages)) => (res, pages), From 6a3855d79d9eede8ccbe3b1119442e5476c11c7c Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 14:24:20 +0000 Subject: [PATCH 04/41] . --- canister/src/heartbeat.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index e13e3c28..a68b481b 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -88,7 +88,7 @@ async fn maybe_fetch_blocks() -> bool { "Received complete response before processing previous response." ); println!( - "Complete response: {} blocks, total {} bytes.", + "Received complete response: {} blocks, total {} bytes.", response.blocks.len(), response.blocks.iter().map(|b| b.len()).sum::() ); @@ -101,7 +101,7 @@ async fn maybe_fetch_blocks() -> bool { "Received partial response before processing previous response." ); println!( - "Partial response: {} bytes, {} follow-ups remaining.", + "Received partial response: {} bytes, {} follow-ups remaining.", partial_response.partial_block.len(), partial_response.remaining_follow_ups, ); @@ -112,7 +112,7 @@ async fn maybe_fetch_blocks() -> bool { // Received a follow-up response. // A follow-up response is only expected, and only makes sense, when there's // a partial response to process. - println!("Follow-up response: {} bytes.", block_bytes.len()); + println!("Received follow-up response: {} bytes.", block_bytes.len()); let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { Some(ResponseToProcess::Partial(res, pages)) => (res, pages), From eb2aa61354b0b3fa9f54680cf253131f548a49d9 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:04:37 +0000 Subject: [PATCH 05/41] add successor_response_stats --- canister/src/api/metrics.rs | 15 +++++++++++++ canister/src/heartbeat.rs | 43 ++++++++++++++++++++++++++++++----- canister/src/state.rs | 45 +++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index 164abd86..9226f506 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -169,6 +169,21 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { .value(&[("flag", "enabled")], enabled)? .value(&[("flag", "disabled")], disabled)?; + if let Some(stats) = &state.syncing_state.successor_response_stats { + encode_labeled_gauge( + w, + "successor_response_block_count", + "Block count statistics for the latest GetSuccessorsResponse.", + &stats.get_block_count_metrics(), + )?; + encode_labeled_gauge( + w, + "successor_response_block_size", + "Block size statistics for the latest GetSuccessorsResponse.", + &stats.get_block_size_metrics(), + )?; + } + Ok(()) }) } diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index a68b481b..7b936c47 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -1,7 +1,7 @@ use crate::{ api::get_current_fee_percentiles_impl, runtime::{call_get_successors, cycles_burn, print}, - state::{self, ResponseToProcess}, + state::{self, ResponseToProcess, SuccessorsResponseStats}, types::{ GetSuccessorsCompleteResponse, GetSuccessorsRequest, GetSuccessorsRequestInitial, GetSuccessorsResponse, @@ -80,6 +80,9 @@ async fn maybe_fetch_blocks() -> bool { } }; + if s.syncing_state.successor_response_stats.is_none() { + s.syncing_state.successor_response_stats = Some(SuccessorsResponseStats::default()); + } match response { GetSuccessorsResponse::Complete(response) => { // Received complete response. @@ -87,11 +90,20 @@ async fn maybe_fetch_blocks() -> bool { s.syncing_state.response_to_process.is_none(), "Received complete response before processing previous response." ); + let count = response.blocks.len() as u64; + let bytes = response.blocks.iter().map(|b| b.len() as u64).sum::(); println!( "Received complete response: {} blocks, total {} bytes.", - response.blocks.len(), - response.blocks.iter().map(|b| b.len()).sum::() + count, bytes ); + if let Some(successor_response_stats) = + s.syncing_state.successor_response_stats.as_mut() + { + successor_response_stats.complete_block_count += count; + successor_response_stats.complete_block_size += bytes; + successor_response_stats.total_block_count += count; + successor_response_stats.total_block_size += bytes; + } s.syncing_state.response_to_process = Some(ResponseToProcess::Complete(response)); } GetSuccessorsResponse::Partial(partial_response) => { @@ -100,11 +112,21 @@ async fn maybe_fetch_blocks() -> bool { s.syncing_state.response_to_process.is_none(), "Received partial response before processing previous response." ); + let bytes = partial_response.partial_block.len() as u64; + let remaining = partial_response.remaining_follow_ups as u64; println!( "Received partial response: {} bytes, {} follow-ups remaining.", - partial_response.partial_block.len(), - partial_response.remaining_follow_ups, + bytes, remaining, ); + if let Some(successor_response_stats) = + s.syncing_state.successor_response_stats.as_mut() + { + successor_response_stats.partial_block_count += 1; + successor_response_stats.partial_block_size += bytes; + successor_response_stats.partial_follow_ups_remaining += remaining; + successor_response_stats.total_block_count += 1; + successor_response_stats.total_block_size += bytes; + } s.syncing_state.response_to_process = Some(ResponseToProcess::Partial(partial_response, 0)); } @@ -112,7 +134,16 @@ async fn maybe_fetch_blocks() -> bool { // Received a follow-up response. // A follow-up response is only expected, and only makes sense, when there's // a partial response to process. - println!("Received follow-up response: {} bytes.", block_bytes.len()); + let bytes = block_bytes.len() as u64; + println!("Received follow-up response: {} bytes.", bytes); + if let Some(successor_response_stats) = + s.syncing_state.successor_response_stats.as_mut() + { + successor_response_stats.follow_up_count += 1; + successor_response_stats.follow_up_size += bytes; + successor_response_stats.total_block_count += 1; + successor_response_stats.total_block_size += bytes; + } let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { Some(ResponseToProcess::Partial(res, pages)) => (res, pages), diff --git a/canister/src/state.rs b/canister/src/state.rs index be72d3a0..ab68ca86 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -325,6 +325,8 @@ pub struct SyncingState { /// The number of errors occurred when inserting a block. pub num_insert_block_errors: u64, + + pub successor_response_stats: Option, } impl Default for SyncingState { @@ -336,10 +338,53 @@ impl Default for SyncingState { num_get_successors_rejects: 0, num_block_deserialize_errors: 0, num_insert_block_errors: 0, + successor_response_stats: None, } } } +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)] +pub struct SuccessorsResponseStats { + pub total_block_count: u64, + pub total_block_size: u64, + + pub complete_block_count: u64, + pub complete_block_size: u64, + + pub partial_block_count: u64, + pub partial_block_size: u64, + pub partial_follow_ups_remaining: u64, + + pub follow_up_count: u64, + pub follow_up_size: u64, +} + +impl SuccessorsResponseStats { + pub fn get_block_count_metrics(&self) -> Vec<((&str, &str), u64)> { + vec![ + (("total_block_count", "total"), self.total_block_count), + ( + ("complete_block_count", "complete"), + self.complete_block_count, + ), + (("partial_block_count", "partial"), self.partial_block_count), + (("follow_up_count", "follow_up"), self.follow_up_count), + ] + } + + pub fn get_block_size_metrics(&self) -> Vec<((&str, &str), u64)> { + vec![ + (("total_block_size", "total"), self.total_block_size), + ( + ("complete_block_size", "complete"), + self.complete_block_size, + ), + (("partial_block_size", "partial"), self.partial_block_size), + (("follow_up_size", "follow_up"), self.follow_up_size), + ] + } +} + /// Cache for storing last calculated fee percentiles /// /// Stores last tip block hash and fee percentiles associated with it. From 99eea13714a3b5d2adc59b4ad3b4dc6d8bbd49a5 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:08:23 +0000 Subject: [PATCH 06/41] update ignore files --- .dockerignore | 5 ++++- .gitignore | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 328aba36..0a971641 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,7 +4,10 @@ out # Exclude intermediate files for computing canister state, # except `chunk_hashes.txt`. -bootstrap/output +bootstrap/bitcoin-* +bootstrap/output* +*.log +*.csv # Exclude all hidden files and directories .* diff --git a/.gitignore b/.gitignore index 9c220f4a..1ed8c2d3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ target .dfx -canister_ids.json +canister_ids*.json .canbench pocket-ic @@ -14,3 +14,6 @@ pocket-ic bootstrap/bitcoin-* bootstrap/output* chunk_hashes.txt + +*.log +*.csv From 173a790850d0520bbc6d48725dbd6094db9e80af Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:09:07 +0000 Subject: [PATCH 07/41] TESTNET_CHAIN_MAX_DEPTH: u128 = 200 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index b5c15c1c..58649053 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 1000; +const TESTNET_CHAIN_MAX_DEPTH: u128 = 200; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 30c4a02346ca3fe4f2f81d288040475d22097dbc Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:11:13 +0000 Subject: [PATCH 08/41] log_metrics --- canister/src/heartbeat.rs | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 7b936c47..2cf2979d 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -18,6 +18,8 @@ use ic_btc_types::{Block, BlockHash}; pub async fn heartbeat() { print("Starting heartbeat..."); + log_metrics(); // TODO: do not submit! this is only for testing. + maybe_burn_cycles(); if ingest_stable_blocks_into_utxoset() { @@ -39,6 +41,77 @@ pub async fn heartbeat() { maybe_compute_fee_percentiles(); } +fn log_metrics() { + with_state(|s| { + // General stats + print(&format!( + "main_chain_height: {}", + state::main_chain_height(s) + )); + print(&format!("stable_height: {}", s.stable_height())); + print(&format!("utxos_length: {}", s.utxos.utxos_len())); + print(&format!( + "address_utxos_length: {}", + s.utxos.address_utxos_len() + )); + + // Unstable blocks and stability threshold + print(&format!( + "anchor_difficulty: {}", + s.unstable_blocks.anchor_difficulty() + )); + print(&format!( + "normalized_stability_threshold: {}", + s.unstable_blocks.normalized_stability_threshold() + )); + print(&format!( + "unstable_blocks_num_tips: {}", + s.unstable_blocks.num_tips() + )); + print(&format!( + "unstable_blocks_total: {}", + state::get_unstable_blocks(s).len() + )); + print(&format!( + "unstable_blocks_depth: {}", + s.unstable_blocks.blocks_depth() + )); + print(&format!( + "unstable_blocks_difficulty_based_depth: {}", + s.unstable_blocks.blocks_difficulty_based_depth() + )); + + // Errors + print(&format!( + "num_get_successors_rejects: {}", + s.syncing_state.num_get_successors_rejects + )); + print(&format!( + "num_block_deserialize_errors: {}", + s.syncing_state.num_block_deserialize_errors + )); + print(&format!( + "num_insert_block_errors: {}", + s.syncing_state.num_insert_block_errors + )); + + // Metrics + print(&format!( + "send_transaction_count: {}", + s.metrics.send_transaction_count + )); + print(&format!( + "cycles_burnt: {}", + s.metrics.cycles_burnt.unwrap_or_default() + )); + print(&format!( + "cycles_balance: {}", + ic_cdk::api::canister_balance() + )); + print(&format!("is_synced: {}", crate::is_synced())); + }); +} + // Fetches new blocks if there isn't a request in progress and no complete response to process. // Returns true if a call to the `blocks_source` has been made, false otherwise. async fn maybe_fetch_blocks() -> bool { From 47e985ae58b02e30334fac3dd1267d6ae925de01 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:13:22 +0000 Subject: [PATCH 09/41] fix labels --- canister/src/state.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/canister/src/state.rs b/canister/src/state.rs index ab68ca86..3962f21b 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -362,25 +362,19 @@ pub struct SuccessorsResponseStats { impl SuccessorsResponseStats { pub fn get_block_count_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("total_block_count", "total"), self.total_block_count), - ( - ("complete_block_count", "complete"), - self.complete_block_count, - ), - (("partial_block_count", "partial"), self.partial_block_count), - (("follow_up_count", "follow_up"), self.follow_up_count), + (("block_count", "total"), self.total_block_count), + (("block_count", "complete"), self.complete_block_count), + (("block_count", "partial"), self.partial_block_count), + (("block_count", "follow_up"), self.follow_up_count), ] } pub fn get_block_size_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("total_block_size", "total"), self.total_block_size), - ( - ("complete_block_size", "complete"), - self.complete_block_size, - ), - (("partial_block_size", "partial"), self.partial_block_size), - (("follow_up_size", "follow_up"), self.follow_up_size), + (("block_size", "total"), self.total_block_size), + (("block_size", "complete"), self.complete_block_size), + (("block_size", "partial"), self.partial_block_size), + (("block_size", "follow_up"), self.follow_up_size), ] } } From cedb00fc19b6cd5920b50c690a02fc0d1bba41b1 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:25:06 +0000 Subject: [PATCH 10/41] serde default --- canister/src/state.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/canister/src/state.rs b/canister/src/state.rs index 3962f21b..1f1fb673 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -326,6 +326,8 @@ pub struct SyncingState { /// The number of errors occurred when inserting a block. pub num_insert_block_errors: u64, + /// Stats about the responses received from GetSuccessors. + #[serde(default)] // Ensures backward compatibility during deserialization pub successor_response_stats: Option, } From 334c7d9c53e23f96afb2e86d21a3dc69e01dd629 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:32:40 +0000 Subject: [PATCH 11/41] add CARGO_TERM_COLOR always to CI --- .github/workflows/workflow.yml | 41 +++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 6a9925cc..ccd38d5c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -4,6 +4,7 @@ env: RUST_VERSION: 1.76.0 DFX_VERSION: 0.21.0 POCKET_IC_SERVER_VERSION: 7.0.0 + CARGO_TERM_COLOR: always # Force Cargo to use colors on: push: @@ -12,12 +13,11 @@ on: pull_request: jobs: - cargo-build: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-20.04, macos-13 ] + os: [ubuntu-20.04, macos-13] steps: - uses: actions/checkout@v4 @@ -48,7 +48,7 @@ jobs: needs: cargo-build strategy: matrix: - os: [ ubuntu-20.04, macos-13 ] + os: [ubuntu-20.04, macos-13] steps: - uses: actions/checkout@v4 @@ -146,11 +146,11 @@ jobs: name: ShellCheck runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v4 - - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master - env: - SHELLCHECK_OPTS: -e SC1090 -e SC2119 -e SC1091 + - uses: actions/checkout@v4 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + env: + SHELLCHECK_OPTS: -e SC1090 -e SC2119 -e SC1091 e2e-scenario-1: runs-on: ubuntu-20.04 @@ -648,9 +648,28 @@ jobs: checks-pass: # Always run this job! if: always() - needs: [cargo-tests, shell-checks, cargo-clippy, rustfmt, e2e-disable-api-if-not-fully-synced-flag, e2e-scenario-1, e2e-scenario-2, - e2e-scenario-3, charge-cycles-on-reject, upgradability, set_config, cycles_burn, benchmark, watchdog_health_status, - watchdog_get_config, watchdog_metrics, watchdog_upgradability, canister-build-reproducibility, bitcoin_canister_metadata] + needs: + [ + cargo-tests, + shell-checks, + cargo-clippy, + rustfmt, + e2e-disable-api-if-not-fully-synced-flag, + e2e-scenario-1, + e2e-scenario-2, + e2e-scenario-3, + charge-cycles-on-reject, + upgradability, + set_config, + cycles_burn, + benchmark, + watchdog_health_status, + watchdog_get_config, + watchdog_metrics, + watchdog_upgradability, + canister-build-reproducibility, + bitcoin_canister_metadata, + ] runs-on: ubuntu-20.04 steps: - name: check cargo-tests result From aa70945c58abf78dacfc842a65889bdc45299cd7 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:51:51 +0000 Subject: [PATCH 12/41] TESTNET_CHAIN_MAX_DEPTH 1000 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 58649053..2aed1724 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 200; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 1_000; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 5bf02013e9513dd6a87a081f4d2104e68f1b4612 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:52:08 +0000 Subject: [PATCH 13/41] TESTNET_CHAIN_MAX_DEPTH: u128 = 500 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 2aed1724..1462efd9 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 1_000; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 500; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 308dfa6943d4f232d2df68b5f7235d4d281e65ee Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:52:29 +0000 Subject: [PATCH 14/41] TESTNET_CHAIN_MAX_DEPTH: u128 = 300 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 1462efd9..545407cb 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 500; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 300; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 6aaa505eda9f15e942c7937a32cf006eba3dd6c3 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 15:52:51 +0000 Subject: [PATCH 15/41] TESTNET_CHAIN_MAX_DEPTH: u128 = 700 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 545407cb..4bbcee16 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 300; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 700; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From a06b9664b99cf2cac6664c00f1a88e38894c68d2 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:08:07 +0000 Subject: [PATCH 16/41] turn of extra logging --- canister/src/heartbeat.rs | 142 ++++++++++++++++---------------- canister/src/unstable_blocks.rs | 2 +- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 2cf2979d..aa47f7db 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -18,7 +18,7 @@ use ic_btc_types::{Block, BlockHash}; pub async fn heartbeat() { print("Starting heartbeat..."); - log_metrics(); // TODO: do not submit! this is only for testing. + //log_metrics(); // TODO: do not submit! this is only for testing. maybe_burn_cycles(); @@ -41,76 +41,76 @@ pub async fn heartbeat() { maybe_compute_fee_percentiles(); } -fn log_metrics() { - with_state(|s| { - // General stats - print(&format!( - "main_chain_height: {}", - state::main_chain_height(s) - )); - print(&format!("stable_height: {}", s.stable_height())); - print(&format!("utxos_length: {}", s.utxos.utxos_len())); - print(&format!( - "address_utxos_length: {}", - s.utxos.address_utxos_len() - )); - - // Unstable blocks and stability threshold - print(&format!( - "anchor_difficulty: {}", - s.unstable_blocks.anchor_difficulty() - )); - print(&format!( - "normalized_stability_threshold: {}", - s.unstable_blocks.normalized_stability_threshold() - )); - print(&format!( - "unstable_blocks_num_tips: {}", - s.unstable_blocks.num_tips() - )); - print(&format!( - "unstable_blocks_total: {}", - state::get_unstable_blocks(s).len() - )); - print(&format!( - "unstable_blocks_depth: {}", - s.unstable_blocks.blocks_depth() - )); - print(&format!( - "unstable_blocks_difficulty_based_depth: {}", - s.unstable_blocks.blocks_difficulty_based_depth() - )); - - // Errors - print(&format!( - "num_get_successors_rejects: {}", - s.syncing_state.num_get_successors_rejects - )); - print(&format!( - "num_block_deserialize_errors: {}", - s.syncing_state.num_block_deserialize_errors - )); - print(&format!( - "num_insert_block_errors: {}", - s.syncing_state.num_insert_block_errors - )); - - // Metrics - print(&format!( - "send_transaction_count: {}", - s.metrics.send_transaction_count - )); - print(&format!( - "cycles_burnt: {}", - s.metrics.cycles_burnt.unwrap_or_default() - )); - print(&format!( - "cycles_balance: {}", - ic_cdk::api::canister_balance() - )); - print(&format!("is_synced: {}", crate::is_synced())); - }); -} +// fn log_metrics() { +// with_state(|s| { +// // General stats +// print(&format!( +// "main_chain_height: {}", +// state::main_chain_height(s) +// )); +// print(&format!("stable_height: {}", s.stable_height())); +// print(&format!("utxos_length: {}", s.utxos.utxos_len())); +// print(&format!( +// "address_utxos_length: {}", +// s.utxos.address_utxos_len() +// )); + +// // Unstable blocks and stability threshold +// print(&format!( +// "anchor_difficulty: {}", +// s.unstable_blocks.anchor_difficulty() +// )); +// print(&format!( +// "normalized_stability_threshold: {}", +// s.unstable_blocks.normalized_stability_threshold() +// )); +// print(&format!( +// "unstable_blocks_num_tips: {}", +// s.unstable_blocks.num_tips() +// )); +// print(&format!( +// "unstable_blocks_total: {}", +// state::get_unstable_blocks(s).len() +// )); +// print(&format!( +// "unstable_blocks_depth: {}", +// s.unstable_blocks.blocks_depth() +// )); +// print(&format!( +// "unstable_blocks_difficulty_based_depth: {}", +// s.unstable_blocks.blocks_difficulty_based_depth() +// )); + +// // Errors +// print(&format!( +// "num_get_successors_rejects: {}", +// s.syncing_state.num_get_successors_rejects +// )); +// print(&format!( +// "num_block_deserialize_errors: {}", +// s.syncing_state.num_block_deserialize_errors +// )); +// print(&format!( +// "num_insert_block_errors: {}", +// s.syncing_state.num_insert_block_errors +// )); + +// // Metrics +// print(&format!( +// "send_transaction_count: {}", +// s.metrics.send_transaction_count +// )); +// print(&format!( +// "cycles_burnt: {}", +// s.metrics.cycles_burnt.unwrap_or_default() +// )); +// print(&format!( +// "cycles_balance: {}", +// ic_cdk::api::canister_balance() +// )); +// print(&format!("is_synced: {}", crate::is_synced())); +// }); +// } // Fetches new blocks if there isn't a request in progress and no complete response to process. // Returns true if a call to the `blocks_source` has been made, false otherwise. diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 4bbcee16..2aed1724 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 700; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 1_000; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 52679b7d915d695b86b087b93f1fa4044ea4477d Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:09:29 +0000 Subject: [PATCH 17/41] turn off metrics --- canister/src/api/metrics.rs | 28 +++++++++---------- canister/src/heartbeat.rs | 56 ++++++++++++++++++------------------- canister/src/state.rs | 7 ++--- 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index 9226f506..6f23a6c1 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -169,20 +169,20 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { .value(&[("flag", "enabled")], enabled)? .value(&[("flag", "disabled")], disabled)?; - if let Some(stats) = &state.syncing_state.successor_response_stats { - encode_labeled_gauge( - w, - "successor_response_block_count", - "Block count statistics for the latest GetSuccessorsResponse.", - &stats.get_block_count_metrics(), - )?; - encode_labeled_gauge( - w, - "successor_response_block_size", - "Block size statistics for the latest GetSuccessorsResponse.", - &stats.get_block_size_metrics(), - )?; - } + // if let Some(stats) = &state.syncing_state.successor_response_stats { + // encode_labeled_gauge( + // w, + // "successor_response_block_count", + // "Block count statistics for the latest GetSuccessorsResponse.", + // &stats.get_block_count_metrics(), + // )?; + // encode_labeled_gauge( + // w, + // "successor_response_block_size", + // "Block size statistics for the latest GetSuccessorsResponse.", + // &stats.get_block_size_metrics(), + // )?; + // } Ok(()) }) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index aa47f7db..91a52dac 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -153,9 +153,9 @@ async fn maybe_fetch_blocks() -> bool { } }; - if s.syncing_state.successor_response_stats.is_none() { - s.syncing_state.successor_response_stats = Some(SuccessorsResponseStats::default()); - } + // if s.syncing_state.successor_response_stats.is_none() { + // s.syncing_state.successor_response_stats = Some(SuccessorsResponseStats::default()); + // } match response { GetSuccessorsResponse::Complete(response) => { // Received complete response. @@ -169,14 +169,14 @@ async fn maybe_fetch_blocks() -> bool { "Received complete response: {} blocks, total {} bytes.", count, bytes ); - if let Some(successor_response_stats) = - s.syncing_state.successor_response_stats.as_mut() - { - successor_response_stats.complete_block_count += count; - successor_response_stats.complete_block_size += bytes; - successor_response_stats.total_block_count += count; - successor_response_stats.total_block_size += bytes; - } + // if let Some(successor_response_stats) = + // s.syncing_state.successor_response_stats.as_mut() + // { + // successor_response_stats.complete_block_count += count; + // successor_response_stats.complete_block_size += bytes; + // successor_response_stats.total_block_count += count; + // successor_response_stats.total_block_size += bytes; + // } s.syncing_state.response_to_process = Some(ResponseToProcess::Complete(response)); } GetSuccessorsResponse::Partial(partial_response) => { @@ -191,15 +191,15 @@ async fn maybe_fetch_blocks() -> bool { "Received partial response: {} bytes, {} follow-ups remaining.", bytes, remaining, ); - if let Some(successor_response_stats) = - s.syncing_state.successor_response_stats.as_mut() - { - successor_response_stats.partial_block_count += 1; - successor_response_stats.partial_block_size += bytes; - successor_response_stats.partial_follow_ups_remaining += remaining; - successor_response_stats.total_block_count += 1; - successor_response_stats.total_block_size += bytes; - } + // if let Some(successor_response_stats) = + // s.syncing_state.successor_response_stats.as_mut() + // { + // successor_response_stats.partial_block_count += 1; + // successor_response_stats.partial_block_size += bytes; + // successor_response_stats.partial_follow_ups_remaining += remaining; + // successor_response_stats.total_block_count += 1; + // successor_response_stats.total_block_size += bytes; + // } s.syncing_state.response_to_process = Some(ResponseToProcess::Partial(partial_response, 0)); } @@ -209,14 +209,14 @@ async fn maybe_fetch_blocks() -> bool { // a partial response to process. let bytes = block_bytes.len() as u64; println!("Received follow-up response: {} bytes.", bytes); - if let Some(successor_response_stats) = - s.syncing_state.successor_response_stats.as_mut() - { - successor_response_stats.follow_up_count += 1; - successor_response_stats.follow_up_size += bytes; - successor_response_stats.total_block_count += 1; - successor_response_stats.total_block_size += bytes; - } + // if let Some(successor_response_stats) = + // s.syncing_state.successor_response_stats.as_mut() + // { + // successor_response_stats.follow_up_count += 1; + // successor_response_stats.follow_up_size += bytes; + // successor_response_stats.total_block_count += 1; + // successor_response_stats.total_block_size += bytes; + // } let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { Some(ResponseToProcess::Partial(res, pages)) => (res, pages), diff --git a/canister/src/state.rs b/canister/src/state.rs index 1f1fb673..4efc4f76 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -325,10 +325,9 @@ pub struct SyncingState { /// The number of errors occurred when inserting a block. pub num_insert_block_errors: u64, - - /// Stats about the responses received from GetSuccessors. - #[serde(default)] // Ensures backward compatibility during deserialization - pub successor_response_stats: Option, + // /// Stats about the responses received from GetSuccessors. + // #[serde(default)] // Ensures backward compatibility during deserialization + // pub successor_response_stats: Option, } impl Default for SyncingState { From a9af1189be79f83fe0ae70bbc2df9b521ece3f1a Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:10:08 +0000 Subject: [PATCH 18/41] . --- canister/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/state.rs b/canister/src/state.rs index 4efc4f76..380a2ce8 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -339,7 +339,7 @@ impl Default for SyncingState { num_get_successors_rejects: 0, num_block_deserialize_errors: 0, num_insert_block_errors: 0, - successor_response_stats: None, + //successor_response_stats: None, } } } From dc27d2110aacfca1dc6aa0b2402ec1f45338856c Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:12:33 +0000 Subject: [PATCH 19/41] enable metrics --- canister/src/api/metrics.rs | 28 ++++++++--------- canister/src/heartbeat.rs | 56 ++++++++++++++++----------------- canister/src/state.rs | 8 ++--- canister/src/unstable_blocks.rs | 2 +- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index 6f23a6c1..9226f506 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -169,20 +169,20 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { .value(&[("flag", "enabled")], enabled)? .value(&[("flag", "disabled")], disabled)?; - // if let Some(stats) = &state.syncing_state.successor_response_stats { - // encode_labeled_gauge( - // w, - // "successor_response_block_count", - // "Block count statistics for the latest GetSuccessorsResponse.", - // &stats.get_block_count_metrics(), - // )?; - // encode_labeled_gauge( - // w, - // "successor_response_block_size", - // "Block size statistics for the latest GetSuccessorsResponse.", - // &stats.get_block_size_metrics(), - // )?; - // } + if let Some(stats) = &state.syncing_state.successor_response_stats { + encode_labeled_gauge( + w, + "successor_response_block_count", + "Block count statistics for the latest GetSuccessorsResponse.", + &stats.get_block_count_metrics(), + )?; + encode_labeled_gauge( + w, + "successor_response_block_size", + "Block size statistics for the latest GetSuccessorsResponse.", + &stats.get_block_size_metrics(), + )?; + } Ok(()) }) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 91a52dac..aa47f7db 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -153,9 +153,9 @@ async fn maybe_fetch_blocks() -> bool { } }; - // if s.syncing_state.successor_response_stats.is_none() { - // s.syncing_state.successor_response_stats = Some(SuccessorsResponseStats::default()); - // } + if s.syncing_state.successor_response_stats.is_none() { + s.syncing_state.successor_response_stats = Some(SuccessorsResponseStats::default()); + } match response { GetSuccessorsResponse::Complete(response) => { // Received complete response. @@ -169,14 +169,14 @@ async fn maybe_fetch_blocks() -> bool { "Received complete response: {} blocks, total {} bytes.", count, bytes ); - // if let Some(successor_response_stats) = - // s.syncing_state.successor_response_stats.as_mut() - // { - // successor_response_stats.complete_block_count += count; - // successor_response_stats.complete_block_size += bytes; - // successor_response_stats.total_block_count += count; - // successor_response_stats.total_block_size += bytes; - // } + if let Some(successor_response_stats) = + s.syncing_state.successor_response_stats.as_mut() + { + successor_response_stats.complete_block_count += count; + successor_response_stats.complete_block_size += bytes; + successor_response_stats.total_block_count += count; + successor_response_stats.total_block_size += bytes; + } s.syncing_state.response_to_process = Some(ResponseToProcess::Complete(response)); } GetSuccessorsResponse::Partial(partial_response) => { @@ -191,15 +191,15 @@ async fn maybe_fetch_blocks() -> bool { "Received partial response: {} bytes, {} follow-ups remaining.", bytes, remaining, ); - // if let Some(successor_response_stats) = - // s.syncing_state.successor_response_stats.as_mut() - // { - // successor_response_stats.partial_block_count += 1; - // successor_response_stats.partial_block_size += bytes; - // successor_response_stats.partial_follow_ups_remaining += remaining; - // successor_response_stats.total_block_count += 1; - // successor_response_stats.total_block_size += bytes; - // } + if let Some(successor_response_stats) = + s.syncing_state.successor_response_stats.as_mut() + { + successor_response_stats.partial_block_count += 1; + successor_response_stats.partial_block_size += bytes; + successor_response_stats.partial_follow_ups_remaining += remaining; + successor_response_stats.total_block_count += 1; + successor_response_stats.total_block_size += bytes; + } s.syncing_state.response_to_process = Some(ResponseToProcess::Partial(partial_response, 0)); } @@ -209,14 +209,14 @@ async fn maybe_fetch_blocks() -> bool { // a partial response to process. let bytes = block_bytes.len() as u64; println!("Received follow-up response: {} bytes.", bytes); - // if let Some(successor_response_stats) = - // s.syncing_state.successor_response_stats.as_mut() - // { - // successor_response_stats.follow_up_count += 1; - // successor_response_stats.follow_up_size += bytes; - // successor_response_stats.total_block_count += 1; - // successor_response_stats.total_block_size += bytes; - // } + if let Some(successor_response_stats) = + s.syncing_state.successor_response_stats.as_mut() + { + successor_response_stats.follow_up_count += 1; + successor_response_stats.follow_up_size += bytes; + successor_response_stats.total_block_count += 1; + successor_response_stats.total_block_size += bytes; + } let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { Some(ResponseToProcess::Partial(res, pages)) => (res, pages), diff --git a/canister/src/state.rs b/canister/src/state.rs index 380a2ce8..752d268d 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -325,9 +325,9 @@ pub struct SyncingState { /// The number of errors occurred when inserting a block. pub num_insert_block_errors: u64, - // /// Stats about the responses received from GetSuccessors. - // #[serde(default)] // Ensures backward compatibility during deserialization - // pub successor_response_stats: Option, + /// Stats about the responses received from GetSuccessors. + #[serde(default)] // Ensures backward compatibility during deserialization + pub successor_response_stats: Option, } impl Default for SyncingState { @@ -339,7 +339,7 @@ impl Default for SyncingState { num_get_successors_rejects: 0, num_block_deserialize_errors: 0, num_insert_block_errors: 0, - //successor_response_stats: None, + successor_response_stats: None, } } } diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 2aed1724..58649053 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 1_000; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 200; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 4176aeb6063cd9a9bf702ca661596a85b02bdf62 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:28:44 +0000 Subject: [PATCH 20/41] TESTNET_CHAIN_MAX_DEPTH 1000 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 58649053..e137f518 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 200; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 1000; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From fb03fcbd55f3b521efac619f6b43f5cb390b64a5 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:29:54 +0000 Subject: [PATCH 21/41] TESTNET_CHAIN_MAX_DEPTH 700 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index e137f518..4bbcee16 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 1000; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 700; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 66519593ed15966cfd4b6d2bac2f355904a9c36a Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:30:07 +0000 Subject: [PATCH 22/41] TESTNET_CHAIN_MAX_DEPTH 500 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 4bbcee16..1462efd9 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 700; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 500; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 4e2046ddeecac4640586f9bf9a7f54fcbeec313c Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:30:23 +0000 Subject: [PATCH 23/41] TESTNET_CHAIN_MAX_DEPTH 300 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 1462efd9..545407cb 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 500; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 300; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From ab520d2ddfb14d9c07c0a3b0d02aa65895c1db36 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:31:46 +0000 Subject: [PATCH 24/41] TESTNET_CHAIN_MAX_DEPTH 500 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 545407cb..1462efd9 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 300; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 500; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From eed2433852714d1c88f5067749c5646417f6c950 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:31:59 +0000 Subject: [PATCH 25/41] TESTNET_CHAIN_MAX_DEPTH 700 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 1462efd9..4bbcee16 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 500; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 700; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 1c348b53e1f3ebb9e2bd9eaccd5cdff2a1043a8e Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:43:57 +0000 Subject: [PATCH 26/41] TESTNET_CHAIN_MAX_DEPTH 1000 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 4bbcee16..e137f518 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 700; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 1000; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 780d564cc59ffb83609434f2f8172d613fd89df8 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:44:11 +0000 Subject: [PATCH 27/41] TESTNET_CHAIN_MAX_DEPTH 900 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index e137f518..b05cb36f 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 1000; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 900; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 4029a9339a5454ec22b268db8b78e3b06bd3a6ec Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 16:44:35 +0000 Subject: [PATCH 28/41] TESTNET_CHAIN_MAX_DEPTH 800 --- canister/src/unstable_blocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index b05cb36f..489ffdea 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 900; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 800; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From 094fa98eaa8502cf8d0a107f70ea35b10f4aa3ce Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 17:56:36 +0000 Subject: [PATCH 29/41] 1000 --- canister/src/heartbeat.rs | 140 ++++++++++++++++---------------- canister/src/unstable_blocks.rs | 2 +- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index aa47f7db..e5cfcb39 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -41,76 +41,76 @@ pub async fn heartbeat() { maybe_compute_fee_percentiles(); } -// fn log_metrics() { -// with_state(|s| { -// // General stats -// print(&format!( -// "main_chain_height: {}", -// state::main_chain_height(s) -// )); -// print(&format!("stable_height: {}", s.stable_height())); -// print(&format!("utxos_length: {}", s.utxos.utxos_len())); -// print(&format!( -// "address_utxos_length: {}", -// s.utxos.address_utxos_len() -// )); - -// // Unstable blocks and stability threshold -// print(&format!( -// "anchor_difficulty: {}", -// s.unstable_blocks.anchor_difficulty() -// )); -// print(&format!( -// "normalized_stability_threshold: {}", -// s.unstable_blocks.normalized_stability_threshold() -// )); -// print(&format!( -// "unstable_blocks_num_tips: {}", -// s.unstable_blocks.num_tips() -// )); -// print(&format!( -// "unstable_blocks_total: {}", -// state::get_unstable_blocks(s).len() -// )); -// print(&format!( -// "unstable_blocks_depth: {}", -// s.unstable_blocks.blocks_depth() -// )); -// print(&format!( -// "unstable_blocks_difficulty_based_depth: {}", -// s.unstable_blocks.blocks_difficulty_based_depth() -// )); - -// // Errors -// print(&format!( -// "num_get_successors_rejects: {}", -// s.syncing_state.num_get_successors_rejects -// )); -// print(&format!( -// "num_block_deserialize_errors: {}", -// s.syncing_state.num_block_deserialize_errors -// )); -// print(&format!( -// "num_insert_block_errors: {}", -// s.syncing_state.num_insert_block_errors -// )); - -// // Metrics -// print(&format!( -// "send_transaction_count: {}", -// s.metrics.send_transaction_count -// )); -// print(&format!( -// "cycles_burnt: {}", -// s.metrics.cycles_burnt.unwrap_or_default() -// )); -// print(&format!( -// "cycles_balance: {}", -// ic_cdk::api::canister_balance() -// )); -// print(&format!("is_synced: {}", crate::is_synced())); -// }); -// } +fn log_metrics() { + with_state(|s| { + // General stats + print(&format!( + "main_chain_height: {}", + state::main_chain_height(s) + )); + print(&format!("stable_height: {}", s.stable_height())); + print(&format!("utxos_length: {}", s.utxos.utxos_len())); + print(&format!( + "address_utxos_length: {}", + s.utxos.address_utxos_len() + )); + + // Unstable blocks and stability threshold + print(&format!( + "anchor_difficulty: {}", + s.unstable_blocks.anchor_difficulty() + )); + print(&format!( + "normalized_stability_threshold: {}", + s.unstable_blocks.normalized_stability_threshold() + )); + print(&format!( + "unstable_blocks_num_tips: {}", + s.unstable_blocks.num_tips() + )); + print(&format!( + "unstable_blocks_total: {}", + state::get_unstable_blocks(s).len() + )); + print(&format!( + "unstable_blocks_depth: {}", + s.unstable_blocks.blocks_depth() + )); + print(&format!( + "unstable_blocks_difficulty_based_depth: {}", + s.unstable_blocks.blocks_difficulty_based_depth() + )); + + // Errors + print(&format!( + "num_get_successors_rejects: {}", + s.syncing_state.num_get_successors_rejects + )); + print(&format!( + "num_block_deserialize_errors: {}", + s.syncing_state.num_block_deserialize_errors + )); + print(&format!( + "num_insert_block_errors: {}", + s.syncing_state.num_insert_block_errors + )); + + // Metrics + print(&format!( + "send_transaction_count: {}", + s.metrics.send_transaction_count + )); + print(&format!( + "cycles_burnt: {}", + s.metrics.cycles_burnt.unwrap_or_default() + )); + print(&format!( + "cycles_balance: {}", + ic_cdk::api::canister_balance() + )); + print(&format!("is_synced: {}", crate::is_synced())); + }); +} // Fetches new blocks if there isn't a request in progress and no complete response to process. // Returns true if a call to the `blocks_source` has been made, false otherwise. diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index 489ffdea..e137f518 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 800; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 1000; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// From f80fc3abe97a2804a40cd04a00f78b4f3376f87e Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Tue, 28 Jan 2025 17:56:57 +0000 Subject: [PATCH 30/41] add extra logs --- canister/src/heartbeat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index e5cfcb39..2cf2979d 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -18,7 +18,7 @@ use ic_btc_types::{Block, BlockHash}; pub async fn heartbeat() { print("Starting heartbeat..."); - //log_metrics(); // TODO: do not submit! this is only for testing. + log_metrics(); // TODO: do not submit! this is only for testing. maybe_burn_cycles(); From 0630d744ed32e2f03d260afd47febce068c9e8c9 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 29 Jan 2025 13:41:28 +0000 Subject: [PATCH 31/41] commet log_metrics --- canister/src/heartbeat.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 2cf2979d..110d2009 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -18,7 +18,7 @@ use ic_btc_types::{Block, BlockHash}; pub async fn heartbeat() { print("Starting heartbeat..."); - log_metrics(); // TODO: do not submit! this is only for testing. + //log_metrics(); // TODO: do not submit! this is only for testing. maybe_burn_cycles(); @@ -41,6 +41,7 @@ pub async fn heartbeat() { maybe_compute_fee_percentiles(); } +#[allow(dead_code)] fn log_metrics() { with_state(|s| { // General stats From 3dd5a294bdd50221f3e8cadec8b95fe5069c1db6 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 29 Jan 2025 13:55:25 +0000 Subject: [PATCH 32/41] rename label --- canister/src/state.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/canister/src/state.rs b/canister/src/state.rs index 752d268d..20c8c46d 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -363,19 +363,19 @@ pub struct SuccessorsResponseStats { impl SuccessorsResponseStats { pub fn get_block_count_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("block_count", "total"), self.total_block_count), - (("block_count", "complete"), self.complete_block_count), - (("block_count", "partial"), self.partial_block_count), - (("block_count", "follow_up"), self.follow_up_count), + (("response_type", "total"), self.total_block_count), + (("response_type", "complete"), self.complete_block_count), + (("response_type", "partial"), self.partial_block_count), + (("response_type", "follow_up"), self.follow_up_count), ] } pub fn get_block_size_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("block_size", "total"), self.total_block_size), - (("block_size", "complete"), self.complete_block_size), - (("block_size", "partial"), self.partial_block_size), - (("block_size", "follow_up"), self.follow_up_size), + (("response_type", "total"), self.total_block_size), + (("response_type", "complete"), self.complete_block_size), + (("response_type", "partial"), self.partial_block_size), + (("response_type", "follow_up"), self.follow_up_size), ] } } From bbc0127fe6c63efccdb982a44b7ecb6bda1fe5f5 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 29 Jan 2025 17:45:09 +0000 Subject: [PATCH 33/41] fix printing logs --- canister/src/heartbeat.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 110d2009..215e83b2 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -166,7 +166,7 @@ async fn maybe_fetch_blocks() -> bool { ); let count = response.blocks.len() as u64; let bytes = response.blocks.iter().map(|b| b.len() as u64).sum::(); - println!( + print!( "Received complete response: {} blocks, total {} bytes.", count, bytes ); @@ -188,7 +188,7 @@ async fn maybe_fetch_blocks() -> bool { ); let bytes = partial_response.partial_block.len() as u64; let remaining = partial_response.remaining_follow_ups as u64; - println!( + print!( "Received partial response: {} bytes, {} follow-ups remaining.", bytes, remaining, ); @@ -209,7 +209,7 @@ async fn maybe_fetch_blocks() -> bool { // A follow-up response is only expected, and only makes sense, when there's // a partial response to process. let bytes = block_bytes.len() as u64; - println!("Received follow-up response: {} bytes.", bytes); + print!("Received follow-up response: {} bytes.", bytes); if let Some(successor_response_stats) = s.syncing_state.successor_response_stats.as_mut() { From 47e05be3c42f54c985da36d90daba237ece32e5e Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Wed, 29 Jan 2025 17:47:10 +0000 Subject: [PATCH 34/41] fix logs --- canister/src/heartbeat.rs | 12 ++++++------ canister/src/unstable_blocks.rs | 2 +- dfx.json | 12 +++++++++--- poll_logs.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100755 poll_logs.sh diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 215e83b2..18acfdc6 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -166,10 +166,10 @@ async fn maybe_fetch_blocks() -> bool { ); let count = response.blocks.len() as u64; let bytes = response.blocks.iter().map(|b| b.len() as u64).sum::(); - print!( + print(&format!( "Received complete response: {} blocks, total {} bytes.", - count, bytes - ); + count, bytes, + )); if let Some(successor_response_stats) = s.syncing_state.successor_response_stats.as_mut() { @@ -188,10 +188,10 @@ async fn maybe_fetch_blocks() -> bool { ); let bytes = partial_response.partial_block.len() as u64; let remaining = partial_response.remaining_follow_ups as u64; - print!( + print(&format!( "Received partial response: {} bytes, {} follow-ups remaining.", bytes, remaining, - ); + )); if let Some(successor_response_stats) = s.syncing_state.successor_response_stats.as_mut() { @@ -209,7 +209,7 @@ async fn maybe_fetch_blocks() -> bool { // A follow-up response is only expected, and only makes sense, when there's // a partial response to process. let bytes = block_bytes.len() as u64; - print!("Received follow-up response: {} bytes.", bytes); + print(&format!("Received follow-up response: {} bytes.", bytes)); if let Some(successor_response_stats) = s.syncing_state.successor_response_stats.as_mut() { diff --git a/canister/src/unstable_blocks.rs b/canister/src/unstable_blocks.rs index e137f518..58649053 100644 --- a/canister/src/unstable_blocks.rs +++ b/canister/src/unstable_blocks.rs @@ -17,7 +17,7 @@ use self::next_block_headers::NextBlockHeaders; // The maximum number of blocks that a chain on testnet can exceed other chains before its // anchor block is marked as stable. -const TESTNET_CHAIN_MAX_DEPTH: u128 = 1000; // TODO: DO NOT SUBMIT! this is only for testing. +const TESTNET_CHAIN_MAX_DEPTH: u128 = 200; // TODO: DO NOT SUBMIT! this is only for testing. /// A data structure for maintaining all unstable blocks. /// diff --git a/dfx.json b/dfx.json index bf31daa7..1155066d 100644 --- a/dfx.json +++ b/dfx.json @@ -1,7 +1,13 @@ { "dfx": "0.21.0", "canisters": { - "bitcoin": { + "bitcoin_t": { + "type": "custom", + "candid": "./canister/candid.did", + "wasm": "target/wasm32-unknown-unknown/release/ic-btc-canister.wasm.gz", + "build": "./scripts/build-canister.sh ic-btc-canister" + }, + "bitcoin_m": { "type": "custom", "candid": "./canister/candid.did", "wasm": "target/wasm32-unknown-unknown/release/ic-btc-canister.wasm.gz", @@ -79,10 +85,10 @@ }, "testnet": { "providers": [ - "http://[2a00:fb01:400:42:5000:aaff:fea4:ae46]:8080" + "http://[2600:c00:2:100:505e:86ff:fed7:a12]:8080" ], "type": "persistent" } }, "version": 1 -} +} \ No newline at end of file diff --git a/poll_logs.sh b/poll_logs.sh new file mode 100755 index 00000000..8e3b6a00 --- /dev/null +++ b/poll_logs.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +CANISTER_ID="g4xu7-jiaaa-aaaan-aaaaq-cai" + +# Function to fetch logs and filter out new lines +fetch_and_filter_logs() { + # Fetch logs + new_logs=$(dfx canister logs --network testnet $CANISTER_ID) + + # Compare with previous logs to find new ones + while IFS= read -r line; do + if [[ ! "${previous_logs[*]}" =~ "$line" ]]; then + echo "$line" + fi + done <<< "$new_logs" + + # Update previous logs + previous_logs=("$new_logs") +} + +# Initial fetch and filter +fetch_and_filter_logs + +# Infinite loop to continuously fetch and filter logs +while true; do + fetch_and_filter_logs + sleep 0.1 +done From cce30adbee05ce535bc9c87314bca41acc94ae7b Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Fri, 31 Jan 2025 16:25:49 +0000 Subject: [PATCH 35/41] add successor_request_stats metric --- canister/src/api/metrics.rs | 13 +++++++++++-- canister/src/heartbeat.rs | 19 ++++++++++++++++++- canister/src/state.rs | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index 9226f506..8c369152 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -169,17 +169,26 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { .value(&[("flag", "enabled")], enabled)? .value(&[("flag", "disabled")], disabled)?; + if let Some(stats) = &state.syncing_state.successor_request_stats { + encode_labeled_gauge( + w, + "successor_request_tx_count", + "Transaction count statistics for GetSuccessorsRequest.", + &stats.get_tx_count_metrics(), + )?; + } + if let Some(stats) = &state.syncing_state.successor_response_stats { encode_labeled_gauge( w, "successor_response_block_count", - "Block count statistics for the latest GetSuccessorsResponse.", + "Block count statistics for GetSuccessorsResponse.", &stats.get_block_count_metrics(), )?; encode_labeled_gauge( w, "successor_response_block_size", - "Block size statistics for the latest GetSuccessorsResponse.", + "Block size statistics for GetSuccessorsResponse.", &stats.get_block_size_metrics(), )?; } diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 18acfdc6..e70b7480 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -1,7 +1,7 @@ use crate::{ api::get_current_fee_percentiles_impl, runtime::{call_get_successors, cycles_burn, print}, - state::{self, ResponseToProcess, SuccessorsResponseStats}, + state::{self, ResponseToProcess, SuccessorsRequestStats, SuccessorsResponseStats}, types::{ GetSuccessorsCompleteResponse, GetSuccessorsRequest, GetSuccessorsRequestInitial, GetSuccessorsResponse, @@ -137,6 +137,23 @@ async fn maybe_fetch_blocks() -> bool { } }; + with_state_mut(|s| { + let successor_request_stats = s + .syncing_state + .successor_request_stats + .get_or_insert_with(SuccessorsRequestStats::default); + + successor_request_stats.total_tx_count += 1; + match request { + GetSuccessorsRequest::Initial(_) => { + successor_request_stats.initial_tx_count += 1; + } + GetSuccessorsRequest::FollowUp(_) => { + successor_request_stats.follow_up_tx_count += 1; + } + } + }); + print(&format!("Sending request: {:?}", request)); let response: Result<(GetSuccessorsResponse,), _> = diff --git a/canister/src/state.rs b/canister/src/state.rs index 20c8c46d..93a86835 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -325,6 +325,11 @@ pub struct SyncingState { /// The number of errors occurred when inserting a block. pub num_insert_block_errors: u64, + + /// Stats about the request sent to GetSuccessors. + #[serde(default)] // Ensures backward compatibility during deserialization + pub successor_request_stats: Option, + /// Stats about the responses received from GetSuccessors. #[serde(default)] // Ensures backward compatibility during deserialization pub successor_response_stats: Option, @@ -339,11 +344,29 @@ impl Default for SyncingState { num_get_successors_rejects: 0, num_block_deserialize_errors: 0, num_insert_block_errors: 0, + successor_request_stats: None, successor_response_stats: None, } } } +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)] +pub struct SuccessorsRequestStats { + pub total_tx_count: u64, + pub initial_tx_count: u64, + pub follow_up_tx_count: u64, +} + +impl SuccessorsRequestStats { + pub fn get_tx_count_metrics(&self) -> Vec<((&str, &str), u64)> { + vec![ + (("request_type", "total"), self.total_tx_count), + (("request_type", "initial"), self.initial_tx_count), + (("request_type", "follow_up"), self.follow_up_tx_count), + ] + } +} + #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)] pub struct SuccessorsResponseStats { pub total_block_count: u64, From a802bcbb2657c93b74fcf5328fcacab3516f6e12 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Fri, 31 Jan 2025 17:09:22 +0000 Subject: [PATCH 36/41] . --- canister/src/api/metrics.rs | 4 ++-- canister/src/state.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index 8c369152..f774226b 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -172,9 +172,9 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { if let Some(stats) = &state.syncing_state.successor_request_stats { encode_labeled_gauge( w, - "successor_request_tx_count", + "successor_request_count", "Transaction count statistics for GetSuccessorsRequest.", - &stats.get_tx_count_metrics(), + &stats.get_request_count_metrics(), )?; } diff --git a/canister/src/state.rs b/canister/src/state.rs index 93a86835..0f872085 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -358,7 +358,7 @@ pub struct SuccessorsRequestStats { } impl SuccessorsRequestStats { - pub fn get_tx_count_metrics(&self) -> Vec<((&str, &str), u64)> { + pub fn get_request_count_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ (("request_type", "total"), self.total_tx_count), (("request_type", "initial"), self.initial_tx_count), From a988fde8ee53d49b6060270dc962a43fa5da6e97 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Fri, 31 Jan 2025 17:15:43 +0000 Subject: [PATCH 37/41] . --- canister/src/api/metrics.rs | 10 +++---- canister/src/heartbeat.rs | 58 +++++++++++++++---------------------- canister/src/state.rs | 20 ++++++------- 3 files changed, 39 insertions(+), 49 deletions(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index f774226b..1e308b0c 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -169,25 +169,25 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { .value(&[("flag", "enabled")], enabled)? .value(&[("flag", "disabled")], disabled)?; - if let Some(stats) = &state.syncing_state.successor_request_stats { + if let Some(stats) = &state.syncing_state.get_successors_request_stats { encode_labeled_gauge( w, - "successor_request_count", + "get_successors_request_count", "Transaction count statistics for GetSuccessorsRequest.", &stats.get_request_count_metrics(), )?; } - if let Some(stats) = &state.syncing_state.successor_response_stats { + if let Some(stats) = &state.syncing_state.get_successors_response_stats { encode_labeled_gauge( w, - "successor_response_block_count", + "get_successors_response_block_count", "Block count statistics for GetSuccessorsResponse.", &stats.get_block_count_metrics(), )?; encode_labeled_gauge( w, - "successor_response_block_size", + "get_successors_response_block_size", "Block size statistics for GetSuccessorsResponse.", &stats.get_block_size_metrics(), )?; diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index e70b7480..bdfbcfce 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -138,19 +138,14 @@ async fn maybe_fetch_blocks() -> bool { }; with_state_mut(|s| { - let successor_request_stats = s + let stats = s .syncing_state - .successor_request_stats + .get_successors_request_stats .get_or_insert_with(SuccessorsRequestStats::default); - - successor_request_stats.total_tx_count += 1; + stats.total_rx_count += 1; match request { - GetSuccessorsRequest::Initial(_) => { - successor_request_stats.initial_tx_count += 1; - } - GetSuccessorsRequest::FollowUp(_) => { - successor_request_stats.follow_up_tx_count += 1; - } + GetSuccessorsRequest::Initial(_) => stats.initial_rx_count += 1, + GetSuccessorsRequest::FollowUp(_) => stats.follow_up_rx_count += 1, } }); @@ -171,8 +166,9 @@ async fn maybe_fetch_blocks() -> bool { } }; - if s.syncing_state.successor_response_stats.is_none() { - s.syncing_state.successor_response_stats = Some(SuccessorsResponseStats::default()); + if s.syncing_state.get_successors_response_stats.is_none() { + s.syncing_state.get_successors_response_stats = + Some(SuccessorsResponseStats::default()); } match response { GetSuccessorsResponse::Complete(response) => { @@ -187,13 +183,11 @@ async fn maybe_fetch_blocks() -> bool { "Received complete response: {} blocks, total {} bytes.", count, bytes, )); - if let Some(successor_response_stats) = - s.syncing_state.successor_response_stats.as_mut() - { - successor_response_stats.complete_block_count += count; - successor_response_stats.complete_block_size += bytes; - successor_response_stats.total_block_count += count; - successor_response_stats.total_block_size += bytes; + if let Some(stats) = s.syncing_state.get_successors_response_stats.as_mut() { + stats.complete_block_count += count; + stats.complete_block_size += bytes; + stats.total_block_count += count; + stats.total_block_size += bytes; } s.syncing_state.response_to_process = Some(ResponseToProcess::Complete(response)); } @@ -209,14 +203,12 @@ async fn maybe_fetch_blocks() -> bool { "Received partial response: {} bytes, {} follow-ups remaining.", bytes, remaining, )); - if let Some(successor_response_stats) = - s.syncing_state.successor_response_stats.as_mut() - { - successor_response_stats.partial_block_count += 1; - successor_response_stats.partial_block_size += bytes; - successor_response_stats.partial_follow_ups_remaining += remaining; - successor_response_stats.total_block_count += 1; - successor_response_stats.total_block_size += bytes; + if let Some(stats) = s.syncing_state.get_successors_response_stats.as_mut() { + stats.partial_block_count += 1; + stats.partial_block_size += bytes; + stats.partial_follow_ups_remaining += remaining; + stats.total_block_count += 1; + stats.total_block_size += bytes; } s.syncing_state.response_to_process = Some(ResponseToProcess::Partial(partial_response, 0)); @@ -227,13 +219,11 @@ async fn maybe_fetch_blocks() -> bool { // a partial response to process. let bytes = block_bytes.len() as u64; print(&format!("Received follow-up response: {} bytes.", bytes)); - if let Some(successor_response_stats) = - s.syncing_state.successor_response_stats.as_mut() - { - successor_response_stats.follow_up_count += 1; - successor_response_stats.follow_up_size += bytes; - successor_response_stats.total_block_count += 1; - successor_response_stats.total_block_size += bytes; + if let Some(stats) = s.syncing_state.get_successors_response_stats.as_mut() { + stats.follow_up_count += 1; + stats.follow_up_size += bytes; + stats.total_block_count += 1; + stats.total_block_size += bytes; } let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { diff --git a/canister/src/state.rs b/canister/src/state.rs index 0f872085..815130fc 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -328,11 +328,11 @@ pub struct SyncingState { /// Stats about the request sent to GetSuccessors. #[serde(default)] // Ensures backward compatibility during deserialization - pub successor_request_stats: Option, + pub get_successors_request_stats: Option, /// Stats about the responses received from GetSuccessors. #[serde(default)] // Ensures backward compatibility during deserialization - pub successor_response_stats: Option, + pub get_successors_response_stats: Option, } impl Default for SyncingState { @@ -344,25 +344,25 @@ impl Default for SyncingState { num_get_successors_rejects: 0, num_block_deserialize_errors: 0, num_insert_block_errors: 0, - successor_request_stats: None, - successor_response_stats: None, + get_successors_request_stats: None, + get_successors_response_stats: None, } } } #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)] pub struct SuccessorsRequestStats { - pub total_tx_count: u64, - pub initial_tx_count: u64, - pub follow_up_tx_count: u64, + pub total_rx_count: u64, + pub initial_rx_count: u64, + pub follow_up_rx_count: u64, } impl SuccessorsRequestStats { pub fn get_request_count_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("request_type", "total"), self.total_tx_count), - (("request_type", "initial"), self.initial_tx_count), - (("request_type", "follow_up"), self.follow_up_tx_count), + (("request_type", "total"), self.total_rx_count), + (("request_type", "initial"), self.initial_rx_count), + (("request_type", "follow_up"), self.follow_up_rx_count), ] } } From 73a22b8e3b3658d0a8fca609f3a2becb87e0da6d Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Fri, 31 Jan 2025 17:18:03 +0000 Subject: [PATCH 38/41] . --- canister/src/api/metrics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index 1e308b0c..05c37374 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -173,7 +173,7 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { encode_labeled_gauge( w, "get_successors_request_count", - "Transaction count statistics for GetSuccessorsRequest.", + "The statistics of the GetSuccessorsRequest.", &stats.get_request_count_metrics(), )?; } From 989b2993fd1d0092c957540e7cdbf2e2191c992f Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Fri, 31 Jan 2025 17:19:29 +0000 Subject: [PATCH 39/41] . --- canister/src/heartbeat.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index bdfbcfce..8d39ccb4 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -166,10 +166,10 @@ async fn maybe_fetch_blocks() -> bool { } }; - if s.syncing_state.get_successors_response_stats.is_none() { - s.syncing_state.get_successors_response_stats = - Some(SuccessorsResponseStats::default()); - } + s.syncing_state + .get_successors_response_stats + .get_or_insert_with(SuccessorsResponseStats::default); + match response { GetSuccessorsResponse::Complete(response) => { // Received complete response. From cc17a793554d59a2c889f0bac1f5b4665ab087f2 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Fri, 31 Jan 2025 18:12:48 +0000 Subject: [PATCH 40/41] fix rx/tx metrics --- canister/src/api/metrics.rs | 20 ++++++++++------ canister/src/heartbeat.rs | 45 ++++++++++++++++++++---------------- canister/src/state.rs | 46 +++++++++++++++++++++++-------------- 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/canister/src/api/metrics.rs b/canister/src/api/metrics.rs index 05c37374..a7288714 100644 --- a/canister/src/api/metrics.rs +++ b/canister/src/api/metrics.rs @@ -172,23 +172,29 @@ fn encode_metrics(w: &mut MetricsEncoder>) -> std::io::Result<()> { if let Some(stats) = &state.syncing_state.get_successors_request_stats { encode_labeled_gauge( w, - "get_successors_request_count", - "The statistics of the GetSuccessorsRequest.", - &stats.get_request_count_metrics(), + "get_successors_tx_count", + "The number of get_successors requests.", + &stats.get_count_metrics(), )?; } if let Some(stats) = &state.syncing_state.get_successors_response_stats { encode_labeled_gauge( w, - "get_successors_response_block_count", - "Block count statistics for GetSuccessorsResponse.", + "get_successors_rx_count", + "The number of get_successors responses.", + &stats.get_count_metrics(), + )?; + encode_labeled_gauge( + w, + "get_successors_rx_block_count", + "The number of blocks in get_successors responses.", &stats.get_block_count_metrics(), )?; encode_labeled_gauge( w, - "get_successors_response_block_size", - "Block size statistics for GetSuccessorsResponse.", + "get_successors_rx_block_size", + "The total size of the blocks in get_successors responses.", &stats.get_block_size_metrics(), )?; } diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 8d39ccb4..be6aef84 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -138,14 +138,14 @@ async fn maybe_fetch_blocks() -> bool { }; with_state_mut(|s| { - let stats = s + let tx_stats = s .syncing_state .get_successors_request_stats .get_or_insert_with(SuccessorsRequestStats::default); - stats.total_rx_count += 1; + tx_stats.total_count += 1; match request { - GetSuccessorsRequest::Initial(_) => stats.initial_rx_count += 1, - GetSuccessorsRequest::FollowUp(_) => stats.follow_up_rx_count += 1, + GetSuccessorsRequest::Initial(_) => tx_stats.initial_count += 1, + GetSuccessorsRequest::FollowUp(_) => tx_stats.follow_up_count += 1, } }); @@ -183,11 +183,13 @@ async fn maybe_fetch_blocks() -> bool { "Received complete response: {} blocks, total {} bytes.", count, bytes, )); - if let Some(stats) = s.syncing_state.get_successors_response_stats.as_mut() { - stats.complete_block_count += count; - stats.complete_block_size += bytes; - stats.total_block_count += count; - stats.total_block_size += bytes; + if let Some(rx_stats) = s.syncing_state.get_successors_response_stats.as_mut() { + rx_stats.complete_count += 1; + rx_stats.complete_block_count += count; + rx_stats.complete_block_size += bytes; + rx_stats.total_count += 1; + rx_stats.total_block_count += count; + rx_stats.total_block_size += bytes; } s.syncing_state.response_to_process = Some(ResponseToProcess::Complete(response)); } @@ -203,12 +205,13 @@ async fn maybe_fetch_blocks() -> bool { "Received partial response: {} bytes, {} follow-ups remaining.", bytes, remaining, )); - if let Some(stats) = s.syncing_state.get_successors_response_stats.as_mut() { - stats.partial_block_count += 1; - stats.partial_block_size += bytes; - stats.partial_follow_ups_remaining += remaining; - stats.total_block_count += 1; - stats.total_block_size += bytes; + if let Some(rx_stats) = s.syncing_state.get_successors_response_stats.as_mut() { + rx_stats.partial_count += 1; + rx_stats.partial_block_count += 1; + rx_stats.partial_block_size += bytes; + rx_stats.total_count += 1; + rx_stats.total_block_count += 1; + rx_stats.total_block_size += bytes; } s.syncing_state.response_to_process = Some(ResponseToProcess::Partial(partial_response, 0)); @@ -219,11 +222,13 @@ async fn maybe_fetch_blocks() -> bool { // a partial response to process. let bytes = block_bytes.len() as u64; print(&format!("Received follow-up response: {} bytes.", bytes)); - if let Some(stats) = s.syncing_state.get_successors_response_stats.as_mut() { - stats.follow_up_count += 1; - stats.follow_up_size += bytes; - stats.total_block_count += 1; - stats.total_block_size += bytes; + if let Some(rx_stats) = s.syncing_state.get_successors_response_stats.as_mut() { + rx_stats.follow_up_count += 1; + rx_stats.follow_up_block_count += 1; + rx_stats.follow_up_block_size += bytes; + rx_stats.total_count += 1; + rx_stats.total_block_count += 1; + rx_stats.total_block_size += bytes; } let (mut partial_response, mut follow_up_index) = match s.syncing_state.response_to_process.take() { diff --git a/canister/src/state.rs b/canister/src/state.rs index 815130fc..30ef51aa 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -352,53 +352,65 @@ impl Default for SyncingState { #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)] pub struct SuccessorsRequestStats { - pub total_rx_count: u64, - pub initial_rx_count: u64, - pub follow_up_rx_count: u64, + pub total_count: u64, + pub initial_count: u64, + pub follow_up_count: u64, } impl SuccessorsRequestStats { - pub fn get_request_count_metrics(&self) -> Vec<((&str, &str), u64)> { + pub fn get_count_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("request_type", "total"), self.total_rx_count), - (("request_type", "initial"), self.initial_rx_count), - (("request_type", "follow_up"), self.follow_up_rx_count), + (("type", "total"), self.total_count), + (("type", "initial"), self.initial_count), + (("type", "follow_up"), self.follow_up_count), ] } } #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)] pub struct SuccessorsResponseStats { + pub total_count: u64, pub total_block_count: u64, pub total_block_size: u64, + pub complete_count: u64, pub complete_block_count: u64, pub complete_block_size: u64, + pub partial_count: u64, pub partial_block_count: u64, pub partial_block_size: u64, - pub partial_follow_ups_remaining: u64, pub follow_up_count: u64, - pub follow_up_size: u64, + pub follow_up_block_count: u64, + pub follow_up_block_size: u64, } impl SuccessorsResponseStats { + pub fn get_count_metrics(&self) -> Vec<((&str, &str), u64)> { + vec![ + (("type", "total"), self.total_count), + (("type", "complete"), self.complete_count), + (("type", "partial"), self.partial_count), + (("type", "follow_up"), self.follow_up_count), + ] + } + pub fn get_block_count_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("response_type", "total"), self.total_block_count), - (("response_type", "complete"), self.complete_block_count), - (("response_type", "partial"), self.partial_block_count), - (("response_type", "follow_up"), self.follow_up_count), + (("type", "total"), self.total_block_count), + (("type", "complete"), self.complete_block_count), + (("type", "partial"), self.partial_block_count), + (("type", "follow_up"), self.follow_up_block_count), ] } pub fn get_block_size_metrics(&self) -> Vec<((&str, &str), u64)> { vec![ - (("response_type", "total"), self.total_block_size), - (("response_type", "complete"), self.complete_block_size), - (("response_type", "partial"), self.partial_block_size), - (("response_type", "follow_up"), self.follow_up_size), + (("type", "total"), self.total_block_size), + (("type", "complete"), self.complete_block_size), + (("type", "partial"), self.partial_block_size), + (("type", "follow_up"), self.follow_up_block_size), ] } } From b3ad75845bd2e10449224d52d9e7c41d17123f94 Mon Sep 17 00:00:00 2001 From: Maksym Arutyunyan Date: Mon, 3 Feb 2025 13:31:35 +0000 Subject: [PATCH 41/41] rm log_metrics --- canister/src/heartbeat.rs | 74 --------------------------------------- 1 file changed, 74 deletions(-) diff --git a/canister/src/heartbeat.rs b/canister/src/heartbeat.rs index 0997ff0d..18808ede 100644 --- a/canister/src/heartbeat.rs +++ b/canister/src/heartbeat.rs @@ -18,8 +18,6 @@ use ic_btc_types::{Block, BlockHash}; pub async fn heartbeat() { print("Starting heartbeat..."); - //log_metrics(); // TODO: do not submit! this is only for testing. - maybe_burn_cycles(); if ingest_stable_blocks_into_utxoset() { @@ -41,78 +39,6 @@ pub async fn heartbeat() { maybe_compute_fee_percentiles(); } -#[allow(dead_code)] -fn log_metrics() { - with_state(|s| { - // General stats - print(&format!( - "main_chain_height: {}", - state::main_chain_height(s) - )); - print(&format!("stable_height: {}", s.stable_height())); - print(&format!("utxos_length: {}", s.utxos.utxos_len())); - print(&format!( - "address_utxos_length: {}", - s.utxos.address_utxos_len() - )); - - // Unstable blocks and stability threshold - print(&format!( - "anchor_difficulty: {}", - s.unstable_blocks.anchor_difficulty() - )); - print(&format!( - "normalized_stability_threshold: {}", - s.unstable_blocks.normalized_stability_threshold() - )); - print(&format!( - "unstable_blocks_num_tips: {}", - s.unstable_blocks.num_tips() - )); - print(&format!( - "unstable_blocks_total: {}", - state::get_unstable_blocks(s).len() - )); - print(&format!( - "unstable_blocks_depth: {}", - s.unstable_blocks.blocks_depth() - )); - print(&format!( - "unstable_blocks_difficulty_based_depth: {}", - s.unstable_blocks.blocks_difficulty_based_depth() - )); - - // Errors - print(&format!( - "num_get_successors_rejects: {}", - s.syncing_state.num_get_successors_rejects - )); - print(&format!( - "num_block_deserialize_errors: {}", - s.syncing_state.num_block_deserialize_errors - )); - print(&format!( - "num_insert_block_errors: {}", - s.syncing_state.num_insert_block_errors - )); - - // Metrics - print(&format!( - "send_transaction_count: {}", - s.metrics.send_transaction_count - )); - print(&format!( - "cycles_burnt: {}", - s.metrics.cycles_burnt.unwrap_or_default() - )); - print(&format!( - "cycles_balance: {}", - ic_cdk::api::canister_balance() - )); - print(&format!("is_synced: {}", crate::is_synced())); - }); -} - // Fetches new blocks if there isn't a request in progress and no complete response to process. // Returns true if a call to the `blocks_source` has been made, false otherwise. async fn maybe_fetch_blocks() -> bool {