New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BIP152 (Compact Blocks) structures #249
Conversation
990a31d
to
c8d0814
Compare
So I understand we don't want a |
yes, siphash is also used in BIP158. It would be better included into bitcoin_hashes |
@tamasblummer Could you check if that suits your need for BIP 158 usage? I'm actually very interested in BIP-158 implementation in rust-bitcoin. Are you planning to do them? |
@stevenroose will review tomorrow. I already implemented and using BIP158 in murmel: https://github.com/rust-bitcoin/murmel/blob/master/src/blockfilter.rs |
c8d0814
to
7a70807
Compare
@tamasblummer would you mind upstreaming that to rust-bitcoin? Into |
3a12d50
to
50717b1
Compare
@tamasblummer I made 2 changes:
|
50717b1
to
a6beaed
Compare
a6beaed
to
2ed6915
Compare
2ed6915
to
805aec6
Compare
This is rebased and ready to be reviewed. Uses the new bitcoin_hashes siphash impl. |
805aec6
to
f394fe0
Compare
f394fe0
to
b6ff8bb
Compare
rebased |
@dr-orlovsky Addressed all your derives, had to derive |
ae56a06
to
1d519df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack 1d519df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. I am not knowledgeable in compact filters to do a code vs standard review though :(
// strip witness for version 1 | ||
let mut no_witness = tx.clone(); | ||
no_witness.input.iter_mut().for_each(|i| i.witness.clear()); | ||
no_witness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this PR is a million years old, but can you provide a citation/explanation for this witness-stripping behavior? I don't see it in Core or in BIP 152 or 158.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been ages indeed, but it says that txs inside v1 should be like responses to MSG_TX and v2 should be like responses to MSG_WITNESS_TX:
https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki#specification-for-version-2
Done review of 1d519df ACK except for the thing about witness stripping. I think this PR beats Carl's PSBT PR for "longest open PR" :) |
1d519df
to
68760f5
Compare
Rebased once again! :) |
} | ||
} | ||
|
||
impl hex::FromHex for ShortId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should use impl_bytes_newtype
to get this and the impls below?
|
||
/// Short transaction IDs are used to represent a transaction without sending a full 256-bit hash. | ||
#[derive(PartialEq, Eq, Clone, Copy, Hash, Default, PartialOrd, Ord)] | ||
pub struct ShortId(pub [u8; 6]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have an AsRef
implementation for ShortId
as well?
Nice, was looking for the BIP152 network messages in rust-bitcoin and was about to implement them myself. Will test against Bitcoin Core's network messages and review! |
/// The blockhash of the block which the transactions being requested are in. | ||
pub block_hash: BlockHash, | ||
/// The indexes of the transactions being requested in the block. | ||
pub indexes: Vec<u64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess using u64
is fine here though we'll probably not even going to get close to u32::MAX
transactions in a block too.
Hey mate, this PR is currently marked as part of the 0.29 milestone, would you like to get this functionality in before the 0.29 release? |
I'm interested in seeing this in 0.29. I've rebased this branch on current |
Legend @0xB10C, thanks. Perhaps if @stevenroose does not pick this up in a week or so you could create a PR and just mention that its Steven's work and it supersedes this one [0]. I can do it if you either don't have time or don't feel comfortable doing so. I'm totally speaking for @stevenroose here, Steven you can go right ahead and slap me if I'm out of place :) [0]: When doing so I typically add a |
for _ in 0..nb_indexes { | ||
let differential: VarInt = Decodable::consensus_decode(&mut d)?; | ||
last_index = match last_index.checked_add(differential.0 + 1) { | ||
Some(r) => r, | ||
None => return Err(encode::Error::ParseFailed("block index overflow")), | ||
}; | ||
indexes.push(last_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for reference: While adding a deserialize(serialize(BlockTransactionsRequest{..}))
test I noticed a subtle off-by-one error here. The increment in L321 (differential.0 + 1
) is too early. This should only be incremented after we indexes.push(last_index);
. Otherwise a differentially encoded [0, 1, 0]
would become [1, 3, 4]
when it should be [0, 2, 3]
.
Fixed this in #1088.
Superseded by #1088 I've messaged @stevenroose via text also to make sure he is aware of this. |
ee29910 BIP152: Test net msg ser/der and diff encoding (0xb10c) cd1aaaf BIP152: Add Compact Block unit test based on Elements (Steven Roose) d4d92a8 BIP152: Add Compact Blocks network messages (Steven Roose) f2fcdc8 BIP152: Add basic Compact Block structures (Steven Roose) a9a39c4 blockdata: Derive PartialOrd, Ord and Hash for BlockHeader (Steven Roose) Pull request description: > Adds the basic structures for BIP152 and a method to create a compact block from a full block. This is a rebase of #249 by stevenroose (see #249 (comment)) with a milestone for 29.0. I've added deserialization and serialization tests for the network messages and fixed an off-by-one bug in the deserialization of the differentially encoded varints in the `getblocktxn` message (see #249 (comment)). Closes #249. ACKs for top commit: tcharding: ACK ee29910 apoelstra: ACK ee29910 Tree-SHA512: 462a91576281f5a2ffdc2610769ea93970b60dac75a150c827966c48daec7cf93f526f9f202e7ba1dbb1410b49148579880260a3c3df298b98330c0d891a4cca
…uctures ee29910 BIP152: Test net msg ser/der and diff encoding (0xb10c) cd1aaaf BIP152: Add Compact Block unit test based on Elements (Steven Roose) d4d92a8 BIP152: Add Compact Blocks network messages (Steven Roose) f2fcdc8 BIP152: Add basic Compact Block structures (Steven Roose) a9a39c4 blockdata: Derive PartialOrd, Ord and Hash for BlockHeader (Steven Roose) Pull request description: > Adds the basic structures for BIP152 and a method to create a compact block from a full block. This is a rebase of #249 by stevenroose (see rust-bitcoin/rust-bitcoin#249 (comment)) with a milestone for 29.0. I've added deserialization and serialization tests for the network messages and fixed an off-by-one bug in the deserialization of the differentially encoded varints in the `getblocktxn` message (see rust-bitcoin/rust-bitcoin#249 (comment)). Closes #249. ACKs for top commit: tcharding: ACK ee29910 apoelstra: ACK ee29910 Tree-SHA512: 462a91576281f5a2ffdc2610769ea93970b60dac75a150c827966c48daec7cf93f526f9f202e7ba1dbb1410b49148579880260a3c3df298b98330c0d891a4cca
b3503ba Add example to SharedSecret (Tobin Harding) Pull request description: Currently the rustdoc on `SharedSecret` is wildly incorrect (possibly a cut'n'pasta error). Fix the rustdoc for `SharedSecret` and add an examples section to assist testing the public API. Fixes: rust-bitcoin#249 ACKs for top commit: apoelstra: ACK b3503ba Tree-SHA512: 650092388099bb415c11ea335ca6b64c90094f1a51ceecc403911316ee62da0279488af6fa66e00ee5269c129f06d4641085f8ab9be91c98d24a7a4449d235c2
Change freenode link to Libera
Adds the basic structures for BIP152 and a method to create a compact block from a full block.
Depends on rust-bitcoin/bitcoin_hashes#46.