Skip to content
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

Merged
merged 6 commits into from Sep 25, 2018

Conversation

dongcarl
Copy link
Member

Closes: #155

@dongcarl dongcarl changed the title WIP: Clean up network::encodable and network::serialize Ready for Review: Clean up network::encodable and network::serialize Sep 3, 2018
@apoelstra apoelstra added this to the 0.15 milestone Sep 5, 2018
@apoelstra apoelstra self-requested a review September 5, 2018 16:11
@dongcarl
Copy link
Member Author

dongcarl commented Sep 8, 2018

Rebased.

@dongcarl dongcarl force-pushed the 2018-8-network-cleanup branch 2 times, most recently from 2949f70 to a3a8b74 Compare September 9, 2018 10:23
@dongcarl
Copy link
Member Author

Rebased.

src/util/hash.rs Outdated
fn bitcoin_hash(&self) -> Sha256dHash {
Sha256dHash::from_data(&self[..])
}
}
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

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?

//! conform to Bitcoin consensus.
//!

pub mod params;
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in: cccbb05

}

/// A simple Encoder trait
pub trait SimpleEncoder {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in: 58b6600

}

/// An encoder for raw binary data
pub struct RawEncoder<W> {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in: 58b6600

pub mod params;

pub use self::encode::{Encodable, Decodable};
Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

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

and deserialize and serialize

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in: cccbb05


/// Encode an object into a vector
pub fn serialize<T: ?Sized>(data: &T) -> Result<Vec<u8>, Error>
where T: Encodable<RawEncoder<Cursor<Vec<u8>>>>,
Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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 Writes can take over.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in: 4f76787

@dongcarl dongcarl force-pushed the 2018-8-network-cleanup branch 2 times, most recently from 2ba4074 to d66a34b Compare September 16, 2018 19:25
@dongcarl
Copy link
Member Author

Done.

@apoelstra
Copy link
Member

Can you rebase everything so I can just review the whole changeset again?

@dongcarl
Copy link
Member Author

@apoelstra rebase over...? Confused.

@apoelstra
Copy link
Member

@dongcarl use rebase -i to make a readable history that does not have a bunch of commits undoing other commits.

@dongcarl
Copy link
Member Author

@apoelstra Squashed commits together that only mvs/rms stuff

@dongcarl
Copy link
Member Author

Retriggering Travis.

@dongcarl dongcarl closed this Sep 16, 2018
@dongcarl dongcarl reopened this Sep 16, 2018
@dongcarl
Copy link
Member Author

Does anyone know why it's not testing the latest commit?

@dongcarl
Copy link
Member Author

Looks like it's working now.

@apoelstra
Copy link
Member

@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.

@dongcarl
Copy link
Member Author

@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
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ack

@apoelstra apoelstra merged commit 45140a3 into rust-bitcoin:master Sep 25, 2018
Davidson-Souza pushed a commit to Davidson-Souza/rust-bitcoin that referenced this pull request Jul 12, 2023
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
casey pushed a commit to casey/rust-bitcoin that referenced this pull request Nov 28, 2023
yancyribbens pushed a commit to yancyribbens/rust-bitcoin that referenced this pull request Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants