decode block rlp less often (#9252)
in total: - removed 4 redundant rlp deserializations - avoid 1 redundant block data copy
This commit is contained in:
committed by
André Silva
parent
f442665c46
commit
b4ae1b6528
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user