Repository navigation
p2p_core%feat!: type the block, tx and BIP152 compact block messages - #135
Conversation
|
Note This pull request has no conflicts! 🎊 🎉 🎊 |
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
|
/self-reviewed 681099d |
|
✅ Final review complete — no blockers (commit e22e6a5) · triage: critical |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Updated after discussion: 1 finding(s) of this review were settled in the inline threads.
- ✅ Withdrawn: 🟡 Add a direct regression test for oversized prefilled indexes
The implementation correctly types the five relay messages, preserves Dash Core wire semantics, and applies the relevant bounds before allocation or narrowing. One in-scope test-coverage gap remains: the new prefilled-index narrowing path is not exercised by a p2p_core decode-error test. CI functional and platform checks passed; the lint failure is limited to cargo-deny advisories for unchanged transitive dependencies (chrono and libz-sys).
🟡 1 0 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate change to peer-facing network deserialization inpkgs/p2p_core/src/msg/compact.rsand related message decoding, including bounds and index validation for remotely supplied payloads. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `pkgs/p2p_core/src/msg/compact.rs`:
- [SUGGESTION → WITHDRAWN in discussion; do not fix] pkgs/p2p_core/src/msg/compact.rs:47-53: Add a direct regression test for oversized prefilled indexes
`PrefilledTransaction::decode` correctly uses `CompactSize::decode_as::<u16>`, so an index greater than `u16::MAX` is rejected rather than truncated. However, the p2p_core tests cover the analogous compact-block count and getblocktxn differential-index failures without exercising this new wire path; the existing generic dash-types test does not protect the message-level wiring. Add a direct case that encodes `65536` followed by a minimal transaction and asserts `CompactSizeExceedsLimit`.
| impl BaseCodec for PrefilledTransaction { | ||
| fn decode(data: &mut &[u8]) -> Result<Self, DecodeError> { | ||
| Ok(Self { | ||
| idx: CompactSize::decode_as(data)?, | ||
| tx: Transaction::decode(data)?, | ||
| }) | ||
| } |
There was a problem hiding this comment.
✅ Withdrawn at
e22e6a5a; see the replies below.
🟡 Suggestion: Add a direct regression test for oversized prefilled indexes
PrefilledTransaction::decode correctly uses CompactSize::decode_as::<u16>, so an index greater than u16::MAX is rejected rather than truncated. However, the p2p_core tests cover the analogous compact-block count and getblocktxn differential-index failures without exercising this new wire path; the existing generic dash-types test does not protect the message-level wiring. Add a direct case that encodes 65536 followed by a minimal transaction and asserts CompactSizeExceedsLimit.
| impl BaseCodec for PrefilledTransaction { | |
| fn decode(data: &mut &[u8]) -> Result<Self, DecodeError> { | |
| Ok(Self { | |
| idx: CompactSize::decode_as(data)?, | |
| tx: Transaction::decode(data)?, | |
| }) | |
| } | |
| #[rstest] | |
| fn prefilled_index_is_narrowed_to_u16() { | |
| let mut raw = Vec::new(); | |
| CompactSize::from(u64::from(u16::MAX) + 1).encode(&mut raw); | |
| tx().encode(&mut raw); | |
| assert_eq!( | |
| PrefilledTransaction::decode(&mut raw.as_slice()), | |
| Err(DecodeError::CompactSizeExceedsLimit { | |
| limit: u16::MAX as usize, | |
| value: u64::from(u16::MAX) + 1, | |
| }) | |
| ); | |
| } |
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
There was a problem hiding this comment.
Not adding this one. The bound comes from the u16 field and CompactSize::decode_as; PrefilledTransaction::decode adds no check of its own. dash-types tests that type bound in decode_as_bounds_the_value_by_the_type, and an earlier review of this PR dropped the same test for that reason. The getblocktxn case is tested here because GetBlockTxn::decode does its own range check on the running sum.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
There was a problem hiding this comment.
I agree this is not needed to establish correctness: PrefilledTransaction::decode delegates the range check directly to the generic CompactSize::decode_as, and the shared dash-types tests cover that contract. A message-level case could improve coverage, but it is optional rather than a defect or merge requirement, so I’m withdrawing the suggestion.
Withdrawing this finding.
There was a problem hiding this comment.
Withdrawn (re-reviewed at e22e6a5a): You're right that idx: u16 selects the same checked conversion path exercised by the generic decode_as test. The current head adds no prefilled-index arithmetic or separate range check, so I'm leaving the suggestion withdrawn.
681099d to
9d117ce
Compare
|
Ready for steward review at 9d117ce Rebased onto 🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta. |
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Steward review at 9d117ce: one more push, all conventions. The independent review and my own pass found nothing wrong with what the five messages accept, refuse or write:
- field order, widths and endianness match the reference at v24.0.0 (
blockencodings.hL22-L42, L56-L80, L116-L125;serialize.hL713-L726); - the combined count, the 16-bit prefilled index and the differential
getblocktxnindexes refuse the same byte strings as the reference.CompactSize::decodecaps each difference, so the running sum cannot overflow; - the testnet rows are what their comments say. Both blocks' merkle roots recompute, and every short ID in the
cmpctblockrows recomputes from its block's transactions; - fork
just combpasses on both commits, and CI passes on this head.
Changes (each in the commit that added the code, then force-push):
- Struct docs are headlines (
compact.rs:19,:31-32,:36,:115-116,:193). "A struct's doc is a headline. Decoder and encoder facts go on theBaseCodec::decodeandencodedocs" (#86, #87). The CompactSize offsets, the 16-bit narrowing and the differential encoding move to thedecode/encodedocs, or go. Compare "Afilterloadpayload." and "The filter of one block." ondevelop. - No
blockandtxcorpus indash-p2p-core(3947220:corpus/blocks.json5blockandtxsections and their program,corpus_blockandcorpus_txinblocks.rs).dash-primitivesalready proves theBlockandTransactioncodecs. What this crate adds is the command-to-variant mapping, which is a plain read in the reference. "Test a property once, in the crate that owns it. Consumers test only their own mapping onto it" (design rulings §5). Thegovobjandgovobjvotevariants have no corpus here either. Replace them with onerstestthat checksdecode_payloadmapsblockandtxbytes toP2pMsg::BlockandP2pMsg::Tx. combined_counts_are_boundedwithout the branch (compact.rs:228-255). Theif full == 0builds a different payload, limit and value in each arm, so the reader has to work out which case runs which arm ("Clever code golf is hard to read", #87). Split it into two plain tests, one for the short-ID count and one for the prefilled count, or pass the expected limit and value as case parameters.- Description: names. rust-bitcoin names the message structs
HeaderAndShortIds,BlockTransactionsRequestandBlockTransactions. This PR names them after their variants, asGetHeadersandGetBlocksare. Say that. OnlyPrefilledTransaction,idxandprefilled_txsfollow rust-bitcoin. - Description: disclosure. Give the effort for each authoring model, not only for the reviewer.
Considered and not asked for
- Constraining
CmpctBlock::newand its deserialization toMAX_TX_COUNT.encodecan then write a listdecoderefuses, but the reference's writer does the same. This was declined on #128 forIsdLockandSpork.GetBlockTxnis different: an unordered list would makeencodesubtract past zero. It goes in the log as a judgment call. - A reference row with a gapped
getblocktxnrequest or a non-zero prefilled index. The rows are captured testnet traffic, and thesumcase covers gap encoding.
After the push: post the ready line with the range-diff from 9d117ce. I will check the range myself. If it holds only these changes, there is no further review round.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
`block` and `tx` decode with the existing primitive decoders.
Decode `cmpctblock`, `getblocktxn` and `blocktxn`. A `cmpctblock` carries at most `CmpctBlock::MAX_TX_COUNT` short IDs and prefilled transactions together.
9d117ce to
e22e6a5
Compare
|
Ready for steward review at e22e6a5 Fork
|
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
At e22e6a5, the BIP152 count and differential-index checks match Dash Core, and I found no blocking issue; the suggestions address avoidable relay copies and document the SDK's stricter handling of trailing bytes. Lint, P2P MSRV, stable, and cross-platform checks passed; only the review check is pending.
🟡 2 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Follow-up candidates (optional) (1)
New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.
🟡 Suggestion: Encode typed block payloads directly into the caller's buffer
pkgs/p2p_core/src/msg/mod.rs:80-83
Moving Block and Tx from the raw arm to the parsed arm introduces two full-payload copies after serialization. The generated encoder first writes into a VecEncoder buffer, encode_to_vec copies those bytes into a second vector, and encode_payload copies that vector into the caller's buffer. Both copies happen even when the caller has reserved enough capacity. Call dash_types::codec::BaseCodec::encode(m, buf) directly in the parsed arm of define_p2p!; it is the same codec the generated encoder already uses.
source: gpt-6.2-astra (phase2-reviewer: rust-quality)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The new peer-facing BIP152 decoders in pkgs/p2p_core/src/msg/compact.rs implement differential index arithmetic, integer narrowing, and combined transaction-count checks on untrusted wire data. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Code unchanged since the last final review (
681099d4): 1 new suggestion(s) listed as follow-up candidates, not posted inline - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `pkgs/p2p_core/src/msg/compact.rs`:
- [SUGGESTION] pkgs/p2p_core/src/msg/compact.rs:206: Let block reconstruction take ownership of reply transactions
A relay that owns a decoded `BlockTxn` can check `block_hash()`, but it cannot move the transactions out: the vector is private and `transactions()` only borrows it. Filling an owned `Block` from the reply therefore requires cloning the transactions and their buffers. A consuming accessor lets callers move them into the reconstructed block while preserving the borrowing API.
In `pkgs/p2p_core/src/msg/blocks.rs`:
- [SUGGESTION] pkgs/p2p_core/src/msg/blocks.rs:85-89: Document trailing-byte rejection on the newly typed routes
The five commands now go through `decode_msg`, which returns `TrailingBytes` even when the message itself decoded successfully. Dash Core at `938fba5028` reads the object without requiring the payload to be exhausted (for example, `tx` at `net_processing.cpp:4896` and `block` at `net_processing.cpp:5375`). Call out this stricter SDK behavior explicitly in Breaking Changes and add a trailing-byte case to the new dispatch test. The existing `ping` test covers the shared guard, but the new `block` and `tx` cases only cover successful dispatch.
| #[getset(get = "pub")] | ||
| transactions: Vec<Transaction>, | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 Suggestion: Let block reconstruction take ownership of reply transactions
A relay that owns a decoded BlockTxn can check block_hash(), but it cannot move the transactions out: the vector is private and transactions() only borrows it. Filling an owned Block from the reply therefore requires cloning the transactions and their buffers. A consuming accessor lets callers move them into the reconstructed block while preserving the borrowing API.
| } | |
| } | |
| impl BlockTxn { | |
| /// Consumes the reply and returns its transactions in wire order. | |
| pub fn into_transactions(self) -> Vec<Transaction> { | |
| self.transactions | |
| } | |
| } |
source: gpt-6.2-astra (phase2-reviewer: rust-quality)
There was a problem hiding this comment.
Declined for this PR. No message or primitive on develop has a consuming accessor; Headers, Block and the rest only borrow. Adding one here would be the first, and new public API goes in with the consumer that needs it (#92), not ahead of it. If the node's compact relay needs to move the transactions out, it can propose the accessor then, for every message that carries a list.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
| #[rstest] | ||
| #[case::block(CommandString::BLOCK, wire(&block()), P2pMsg::Block(block()))] | ||
| #[case::tx(CommandString::TX, wire(&tx()), P2pMsg::Tx(tx()))] | ||
| fn block_and_tx_decode_to_their_variants(#[case] command: CommandString, #[case] raw: Vec<u8>, #[case] msg: P2pMsg) { | ||
| assert_eq!(P2pMsg::decode_payload(&command, &raw), Ok(msg)); |
There was a problem hiding this comment.
🟡 Suggestion: Document trailing-byte rejection on the newly typed routes
The five commands now go through decode_msg, which returns TrailingBytes even when the message itself decoded successfully. Dash Core at 938fba5028 reads the object without requiring the payload to be exhausted (for example, tx at net_processing.cpp:4896 and block at net_processing.cpp:5375). Call out this stricter SDK behavior explicitly in Breaking Changes and add a trailing-byte case to the new dispatch test. The existing ping test covers the shared guard, but the new block and tx cases only cover successful dispatch.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, rust-quality, security-auditor)
There was a problem hiding this comment.
Declined. Refusing trailing bytes is develop's behaviour for every typed command since e12661a, and #128 extended it the same way without a per-command note. It is tested once on the shared guard, and repeating that case per command is the per-struct test the maintainer has declined. The Breaking Changes section already says a payload that does not decode as its message is now refused.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
Motivation
dash-p2p-corerecognisesblock,tx,cmpctblock,getblocktxnandblocktxnbut hands their payloads back as raw bytes. A client that relays blocks, transactions or compact blocks has to lay out and parse each message itself. This pull request types the five messages.blockandtxuse the existingdash-primitivesdecoders. The message structs are named after theirP2pMsgvariants, asGetHeadersandGetBlocksare, where rust-bitcoin hasHeaderAndShortIds,BlockTransactionsRequestandBlockTransactions. OnlyPrefilledTransaction,idxandprefilled_txsfollow rust-bitcoin. The short ID isShortTxIdbecauseShortIdalready names the BIP324 short message ID in this crate. Computing short IDs is left to the caller.Additional Information
P2pMsg::BlockandP2pMsg::TxcarryBlockandTransaction, decoded by the existing primitive decoders.dash-primitivesalready tests those codecs, so the test here checks only thatblockandtxpayloads decode to these variants.ShortTxId,PrefilledTransaction,CmpctBlock,GetBlockTxnandBlockTxninmsg/compact.rs. Acmpctblockwhose short IDs and prefilled transactions together exceedCmpctBlock::MAX_TX_COUNTis refused while reading the counts, which accepts and refuses the same inputs as the reference's check after both lists. A prefilled index that does not fitu16, and agetblocktxnindex whose running sum does not fitu16, are refused while reading.GetBlockTxn::newand its deserialization take only strictly increasing indexes, the only lists the reference writes. Every section of the newcorpus/compact.json5is printed by the program above it, run innet_testsat v24.0.0. Its literals are, for blocks 1592894 and 1592891, a testnet peer'scmpctblockreply, thegetblocktxnwe sent for every transaction it left out, and the peer'sblocktxnreply.The
getblocktxnindex list and theblocktxntransaction list have no bound beyond ordinary vector decoding.Consumers, all in the rust-dashcore node:
dash-p2p/src/read.rs.CmpctBlock,GetBlockTxnandBlockTxn: compact block relay indashd-p2p/src/processing/compact.rs.Breaking Changes
P2pMsg::Block,P2pMsg::Tx,P2pMsg::CmpctBlock,P2pMsg::GetBlockTxnandP2pMsg::BlockTxnhold the typed messages instead ofVec<u8>, so code that builds or matches them must change, and a payload that does not decode as its message is now refused.P2pMsg::is_stubisfalsefor them.How Has This Been Tested?
Checklist
comments and concerns without said assistance. I assume authorship of the code submitted.
Agent disclosure
Code was generated with Codex using GPT 6.1 Sol at
higheffort, with Muse Wonder athigheffort, and with Claude Code using Claude Opus 5.5 atmediumandhigheffort, running autonomously as agents on behalf of the author. The corpus programs, the capture of the testnet messages, commit messages and this description were generated with Claude Code using Claude Opus 5.5 athigheffort. The agents also built the reference implementation's unit tests at v24.0.0 and ran the programs that wrote the vectors. The change was reviewed by a Claude Code agent using Opus 5.5 athigheffort.🤖 Generated with Claude Code