Merge pull request #687 from ethcore/pv63-receipts

PV63 receipts response
This commit is contained in:
Gav Wood 2016-03-14 20:18:10 +01:00
commit 7ba396b8d3
4 changed files with 34 additions and 17 deletions

View File

@ -108,13 +108,13 @@ pub struct Client<V = CanonVerifier> where V: Verifier {
verifier: PhantomData<V>, verifier: PhantomData<V>,
} }
const HISTORY: u64 = 1000; const HISTORY: u64 = 1200;
// DO NOT TOUCH THIS ANY MORE UNLESS YOU REALLY KNOW WHAT YOU'RE DOING. // DO NOT TOUCH THIS ANY MORE UNLESS YOU REALLY KNOW WHAT YOU'RE DOING.
// Altering it will force a blanket DB update for *all* JournalDB-derived // Altering it will force a blanket DB update for *all* JournalDB-derived
// databases. // databases.
// Instead, add/upgrade the version string of the individual JournalDB-derived database // Instead, add/upgrade the version string of the individual JournalDB-derived database
// of which you actually want force an upgrade. // of which you actually want force an upgrade.
const CLIENT_DB_VER_STR: &'static str = "5.2"; const CLIENT_DB_VER_STR: &'static str = "5.3";
impl Client<CanonVerifier> { impl Client<CanonVerifier> {
/// Create a new client with given spec and DB path. /// Create a new client with given spec and DB path.
@ -505,12 +505,12 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
} }
} }
fn state_data(&self, _hash: &H256) -> Option<Bytes> { fn state_data(&self, hash: &H256) -> Option<Bytes> {
None self.state_db.lock().unwrap().state(hash)
} }
fn block_receipts(&self, _hash: &H256) -> Option<Bytes> { fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
None self.chain.block_receipts(hash).map(|receipts| rlp::encode(&receipts).to_vec())
} }
fn import_block(&self, bytes: Bytes) -> ImportResult { fn import_block(&self, bytes: Bytes) -> ImportResult {

View File

@ -24,7 +24,9 @@ use header::{Header as BlockHeader, BlockNumber};
use filter::Filter; use filter::Filter;
use log_entry::LocalizedLogEntry; use log_entry::LocalizedLogEntry;
use receipt::Receipt; use receipt::Receipt;
use extras::BlockReceipts;
use error::{ImportResult}; use error::{ImportResult};
use block_queue::BlockQueueInfo; use block_queue::BlockQueueInfo;
use block::{SealedBlock, ClosedBlock}; use block::{SealedBlock, ClosedBlock};
@ -292,10 +294,10 @@ impl BlockChainClient for TestBlockChainClient {
fn block_receipts(&self, hash: &H256) -> Option<Bytes> { fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
// starts with 'f' ? // starts with 'f' ?
if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") {
let receipt = Receipt::new( let receipt = BlockReceipts::new(vec![Receipt::new(
H256::zero(), H256::zero(),
U256::zero(), U256::zero(),
vec![]); vec![])]);
let mut rlp = RlpStream::new(); let mut rlp = RlpStream::new();
rlp.append(&receipt); rlp.append(&receipt);
return Some(rlp.out()); return Some(rlp.out());

View File

@ -35,6 +35,17 @@ fn imports_from_empty() {
client.flush_queue(); 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] #[test]
fn imports_good_block() { fn imports_good_block() {
let dir = RandomTempPath::new(); let dir = RandomTempPath::new();

View File

@ -64,6 +64,7 @@ const MAX_BODIES_TO_SEND: usize = 256;
const MAX_HEADERS_TO_SEND: usize = 512; const MAX_HEADERS_TO_SEND: usize = 512;
const MAX_NODE_DATA_TO_SEND: usize = 1024; const MAX_NODE_DATA_TO_SEND: usize = 1024;
const MAX_RECEIPTS_TO_SEND: usize = 1024; const MAX_RECEIPTS_TO_SEND: usize = 1024;
const MAX_RECEIPTS_HEADERS_TO_SEND: usize = 256;
const MAX_HEADERS_TO_REQUEST: usize = 512; const MAX_HEADERS_TO_REQUEST: usize = 512;
const MAX_BODIES_TO_REQUEST: usize = 256; const MAX_BODIES_TO_REQUEST: usize = 256;
const MIN_PEERS_PROPAGATION: usize = 4; const MIN_PEERS_PROPAGATION: usize = 4;
@ -1053,17 +1054,20 @@ impl ChainSync {
debug!(target: "sync", "Empty GetReceipts request, ignoring."); debug!(target: "sync", "Empty GetReceipts request, ignoring.");
return Ok(None); return Ok(None);
} }
count = min(count, MAX_RECEIPTS_TO_SEND); count = min(count, MAX_RECEIPTS_HEADERS_TO_SEND);
let mut added = 0usize; let mut added_headers = 0usize;
let mut added_receipts = 0usize;
let mut data = Bytes::new(); let mut data = Bytes::new();
for i in 0..count { for i in 0..count {
if let Some(mut hdr) = io.chain().block_receipts(&try!(rlp.val_at::<H256>(i))) { if let Some(mut receipts_bytes) = io.chain().block_receipts(&try!(rlp.val_at::<H256>(i))) {
data.append(&mut hdr); data.append(&mut receipts_bytes);
added += 1; added_receipts += receipts_bytes.len();
added_headers += 1;
if added_receipts > MAX_RECEIPTS_TO_SEND { break; }
} }
} }
let mut rlp_result = RlpStream::new_list(added); let mut rlp_result = RlpStream::new_list(added_headers);
rlp_result.append_raw(&data, added); rlp_result.append_raw(&data, added_headers);
Ok(Some((RECEIPTS_PACKET, rlp_result))) Ok(Some((RECEIPTS_PACKET, rlp_result)))
} }
@ -1358,7 +1362,7 @@ mod tests {
assert!(rlp_result.is_some()); assert!(rlp_result.is_some());
// the length of two rlp-encoded receipts // 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()); let mut sync = dummy_sync_with_peer(H256::new());
io.sender = Some(2usize); io.sender = Some(2usize);