feat: Add command to dump cbor hex of block#72
Conversation
There was a problem hiding this comment.
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-blockcommand 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. |
There was a problem hiding this comment.
Corrected verb agreement: 'dump' should be 'dumps' (third-person singular present).
| 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. |
| --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> |
There was a problem hiding this comment.
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'.
| -p, --port <port> | |
| -p, --port <port> cardano-node port [default: 3001] |
| 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" } |
There was a problem hiding this comment.
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.
| amaru-ouroboros = { git = "https://github.com/pragma-org/amaru", rev = "8a4f994" } | |
| amaru-ouroboros = { git = "https://github.com/pragma-org/amaru", rev = "8a4f994e2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2e2e3e2b7c2" } |
| futures = "0.3" | ||
| hex = "0.4" | ||
| #malachite-base = "0.4.16" | ||
| #malachite = "0.4.16" |
There was a problem hiding this comment.
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.
| #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. |
| 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;")?; |
There was a problem hiding this comment.
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.
| let hash = chain_record.hash.clone(); | ||
| blocks.push((slot_number, hash)); | ||
| if blocks.len() >= 33 { | ||
| if blocks.len() >= 262145 { |
There was a problem hiding this comment.
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.
Description
Adds new
dump-blockcommand useful in debugging chain issues so you can look at the raw cbor for any block.Which issue it fixes?
Closes #70