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>,
}
const HISTORY: u64 = 1000;
const HISTORY: u64 = 1200;
// 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
// databases.
// Instead, add/upgrade the version string of the individual JournalDB-derived database
// 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> {
/// Create a new client with given spec and DB path.
@ -252,7 +252,7 @@ impl<V> Client<V> where V: Verifier {
// And convert tuples to keys
(map_to_vec(enacted), map_to_vec(retracted))
}
/// This is triggered by a message coming from a block queue when the block is ready for insertion
pub fn import_verified_blocks(&self, io: &IoChannel<NetSyncMessage>) -> usize {
let max_blocks_to_import = 128;
@ -505,12 +505,12 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
}
}
fn state_data(&self, _hash: &H256) -> Option<Bytes> {
None
fn state_data(&self, hash: &H256) -> Option<Bytes> {
self.state_db.lock().unwrap().state(hash)
}
fn block_receipts(&self, _hash: &H256) -> Option<Bytes> {
None
fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
self.chain.block_receipts(hash).map(|receipts| rlp::encode(&receipts).to_vec())
}
fn import_block(&self, bytes: Bytes) -> ImportResult {

View File

@ -24,7 +24,9 @@ use header::{Header as BlockHeader, BlockNumber};
use filter::Filter;
use log_entry::LocalizedLogEntry;
use receipt::Receipt;
use extras::BlockReceipts;
use error::{ImportResult};
use block_queue::BlockQueueInfo;
use block::{SealedBlock, ClosedBlock};
@ -292,10 +294,10 @@ impl BlockChainClient for TestBlockChainClient {
fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
// 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());

View File

@ -35,6 +35,17 @@ 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();

View File

@ -64,6 +64,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 = 256;
const MAX_HEADERS_TO_REQUEST: usize = 512;
const MAX_BODIES_TO_REQUEST: usize = 256;
const MIN_PEERS_PROPAGATION: usize = 4;
@ -1053,17 +1054,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::<H256>(i))) {
data.append(&mut hdr);
added += 1;
if let Some(mut receipts_bytes) = io.chain().block_receipts(&try!(rlp.val_at::<H256>(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)))
}
@ -1358,7 +1362,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);