Skip to content

Conversation

@maksymar
Copy link
Contributor

@maksymar maksymar commented Mar 26, 2025

DO NOT SUBMIT!

this is a debug PR that adds an extra method to read unstable blocks from testnet4 and present them as a tree.

@github-actions
Copy link

github-actions bot commented Mar 26, 2025

canbench 🏋 (dir: .) fde78fb 2025-03-26 17:16:17 UTC

ℹ️ No significant performance changes detected 👍
./canbench_results.yml is up to date

~/work/bitcoin-canister/bitcoin-canister/scripts ~/work/bitcoin-canister/bitcoin-canister
~/work/bitcoin-canister/bitcoin-canister

---------------------------------------------------

Benchmark: insert_300_blocks
  total:
    instructions: 475.55 M (no change)
    heap_increase: 10 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: get_metrics
  total:
    instructions: 7.90 M (-0.06%) (change within noise threshold)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: insert_block_headers
  total:
    instructions: 3.11 B (no change)
    heap_increase: 1 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: insert_block_headers_multiple_times
  total:
    instructions: 11.40 B (no change)
    heap_increase: 7 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

Benchmark: pre_upgrade_with_many_unstable_blocks
  total:
    instructions: 5.99 B (-0.00%) (change within noise threshold)
    heap_increase: 4097 pages (no change)
    stable_memory_increase: 1792 pages (no change)

  serialize_blocktree (scope):
    instructions: 2.40 B (-0.00%) (change within noise threshold)
    heap_increase: 2048 pages (no change)
    stable_memory_increase: 0 pages (no change)

  serialize_blocktree_flatten (scope):
    instructions: 183.68 K (-0.03%) (change within noise threshold)
    heap_increase: 0 pages (no change)
    stable_memory_increase: 0 pages (no change)

  serialize_blocktree_serialize_seq (scope):
    instructions: 2.40 B (-0.00%) (change within noise threshold)
    heap_increase: 2048 pages (no change)
    stable_memory_increase: 0 pages (no change)

---------------------------------------------------

@maksymar maksymar requested a review from Copilot May 7, 2025 11:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This debug PR introduces a new method for retrieving unstable block data and a set of visualization tools to represent blockchain data as graphs. Key changes include:

  • New scripts for generating blockchain visualizations using Graphviz and Matplotlib/NetworkX.
  • Addition of functions to parse and serve unstable blocks data in both Python and Rust.
  • Updates to interface definitions and canister endpoints to support the new unstable blocks functionality.

Reviewed Changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
visualize_blockchain_graphviz.py New Graphviz-based visualization script for blockchain structures.
visualize_blockchain.py New matplotlib/networkx visualization script for blockchain data.
unstable_blocks.py New parser for unstable blocks output based on candid text input.
interface/src/lib.rs Added BlockData and UnstableBlocksResult types to support outputs.
canister/src/unstable_blocks.rs Added a function to retrieve block data from unstable blocks.
canister/src/main.rs Exposed a new query endpoint get_unstable_blocks.
canister/src/lib.rs Introduced a new get_unstable_blocks function returning block data.
canister/src/blocktree.rs Extended BlockTree with a new method to extract block data recursively.
Files not reviewed (2)
  • canister/candid.did: Language not supported
  • process_unstable_blocks.sh: Language not supported

Comment on lines +47 to +58
// let max_depth_diff = MAX_TESTNET_UNSTABLE_DEPTH_DIFFERENCE.get() as u32;
// let min_depth_diff = stability_threshold.min(max_depth_diff - 1);

if total_unstable_blocks >= MAX_UNSTABLE_BLOCKS {
return Depth::new(min_depth_diff as u64);
}
// if total_unstable_blocks >= MAX_UNSTABLE_BLOCKS {
// return Depth::new(min_depth_diff as u64);
// }

let range = (max_depth_diff - min_depth_diff) as f64;
let ratio = total_unstable_blocks as f64 / MAX_UNSTABLE_BLOCKS as f64;
let interpolated = max_depth_diff as f64 - ratio * range;
// let range = (max_depth_diff - min_depth_diff) as f64;
// let ratio = total_unstable_blocks as f64 / MAX_UNSTABLE_BLOCKS as f64;
// let interpolated = max_depth_diff as f64 - ratio * range;

Depth::new(interpolated.round() as u64)
// Depth::new(interpolated.round() as u64)
Copy link

Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The function 'testnet_unstable_max_depth_difference' contains several commented-out lines which may reduce clarity. Consider removing or clearly documenting the purpose of this debug code once it is no longer needed.

Copilot uses AI. Check for mistakes.
import sys
from graphviz import Digraph

def short_hash(hash_hex):
Copy link

Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The 'short_hash' function is duplicated across multiple files. Consider centralizing its implementation to avoid code duplication and simplify future maintenance.

Copilot uses AI. Check for mistakes.
@maksymar maksymar changed the title debug: add get_unstable_blocks [DO NOT SUBMIT] debug: add get_unstable_blocks May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant