Skip to content

feat: Add command to dump cbor hex of block#72

Merged
AndrewWestberg merged 1 commit intodevelopfrom
amw/dump_block
Nov 23, 2025
Merged

feat: Add command to dump cbor hex of block#72
AndrewWestberg merged 1 commit intodevelopfrom
amw/dump_block

Conversation

@AndrewWestberg
Copy link
Collaborator

Description

Adds new dump-block command useful in debugging chain issues so you can look at the raw cbor for any block.

Which issue it fixes?

Closes #70

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 PR adds a new dump-block command to retrieve and output the raw CBOR hex of a block from the Cardano blockchain, useful for debugging chain issues. The implementation connects to a cardano-node via the network protocol, synchronizes to a specified block, and dumps its raw content.

Key Changes

  • Adds new dump-block command with network client implementation to fetch and output block CBOR data
  • Updates blockstore query limits from 33 to 262145 blocks and extends intersection point sequence documentation
  • Updates dependencies including pallas libraries (0.32.1 → 0.33.0) and downgrades minicbor (0.26 → 0.25.1)

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/nodeclient/dumpblock/mod.rs New module implementing the dump-block command with network client logic
src/nodeclient/dumpblock/hash_utils.rs Helper functions for extracting block header information
src/nodeclient/mod.rs Registers the new dumpblock module
src/lib.rs Adds DumpBlock command variant and execution handler
USAGE.md Documents the new dump-block command usage
Cargo.toml Version bump to 6.7.0, updates pallas dependencies, downgrades minicbor
Cargo.lock Comprehensive dependency update including pallas, amaru, and various ecosystem crates
src/nodeclient/sync/mod.rs Extends comment documenting powers of 2 sequence for intersection points
src/nodeclient/blockstore/sqlite.rs Increases block query limit from 100/33 to 524289/262145
src/nodeclient/blockstore/redb.rs Increases block query limit from 33 to 262145 with updated comment

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


### Dump Block Command

This command dump the raw cbor hex of a block given the previous block's hash and slot number.
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

Corrected verb agreement: 'dump' should be 'dumps' (third-person singular present).

Suggested change
This command dump the raw cbor hex of a block given the previous block's hash and slot number.
This command dumps the raw cbor hex of a block given the previous block's hash and slot number.

Copilot uses AI. Check for mistakes.
--intersect-hash <intersect-hash> Block hash of the intersect point (hex)
--intersect-slot <intersect-slot> Slot number of the intersect point
--network-magic <network-magic> network magic. [default: 764824073]
-p, --port <port>
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The port option is missing both a description and default value in the documentation. Based on the code in lib.rs line 71, the default value is '3001' and the description should be 'cardano-node port'.

Suggested change
-p, --port <port>
-p, --port <port> cardano-node port [default: 3001]

Copilot uses AI. Check for mistakes.
pallas-math = "0.33.0"
pallas-network = "0.33.0"
pallas-traverse = "0.33.0"
amaru-ouroboros = { git = "https://github.com/pragma-org/amaru", rev = "8a4f994" }
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

Git revision '8a4f994' is abbreviated (7 characters). Consider using the full 40-character SHA for unambiguous dependency pinning. While Cargo accepts short SHAs, full SHAs are recommended for production dependencies to avoid potential ambiguity.

Suggested change
amaru-ouroboros = { git = "https://github.com/pragma-org/amaru", rev = "8a4f994" }
amaru-ouroboros = { git = "https://github.com/pragma-org/amaru", rev = "8a4f994e2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2" }

Copilot uses AI. Check for mistakes.
futures = "0.3"
hex = "0.4"
#malachite-base = "0.4.16"
#malachite = "0.4.16"
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The minicbor dependency appears to be downgraded from 0.26.5 to 0.25.1. While this may be intentional for compatibility with pallas 0.33.0, consider verifying this is necessary and documenting the reason for the downgrade, as version downgrades can introduce subtle incompatibilities.

Suggested change
#malachite = "0.4.16"
#malachite = "0.4.16"
# NOTE: minicbor is pinned to 0.25.1 for compatibility with pallas 0.33.0.
# If upgrading minicbor, verify compatibility with pallas and update this comment.

Copilot uses AI. Check for mistakes.
let db = &self.db;
let mut stmt = db
.prepare("SELECT slot_number, hash FROM (SELECT slot_number, hash, orphaned FROM chain ORDER BY slot_number DESC LIMIT 100) WHERE orphaned = 0 ORDER BY slot_number DESC LIMIT 33;")?;
.prepare("SELECT slot_number, hash FROM (SELECT slot_number, hash, orphaned FROM chain ORDER BY slot_number DESC LIMIT 524289) WHERE orphaned = 0 ORDER BY slot_number DESC LIMIT 262145;")?;
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The magic numbers 524289 and 262145 are powers of 2 plus 1 (2^19+1 and 2^18+1). Consider defining these as named constants with documentation explaining why these specific limits were chosen, improving code maintainability and making the relationship to the intersection point selection algorithm in sync/mod.rs more explicit.

Copilot uses AI. Check for mistakes.
let hash = chain_record.hash.clone();
blocks.push((slot_number, hash));
if blocks.len() >= 33 {
if blocks.len() >= 262145 {
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

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

The magic number 262145 (2^18+1) should be defined as a named constant, ideally shared with sqlite.rs:315. This would ensure consistency between database implementations and improve maintainability when the block limit needs adjustment.

Copilot uses AI. Check for mistakes.
@AndrewWestberg AndrewWestberg merged commit 8162cfb into develop Nov 23, 2025
10 checks passed
@AndrewWestberg AndrewWestberg deleted the amw/dump_block branch November 23, 2025 22:56
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.

cncli fails to sync after Mithril DB restore: Missing eta_v

2 participants