Skip to content

Backport: Make SendCmpct idempotent#6525

Merged
apoelstra merged 4 commits into
rust-bitcoin:0.32.xxxfrom
mpbagot:feature/0.32-sendcmpct-indempotent
Jul 13, 2026
Merged

Backport: Make SendCmpct idempotent#6525
apoelstra merged 4 commits into
rust-bitcoin:0.32.xxxfrom
mpbagot:feature/0.32-sendcmpct-indempotent

Conversation

@mpbagot

@mpbagot mpbagot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Backport of #6317

From the spec https://bips.dev/152/

The "high-bandwidth" mode, which nodes may only enable for a few of their peers, is enabled by setting the first boolean to 1 in a sendcmpct message.

The "low-bandwidth" mode is enabled by setting the first boolean to 0 in a sendcmpct message

It seems like the spec says that anything besides 1 or 0 is actually an error, though..

Original work by:

mpbagot added 3 commits July 12, 2026 17:10
The SendCmpct type uses the impl_consensus_encoding macro to implement
Encodable and Decodable. Since we want to include a new failure mode
for the decoding side, the full logic will need to be brought out
first.

Replace call of impl_consensus_encoding for SendCmpct with trait
impls for Encodable and Decodable.
Normalizing the mode bit makes serialization/deserialization _not_
idempotent.  That's due to the checksum that's created before
normalization which if serialized again, no longer has the same
checksum.  This cases a failure to serialize the same `SendCmpct` which
was received if the mode bit is anything other then 0 or 1.
Furthermore, the spec https://bips.dev/152/ defines only 0
(low-bandwidth mode) or 1 (high-bandwidth mode) so anything other than
0 or 1 is unspecified and should result in an error.

As quoted from spec https://bips.dev/152/:
The first integer SHALL be interpreted as a boolean (and MUST have a
value of either 1 or 0)

Original work by yancy<github@yancy.lol>
Add a test that if the mode bit of the sendcmpct should fail if not 1 or
0.

Original work by:
- Abeeujah <abeeujah@gmail.com>
- yancy <github@yancy.lol>
@github-actions github-actions Bot added the C-bitcoin PRs modifying the bitcoin crate label Jul 12, 2026
@mpbagot

mpbagot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Should this also be backported to 0.32.xx?

@mpbagot mpbagot marked this pull request as ready for review July 12, 2026 09:16
@tcharding

Copy link
Copy Markdown
Member

Can/should this be draft until the original merges?

@tcharding

Copy link
Copy Markdown
Member

Should this also be backported to 0.32.xx?

If you can be bothered then I"ll review it.

@mpbagot mpbagot marked this pull request as draft July 13, 2026 04:40
@yancyribbens

Copy link
Copy Markdown
Contributor

Can/should this be draft until the original merges?

This one can go first I believe. The "original" is not passing Andrews fuzz tests because 0.32.x does not have this change. Although I guess arguably they could go in any order since the result is that then both 0.32.x and p2p@master will behave the same.

@apoelstra

Copy link
Copy Markdown
Member

I'd like them to go in around the same time. Let's undraft this and get all the needed ACKs in, and I'll merge them in one go.

@apoelstra apoelstra marked this pull request as ready for review July 13, 2026 13:59
@apoelstra

Copy link
Copy Markdown
Member

Oh, I see, what actually needs to happen is:

So there is no need to do anything "at the same time", but we do need to do the backport first.

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK a3ae2bc; successfully ran local tests

@apoelstra apoelstra merged commit 2098942 into rust-bitcoin:0.32.xxx Jul 13, 2026
17 checks passed
@apoelstra

Copy link
Copy Markdown
Member

There. Now we have to get #6317 in.

@tcharding

Copy link
Copy Markdown
Member

Release is ready to go: #6471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants