Replace all Rlp usages with UntrustedRlp except for ethcore views (#8233)
* Replace Rlp with UntrustedRlp and unsafely unwrap
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.
* Handle DecoderError for tendermint message
* Unwrap rlp results in TestBlockcChainClient
Rlp should be valid since created manually in tests
* Replace `use rlp::*` with explicit imports
* Remove rlp decode unwraps from light cli request
* Structured rlp encoding for curr best and latest in header chain
* Propogate decoder errors from send_packet
* Fix body uncles rlp index
* Use BodyView in sync and `expect` rlp errors
* Revert bbf28f removing original Rlp for this phase
This can be done again in the next phase, in order that we can leave the ethcore views unchanged
* Restore legacy Rlp and UntrustedRlp
Use legacy Rlp for ethcore views. Will redo replacing Rlp with UntrustedRlp in a subsequent PR
* Fix tests
* Replace boilerplate Encodable/Decodable with derive
* Use BlockView instead of Rlp, remove unwrap
* Remove rlp test_cli unwraps by using BlockView instead of Rlp directly
* Remove unneccesary change to use borrowed hash
* Construct sync block using new_from_header_and_body
This commit is contained in:
@@ -22,7 +22,7 @@ use std::collections::{HashSet, VecDeque};
|
||||
use std::cmp;
|
||||
use heapsize::HeapSizeOf;
|
||||
use ethereum_types::H256;
|
||||
use rlp::*;
|
||||
use rlp::UntrustedRlp;
|
||||
use ethcore::views::{BlockView};
|
||||
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||
use ethcore::client::{BlockStatus, BlockId, BlockImportError};
|
||||
|
||||
@@ -22,8 +22,10 @@ use heapsize::HeapSizeOf;
|
||||
use ethereum_types::H256;
|
||||
use triehash::ordered_trie_root;
|
||||
use bytes::Bytes;
|
||||
use rlp::*;
|
||||
use rlp::{UntrustedRlp, RlpStream, DecoderError};
|
||||
use network;
|
||||
use ethcore::encoded::Block;
|
||||
use ethcore::views::{HeaderView, BodyView};
|
||||
use ethcore::header::Header as BlockHeader;
|
||||
|
||||
known_heap_size!(0, HeaderId);
|
||||
@@ -290,15 +292,10 @@ impl BlockCollection {
|
||||
}
|
||||
|
||||
for block in blocks {
|
||||
let mut block_rlp = RlpStream::new_list(3);
|
||||
block_rlp.append_raw(&block.header, 1);
|
||||
{
|
||||
let body = Rlp::new(block.body.as_ref().expect("blocks contains only full blocks; qed"));
|
||||
block_rlp.append_raw(body.at(0).as_raw(), 1);
|
||||
block_rlp.append_raw(body.at(1).as_raw(), 1);
|
||||
}
|
||||
let body = BodyView::new(block.body.as_ref().expect("blocks contains only full blocks; qed"));
|
||||
let block_view = Block::new_from_header_and_body(&HeaderView::new(&block.header), &body);
|
||||
drained.push(BlockAndReceipts {
|
||||
block: block_rlp.out(),
|
||||
block: block_view.rlp().as_raw().to_vec(),
|
||||
receipts: block.receipts.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ use ethereum_types::{H256, U256};
|
||||
use plain_hasher::H256FastMap;
|
||||
use parking_lot::RwLock;
|
||||
use bytes::Bytes;
|
||||
use rlp::*;
|
||||
use rlp::{UntrustedRlp, RlpStream, DecoderError, Encodable};
|
||||
use network::{self, PeerId, PacketId};
|
||||
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||
use ethcore::client::{BlockChainClient, BlockStatus, BlockId, BlockChainInfo, BlockImportError, BlockQueueInfo};
|
||||
|
||||
Reference in New Issue
Block a user