-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Handle rlp decoding Result in patricia trie #8166
Conversation
It looks like @ascjones signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
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.
nice! I like the fact that printing an invalid trie finally does not panic :) I remember that we had a separate issue for that, but I can't find it right now
// something went wrong. | ||
_ => panic!("Rlp is not valid.") | ||
_ => Err(DecoderError::Custom("Rlp is not valid.")) |
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.
maybe use bail!
instead docs
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.
Done.
self.fmt_all(Node::decoded(&node), f, deepness)?; | ||
match Node::decoded(&node) { | ||
Ok(n) => self.fmt_all(n, f, deepness)?, | ||
Err(err) => writeln!(f, "ERROR decoding node extension Rlp: {}", err)?, |
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.
unrelated:
instead of writeln
, we should use debug_struct which takes into an account an alternate flag of the formatter which allows pretty-printing
util/patricia_trie/src/node.rs
Outdated
@@ -63,7 +63,7 @@ impl<'a> Node<'a> { | |||
// an empty branch index. | |||
Prototype::Data(0) => Ok(Node::Empty), | |||
// something went wrong. | |||
_ => Err(DecoderError::Custom("Rlp is not valid.")) | |||
_ => bail!("Rlp is not valid.") |
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.
ah, sorry. I thought that this Error is already an error from error_chain. Wouldn't ask for this change if I knew it was not.
2c4b777
to
83aba3e
Compare
I reverted this last commit. Sorry, my suggestion was wrong. I'll merge the pr once it's green |
Part of #8033, replacing existing usage of
Rlp
withUntrustedRlp
.Unwraps the result of decoding a node's rlp, assuming valid rlp since it is a local read from the db.
Next step might be to introduce another case to TrieError for a DecoderError to avoid the unwraps.