Replace legacy Rlp with UntrustedRlp and use in ethcore rlp views (#8316)

* WIP

* Replace Rlp with UntrustedRlp in views, explicity unwrap with expect

First pass to get it to compile. Need to figure out whether to do this or to propogate Errors upstream, which would require many more changes to dependent code. If we do this way we are assuming that the views are always used in a context where the rlp is trusted to be valid e.g. when reading from our own DB. So need to fid out whether views are used with data received from an untrusted (e.g. extrernal peer).

* Remove original Rlp impl, rename UntrustedRlp -> Rlp

* Create rlp views with view! macro to record debug info

Views are assumed to be over valid rlp, so if there is a decoding error we record where the view was created in the first place and report it in the expect

* Use $crate in view! macro to avoid import, fix tests

* Expect valid rlp in decode functions for now

* Replace spaces with tabs in new file

* Add doc tests for creating views with macro

* Update rlp docs to reflect removing of UntrustedRlp

* Replace UntrustedRlp usages in private-tx merge
This commit is contained in:
Andrew Jones
2018-04-16 14:52:12 +01:00
committed by Afri Schoedon
parent db7a8c4ac7
commit a04c5b180a
86 changed files with 944 additions and 1055 deletions

View File

@@ -31,7 +31,7 @@ use provider::Provider;
use request;
use request::*;
use rlp::{UntrustedRlp, RlpStream};
use rlp::{Rlp, RlpStream};
use ethereum_types::{H256, U256, Address};
use std::sync::Arc;
@@ -688,7 +688,7 @@ fn id_guard() {
stream.begin_list(2).append(&125usize).append(&3usize);
let packet = stream.out();
assert!(proto.response(&peer_id, &Expect::Nothing, UntrustedRlp::new(&packet)).is_err());
assert!(proto.response(&peer_id, &Expect::Nothing, Rlp::new(&packet)).is_err());
}
// next, do an unexpected response.
@@ -699,7 +699,7 @@ fn id_guard() {
stream.begin_list(0);
let packet = stream.out();
assert!(proto.response(&peer_id, &Expect::Nothing, UntrustedRlp::new(&packet)).is_err());
assert!(proto.response(&peer_id, &Expect::Nothing, Rlp::new(&packet)).is_err());
}
// lastly, do a valid (but empty) response.
@@ -710,7 +710,7 @@ fn id_guard() {
stream.begin_list(0);
let packet = stream.out();
assert!(proto.response(&peer_id, &Expect::Nothing, UntrustedRlp::new(&packet)).is_ok());
assert!(proto.response(&peer_id, &Expect::Nothing, Rlp::new(&packet)).is_ok());
}
let peers = proto.peers.read();