Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: correctly track bitcoin block append metrics; add additional metrics #563

Merged
merged 9 commits into from
Apr 12, 2024
17 changes: 16 additions & 1 deletion components/chainhook-sdk/src/indexer/fork_scratch_pad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl ForkScratchPad {
}
None => {
ctx.try_log(|logger| {
slog::debug!(
slog::error!(
logger,
"Unable to process Bitcoin {} - inboxed for later",
header.block_identifier
Expand Down Expand Up @@ -253,6 +253,13 @@ impl ForkScratchPad {
}
}

ctx.try_log(|logger| {
slog::debug!(
logger,
"Removing {} confirmed blocks from block store.",
canonical_segment[6..].len()
)
});
for confirmed_block in canonical_segment[6..].into_iter() {
let block = match self.headers_store.remove(confirmed_block) {
None => {
Expand All @@ -267,6 +274,14 @@ impl ForkScratchPad {
}

// Prune data
ctx.try_log(|logger| {
slog::debug!(
logger,
"Pruning {} blocks and {} forks.",
blocks_to_prune.len(),
forks_to_prune.len()
)
});
for block_to_prune in blocks_to_prune {
self.headers_store.remove(&block_to_prune);
}
Expand Down
15 changes: 11 additions & 4 deletions components/chainhook-sdk/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,24 @@ impl Indexer {
event
}

pub fn handle_stacks_marshalled_block(
pub fn standardize_stacks_marshalled_block(
&mut self,
marshalled_block: JsonValue,
ctx: &Context,
) -> Result<Option<StacksChainEvent>, String> {
let block = stacks::standardize_stacks_marshalled_block(
) -> Result<StacksBlockData, String> {
stacks::standardize_stacks_marshalled_block(
&self.config,
marshalled_block,
&mut self.stacks_context,
ctx,
)?;
)
}

pub fn process_stacks_block(
&mut self,
block: StacksBlockData,
ctx: &Context,
) -> Result<Option<StacksChainEvent>, String> {
self.stacks_blocks_pool.process_block(block, ctx)
}

Expand Down
17 changes: 15 additions & 2 deletions components/chainhook-sdk/src/indexer/stacks/blocks_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ impl StacksBlockPool {
// that must be merged in Block 7.
let mut blocks_to_confirm = canonical_segment[6..].to_vec();
blocks_to_confirm.reverse();
ctx.try_log(|logger| {
slog::debug!(
logger,
"Removing {} confirmed blocks from block store.",
blocks_to_confirm.len()
)
});
for confirmed_block in blocks_to_confirm.iter() {
let block = match self.block_store.remove(confirmed_block) {
None => {
Expand All @@ -371,6 +378,14 @@ impl StacksBlockPool {
}

// Prune data
ctx.try_log(|logger| {
slog::debug!(
logger,
"Pruning {} blocks and {} forks.",
blocks_to_prune.len(),
forks_to_prune.len()
)
});
for block_to_prune in blocks_to_prune {
self.block_store.remove(&block_to_prune);
self.micro_forks.remove(&block_to_prune);
Expand All @@ -381,8 +396,6 @@ impl StacksBlockPool {
self.forks.remove(&fork_id);
}
// confirmed_blocks.reverse();

ctx.try_log(|logger| slog::debug!(logger, "AFTER: {:?}", confirmed_blocks.len()));
}

pub fn process_microblocks(
Expand Down
Loading
Loading