From e970dd4530cfc20b0af1e86b49a83bcff62f3ec6 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 11 Mar 2016 23:09:14 +0400 Subject: [PATCH 1/7] client state data func --- ethcore/src/client/client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 1148a0140..8abf3a526 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -466,8 +466,8 @@ impl BlockChainClient for Client where V: Verifier { } } - fn state_data(&self, _hash: &H256) -> Option { - None + fn state_data(&self, hash: &H256) -> Option { + self.state_db.lock().unwrap().state(hash) } fn block_receipts(&self, _hash: &H256) -> Option { From da6f6d57cdc4753c8253866a1fedb84a9ee2f232 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 11 Mar 2016 23:24:44 +0400 Subject: [PATCH 2/7] state data query to client --- ethcore/src/tests/client.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 001d1729b..4818ef69e 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -35,6 +35,19 @@ fn imports_from_empty() { client.flush_queue(); } +#[test] +fn returns_state_root_basic() { + let client_result = generate_dummy_client(6); + let client = client_result.reference(); + + let test_spec = get_test_spec(); + let test_engine = test_spec.to_engine().unwrap(); + let state_root = test_engine.spec().genesis_header().state_root; + + assert!(client.state_data(&state_root).is_some()); + +} + #[test] fn imports_good_block() { let dir = RandomTempPath::new(); From 349584772b6b6bc2c4078ef0fc67d88f023248a6 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 11 Mar 2016 23:34:18 +0400 Subject: [PATCH 3/7] redundant lines --- ethcore/src/tests/client.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 4818ef69e..43b426560 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -39,13 +39,11 @@ fn imports_from_empty() { fn returns_state_root_basic() { let client_result = generate_dummy_client(6); let client = client_result.reference(); - let test_spec = get_test_spec(); let test_engine = test_spec.to_engine().unwrap(); let state_root = test_engine.spec().genesis_header().state_root; assert!(client.state_data(&state_root).is_some()); - } #[test] From 19f23f8445bb34daf8ea3eebd9fa6fb733d8329a Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 11 Mar 2016 23:37:47 +0400 Subject: [PATCH 4/7] increasing history to be useful for geth fast sync --- ethcore/src/client/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 8abf3a526..77cf105ed 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -115,7 +115,7 @@ pub struct Client where V: Verifier { verifier: PhantomData, } -const HISTORY: u64 = 1000; +const HISTORY: u64 = 1200; const CLIENT_DB_VER_STR: &'static str = "5.1"; impl Client { From fb51ac0d95504d94b46908ccb7bdc1cf7c59670f Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 11 Mar 2016 23:33:01 +0100 Subject: [PATCH 5/7] blockchain receipts rlp generation --- ethcore/src/client/client.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 77cf105ed..4642a0103 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -470,8 +470,12 @@ impl BlockChainClient for Client where V: Verifier { self.state_db.lock().unwrap().state(hash) } - fn block_receipts(&self, _hash: &H256) -> Option { - None + fn block_receipts(&self, hash: &H256) -> Option { + self.chain.block_receipts(hash).and_then(|receipts| { + let mut rlp = RlpStream::new(); + rlp.append(&receipts); + Some(rlp.out()) + }) } fn import_block(&self, bytes: Bytes) -> ImportResult { From 0684abd345aa9405d59bda17bae868d319d48329 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Sat, 12 Mar 2016 19:23:17 +0100 Subject: [PATCH 6/7] fixed to return receipts grouped by requested block --- ethcore/src/client/test_client.rs | 5 +++-- sync/src/chain.rs | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 207f1090f..76e13fe9f 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -24,6 +24,7 @@ use header::{Header as BlockHeader, BlockNumber}; use filter::Filter; use log_entry::LocalizedLogEntry; use receipt::Receipt; +use extras::BlockReceipts; use error::{ImportResult, Error}; use block_queue::BlockQueueInfo; use block::ClosedBlock; @@ -254,10 +255,10 @@ impl BlockChainClient for TestBlockChainClient { fn block_receipts(&self, hash: &H256) -> Option { // starts with 'f' ? if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { - let receipt = Receipt::new( + let receipt = BlockReceipts::new(vec![Receipt::new( H256::zero(), U256::zero(), - vec![]); + vec![])]); let mut rlp = RlpStream::new(); rlp.append(&receipt); return Some(rlp.out()); diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 4a2d941a7..ae4744902 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -66,6 +66,7 @@ const MAX_BODIES_TO_SEND: usize = 256; const MAX_HEADERS_TO_SEND: usize = 512; const MAX_NODE_DATA_TO_SEND: usize = 1024; const MAX_RECEIPTS_TO_SEND: usize = 1024; +const MAX_RECEIPTS_HEADERS_TO_SEND: usize = 16; const MAX_HEADERS_TO_REQUEST: usize = 512; const MAX_BODIES_TO_REQUEST: usize = 256; const MIN_PEERS_PROPAGATION: usize = 4; @@ -1060,17 +1061,20 @@ impl ChainSync { debug!(target: "sync", "Empty GetReceipts request, ignoring."); return Ok(None); } - count = min(count, MAX_RECEIPTS_TO_SEND); - let mut added = 0usize; + count = min(count, MAX_RECEIPTS_HEADERS_TO_SEND); + let mut added_headers = 0usize; + let mut added_receipts = 0usize; let mut data = Bytes::new(); for i in 0..count { - if let Some(mut hdr) = io.chain().block_receipts(&try!(rlp.val_at::(i))) { - data.append(&mut hdr); - added += 1; + if let Some(mut receipts_bytes) = io.chain().block_receipts(&try!(rlp.val_at::(i))) { + data.append(&mut receipts_bytes); + added_receipts += receipts_bytes.len(); + added_headers += 1; + if added_receipts > MAX_RECEIPTS_TO_SEND { break; } } } - let mut rlp_result = RlpStream::new_list(added); - rlp_result.append_raw(&data, added); + let mut rlp_result = RlpStream::new_list(added_headers); + rlp_result.append_raw(&data, added_headers); Ok(Some((RECEIPTS_PACKET, rlp_result))) } @@ -1396,7 +1400,7 @@ mod tests { assert!(rlp_result.is_some()); // the length of two rlp-encoded receipts - assert_eq!(597, rlp_result.unwrap().1.out().len()); + assert_eq!(603, rlp_result.unwrap().1.out().len()); let mut sync = dummy_sync_with_peer(H256::new()); io.sender = Some(2usize); From 809c239ff80dd31467fcdef8f5be5da42fe95106 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Sun, 13 Mar 2016 15:59:25 +0100 Subject: [PATCH 7/7] fix rev --- ethcore/src/client/client.rs | 6 +----- sync/src/chain.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 95ee90f7d..81e1ef287 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -471,11 +471,7 @@ impl BlockChainClient for Client where V: Verifier { } fn block_receipts(&self, hash: &H256) -> Option { - self.chain.block_receipts(hash).and_then(|receipts| { - let mut rlp = RlpStream::new(); - rlp.append(&receipts); - Some(rlp.out()) - }) + self.chain.block_receipts(hash).map(|receipts| rlp::encode(&receipts).to_vec()) } fn import_block(&self, bytes: Bytes) -> ImportResult { diff --git a/sync/src/chain.rs b/sync/src/chain.rs index ae4744902..bc3041d02 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -66,7 +66,7 @@ const MAX_BODIES_TO_SEND: usize = 256; const MAX_HEADERS_TO_SEND: usize = 512; const MAX_NODE_DATA_TO_SEND: usize = 1024; const MAX_RECEIPTS_TO_SEND: usize = 1024; -const MAX_RECEIPTS_HEADERS_TO_SEND: usize = 16; +const MAX_RECEIPTS_HEADERS_TO_SEND: usize = 256; const MAX_HEADERS_TO_REQUEST: usize = 512; const MAX_BODIES_TO_REQUEST: usize = 256; const MIN_PEERS_PROPAGATION: usize = 4;