Purging .derefs, fixing clippy warnings. (#1890)
* Fixing clippy warnings * Purging derefs * Simplifying engine derefs * Simplifying more engine derefs
This commit is contained in:
parent
8018b69440
commit
a427208f79
@ -582,23 +582,22 @@ mod tests {
|
|||||||
fn open_block() {
|
fn open_block() {
|
||||||
use spec::*;
|
use spec::*;
|
||||||
let spec = Spec::new_test();
|
let spec = Spec::new_test();
|
||||||
let engine = &spec.engine;
|
|
||||||
let genesis_header = spec.genesis_header();
|
let genesis_header = spec.genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
let b = OpenBlock::new(&*spec.engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||||
let b = b.close_and_lock();
|
let b = b.close_and_lock();
|
||||||
let _ = b.seal(engine.deref(), vec![]);
|
let _ = b.seal(&*spec.engine, vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enact_block() {
|
fn enact_block() {
|
||||||
use spec::*;
|
use spec::*;
|
||||||
let spec = Spec::new_test();
|
let spec = Spec::new_test();
|
||||||
let engine = &spec.engine;
|
let engine = &*spec.engine;
|
||||||
let genesis_header = spec.genesis_header();
|
let genesis_header = spec.genesis_header();
|
||||||
|
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
@ -606,15 +605,15 @@ mod tests {
|
|||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap()
|
let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap()
|
||||||
.close_and_lock().seal(engine.deref(), vec![]).unwrap();
|
.close_and_lock().seal(engine, vec![]).unwrap();
|
||||||
let orig_bytes = b.rlp_bytes();
|
let orig_bytes = b.rlp_bytes();
|
||||||
let orig_db = b.drain();
|
let orig_db = b.drain();
|
||||||
|
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap();
|
let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap();
|
||||||
|
|
||||||
assert_eq!(e.rlp_bytes(), orig_bytes);
|
assert_eq!(e.rlp_bytes(), orig_bytes);
|
||||||
|
|
||||||
@ -627,7 +626,7 @@ mod tests {
|
|||||||
fn enact_block_with_uncle() {
|
fn enact_block_with_uncle() {
|
||||||
use spec::*;
|
use spec::*;
|
||||||
let spec = Spec::new_test();
|
let spec = Spec::new_test();
|
||||||
let engine = &spec.engine;
|
let engine = &*spec.engine;
|
||||||
let genesis_header = spec.genesis_header();
|
let genesis_header = spec.genesis_header();
|
||||||
|
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
@ -635,14 +634,14 @@ mod tests {
|
|||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let mut open_block = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
let mut open_block = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||||
let mut uncle1_header = Header::new();
|
let mut uncle1_header = Header::new();
|
||||||
uncle1_header.extra_data = b"uncle1".to_vec();
|
uncle1_header.extra_data = b"uncle1".to_vec();
|
||||||
let mut uncle2_header = Header::new();
|
let mut uncle2_header = Header::new();
|
||||||
uncle2_header.extra_data = b"uncle2".to_vec();
|
uncle2_header.extra_data = b"uncle2".to_vec();
|
||||||
open_block.push_uncle(uncle1_header).unwrap();
|
open_block.push_uncle(uncle1_header).unwrap();
|
||||||
open_block.push_uncle(uncle2_header).unwrap();
|
open_block.push_uncle(uncle2_header).unwrap();
|
||||||
let b = open_block.close_and_lock().seal(engine.deref(), vec![]).unwrap();
|
let b = open_block.close_and_lock().seal(engine, vec![]).unwrap();
|
||||||
|
|
||||||
let orig_bytes = b.rlp_bytes();
|
let orig_bytes = b.rlp_bytes();
|
||||||
let orig_db = b.drain();
|
let orig_db = b.drain();
|
||||||
@ -650,7 +649,7 @@ mod tests {
|
|||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let e = enact_and_seal(&orig_bytes, engine.deref(), false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap();
|
let e = enact_and_seal(&orig_bytes, engine, false, db, &genesis_header, last_hashes, &Default::default(), Default::default()).unwrap();
|
||||||
|
|
||||||
let bytes = e.rlp_bytes();
|
let bytes = e.rlp_bytes();
|
||||||
assert_eq!(bytes, orig_bytes);
|
assert_eq!(bytes, orig_bytes);
|
||||||
|
@ -258,7 +258,7 @@ pub fn get_temp_journal_db() -> GuardedTempResult<Box<JournalDB>> {
|
|||||||
|
|
||||||
impl MiningBlockChainClient for TestBlockChainClient {
|
impl MiningBlockChainClient for TestBlockChainClient {
|
||||||
fn prepare_open_block(&self, author: Address, gas_range_target: (U256, U256), extra_data: Bytes) -> OpenBlock {
|
fn prepare_open_block(&self, author: Address, gas_range_target: (U256, U256), extra_data: Bytes) -> OpenBlock {
|
||||||
let engine = &self.spec.engine;
|
let engine = &*self.spec.engine;
|
||||||
let genesis_header = self.spec.genesis_header();
|
let genesis_header = self.spec.genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
@ -266,7 +266,7 @@ impl MiningBlockChainClient for TestBlockChainClient {
|
|||||||
|
|
||||||
let last_hashes = vec![genesis_header.hash()];
|
let last_hashes = vec![genesis_header.hash()];
|
||||||
let mut open_block = OpenBlock::new(
|
let mut open_block = OpenBlock::new(
|
||||||
engine.deref(),
|
engine,
|
||||||
self.vm_factory(),
|
self.vm_factory(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
false,
|
false,
|
||||||
@ -482,9 +482,9 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
if number == len {
|
if number == len {
|
||||||
{
|
{
|
||||||
let mut difficulty = self.difficulty.write();
|
let mut difficulty = self.difficulty.write();
|
||||||
*difficulty.deref_mut() = *difficulty.deref() + header.difficulty;
|
*difficulty = *difficulty + header.difficulty;
|
||||||
}
|
}
|
||||||
mem::replace(self.last_hash.write().deref_mut(), h.clone());
|
mem::replace(&mut *self.last_hash.write(), h.clone());
|
||||||
self.blocks.write().insert(h.clone(), b);
|
self.blocks.write().insert(h.clone(), b);
|
||||||
self.numbers.write().insert(number, h.clone());
|
self.numbers.write().insert(number, h.clone());
|
||||||
let mut parent_hash = header.parent_hash;
|
let mut parent_hash = header.parent_hash;
|
||||||
|
@ -246,16 +246,16 @@ mod tests {
|
|||||||
tap.unlock_account_permanently(addr, "".into()).unwrap();
|
tap.unlock_account_permanently(addr, "".into()).unwrap();
|
||||||
|
|
||||||
let spec = new_test_authority();
|
let spec = new_test_authority();
|
||||||
let engine = &spec.engine;
|
let engine = &*spec.engine;
|
||||||
let genesis_header = spec.genesis_header();
|
let genesis_header = spec.genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap();
|
let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||||
let b = b.close_and_lock();
|
let b = b.close_and_lock();
|
||||||
let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap();
|
let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap();
|
||||||
assert!(b.try_seal(engine.deref(), seal).is_ok());
|
assert!(b.try_seal(engine, seal).is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,18 +80,18 @@ mod tests {
|
|||||||
let addr = tap.insert_account("".sha3(), "").unwrap();
|
let addr = tap.insert_account("".sha3(), "").unwrap();
|
||||||
|
|
||||||
let spec = new_test_instant();
|
let spec = new_test_instant();
|
||||||
let engine = &spec.engine;
|
let engine = &*spec.engine;
|
||||||
let genesis_header = spec.genesis_header();
|
let genesis_header = spec.genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap();
|
let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, addr, (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||||
let b = b.close_and_lock();
|
let b = b.close_and_lock();
|
||||||
// Seal with empty AccountProvider.
|
// Seal with empty AccountProvider.
|
||||||
let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap();
|
let seal = engine.generate_seal(b.block(), Some(&tap)).unwrap();
|
||||||
assert!(b.try_seal(engine.deref(), seal).is_ok());
|
assert!(b.try_seal(engine, seal).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -350,14 +350,14 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn on_close_block() {
|
fn on_close_block() {
|
||||||
let spec = new_morden();
|
let spec = new_morden();
|
||||||
let engine = &spec.engine;
|
let engine = &*spec.engine;
|
||||||
let genesis_header = spec.genesis_header();
|
let genesis_header = spec.genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
let b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||||
let b = b.close();
|
let b = b.close();
|
||||||
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
||||||
}
|
}
|
||||||
@ -365,14 +365,14 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn on_close_block_with_uncle() {
|
fn on_close_block_with_uncle() {
|
||||||
let spec = new_morden();
|
let spec = new_morden();
|
||||||
let engine = &spec.engine;
|
let engine = &*spec.engine;
|
||||||
let genesis_header = spec.genesis_header();
|
let genesis_header = spec.genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
|
||||||
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
let last_hashes = Arc::new(vec![genesis_header.hash()]);
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let mut b = OpenBlock::new(engine.deref(), &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
let mut b = OpenBlock::new(engine, &vm_factory, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
|
||||||
let mut uncle = Header::new();
|
let mut uncle = Header::new();
|
||||||
let uncle_author: Address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into();
|
let uncle_author: Address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into();
|
||||||
uncle.author = uncle_author.clone();
|
uncle.author = uncle_author.clone();
|
||||||
|
@ -65,7 +65,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
|||||||
state.commit()
|
state.commit()
|
||||||
.expect(&format!("State test {} failed due to internal error.", name));
|
.expect(&format!("State test {} failed due to internal error.", name));
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let res = state.apply(&env, engine.deref(), &vm_factory, &transaction, false);
|
let res = state.apply(&env, &*engine, &vm_factory, &transaction, false);
|
||||||
|
|
||||||
if fail_unless(state.root() == &post_state_root) {
|
if fail_unless(state.root() == &post_state_root) {
|
||||||
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, state.root(), post_state_root);
|
println!("!!! {}: State mismatch (got: {}, expect: {}):", name, state.root(), post_state_root);
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#![cfg_attr(feature="dev", allow(match_bool))]
|
#![cfg_attr(feature="dev", allow(match_bool))]
|
||||||
// Keeps consistency (all lines with `.clone()`).
|
// Keeps consistency (all lines with `.clone()`).
|
||||||
#![cfg_attr(feature="dev", allow(clone_on_copy))]
|
#![cfg_attr(feature="dev", allow(clone_on_copy))]
|
||||||
|
// Complains on Box<E> when implementing From<Box<E>>
|
||||||
|
#![cfg_attr(feature="dev", allow(boxed_local))]
|
||||||
// TODO [todr] a lot of warnings to be fixed
|
// TODO [todr] a lot of warnings to be fixed
|
||||||
#![cfg_attr(feature="dev", allow(assign_op_pattern))]
|
#![cfg_attr(feature="dev", allow(assign_op_pattern))]
|
||||||
|
|
||||||
|
@ -1464,7 +1464,7 @@ mod test {
|
|||||||
let keypair = KeyPair::create().unwrap();
|
let keypair = KeyPair::create().unwrap();
|
||||||
let tx = new_unsigned_tx(U256::from(123)).sign(keypair.secret());
|
let tx = new_unsigned_tx(U256::from(123)).sign(keypair.secret());
|
||||||
let tx2 = {
|
let tx2 = {
|
||||||
let mut tx2 = tx.deref().clone();
|
let mut tx2 = (*tx).clone();
|
||||||
tx2.gas_price = U256::from(200);
|
tx2.gas_price = U256::from(200);
|
||||||
tx2.sign(keypair.secret())
|
tx2.sign(keypair.secret())
|
||||||
};
|
};
|
||||||
@ -1487,12 +1487,12 @@ mod test {
|
|||||||
let keypair = KeyPair::create().unwrap();
|
let keypair = KeyPair::create().unwrap();
|
||||||
let tx0 = new_unsigned_tx(U256::from(123)).sign(keypair.secret());
|
let tx0 = new_unsigned_tx(U256::from(123)).sign(keypair.secret());
|
||||||
let tx1 = {
|
let tx1 = {
|
||||||
let mut tx1 = tx0.deref().clone();
|
let mut tx1 = (*tx0).clone();
|
||||||
tx1.nonce = U256::from(124);
|
tx1.nonce = U256::from(124);
|
||||||
tx1.sign(keypair.secret())
|
tx1.sign(keypair.secret())
|
||||||
};
|
};
|
||||||
let tx2 = {
|
let tx2 = {
|
||||||
let mut tx2 = tx1.deref().clone();
|
let mut tx2 = (*tx1).clone();
|
||||||
tx2.gas_price = U256::from(200);
|
tx2.gas_price = U256::from(200);
|
||||||
tx2.sign(keypair.secret())
|
tx2.sign(keypair.secret())
|
||||||
};
|
};
|
||||||
|
@ -64,9 +64,9 @@ impl From<::std::io::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<TrieError>> for Error {
|
impl From<TrieError> for Error {
|
||||||
fn from(err: Box<TrieError>) -> Self {
|
fn from(err: TrieError) -> Self {
|
||||||
Error::Trie(*err)
|
Error::Trie(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,4 +74,10 @@ impl From<DecoderError> for Error {
|
|||||||
fn from(err: DecoderError) -> Self {
|
fn from(err: DecoderError) -> Self {
|
||||||
Error::Decoder(err)
|
Error::Decoder(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E> From<Box<E>> for Error where Error: From<E> {
|
||||||
|
fn from(err: Box<E>) -> Self {
|
||||||
|
Error::from(*err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -61,7 +61,7 @@ const PREFERRED_CHUNK_SIZE: usize = 4 * 1024 * 1024;
|
|||||||
const SNAPSHOT_BLOCKS: u64 = 30000;
|
const SNAPSHOT_BLOCKS: u64 = 30000;
|
||||||
|
|
||||||
/// A progress indicator for snapshots.
|
/// A progress indicator for snapshots.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Progress {
|
pub struct Progress {
|
||||||
accounts: AtomicUsize,
|
accounts: AtomicUsize,
|
||||||
blocks: AtomicUsize,
|
blocks: AtomicUsize,
|
||||||
@ -70,16 +70,6 @@ pub struct Progress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Progress {
|
impl Progress {
|
||||||
/// Create a new progress indicator.
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Progress {
|
|
||||||
accounts: AtomicUsize::new(0),
|
|
||||||
blocks: AtomicUsize::new(0),
|
|
||||||
size: AtomicUsize::new(0),
|
|
||||||
done: AtomicBool::new(false),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the number of accounts snapshotted thus far.
|
/// Get the number of accounts snapshotted thus far.
|
||||||
pub fn accounts(&self) -> usize { self.accounts.load(Ordering::Relaxed) }
|
pub fn accounts(&self) -> usize { self.accounts.load(Ordering::Relaxed) }
|
||||||
|
|
||||||
@ -510,12 +500,12 @@ fn rebuild_account_trie(db: &mut HashDB, account_chunk: &[&[u8]], out_chunk: &mu
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Proportion of blocks which we will verify PoW for.
|
/// Proportion of blocks which we will verify `PoW` for.
|
||||||
const POW_VERIFY_RATE: f32 = 0.02;
|
const POW_VERIFY_RATE: f32 = 0.02;
|
||||||
|
|
||||||
/// Rebuilds the blockchain from chunks.
|
/// Rebuilds the blockchain from chunks.
|
||||||
///
|
///
|
||||||
/// Does basic verification for all blocks, but PoW verification for some.
|
/// Does basic verification for all blocks, but `PoW` verification for some.
|
||||||
/// Blocks must be fed in-order.
|
/// Blocks must be fed in-order.
|
||||||
///
|
///
|
||||||
/// The first block in every chunk is disconnected from the last block in the
|
/// The first block in every chunk is disconnected from the last block in the
|
||||||
|
@ -101,7 +101,7 @@ impl Restoration {
|
|||||||
fn new(manifest: &ManifestData, pruning: Algorithm, path: &Path, gb: &[u8]) -> Result<Self, Error> {
|
fn new(manifest: &ManifestData, pruning: Algorithm, path: &Path, gb: &[u8]) -> Result<Self, Error> {
|
||||||
let cfg = DatabaseConfig::with_columns(::client::DB_NO_OF_COLUMNS);
|
let cfg = DatabaseConfig::with_columns(::client::DB_NO_OF_COLUMNS);
|
||||||
let raw_db = Arc::new(try!(Database::open(&cfg, &*path.to_string_lossy())
|
let raw_db = Arc::new(try!(Database::open(&cfg, &*path.to_string_lossy())
|
||||||
.map_err(|s| UtilError::SimpleString(s))));
|
.map_err(UtilError::SimpleString)));
|
||||||
|
|
||||||
let chain = BlockChain::new(Default::default(), gb, raw_db.clone());
|
let chain = BlockChain::new(Default::default(), gb, raw_db.clone());
|
||||||
let blocks = try!(BlockRebuilder::new(chain, manifest.block_number));
|
let blocks = try!(BlockRebuilder::new(chain, manifest.block_number));
|
||||||
@ -207,23 +207,17 @@ impl Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// create the snapshot dir if it doesn't exist.
|
// create the snapshot dir if it doesn't exist.
|
||||||
match fs::create_dir_all(service.snapshot_dir()) {
|
if let Err(e) = fs::create_dir_all(service.snapshot_dir()) {
|
||||||
Err(e) => {
|
if e.kind() != ErrorKind::AlreadyExists {
|
||||||
if e.kind() != ErrorKind::AlreadyExists {
|
return Err(e.into())
|
||||||
return Err(e.into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the temporary restoration dir if it does exist.
|
// delete the temporary restoration dir if it does exist.
|
||||||
match fs::remove_dir_all(service.restoration_dir()) {
|
if let Err(e) = fs::remove_dir_all(service.restoration_dir()) {
|
||||||
Err(e) => {
|
if e.kind() != ErrorKind::NotFound {
|
||||||
if e.kind() != ErrorKind::NotFound {
|
return Err(e.into())
|
||||||
return Err(e.into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(service)
|
Ok(service)
|
||||||
@ -434,4 +428,4 @@ impl SnapshotService for Service {
|
|||||||
self.io_channel.send(ClientIoMessage::FeedBlockChunk(hash, chunk))
|
self.io_channel.send(ClientIoMessage::FeedBlockChunk(hash, chunk))
|
||||||
.expect("snapshot service and io service are kept alive by client service; qed");
|
.expect("snapshot service and io service are kept alive by client service; qed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ fn chunk_and_restore(amount: u64) {
|
|||||||
|
|
||||||
// snapshot it.
|
// snapshot it.
|
||||||
let writer = Mutex::new(PackedWriter::new(&snapshot_path).unwrap());
|
let writer = Mutex::new(PackedWriter::new(&snapshot_path).unwrap());
|
||||||
let block_hashes = chunk_blocks(&bc, (amount, best_hash), &writer, &Progress::new()).unwrap();
|
let block_hashes = chunk_blocks(&bc, (amount, best_hash), &writer, &Progress::default()).unwrap();
|
||||||
writer.into_inner().finish(::snapshot::ManifestData {
|
writer.into_inner().finish(::snapshot::ManifestData {
|
||||||
state_hashes: Vec::new(),
|
state_hashes: Vec::new(),
|
||||||
block_hashes: block_hashes,
|
block_hashes: block_hashes,
|
||||||
@ -88,4 +88,4 @@ fn chunk_and_restore(amount: u64) {
|
|||||||
fn chunk_and_restore_500() { chunk_and_restore(500) }
|
fn chunk_and_restore_500() { chunk_and_restore(500) }
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chunk_and_restore_40k() { chunk_and_restore(40000) }
|
fn chunk_and_restore_40k() { chunk_and_restore(40000) }
|
||||||
|
@ -116,7 +116,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) {
|
|||||||
pub fn compare_dbs(one: &HashDB, two: &HashDB) {
|
pub fn compare_dbs(one: &HashDB, two: &HashDB) {
|
||||||
let keys = one.keys();
|
let keys = one.keys();
|
||||||
|
|
||||||
for (key, _) in keys {
|
for key in keys.keys() {
|
||||||
assert_eq!(one.get(&key).unwrap(), two.get(&key).unwrap());
|
assert_eq!(one.get(&key).unwrap(), two.get(&key).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ fn snap_and_restore() {
|
|||||||
let state_root = producer.state_root();
|
let state_root = producer.state_root();
|
||||||
let writer = Mutex::new(PackedWriter::new(&snap_file).unwrap());
|
let writer = Mutex::new(PackedWriter::new(&snap_file).unwrap());
|
||||||
|
|
||||||
let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::new()).unwrap();
|
let state_hashes = chunk_state(&old_db, &state_root, &writer, &Progress::default()).unwrap();
|
||||||
|
|
||||||
writer.into_inner().finish(::snapshot::ManifestData {
|
writer.into_inner().finish(::snapshot::ManifestData {
|
||||||
state_hashes: state_hashes,
|
state_hashes: state_hashes,
|
||||||
@ -79,4 +79,4 @@ fn snap_and_restore() {
|
|||||||
let new_db = journaldb::new(db, Algorithm::Archive, ::client::DB_COL_STATE);
|
let new_db = journaldb::new(db, Algorithm::Archive, ::client::DB_COL_STATE);
|
||||||
|
|
||||||
compare_dbs(&old_db, new_db.as_hashdb());
|
compare_dbs(&old_db, new_db.as_hashdb());
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,7 @@ impl State {
|
|||||||
let have_key = self.cache.borrow().contains_key(a);
|
let have_key = self.cache.borrow().contains_key(a);
|
||||||
if !have_key {
|
if !have_key {
|
||||||
let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
|
let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
|
||||||
let maybe_acc = match db.get(&a) {
|
let maybe_acc = match db.get(a) {
|
||||||
Ok(acc) => acc.map(Account::from_rlp),
|
Ok(acc) => acc.map(Account::from_rlp),
|
||||||
Err(e) => panic!("Potential DB corruption encountered: {}", e),
|
Err(e) => panic!("Potential DB corruption encountered: {}", e),
|
||||||
};
|
};
|
||||||
@ -375,7 +375,7 @@ impl State {
|
|||||||
let contains_key = self.cache.borrow().contains_key(a);
|
let contains_key = self.cache.borrow().contains_key(a);
|
||||||
if !contains_key {
|
if !contains_key {
|
||||||
let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
|
let db = self.trie_factory.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
|
||||||
let maybe_acc = match db.get(&a) {
|
let maybe_acc = match db.get(a) {
|
||||||
Ok(acc) => acc.map(Account::from_rlp),
|
Ok(acc) => acc.map(Account::from_rlp),
|
||||||
Err(e) => panic!("Potential DB corruption encountered: {}", e),
|
Err(e) => panic!("Potential DB corruption encountered: {}", e),
|
||||||
};
|
};
|
||||||
@ -630,7 +630,7 @@ fn should_trace_call_transaction_to_builtin() {
|
|||||||
|
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_limit = 1_000_000.into();
|
info.gas_limit = 1_000_000.into();
|
||||||
let engine = Spec::new_test().engine;
|
let engine = &*Spec::new_test().engine;
|
||||||
|
|
||||||
let t = Transaction {
|
let t = Transaction {
|
||||||
nonce: 0.into(),
|
nonce: 0.into(),
|
||||||
@ -642,7 +642,7 @@ fn should_trace_call_transaction_to_builtin() {
|
|||||||
}.sign(&"".sha3());
|
}.sign(&"".sha3());
|
||||||
|
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap();
|
let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -673,7 +673,7 @@ fn should_not_trace_subcall_transaction_to_builtin() {
|
|||||||
|
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_limit = 1_000_000.into();
|
info.gas_limit = 1_000_000.into();
|
||||||
let engine = Spec::new_test().engine;
|
let engine = &*Spec::new_test().engine;
|
||||||
|
|
||||||
let t = Transaction {
|
let t = Transaction {
|
||||||
nonce: 0.into(),
|
nonce: 0.into(),
|
||||||
@ -686,7 +686,7 @@ fn should_not_trace_subcall_transaction_to_builtin() {
|
|||||||
|
|
||||||
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060006001610be0f1").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060006001610be0f1").unwrap());
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap();
|
let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -717,7 +717,7 @@ fn should_not_trace_callcode() {
|
|||||||
|
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_limit = 1_000_000.into();
|
info.gas_limit = 1_000_000.into();
|
||||||
let engine = Spec::new_test().engine;
|
let engine = &*Spec::new_test().engine;
|
||||||
|
|
||||||
let t = Transaction {
|
let t = Transaction {
|
||||||
nonce: 0.into(),
|
nonce: 0.into(),
|
||||||
@ -731,7 +731,7 @@ fn should_not_trace_callcode() {
|
|||||||
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b611000f2").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b611000f2").unwrap());
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap();
|
let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -778,7 +778,7 @@ fn should_not_trace_delegatecall() {
|
|||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
info.gas_limit = 1_000_000.into();
|
info.gas_limit = 1_000_000.into();
|
||||||
info.number = 0x789b0;
|
info.number = 0x789b0;
|
||||||
let engine = Spec::new_test().engine;
|
let engine = &*Spec::new_test().engine;
|
||||||
|
|
||||||
println!("schedule.have_delegate_call: {:?}", engine.schedule(&info).have_delegate_call);
|
println!("schedule.have_delegate_call: {:?}", engine.schedule(&info).have_delegate_call);
|
||||||
|
|
||||||
@ -794,7 +794,7 @@ fn should_not_trace_delegatecall() {
|
|||||||
state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap());
|
state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap());
|
||||||
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap());
|
||||||
let vm_factory = Default::default();
|
let vm_factory = Default::default();
|
||||||
let result = state.apply(&info, engine.deref(), &vm_factory, &t, true).unwrap();
|
let result = state.apply(&info, engine, &vm_factory, &t, true).unwrap();
|
||||||
|
|
||||||
let expected_trace = vec![FlatTrace {
|
let expected_trace = vec![FlatTrace {
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
@ -1489,4 +1489,4 @@ fn create_empty() {
|
|||||||
assert_eq!(state.root().hex(), "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
|
assert_eq!(state.root().hex(), "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ pub fn generate_dummy_client_with_spec_and_data<F>(get_test_spec: F, block_numbe
|
|||||||
|
|
||||||
let test_spec = get_test_spec();
|
let test_spec = get_test_spec();
|
||||||
let client = Client::new(ClientConfig::default(), &test_spec, dir.as_path(), Arc::new(Miner::with_spec(&test_spec)), IoChannel::disconnected()).unwrap();
|
let client = Client::new(ClientConfig::default(), &test_spec, dir.as_path(), Arc::new(Miner::with_spec(&test_spec)), IoChannel::disconnected()).unwrap();
|
||||||
let test_engine = &test_spec.engine;
|
let test_engine = &*test_spec.engine;
|
||||||
|
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.take();
|
let mut db = db_result.take();
|
||||||
@ -155,7 +155,7 @@ pub fn generate_dummy_client_with_spec_and_data<F>(get_test_spec: F, block_numbe
|
|||||||
|
|
||||||
// forge block.
|
// forge block.
|
||||||
let mut b = OpenBlock::new(
|
let mut b = OpenBlock::new(
|
||||||
test_engine.deref(),
|
test_engine,
|
||||||
&vm_factory,
|
&vm_factory,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
false,
|
false,
|
||||||
@ -183,7 +183,7 @@ pub fn generate_dummy_client_with_spec_and_data<F>(get_test_spec: F, block_numbe
|
|||||||
n += 1;
|
n += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let b = b.close_and_lock().seal(test_engine.deref(), vec![]).unwrap();
|
let b = b.close_and_lock().seal(test_engine, vec![]).unwrap();
|
||||||
|
|
||||||
if let Err(e) = client.import_block(b.rlp_bytes()) {
|
if let Err(e) = client.import_block(b.rlp_bytes()) {
|
||||||
panic!("error importing block which is valid by definition: {:?}", e);
|
panic!("error importing block which is valid by definition: {:?}", e);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Trace database.
|
//! Trace database.
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::Deref;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use bloomchain::{Number, Config as BloomConfig};
|
use bloomchain::{Number, Config as BloomConfig};
|
||||||
@ -273,8 +273,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
let mut traces = self.traces.write();
|
let mut traces = self.traces.write();
|
||||||
// it's important to use overwrite here,
|
// it's important to use overwrite here,
|
||||||
// cause this value might be queried by hash later
|
// cause this value might be queried by hash later
|
||||||
batch.write_with_cache(DB_COL_TRACE, traces.deref_mut(), request.block_hash, request.traces, CacheUpdatePolicy::Overwrite);
|
batch.write_with_cache(DB_COL_TRACE, &mut *traces, request.block_hash, request.traces, CacheUpdatePolicy::Overwrite);
|
||||||
|
|
||||||
// note_used must be called after locking traces to avoid cache/traces deadlock on garbage collection
|
// note_used must be called after locking traces to avoid cache/traces deadlock on garbage collection
|
||||||
self.note_used(CacheID::Trace(request.block_hash.clone()));
|
self.note_used(CacheID::Trace(request.block_hash.clone()));
|
||||||
}
|
}
|
||||||
@ -303,8 +302,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
|||||||
|
|
||||||
let blooms_keys: Vec<_> = blooms_to_insert.keys().cloned().collect();
|
let blooms_keys: Vec<_> = blooms_to_insert.keys().cloned().collect();
|
||||||
let mut blooms = self.blooms.write();
|
let mut blooms = self.blooms.write();
|
||||||
batch.extend_with_cache(DB_COL_TRACE, blooms.deref_mut(), blooms_to_insert, CacheUpdatePolicy::Remove);
|
batch.extend_with_cache(DB_COL_TRACE, &mut *blooms, blooms_to_insert, CacheUpdatePolicy::Remove);
|
||||||
|
|
||||||
// note_used must be called after locking blooms to avoid cache/traces deadlock on garbage collection
|
// note_used must be called after locking blooms to avoid cache/traces deadlock on garbage collection
|
||||||
for key in blooms_keys.into_iter() {
|
for key in blooms_keys.into_iter() {
|
||||||
self.note_used(CacheID::Bloom(key));
|
self.note_used(CacheID::Bloom(key));
|
||||||
|
@ -344,7 +344,7 @@ mod tests {
|
|||||||
// Test against morden
|
// Test against morden
|
||||||
let mut good = Header::new();
|
let mut good = Header::new();
|
||||||
let spec = Spec::new_test();
|
let spec = Spec::new_test();
|
||||||
let engine = &spec.engine;
|
let engine = &*spec.engine;
|
||||||
|
|
||||||
let min_gas_limit = engine.params().min_gas_limit;
|
let min_gas_limit = engine.params().min_gas_limit;
|
||||||
good.gas_limit = min_gas_limit;
|
good.gas_limit = min_gas_limit;
|
||||||
@ -425,69 +425,69 @@ mod tests {
|
|||||||
bc.insert(create_test_block(&parent7));
|
bc.insert(create_test_block(&parent7));
|
||||||
bc.insert(create_test_block(&parent8));
|
bc.insert(create_test_block(&parent8));
|
||||||
|
|
||||||
check_ok(basic_test(&create_test_block(&good), engine.deref()));
|
check_ok(basic_test(&create_test_block(&good), engine));
|
||||||
|
|
||||||
let mut header = good.clone();
|
let mut header = good.clone();
|
||||||
header.transactions_root = good_transactions_root.clone();
|
header.transactions_root = good_transactions_root.clone();
|
||||||
header.uncles_hash = good_uncles_hash.clone();
|
header.uncles_hash = good_uncles_hash.clone();
|
||||||
check_ok(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref()));
|
check_ok(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine));
|
||||||
|
|
||||||
header.gas_limit = min_gas_limit - From::from(1);
|
header.gas_limit = min_gas_limit - From::from(1);
|
||||||
check_fail(basic_test(&create_test_block(&header), engine.deref()),
|
check_fail(basic_test(&create_test_block(&header), engine),
|
||||||
InvalidGasLimit(OutOfBounds { min: Some(min_gas_limit), max: None, found: header.gas_limit }));
|
InvalidGasLimit(OutOfBounds { min: Some(min_gas_limit), max: None, found: header.gas_limit }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.number = BlockNumber::max_value();
|
header.number = BlockNumber::max_value();
|
||||||
check_fail(basic_test(&create_test_block(&header), engine.deref()),
|
check_fail(basic_test(&create_test_block(&header), engine),
|
||||||
RidiculousNumber(OutOfBounds { max: Some(BlockNumber::max_value()), min: None, found: header.number }));
|
RidiculousNumber(OutOfBounds { max: Some(BlockNumber::max_value()), min: None, found: header.number }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.gas_used = header.gas_limit + From::from(1);
|
header.gas_used = header.gas_limit + From::from(1);
|
||||||
check_fail(basic_test(&create_test_block(&header), engine.deref()),
|
check_fail(basic_test(&create_test_block(&header), engine),
|
||||||
TooMuchGasUsed(OutOfBounds { max: Some(header.gas_limit), min: None, found: header.gas_used }));
|
TooMuchGasUsed(OutOfBounds { max: Some(header.gas_limit), min: None, found: header.gas_used }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.extra_data.resize(engine.maximum_extra_data_size() + 1, 0u8);
|
header.extra_data.resize(engine.maximum_extra_data_size() + 1, 0u8);
|
||||||
check_fail(basic_test(&create_test_block(&header), engine.deref()),
|
check_fail(basic_test(&create_test_block(&header), engine),
|
||||||
ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data.len() }));
|
ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data.len() }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.extra_data.resize(engine.maximum_extra_data_size() + 1, 0u8);
|
header.extra_data.resize(engine.maximum_extra_data_size() + 1, 0u8);
|
||||||
check_fail(basic_test(&create_test_block(&header), engine.deref()),
|
check_fail(basic_test(&create_test_block(&header), engine),
|
||||||
ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data.len() }));
|
ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data.len() }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.uncles_hash = good_uncles_hash.clone();
|
header.uncles_hash = good_uncles_hash.clone();
|
||||||
check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref()),
|
check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine),
|
||||||
InvalidTransactionsRoot(Mismatch { expected: good_transactions_root.clone(), found: header.transactions_root }));
|
InvalidTransactionsRoot(Mismatch { expected: good_transactions_root.clone(), found: header.transactions_root }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.transactions_root = good_transactions_root.clone();
|
header.transactions_root = good_transactions_root.clone();
|
||||||
check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref()),
|
check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine),
|
||||||
InvalidUnclesHash(Mismatch { expected: good_uncles_hash.clone(), found: header.uncles_hash }));
|
InvalidUnclesHash(Mismatch { expected: good_uncles_hash.clone(), found: header.uncles_hash }));
|
||||||
|
|
||||||
check_ok(family_test(&create_test_block(&good), engine.deref(), &bc));
|
check_ok(family_test(&create_test_block(&good), engine, &bc));
|
||||||
check_ok(family_test(&create_test_block_with_data(&good, &good_transactions, &good_uncles), engine.deref(), &bc));
|
check_ok(family_test(&create_test_block_with_data(&good, &good_transactions, &good_uncles), engine, &bc));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.parent_hash = H256::random();
|
header.parent_hash = H256::random();
|
||||||
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref(), &bc),
|
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc),
|
||||||
UnknownParent(header.parent_hash));
|
UnknownParent(header.parent_hash));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.timestamp = 10;
|
header.timestamp = 10;
|
||||||
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref(), &bc),
|
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc),
|
||||||
InvalidTimestamp(OutOfBounds { max: None, min: Some(parent.timestamp + 1), found: header.timestamp }));
|
InvalidTimestamp(OutOfBounds { max: None, min: Some(parent.timestamp + 1), found: header.timestamp }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
header.number = 9;
|
header.number = 9;
|
||||||
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine.deref(), &bc),
|
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc),
|
||||||
InvalidNumber(Mismatch { expected: parent.number + 1, found: header.number }));
|
InvalidNumber(Mismatch { expected: parent.number + 1, found: header.number }));
|
||||||
|
|
||||||
header = good.clone();
|
header = good.clone();
|
||||||
let mut bad_uncles = good_uncles.clone();
|
let mut bad_uncles = good_uncles.clone();
|
||||||
bad_uncles.push(good_uncle1.clone());
|
bad_uncles.push(good_uncle1.clone());
|
||||||
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &bad_uncles), engine.deref(), &bc),
|
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &bad_uncles), engine, &bc),
|
||||||
TooManyUncles(OutOfBounds { max: Some(engine.maximum_uncle_count()), min: None, found: bad_uncles.len() }));
|
TooManyUncles(OutOfBounds { max: Some(engine.maximum_uncle_count()), min: None, found: bad_uncles.len() }));
|
||||||
|
|
||||||
// TODO: some additional uncle checks
|
// TODO: some additional uncle checks
|
||||||
|
@ -136,7 +136,7 @@ pub fn verify_public(public: &Public, signature: &Signature, message: &Message)
|
|||||||
|
|
||||||
let pdata: [u8; 65] = {
|
let pdata: [u8; 65] = {
|
||||||
let mut temp = [4u8; 65];
|
let mut temp = [4u8; 65];
|
||||||
temp[1..65].copy_from_slice(public.deref());
|
temp[1..65].copy_from_slice(&**public);
|
||||||
temp
|
temp
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::ops::{Deref, DerefMut};
|
|
||||||
use ethkey::{KeyPair, sign, Address, Secret, Signature, Message};
|
use ethkey::{KeyPair, sign, Address, Secret, Signature, Message};
|
||||||
use {json, Error, crypto};
|
use {json, Error, crypto};
|
||||||
use crypto::Keccak256;
|
use crypto::Keccak256;
|
||||||
@ -87,7 +86,7 @@ impl Crypto {
|
|||||||
let mut ciphertext = [0u8; 32];
|
let mut ciphertext = [0u8; 32];
|
||||||
|
|
||||||
// aes-128-ctr with initial vector of iv
|
// aes-128-ctr with initial vector of iv
|
||||||
crypto::aes::encrypt(&derived_left_bits, &iv, secret.deref(), &mut ciphertext);
|
crypto::aes::encrypt(&derived_left_bits, &iv, &**secret, &mut ciphertext);
|
||||||
|
|
||||||
// KECCAK(DK[16..31] ++ <ciphertext>), where DK[16..31] - derived_right_bits
|
// KECCAK(DK[16..31] ++ <ciphertext>), where DK[16..31] - derived_right_bits
|
||||||
let mac = crypto::derive_mac(&derived_right_bits, &ciphertext).keccak256();
|
let mac = crypto::derive_mac(&derived_right_bits, &ciphertext).keccak256();
|
||||||
@ -123,7 +122,7 @@ impl Crypto {
|
|||||||
|
|
||||||
match self.cipher {
|
match self.cipher {
|
||||||
Cipher::Aes128Ctr(ref params) => {
|
Cipher::Aes128Ctr(ref params) => {
|
||||||
crypto::aes::decrypt(&derived_left_bits, ¶ms.iv, &self.ciphertext, secret.deref_mut())
|
crypto::aes::decrypt(&derived_left_bits, ¶ms.iv, &self.ciphertext, &mut *secret)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
|||||||
} else if args.cmd_import {
|
} else if args.cmd_import {
|
||||||
let src = try!(key_dir(&args.flag_src));
|
let src = try!(key_dir(&args.flag_src));
|
||||||
let dst = try!(key_dir(&args.flag_dir));
|
let dst = try!(key_dir(&args.flag_dir));
|
||||||
let accounts = try!(import_accounts(src.deref(), dst.deref()));
|
let accounts = try!(import_accounts(*src, *dst));
|
||||||
Ok(format_accounts(&accounts))
|
Ok(format_accounts(&accounts))
|
||||||
} else if args.cmd_import_wallet {
|
} else if args.cmd_import_wallet {
|
||||||
let wallet = try!(PresaleWallet::open(&args.arg_path));
|
let wallet = try!(PresaleWallet::open(&args.arg_path));
|
||||||
|
@ -21,7 +21,6 @@ use self::ansi_term::Style;
|
|||||||
use std::sync::{Arc};
|
use std::sync::{Arc};
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
||||||
use std::time::{Instant, Duration};
|
use std::time::{Instant, Duration};
|
||||||
use std::ops::{Deref, DerefMut};
|
|
||||||
use isatty::{stdout_isatty};
|
use isatty::{stdout_isatty};
|
||||||
use ethsync::{SyncProvider, ManageNetwork};
|
use ethsync::{SyncProvider, ManageNetwork};
|
||||||
use util::{Uint, RwLock, Mutex, H256, Colour};
|
use util::{Uint, RwLock, Mutex, H256, Colour};
|
||||||
@ -112,7 +111,7 @@ impl Informant {
|
|||||||
paint(White.bold(), format!("{:>8}", format!("#{}", chain_info.best_block_number))),
|
paint(White.bold(), format!("{:>8}", format!("#{}", chain_info.best_block_number))),
|
||||||
paint(White.bold(), format!("{}", chain_info.best_block_hash)),
|
paint(White.bold(), format!("{}", chain_info.best_block_hash)),
|
||||||
{
|
{
|
||||||
let last_report = match write_report.deref() { &Some(ref last_report) => last_report.clone(), _ => ClientReport::default() };
|
let last_report = match *write_report { Some(ref last_report) => last_report.clone(), _ => ClientReport::default() };
|
||||||
format!("{} blk/s {} tx/s {} Mgas/s",
|
format!("{} blk/s {} tx/s {} Mgas/s",
|
||||||
paint(Yellow.bold(), format!("{:4}", ((report.blocks_imported - last_report.blocks_imported) * 1000) as u64 / elapsed.as_milliseconds())),
|
paint(Yellow.bold(), format!("{:4}", ((report.blocks_imported - last_report.blocks_imported) * 1000) as u64 / elapsed.as_milliseconds())),
|
||||||
paint(Yellow.bold(), format!("{:4}", ((report.transactions_applied - last_report.transactions_applied) * 1000) as u64 / elapsed.as_milliseconds())),
|
paint(Yellow.bold(), format!("{:4}", ((report.transactions_applied - last_report.transactions_applied) * 1000) as u64 / elapsed.as_milliseconds())),
|
||||||
@ -147,9 +146,9 @@ impl Informant {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
*self.chain_info.write().deref_mut() = Some(chain_info);
|
*self.chain_info.write() = Some(chain_info);
|
||||||
*self.cache_info.write().deref_mut() = Some(cache_info);
|
*self.cache_info.write() = Some(cache_info);
|
||||||
*write_report.deref_mut() = Some(report);
|
*write_report = Some(report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ impl SnapshotCommand {
|
|||||||
warn!("Snapshot restoration is experimental and the format may be subject to change.");
|
warn!("Snapshot restoration is experimental and the format may be subject to change.");
|
||||||
|
|
||||||
let snapshot = service.snapshot_service();
|
let snapshot = service.snapshot_service();
|
||||||
let reader = PackedReader::new(&Path::new(&file))
|
let reader = PackedReader::new(Path::new(&file))
|
||||||
.map_err(|e| format!("Couldn't open snapshot file: {}", e))
|
.map_err(|e| format!("Couldn't open snapshot file: {}", e))
|
||||||
.and_then(|x| x.ok_or("Snapshot file has invalid format.".into()));
|
.and_then(|x| x.ok_or("Snapshot file has invalid format.".into()));
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ impl SnapshotCommand {
|
|||||||
pub fn take_snapshot(self) -> Result<(), String> {
|
pub fn take_snapshot(self) -> Result<(), String> {
|
||||||
let file_path = try!(self.file_path.clone().ok_or("No file path provided.".to_owned()));
|
let file_path = try!(self.file_path.clone().ok_or("No file path provided.".to_owned()));
|
||||||
let file_path: PathBuf = file_path.into();
|
let file_path: PathBuf = file_path.into();
|
||||||
let block_at = self.block_at.clone();
|
let block_at = self.block_at;
|
||||||
let (service, _panic_handler) = try!(self.start_service());
|
let (service, _panic_handler) = try!(self.start_service());
|
||||||
|
|
||||||
warn!("Snapshots are currently experimental. File formats may be subject to change.");
|
warn!("Snapshots are currently experimental. File formats may be subject to change.");
|
||||||
@ -180,7 +180,7 @@ impl SnapshotCommand {
|
|||||||
let writer = try!(PackedWriter::new(&file_path)
|
let writer = try!(PackedWriter::new(&file_path)
|
||||||
.map_err(|e| format!("Failed to open snapshot writer: {}", e)));
|
.map_err(|e| format!("Failed to open snapshot writer: {}", e)));
|
||||||
|
|
||||||
let progress = Arc::new(Progress::new());
|
let progress = Arc::new(Progress::default());
|
||||||
let p = progress.clone();
|
let p = progress.clone();
|
||||||
let informant_handle = ::std::thread::spawn(move || {
|
let informant_handle = ::std::thread::spawn(move || {
|
||||||
::std::thread::sleep(Duration::from_secs(5));
|
::std::thread::sleep(Duration::from_secs(5));
|
||||||
@ -221,4 +221,4 @@ pub fn execute(cmd: SnapshotCommand) -> Result<String, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ use std::process::{Command, Stdio};
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Instant, Duration};
|
use std::time::{Instant, Duration};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::ops::Deref;
|
|
||||||
use ethsync::{SyncProvider, SyncState};
|
use ethsync::{SyncProvider, SyncState};
|
||||||
use ethcore::miner::{MinerService, ExternalMinerService};
|
use ethcore::miner::{MinerService, ExternalMinerService};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
@ -324,7 +323,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
.and_then(|(address, block_number,)| {
|
.and_then(|(address, block_number,)| {
|
||||||
let address: Address = RpcH160::into(address);
|
let address: Address = RpcH160::into(address);
|
||||||
match block_number {
|
match block_number {
|
||||||
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).balance(take_weak!(self.client).deref(), &address))),
|
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).balance(&*take_weak!(self.client), &address))),
|
||||||
id => match take_weak!(self.client).balance(&address, id.into()) {
|
id => match take_weak!(self.client).balance(&address, id.into()) {
|
||||||
Some(balance) => to_value(&RpcU256::from(balance)),
|
Some(balance) => to_value(&RpcU256::from(balance)),
|
||||||
None => Err(errors::state_pruned()),
|
None => Err(errors::state_pruned()),
|
||||||
@ -356,7 +355,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
.and_then(|(address, block_number,)| {
|
.and_then(|(address, block_number,)| {
|
||||||
let address: Address = RpcH160::into(address);
|
let address: Address = RpcH160::into(address);
|
||||||
match block_number {
|
match block_number {
|
||||||
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).nonce(take_weak!(self.client).deref(), &address))),
|
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).nonce(&*take_weak!(self.client), &address))),
|
||||||
id => match take_weak!(self.client).nonce(&address, id.into()) {
|
id => match take_weak!(self.client).nonce(&address, id.into()) {
|
||||||
Some(nonce) => to_value(&RpcU256::from(nonce)),
|
Some(nonce) => to_value(&RpcU256::from(nonce)),
|
||||||
None => Err(errors::state_pruned()),
|
None => Err(errors::state_pruned()),
|
||||||
@ -409,7 +408,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
.and_then(|(address, block_number,)| {
|
.and_then(|(address, block_number,)| {
|
||||||
let address: Address = RpcH160::into(address);
|
let address: Address = RpcH160::into(address);
|
||||||
match block_number {
|
match block_number {
|
||||||
BlockNumber::Pending => to_value(&take_weak!(self.miner).code(take_weak!(self.client).deref(), &address).map_or_else(Bytes::default, Bytes::new)),
|
BlockNumber::Pending => to_value(&take_weak!(self.miner).code(&*take_weak!(self.client), &address).map_or_else(Bytes::default, Bytes::new)),
|
||||||
_ => match take_weak!(self.client).code(&address, block_number.into()) {
|
_ => match take_weak!(self.client).code(&address, block_number.into()) {
|
||||||
Some(code) => to_value(&code.map_or_else(Bytes::default, Bytes::new)),
|
Some(code) => to_value(&code.map_or_else(Bytes::default, Bytes::new)),
|
||||||
None => Err(errors::state_pruned()),
|
None => Err(errors::state_pruned()),
|
||||||
@ -507,7 +506,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
.collect::<Vec<Log>>();
|
.collect::<Vec<Log>>();
|
||||||
|
|
||||||
if include_pending {
|
if include_pending {
|
||||||
let pending = pending_logs(take_weak!(self.miner).deref(), &filter);
|
let pending = pending_logs(&*take_weak!(self.miner), &filter);
|
||||||
logs.extend(pending);
|
logs.extend(pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,7 +540,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
warn!(target: "miner", "Cannot give work package - no author is configured. Use --author to configure!");
|
warn!(target: "miner", "Cannot give work package - no author is configured. Use --author to configure!");
|
||||||
return Err(errors::no_author())
|
return Err(errors::no_author())
|
||||||
}
|
}
|
||||||
miner.map_sealing_work(client.deref(), |b| {
|
miner.map_sealing_work(&*client, |b| {
|
||||||
let pow_hash = b.hash();
|
let pow_hash = b.hash();
|
||||||
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
|
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
|
||||||
let seed_hash = self.seed_compute.lock().get_seedhash(b.block().header().number());
|
let seed_hash = self.seed_compute.lock().get_seedhash(b.block().header().number());
|
||||||
@ -565,7 +564,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
let miner = take_weak!(self.miner);
|
let miner = take_weak!(self.miner);
|
||||||
let client = take_weak!(self.client);
|
let client = take_weak!(self.client);
|
||||||
let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()];
|
let seal = vec![encode(&mix_hash).to_vec(), encode(&nonce).to_vec()];
|
||||||
let r = miner.submit_seal(client.deref(), pow_hash, seal);
|
let r = miner.submit_seal(&*client, pow_hash, seal);
|
||||||
to_value(&r.is_ok())
|
to_value(&r.is_ok())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -597,7 +596,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = try!(self.sign_call(request));
|
let signed = try!(self.sign_call(request));
|
||||||
let r = match block_number {
|
let r = match block_number {
|
||||||
BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()),
|
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
||||||
block_number => take_weak!(self.client).call(&signed, block_number.into(), Default::default()),
|
block_number => take_weak!(self.client).call(&signed, block_number.into(), Default::default()),
|
||||||
};
|
};
|
||||||
to_value(&r.map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![])))
|
to_value(&r.map(|e| Bytes(e.output)).unwrap_or(Bytes::new(vec![])))
|
||||||
@ -611,7 +610,7 @@ impl<C, S: ?Sized, M, EM> Eth for EthClient<C, S, M, EM> where
|
|||||||
let request = CallRequest::into(request);
|
let request = CallRequest::into(request);
|
||||||
let signed = try!(self.sign_call(request));
|
let signed = try!(self.sign_call(request));
|
||||||
let r = match block_number {
|
let r = match block_number {
|
||||||
BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()),
|
BlockNumber::Pending => take_weak!(self.miner).call(&*take_weak!(self.client), &signed, Default::default()),
|
||||||
block => take_weak!(self.client).call(&signed, block.into(), Default::default()),
|
block => take_weak!(self.client).call(&signed, block.into(), Default::default()),
|
||||||
};
|
};
|
||||||
to_value(&RpcU256::from(r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0))))
|
to_value(&RpcU256::from(r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0))))
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
//! Eth Filter RPC implementation
|
//! Eth Filter RPC implementation
|
||||||
|
|
||||||
use std::ops::Deref;
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
@ -160,7 +159,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
|||||||
|
|
||||||
// additionally retrieve pending logs
|
// additionally retrieve pending logs
|
||||||
if include_pending {
|
if include_pending {
|
||||||
let pending_logs = pending_logs(take_weak!(self.miner).deref(), &filter);
|
let pending_logs = pending_logs(&*take_weak!(self.miner), &filter);
|
||||||
|
|
||||||
// remove logs about which client was already notified about
|
// remove logs about which client was already notified about
|
||||||
let new_pending_logs: Vec<_> = pending_logs.iter()
|
let new_pending_logs: Vec<_> = pending_logs.iter()
|
||||||
@ -201,7 +200,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
|||||||
.collect::<Vec<Log>>();
|
.collect::<Vec<Log>>();
|
||||||
|
|
||||||
if include_pending {
|
if include_pending {
|
||||||
logs.extend(pending_logs(take_weak!(self.miner).deref(), &filter));
|
logs.extend(pending_logs(&*take_weak!(self.miner), &filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
to_value(&logs)
|
to_value(&logs)
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
use util::{RotatingLogger};
|
use util::{RotatingLogger};
|
||||||
use util::misc::version_data;
|
use util::misc::version_data;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::ops::Deref;
|
|
||||||
use std::collections::{BTreeMap};
|
use std::collections::{BTreeMap};
|
||||||
use ethcore::client::{MiningBlockChainClient};
|
use ethcore::client::{MiningBlockChainClient};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
@ -95,7 +94,7 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
|
|||||||
try!(self.active());
|
try!(self.active());
|
||||||
try!(expect_no_params(params));
|
try!(expect_no_params(params));
|
||||||
let logs = self.logger.logs();
|
let logs = self.logger.logs();
|
||||||
to_value(&logs.deref().as_slice())
|
to_value(&logs.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dev_logs_levels(&self, params: Params) -> Result<Value, Error> {
|
fn dev_logs_levels(&self, params: Params) -> Result<Value, Error> {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::ops::*;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId,
|
use network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId,
|
||||||
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, NetworkError};
|
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, NetworkError};
|
||||||
@ -75,7 +74,7 @@ pub struct EthSync {
|
|||||||
impl EthSync {
|
impl EthSync {
|
||||||
/// Creates and register protocol with the network service
|
/// Creates and register protocol with the network service
|
||||||
pub fn new(config: SyncConfig, chain: Arc<BlockChainClient>, network_config: NetworkConfiguration) -> Result<Arc<EthSync>, NetworkError> {
|
pub fn new(config: SyncConfig, chain: Arc<BlockChainClient>, network_config: NetworkConfiguration) -> Result<Arc<EthSync>, NetworkError> {
|
||||||
let chain_sync = ChainSync::new(config, chain.deref());
|
let chain_sync = ChainSync::new(config, &*chain);
|
||||||
let service = try!(NetworkService::new(try!(network_config.into_basic())));
|
let service = try!(NetworkService::new(try!(network_config.into_basic())));
|
||||||
let sync = Arc::new(EthSync{
|
let sync = Arc::new(EthSync{
|
||||||
network: service,
|
network: service,
|
||||||
@ -108,20 +107,20 @@ impl NetworkProtocolHandler for SyncProtocolHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
|
fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]) {
|
||||||
ChainSync::dispatch_packet(&self.sync, &mut NetSyncIo::new(io, self.chain.deref()), *peer, packet_id, data);
|
ChainSync::dispatch_packet(&self.sync, &mut NetSyncIo::new(io, &*self.chain), *peer, packet_id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connected(&self, io: &NetworkContext, peer: &PeerId) {
|
fn connected(&self, io: &NetworkContext, peer: &PeerId) {
|
||||||
self.sync.write().on_peer_connected(&mut NetSyncIo::new(io, self.chain.deref()), *peer);
|
self.sync.write().on_peer_connected(&mut NetSyncIo::new(io, &*self.chain), *peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disconnected(&self, io: &NetworkContext, peer: &PeerId) {
|
fn disconnected(&self, io: &NetworkContext, peer: &PeerId) {
|
||||||
self.sync.write().on_peer_aborting(&mut NetSyncIo::new(io, self.chain.deref()), *peer);
|
self.sync.write().on_peer_aborting(&mut NetSyncIo::new(io, &*self.chain), *peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timeout(&self, io: &NetworkContext, _timer: TimerToken) {
|
fn timeout(&self, io: &NetworkContext, _timer: TimerToken) {
|
||||||
self.sync.write().maintain_peers(&mut NetSyncIo::new(io, self.chain.deref()));
|
self.sync.write().maintain_peers(&mut NetSyncIo::new(io, &*self.chain));
|
||||||
self.sync.write().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref()));
|
self.sync.write().maintain_sync(&mut NetSyncIo::new(io, &*self.chain));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +134,7 @@ impl ChainNotify for EthSync {
|
|||||||
_duration: u64)
|
_duration: u64)
|
||||||
{
|
{
|
||||||
self.network.with_context(ETH_PROTOCOL, |context| {
|
self.network.with_context(ETH_PROTOCOL, |context| {
|
||||||
let mut sync_io = NetSyncIo::new(context, self.handler.chain.deref());
|
let mut sync_io = NetSyncIo::new(context, &*self.handler.chain);
|
||||||
self.handler.sync.write().chain_new_blocks(
|
self.handler.sync.write().chain_new_blocks(
|
||||||
&mut sync_io,
|
&mut sync_io,
|
||||||
&imported,
|
&imported,
|
||||||
@ -204,7 +203,7 @@ impl ManageNetwork for EthSync {
|
|||||||
|
|
||||||
fn stop_network(&self) {
|
fn stop_network(&self) {
|
||||||
self.network.with_context(ETH_PROTOCOL, |context| {
|
self.network.with_context(ETH_PROTOCOL, |context| {
|
||||||
let mut sync_io = NetSyncIo::new(context, self.handler.chain.deref());
|
let mut sync_io = NetSyncIo::new(context, &*self.handler.chain);
|
||||||
self.handler.sync.write().abort(&mut sync_io);
|
self.handler.sync.write().abort(&mut sync_io);
|
||||||
});
|
});
|
||||||
self.stop();
|
self.stop();
|
||||||
|
@ -1760,7 +1760,7 @@ mod tests {
|
|||||||
let chain_info = client.chain_info();
|
let chain_info = client.chain_info();
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
let peers = sync.get_lagging_peers(&chain_info, &mut io);
|
let peers = sync.get_lagging_peers(&chain_info, &io);
|
||||||
let peer_count = sync.propagate_new_hashes(&chain_info, &mut io, &peers);
|
let peer_count = sync.propagate_new_hashes(&chain_info, &mut io, &peers);
|
||||||
|
|
||||||
// 1 message should be send
|
// 1 message should be send
|
||||||
@ -1779,7 +1779,7 @@ mod tests {
|
|||||||
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client);
|
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client);
|
||||||
let chain_info = client.chain_info();
|
let chain_info = client.chain_info();
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
let peers = sync.get_lagging_peers(&chain_info, &mut io);
|
let peers = sync.get_lagging_peers(&chain_info, &io);
|
||||||
let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[], &peers);
|
let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[], &peers);
|
||||||
|
|
||||||
// 1 message should be send
|
// 1 message should be send
|
||||||
@ -1799,7 +1799,7 @@ mod tests {
|
|||||||
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client);
|
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5), &client);
|
||||||
let chain_info = client.chain_info();
|
let chain_info = client.chain_info();
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
let peers = sync.get_lagging_peers(&chain_info, &mut io);
|
let peers = sync.get_lagging_peers(&chain_info, &io);
|
||||||
let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[hash.clone()], &peers);
|
let peer_count = sync.propagate_blocks(&chain_info, &mut io, &[hash.clone()], &peers);
|
||||||
|
|
||||||
// 1 message should be send
|
// 1 message should be send
|
||||||
@ -1906,7 +1906,7 @@ mod tests {
|
|||||||
let chain_info = client.chain_info();
|
let chain_info = client.chain_info();
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
let peers = sync.get_lagging_peers(&chain_info, &mut io);
|
let peers = sync.get_lagging_peers(&chain_info, &io);
|
||||||
sync.propagate_new_hashes(&chain_info, &mut io, &peers);
|
sync.propagate_new_hashes(&chain_info, &mut io, &peers);
|
||||||
|
|
||||||
let data = &io.queue[0].data.clone();
|
let data = &io.queue[0].data.clone();
|
||||||
@ -1925,7 +1925,7 @@ mod tests {
|
|||||||
let chain_info = client.chain_info();
|
let chain_info = client.chain_info();
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
let peers = sync.get_lagging_peers(&chain_info, &mut io);
|
let peers = sync.get_lagging_peers(&chain_info, &io);
|
||||||
sync.propagate_blocks(&chain_info, &mut io, &[], &peers);
|
sync.propagate_blocks(&chain_info, &mut io, &[], &peers);
|
||||||
|
|
||||||
let data = &io.queue[0].data.clone();
|
let data = &io.queue[0].data.clone();
|
||||||
|
@ -27,7 +27,7 @@ fn two_peers() {
|
|||||||
net.peer_mut(2).chain.add_blocks(1000, EachBlockWith::Uncle);
|
net.peer_mut(2).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||||
net.sync();
|
net.sync();
|
||||||
assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some());
|
assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some());
|
||||||
assert_eq!(net.peer(0).chain.blocks.read().deref(), net.peer(1).chain.blocks.read().deref());
|
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -37,7 +37,7 @@ fn long_chain() {
|
|||||||
net.peer_mut(1).chain.add_blocks(50000, EachBlockWith::Nothing);
|
net.peer_mut(1).chain.add_blocks(50000, EachBlockWith::Nothing);
|
||||||
net.sync();
|
net.sync();
|
||||||
assert!(net.peer(0).chain.block(BlockID::Number(50000)).is_some());
|
assert!(net.peer(0).chain.block(BlockID::Number(50000)).is_some());
|
||||||
assert_eq!(net.peer(0).chain.blocks.read().deref(), net.peer(1).chain.blocks.read().deref());
|
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -71,7 +71,7 @@ fn empty_blocks() {
|
|||||||
}
|
}
|
||||||
net.sync();
|
net.sync();
|
||||||
assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some());
|
assert!(net.peer(0).chain.block(BlockID::Number(1000)).is_some());
|
||||||
assert_eq!(net.peer(0).chain.blocks.read().deref(), net.peer(1).chain.blocks.read().deref());
|
assert_eq!(*net.peer(0).chain.blocks.read(), *net.peer(1).chain.blocks.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -89,10 +89,10 @@ fn forked() {
|
|||||||
// peer 1 has the best chain of 601 blocks
|
// peer 1 has the best chain of 601 blocks
|
||||||
let peer1_chain = net.peer(1).chain.numbers.read().clone();
|
let peer1_chain = net.peer(1).chain.numbers.read().clone();
|
||||||
net.sync();
|
net.sync();
|
||||||
assert_eq!(net.peer(0).chain.difficulty.read().deref(), net.peer(1).chain.difficulty.read().deref());
|
assert_eq!(*net.peer(0).chain.difficulty.read(), *net.peer(1).chain.difficulty.read());
|
||||||
assert_eq!(net.peer(0).chain.numbers.read().deref(), &peer1_chain);
|
assert_eq!(&*net.peer(0).chain.numbers.read(), &peer1_chain);
|
||||||
assert_eq!(net.peer(1).chain.numbers.read().deref(), &peer1_chain);
|
assert_eq!(&*net.peer(1).chain.numbers.read(), &peer1_chain);
|
||||||
assert_eq!(net.peer(2).chain.numbers.read().deref(), &peer1_chain);
|
assert_eq!(&*net.peer(2).chain.numbers.read(), &peer1_chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -222,3 +222,4 @@ fn high_td_attach() {
|
|||||||
|
|
||||||
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 5);
|
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,9 +490,9 @@ impl Hasher for PlainHasher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specialized version of HashMap with H256 keys and fast hashing function.
|
/// Specialized version of `HashMap` with H256 keys and fast hashing function.
|
||||||
pub type H256FastMap<T> = HashMap<H256, T, BuildHasherDefault<PlainHasher>>;
|
pub type H256FastMap<T> = HashMap<H256, T, BuildHasherDefault<PlainHasher>>;
|
||||||
/// Specialized version of HashSet with H256 keys and fast hashing function.
|
/// Specialized version of `HashSet` with H256 keys and fast hashing function.
|
||||||
pub type H256FastSet = HashSet<H256, BuildHasherDefault<PlainHasher>>;
|
pub type H256FastSet = HashSet<H256, BuildHasherDefault<PlainHasher>>;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
//! Panic utilities
|
//! Panic utilities
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::ops::DerefMut;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ impl PanicHandler {
|
|||||||
/// You should use `catch_panic` instead of calling this method explicitly.
|
/// You should use `catch_panic` instead of calling this method explicitly.
|
||||||
pub fn notify_all(&self, r: String) {
|
pub fn notify_all(&self, r: String) {
|
||||||
let mut listeners = self.listeners.lock();
|
let mut listeners = self.listeners.lock();
|
||||||
for listener in listeners.deref_mut() {
|
for mut listener in &mut **listeners {
|
||||||
listener.call(&r);
|
listener.call(&r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -787,7 +787,7 @@ impl Host {
|
|||||||
let entry = NodeEntry { id: s.id().unwrap().clone(), endpoint: NodeEndpoint { address: address, udp_port: address.port() } };
|
let entry = NodeEntry { id: s.id().unwrap().clone(), endpoint: NodeEndpoint { address: address, udp_port: address.port() } };
|
||||||
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
|
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
|
||||||
let mut discovery = self.discovery.lock();
|
let mut discovery = self.discovery.lock();
|
||||||
if let Some(ref mut discovery) = *discovery.deref_mut() {
|
if let Some(ref mut discovery) = *discovery {
|
||||||
discovery.add_node(entry);
|
discovery.add_node(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ impl TestProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn got_packet(&self) -> bool {
|
pub fn got_packet(&self) -> bool {
|
||||||
self.packet.lock().deref()[..] == b"hello"[..]
|
self.packet.lock()[..] == b"hello"[..]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn got_timeout(&self) -> bool {
|
pub fn got_timeout(&self) -> bool {
|
||||||
|
@ -74,7 +74,7 @@ impl HashDB for ArchiveDB {
|
|||||||
fn keys(&self) -> HashMap<H256, i32> {
|
fn keys(&self) -> HashMap<H256, i32> {
|
||||||
let mut ret: HashMap<H256, i32> = HashMap::new();
|
let mut ret: HashMap<H256, i32> = HashMap::new();
|
||||||
for (key, _) in self.backing.iter(self.column) {
|
for (key, _) in self.backing.iter(self.column) {
|
||||||
let h = H256::from_slice(key.deref());
|
let h = H256::from_slice(&*key);
|
||||||
ret.insert(h, 1);
|
ret.insert(h, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ impl HashDB for EarlyMergeDB {
|
|||||||
fn keys(&self) -> HashMap<H256, i32> {
|
fn keys(&self) -> HashMap<H256, i32> {
|
||||||
let mut ret: HashMap<H256, i32> = HashMap::new();
|
let mut ret: HashMap<H256, i32> = HashMap::new();
|
||||||
for (key, _) in self.backing.iter(self.column) {
|
for (key, _) in self.backing.iter(self.column) {
|
||||||
let h = H256::from_slice(key.deref());
|
let h = H256::from_slice(&*key);
|
||||||
ret.insert(h, 1);
|
ret.insert(h, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ impl HashDB for OverlayRecentDB {
|
|||||||
fn keys(&self) -> HashMap<H256, i32> {
|
fn keys(&self) -> HashMap<H256, i32> {
|
||||||
let mut ret: HashMap<H256, i32> = HashMap::new();
|
let mut ret: HashMap<H256, i32> = HashMap::new();
|
||||||
for (key, _) in self.backing.iter(self.column) {
|
for (key, _) in self.backing.iter(self.column) {
|
||||||
let h = H256::from_slice(key.deref());
|
let h = H256::from_slice(&*key);
|
||||||
ret.insert(h, 1);
|
ret.insert(h, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,11 +348,11 @@ impl HashDB for OverlayRecentDB {
|
|||||||
let v = self.journal_overlay.read().backing_overlay.get(&to_short_key(key)).map(|v| v.to_vec());
|
let v = self.journal_overlay.read().backing_overlay.get(&to_short_key(key)).map(|v| v.to_vec());
|
||||||
match v {
|
match v {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
Some(&self.transaction_overlay.denote(key, x).0)
|
Some(self.transaction_overlay.denote(key, x).0)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(x) = self.payload(key) {
|
if let Some(x) = self.payload(key) {
|
||||||
Some(&self.transaction_overlay.denote(key, x).0)
|
Some(self.transaction_overlay.denote(key, x).0)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
None
|
None
|
||||||
@ -920,4 +920,4 @@ mod tests {
|
|||||||
|
|
||||||
assert!(jdb.get(&key).is_none());
|
assert!(jdb.get(&key).is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ impl JournalDB for RefCountedDB {
|
|||||||
for remove in self.removes.drain(..) {
|
for remove in self.removes.drain(..) {
|
||||||
self.forward.remove(&remove);
|
self.forward.remove(&remove);
|
||||||
}
|
}
|
||||||
self.forward.commit_to_batch(&batch)
|
self.forward.commit_to_batch(batch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +421,6 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
fn test_db(config: &DatabaseConfig) {
|
fn test_db(config: &DatabaseConfig) {
|
||||||
let path = RandomTempPath::create_dir();
|
let path = RandomTempPath::create_dir();
|
||||||
@ -435,13 +434,13 @@ mod tests {
|
|||||||
batch.put(None, &key2, b"dog").unwrap();
|
batch.put(None, &key2, b"dog").unwrap();
|
||||||
db.write(batch).unwrap();
|
db.write(batch).unwrap();
|
||||||
|
|
||||||
assert_eq!(db.get(None, &key1).unwrap().unwrap().deref(), b"cat");
|
assert_eq!(&*db.get(None, &key1).unwrap().unwrap(), b"cat");
|
||||||
|
|
||||||
let contents: Vec<_> = db.iter(None).collect();
|
let contents: Vec<_> = db.iter(None).collect();
|
||||||
assert_eq!(contents.len(), 2);
|
assert_eq!(contents.len(), 2);
|
||||||
assert_eq!(&*contents[0].0, key1.deref());
|
assert_eq!(&*contents[0].0, &*key1);
|
||||||
assert_eq!(&*contents[0].1, b"cat");
|
assert_eq!(&*contents[0].1, b"cat");
|
||||||
assert_eq!(&*contents[1].0, key2.deref());
|
assert_eq!(&*contents[1].0, &*key2);
|
||||||
assert_eq!(&*contents[1].1, b"dog");
|
assert_eq!(&*contents[1].1, b"dog");
|
||||||
|
|
||||||
let batch = db.transaction();
|
let batch = db.transaction();
|
||||||
@ -459,10 +458,10 @@ mod tests {
|
|||||||
transaction.delete(None, &key1).unwrap();
|
transaction.delete(None, &key1).unwrap();
|
||||||
db.write(transaction).unwrap();
|
db.write(transaction).unwrap();
|
||||||
assert!(db.get(None, &key1).unwrap().is_none());
|
assert!(db.get(None, &key1).unwrap().is_none());
|
||||||
assert_eq!(db.get(None, &key3).unwrap().unwrap().deref(), b"elephant");
|
assert_eq!(&*db.get(None, &key3).unwrap().unwrap(), b"elephant");
|
||||||
|
|
||||||
assert_eq!(db.get_by_prefix(None, &key3).unwrap().deref(), b"elephant");
|
assert_eq!(&*db.get_by_prefix(None, &key3).unwrap(), b"elephant");
|
||||||
assert_eq!(db.get_by_prefix(None, &key2).unwrap().deref(), b"dog");
|
assert_eq!(&*db.get_by_prefix(None, &key2).unwrap(), b"dog");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -22,7 +22,6 @@ use bytes::*;
|
|||||||
use rlp::*;
|
use rlp::*;
|
||||||
use hashdb::*;
|
use hashdb::*;
|
||||||
use memorydb::*;
|
use memorydb::*;
|
||||||
use std::ops::*;
|
|
||||||
use std::sync::*;
|
use std::sync::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use kvdb::{Database, DBTransaction};
|
use kvdb::{Database, DBTransaction};
|
||||||
@ -130,7 +129,7 @@ impl HashDB for OverlayDB {
|
|||||||
fn keys(&self) -> HashMap<H256, i32> {
|
fn keys(&self) -> HashMap<H256, i32> {
|
||||||
let mut ret: HashMap<H256, i32> = HashMap::new();
|
let mut ret: HashMap<H256, i32> = HashMap::new();
|
||||||
for (key, _) in self.backing.iter(self.column) {
|
for (key, _) in self.backing.iter(self.column) {
|
||||||
let h = H256::from_slice(key.deref());
|
let h = H256::from_slice(&*key);
|
||||||
let r = self.payload(&h).unwrap().1;
|
let r = self.payload(&h).unwrap().1;
|
||||||
ret.insert(h, r as i32);
|
ret.insert(h, r as i32);
|
||||||
}
|
}
|
||||||
@ -305,7 +304,7 @@ fn playpen() {
|
|||||||
batch.put(None, b"test", b"test2").unwrap();
|
batch.put(None, b"test", b"test2").unwrap();
|
||||||
db.write(batch).unwrap();
|
db.write(batch).unwrap();
|
||||||
match db.get(None, b"test") {
|
match db.get(None, b"test") {
|
||||||
Ok(Some(value)) => println!("Got value {:?}", value.deref()),
|
Ok(Some(value)) => println!("Got value {:?}", &*value),
|
||||||
Ok(None) => println!("No value for that key"),
|
Ok(None) => println!("No value for that key"),
|
||||||
Err(..) => println!("Gah"),
|
Err(..) => println!("Gah"),
|
||||||
}
|
}
|
||||||
@ -314,4 +313,4 @@ fn playpen() {
|
|||||||
db.write(batch).unwrap();
|
db.write(batch).unwrap();
|
||||||
}
|
}
|
||||||
fs::remove_dir_all("/tmp/test").unwrap();
|
fs::remove_dir_all("/tmp/test").unwrap();
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::ops::Deref;
|
|
||||||
use std::default::Default;
|
|
||||||
use elastic_array::*;
|
use elastic_array::*;
|
||||||
use rlp::bytes::{ToBytes, VecLike};
|
use rlp::bytes::{ToBytes, VecLike};
|
||||||
use rlp::{Stream, Encoder, Encodable};
|
use rlp::{Stream, Encoder, Encodable};
|
||||||
@ -293,7 +291,7 @@ impl<'a> Encodable for &'a[u8] {
|
|||||||
|
|
||||||
impl Encodable for Vec<u8> {
|
impl Encodable for Vec<u8> {
|
||||||
fn rlp_append(&self, s: &mut RlpStream) {
|
fn rlp_append(&self, s: &mut RlpStream) {
|
||||||
s.append_value(&U8Slice(self.deref()))
|
s.append_value(&U8Slice(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,7 +332,7 @@ impl<'a, T> Encodable for &'a[T] where T: Encodable {
|
|||||||
|
|
||||||
impl<T> Encodable for Vec<T> where T: Encodable {
|
impl<T> Encodable for Vec<T> where T: Encodable {
|
||||||
fn rlp_append(&self, s: &mut RlpStream) {
|
fn rlp_append(&self, s: &mut RlpStream) {
|
||||||
Encodable::rlp_append(&self.deref(), s);
|
Encodable::rlp_append(&self.as_slice(), s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Common RLP traits
|
//! Common RLP traits
|
||||||
use std::ops::Deref;
|
|
||||||
use rlp::bytes::VecLike;
|
use rlp::bytes::VecLike;
|
||||||
use rlp::{DecoderError, UntrustedRlp};
|
use rlp::{DecoderError, UntrustedRlp};
|
||||||
use rlp::rlpstream::RlpStream;
|
use rlp::rlpstream::RlpStream;
|
||||||
@ -244,7 +243,7 @@ pub trait ByteEncodable {
|
|||||||
fn bytes_len(&self) -> usize;
|
fn bytes_len(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Structure encodable to RLP. Implement this trait for
|
/// Structure encodable to RLP. Implement this trait for
|
||||||
pub trait Encodable {
|
pub trait Encodable {
|
||||||
/// Append a value to the stream
|
/// Append a value to the stream
|
||||||
fn rlp_append(&self, s: &mut RlpStream);
|
fn rlp_append(&self, s: &mut RlpStream);
|
||||||
@ -257,7 +256,7 @@ pub trait Encodable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the hash or RLP encoded representation
|
/// Get the hash or RLP encoded representation
|
||||||
fn rlp_sha3(&self) -> H256 { self.rlp_bytes().deref().sha3() }
|
fn rlp_sha3(&self) -> H256 { (&*self.rlp_bytes()).sha3() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Encodable wrapper trait required to handle special case of encoding a &[u8] as string and not as list
|
/// Encodable wrapper trait required to handle special case of encoding a &[u8] as string and not as list
|
||||||
|
@ -192,7 +192,7 @@ impl<'db> TrieDB<'db> {
|
|||||||
where 'db: 'key
|
where 'db: 'key
|
||||||
{
|
{
|
||||||
let root_rlp = try!(self.root_data());
|
let root_rlp = try!(self.root_data());
|
||||||
self.get_from_node(&root_rlp, key)
|
self.get_from_node(root_rlp, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no
|
/// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no
|
||||||
|
Loading…
Reference in New Issue
Block a user