Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Replace all Rlp usages with UntrustedRlp except for ethcore views #8233

Merged
merged 17 commits into from
Mar 29, 2018

Conversation

ascjones
Copy link
Contributor

Part of #8033, replacing Rlp with UntrustedRlp.

Now everywhere (except ethcore views) are using UntrustedRlp and handling the Result<_,DecoderError>.

This paves the way for the next phase, which would be to replace Rlp with UntrustedRlp in the ethcore views. Once that is done we can remove the legacy Rlp implementation.

All Rlp methods return Result<_,DecoderError> now, so for this first
pass each will be marked with `expect("TODO")`. In the next pass we can
categorise figure out how to handle each case.
Rlp should be valid since created manually in tests
This can be done again in the next phase, in order that we can leave the ethcore views unchanged
Use legacy Rlp for ethcore views. Will redo replacing Rlp with UntrustedRlp in  a subsequent PR
@ascjones ascjones added the A0-pleasereview 🤓 Pull request needs code review. label Mar 27, 2018
@parity-cla-bot
Copy link

It looks like @ascjones signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Copy link
Collaborator

@debris debris left a comment

Choose a reason for hiding this comment

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

just a minor grumble

@@ -74,6 +74,38 @@ pub struct BlockDescriptor {
pub total_difficulty: U256,
}

// best block data
struct BestAndLatest {
Copy link
Collaborator

@debris debris Mar 28, 2018

Choose a reason for hiding this comment

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

handwritten implementations of Encodable and Decodable can be replaced with

#[derive(RlpEncodable, RlpDecodable)]
struct {
  // ..
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course! Fixed.

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

I'm against unwraps, but looks good otherwise.

I hope that views won't return errors, will they? IMHO it's fine to trust that DB content contains correct RLPs and panic otherwise.

@@ -469,7 +469,7 @@ impl ChainInfo for TestBlockChainClient {
impl BlockInfo for TestBlockChainClient {
fn block_header(&self, id: BlockId) -> Option<encoded::Header> {
self.block_hash(id)
.and_then(|hash| self.blocks.read().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
.and_then(|hash| self.blocks.read().get(&hash).map(|r| UntrustedRlp::new(r).at(0).unwrap().as_raw().to_vec()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We fought hard to get rid of unwraps() in the code base and this PR intorudces it back, can we please replace them with expects()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sorry that unwrap snuck in. Removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There seems to be way more than that one. It's fine in tests code, but would avoid it in regular code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the unwraps I added in this PR. There are plenty in there still from before - like you say probably okay for tests. Which is why I was lazy in this case and just added them. Broken windows and all!

@5chdn 5chdn added this to the 1.11 milestone Mar 28, 2018
@5chdn 5chdn added the M4-core ⛓ Core client code / Rust. label Mar 28, 2018
@@ -293,9 +294,9 @@ impl BlockCollection {
let mut block_rlp = RlpStream::new_list(3);
block_rlp.append_raw(&block.header, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

new_from_header_and_body()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. See latest commit.

@tomusdrw tomusdrw added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Mar 29, 2018
@5chdn 5chdn merged commit e3f7b70 into master Mar 29, 2018
@5chdn 5chdn deleted the replace_rlp_with_untrusted_impl branch March 29, 2018 09:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants