From f0ba26dedeadab99128e70a23f112eecea671c6d Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Mon, 1 Dec 2025 23:19:52 -0600 Subject: [PATCH 1/7] fix: match block with hash --- .../chainhook-cli/src/storage/database_access.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/chainhook-cli/src/storage/database_access.rs b/components/chainhook-cli/src/storage/database_access.rs index ca37268e..daf6f811 100644 --- a/components/chainhook-cli/src/storage/database_access.rs +++ b/components/chainhook-cli/src/storage/database_access.rs @@ -3,7 +3,10 @@ use chainhook_sdk::types::BlockIdentifier; use chainhook_sdk::utils::Context; use std::path::PathBuf; -use crate::storage::{is_stacks_block_present, open_readonly_stacks_db_conn_with_retry}; +use crate::storage::{ + get_stacks_block_at_block_height, is_stacks_block_present, + open_readonly_stacks_db_conn_with_retry, +}; /// Implementation of DatabaseAccess trait for chainhook-cli /// This provides database access to the SDK without creating circular dependencies @@ -24,6 +27,13 @@ impl BlocksDatabaseAccess for StacksDatabaseAccess { ctx: &Context, ) -> Result { let stacks_db = open_readonly_stacks_db_conn_with_retry(&self.db_path, 0, ctx)?; - Ok(is_stacks_block_present(block_identifier, 0, &stacks_db)) + if let Some(block) = + get_stacks_block_at_block_height(block_identifier.index, true, 0, &stacks_db)? + { + if block.block_identifier.hash == block_identifier.hash { + return Ok(true); + } + } + return Ok(false); } } From 212c6c471cd2bbb6d3032e9d67cd40ec19922464 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Mon, 1 Dec 2025 23:31:56 -0600 Subject: [PATCH 2/7] fix: set segment min length to 128 --- components/chainhook-sdk/src/indexer/fork_scratch_pad.rs | 2 +- components/chainhook-sdk/src/indexer/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs b/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs index 65eaae40..6455e93f 100644 --- a/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs +++ b/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs @@ -16,7 +16,7 @@ pub struct ForkScratchPad { forks: BTreeMap, headers_store: BTreeMap, } -pub const CONFIRMED_SEGMENT_MINIMUM_LENGTH: i32 = 7; +pub const CONFIRMED_SEGMENT_MINIMUM_LENGTH: i32 = 128; impl Default for ForkScratchPad { fn default() -> Self { Self::new() diff --git a/components/chainhook-sdk/src/indexer/mod.rs b/components/chainhook-sdk/src/indexer/mod.rs index 881d013e..968de4e0 100644 --- a/components/chainhook-sdk/src/indexer/mod.rs +++ b/components/chainhook-sdk/src/indexer/mod.rs @@ -462,9 +462,9 @@ impl std::fmt::Display for ChainSegment { "Fork [{}], length = {}", self.block_ids .iter() + .next() .map(|b| format!("{}", b)) - .collect::>() - .join(", "), + .unwrap_or_else(|| "".to_string()), self.get_length() ) } From 95d6ced5d6e49cfe98699cb193d6631fd6ff17f4 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Mon, 1 Dec 2025 23:34:10 -0600 Subject: [PATCH 3/7] fix: warning --- components/chainhook-cli/src/storage/database_access.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/chainhook-cli/src/storage/database_access.rs b/components/chainhook-cli/src/storage/database_access.rs index daf6f811..116ff874 100644 --- a/components/chainhook-cli/src/storage/database_access.rs +++ b/components/chainhook-cli/src/storage/database_access.rs @@ -3,10 +3,7 @@ use chainhook_sdk::types::BlockIdentifier; use chainhook_sdk::utils::Context; use std::path::PathBuf; -use crate::storage::{ - get_stacks_block_at_block_height, is_stacks_block_present, - open_readonly_stacks_db_conn_with_retry, -}; +use crate::storage::{get_stacks_block_at_block_height, open_readonly_stacks_db_conn_with_retry}; /// Implementation of DatabaseAccess trait for chainhook-cli /// This provides database access to the SDK without creating circular dependencies From 6beb9bbfa484adabc5a2d5bbb763418f4f8fd834 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Wed, 3 Dec 2025 09:46:02 -0600 Subject: [PATCH 4/7] fix: move to local nightly rust for stacks-codec compat --- components/chainhook-sdk/src/indexer/fork_scratch_pad.rs | 2 +- rust-toolchain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs b/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs index 6455e93f..65eaae40 100644 --- a/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs +++ b/components/chainhook-sdk/src/indexer/fork_scratch_pad.rs @@ -16,7 +16,7 @@ pub struct ForkScratchPad { forks: BTreeMap, headers_store: BTreeMap, } -pub const CONFIRMED_SEGMENT_MINIMUM_LENGTH: i32 = 128; +pub const CONFIRMED_SEGMENT_MINIMUM_LENGTH: i32 = 7; impl Default for ForkScratchPad { fn default() -> Self { Self::new() diff --git a/rust-toolchain b/rust-toolchain index 292fe499..5d56faf9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,2 +1,2 @@ [toolchain] -channel = "stable" +channel = "nightly" From 03434104b09d32ec92a925303fac01d6a1fa5eac Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Wed, 3 Dec 2025 09:59:24 -0600 Subject: [PATCH 5/7] chore: restore debug --- components/chainhook-sdk/src/indexer/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/chainhook-sdk/src/indexer/mod.rs b/components/chainhook-sdk/src/indexer/mod.rs index 968de4e0..881d013e 100644 --- a/components/chainhook-sdk/src/indexer/mod.rs +++ b/components/chainhook-sdk/src/indexer/mod.rs @@ -462,9 +462,9 @@ impl std::fmt::Display for ChainSegment { "Fork [{}], length = {}", self.block_ids .iter() - .next() .map(|b| format!("{}", b)) - .unwrap_or_else(|| "".to_string()), + .collect::>() + .join(", "), self.get_length() ) } From 52f347ab7d73ab03c1df821c53754f900d250fdb Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Wed, 3 Dec 2025 10:01:08 -0600 Subject: [PATCH 6/7] chore: toolchain --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 5d56faf9..292fe499 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly" +channel = "stable" From 224e9ee2bcb8f7507f2f6e9747bd948cbcd26536 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Wed, 3 Dec 2025 10:59:49 -0600 Subject: [PATCH 7/7] chore: comment --- components/chainhook-cli/src/storage/database_access.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/chainhook-cli/src/storage/database_access.rs b/components/chainhook-cli/src/storage/database_access.rs index 116ff874..3527e889 100644 --- a/components/chainhook-cli/src/storage/database_access.rs +++ b/components/chainhook-cli/src/storage/database_access.rs @@ -24,6 +24,8 @@ impl BlocksDatabaseAccess for StacksDatabaseAccess { ctx: &Context, ) -> Result { let stacks_db = open_readonly_stacks_db_conn_with_retry(&self.db_path, 0, ctx)?; + // We have to retrieve the full block to check and compare both its hash and index. There's a function called + // `is_stacks_block_present` that sounds like could be used here but it only checks the index. if let Some(block) = get_stacks_block_at_block_height(block_identifier.index, true, 0, &stacks_db)? {