-
Notifications
You must be signed in to change notification settings - Fork 729
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
Ready for Review: Clean up network::encodable
and network::serialize
#156
Ready for Review: Clean up network::encodable
and network::serialize
#156
Conversation
307ec2e
to
ed5a358
Compare
network::encodable
and network::serialize
network::encodable
and network::serialize
ed5a358
to
8f982ff
Compare
Rebased. |
2949f70
to
a3a8b74
Compare
a3a8b74
to
5c4ca24
Compare
Rebased. |
src/util/hash.rs
Outdated
fn bitcoin_hash(&self) -> Sha256dHash { | ||
Sha256dHash::from_data(&self[..]) | ||
} | ||
} |
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.
Is this used anywhere? It's pretty surprising that the "bitcoin hash" of a Vec does not include its length prefix.
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.
Used here but doesn't seem to be needed?
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.
Like, the merkle_root()
method calls .bitcoin_hash()
on a Vec<u8>
? Yeah, that should be made more explicit.
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.
Can you add a commit fixing merkle_root
to use Sha256dEncoder
and then fix this commit so it doesn't add useless code?
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.
Addressed in: ba84548
Not sure which commit you mean?
src/consensus/mod.rs
Outdated
//! conform to Bitcoin consensus. | ||
//! | ||
|
||
pub mod params; |
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.
Can you add a pub use params::Params
here so that people can use this as bitcoin::consensus::Params
?
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.
Can you change this commit to address this?
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.
Addressed in: cccbb05
src/consensus/encode.rs
Outdated
} | ||
|
||
/// A simple Encoder trait | ||
pub trait SimpleEncoder { |
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 be renamed to Encoder
. Ditto for SimpleDecoder
.
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.
Addressed in: 58b6600
src/consensus/encode.rs
Outdated
} | ||
|
||
/// An encoder for raw binary data | ||
pub struct RawEncoder<W> { |
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.
We should drop RawEncoder
and just do an impl<T: Write> Encoder for T
, the way ReadExtBytes
in byteorder works. Similar for RawDecoder
.
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.
Addressed in: 58b6600
src/consensus/mod.rs
Outdated
pub mod params; | ||
|
||
pub use self::encode::{Encodable, Decodable}; |
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 also pub use
Encoder and Decoder (suggested renames of SimpleEncoder and SimpleDecoder)
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.
and deserialize
and serialize
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.
Addressed in: cccbb05
src/consensus/encode.rs
Outdated
|
||
/// Encode an object into a vector | ||
pub fn serialize<T: ?Sized>(data: &T) -> Result<Vec<u8>, Error> | ||
where T: Encodable<RawEncoder<Cursor<Vec<u8>>>>, |
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.
We should just unwrap
in here, not return an error, and document in the Encodable
trait that you should only ever error if the underlying Encoder
errors.
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.
Addressed in: efb85a1
src/util/hash.rs
Outdated
@@ -108,59 +108,59 @@ impl Sha256dEncoder { | |||
} | |||
|
|||
impl SimpleEncoder for Sha256dEncoder { |
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.
We should impl Write
for this rather than SimpleEncoder
, then the default impl for all Write
s can take over.
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.
Addressed in: 4f76787
2ba4074
to
d66a34b
Compare
Done. |
Can you rebase everything so I can just review the whole changeset again? |
@apoelstra rebase over...? Confused. |
@dongcarl use |
d66a34b
to
c4f4d5f
Compare
@apoelstra Squashed commits together that only |
Retriggering Travis. |
Does anyone know why it's not testing the latest commit? |
c4f4d5f
to
bac7a9d
Compare
Looks like it's working now. |
@dongcarl I need a history where my nits are addressed. I can't tell where or if you've fixed things when they're all spread around. |
bac7a9d
to
4f76787
Compare
@apoelstra I've split the commits up a little more so it's obvious what's addressing what, I've also commented the relevant commits on your reviews, 58b6600 is a little too convoluted to split up in reasonable time 🙁 |
- Modify VersionMessage constructor to take in parameters directly that would have otherwise been extracted from a Socket (now removed)
- Use Sha256dEncoder for calculating merkle root - Remove BitcoinHash implementation for Vec<u8>
- Move network::encodable::* to consensus::encode::* - Rename Consensus{En,De}codable to {En,De}codable (now under consensus::encode) - Move network::serialize::Error to consensus::encode::Error - Remove Raw{En,De}coder, implement {En,De}coder for T: {Write,Read} instead - Move network::serialize::Simple{En,De}coder to consensus::encode::{En,De}coder - Rename util::Error::Serialize to util::Error::Encode - Modify comments to refer to new names - Modify files to refer to new names - Expose {En,De}cod{able,er}, {de,}serialize, Params - Do not return Result for serialize{,_hex} as serializing to a Vec should never fail
4f76787
to
c42252c
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
845bff2 Bump version to 0.15.4 (Steven Roose) 07ef3a1 Pin version of build dependency cc to <1.0.42 (Steven Roose) Pull request description: Version 1.0.42 broke compatibility with rustc 1.22.0. ACKs for top commit: jonasnick: ACK 845bff2 Tree-SHA512: 21161e6e85494d064b45b9800baa0355784e3b47772dff2716f049b1b15c047832ceb756b2031ef73374952c21aa04a8852a333eb3edbb73f5608c7ce8344c12
Bump bitcoin dependency to 0.26
Changed miri tests passing
Closes: #155