decode block rlp less often (#9252)

in total:
- removed 4 redundant rlp deserializations
- avoid 1 redundant block data copy
This commit is contained in:
Marek Kotewicz
2018-08-02 11:20:46 +02:00
committed by André Silva
parent f442665c46
commit b4ae1b6528
17 changed files with 116 additions and 165 deletions

View File

@@ -35,9 +35,9 @@ use views::BlockView;
use ethkey::KeyPair;
use transaction::{PendingTransaction, Transaction, Action, Condition};
use miner::MinerService;
use rlp::{RlpStream, EMPTY_LIST_RLP};
use tempdir::TempDir;
use test_helpers;
use verification::queue::kind::blocks::Unverified;
#[test]
fn imports_from_empty() {
@@ -97,7 +97,7 @@ fn imports_good_block() {
IoChannel::disconnected(),
).unwrap();
let good_block = get_good_dummy_block();
if client.import_block(good_block).is_err() {
if client.import_block(Unverified::from_rlp(good_block).unwrap()).is_err() {
panic!("error importing block being good by definition");
}
client.flush_queue();
@@ -107,24 +107,6 @@ fn imports_good_block() {
assert!(!block.into_inner().is_empty());
}
#[test]
fn fails_to_import_block_with_invalid_rlp() {
use error::{BlockImportError, BlockImportErrorKind};
let client = generate_dummy_client(6);
let mut rlp = RlpStream::new_list(3);
rlp.append_raw(&EMPTY_LIST_RLP, 1); // empty header
rlp.append_raw(&EMPTY_LIST_RLP, 1);
rlp.append_raw(&EMPTY_LIST_RLP, 1);
let invalid_header_block = rlp.out();
match client.import_block(invalid_header_block) {
Err(BlockImportError(BlockImportErrorKind::Decoder(_), _)) => (), // all good
Err(_) => panic!("Should fail with a decoder error"),
Ok(_) => panic!("Should not import block with invalid header"),
}
}
#[test]
fn query_none_block() {
let db = test_helpers::new_db();

View File

@@ -33,6 +33,7 @@ use views::BlockView;
use trace::{RewardType, LocalizedTrace};
use trace::trace::Action::Reward;
use test_helpers;
use verification::queue::kind::blocks::Unverified;
#[test]
fn can_trace_block_and_uncle_reward() {
@@ -91,7 +92,7 @@ fn can_trace_block_and_uncle_reward() {
let root_block = root_block.close_and_lock().unwrap().seal(engine, vec![]).unwrap();
if let Err(e) = client.import_block(root_block.rlp_bytes()) {
if let Err(e) = client.import_block(Unverified::from_rlp(root_block.rlp_bytes()).unwrap()) {
panic!("error importing block which is valid by definition: {:?}", e);
}
@@ -120,7 +121,7 @@ fn can_trace_block_and_uncle_reward() {
let parent_block = parent_block.close_and_lock().unwrap().seal(engine, vec![]).unwrap();
if let Err(e) = client.import_block(parent_block.rlp_bytes()) {
if let Err(e) = client.import_block(Unverified::from_rlp(parent_block.rlp_bytes()).unwrap()) {
panic!("error importing block which is valid by definition: {:?}", e);
}
@@ -170,7 +171,7 @@ fn can_trace_block_and_uncle_reward() {
let block = block.close_and_lock().unwrap().seal(engine, vec![]).unwrap();
let res = client.import_block(block.rlp_bytes());
let res = client.import_block(Unverified::from_rlp(block.rlp_bytes()).unwrap());
if res.is_err() {
panic!("error importing block: {:#?}", res.err().unwrap());
}