Merge branch 'master' into gav

This commit is contained in:
Gav Wood
2016-01-18 16:20:35 +01:00
21 changed files with 380 additions and 145 deletions

View File

@@ -401,7 +401,7 @@ impl ChainSync {
let header_view = HeaderView::new(header_rlp.as_raw());
// TODO: Decompose block and add to self.headers and self.bodies instead
if header_view.number() == From::from(self.last_imported_block + 1) {
match io.chain().import_block(block_rlp.as_raw()) {
match io.chain().import_block(block_rlp.as_raw().to_vec()) {
Err(ImportError::AlreadyInChain) => {
trace!(target: "sync", "New block already in chain {:?}", h);
},
@@ -655,7 +655,7 @@ impl ChainSync {
block_rlp.append_raw(body.at(0).as_raw(), 1);
block_rlp.append_raw(body.at(1).as_raw(), 1);
let h = &headers.1[i].hash;
match io.chain().import_block(&block_rlp.out()) {
match io.chain().import_block(block_rlp.out()) {
Err(ImportError::AlreadyInChain) => {
trace!(target: "sync", "Block already in chain {:?}", h);
self.last_imported_block = headers.0 + i as BlockNumber;

View File

@@ -43,7 +43,7 @@ pub enum SyncMessage {
/// New block has been imported into the blockchain
NewChainBlock(Bytes),
/// A block is ready
BlockVerified(Bytes),
BlockVerified,
}
pub type NetSyncMessage = NetworkIoMessage<SyncMessage>;

View File

@@ -43,7 +43,7 @@ impl TestBlockChainClient {
rlp.append(&header);
rlp.append_raw(&rlp::NULL_RLP, 1);
rlp.append_raw(uncles.as_raw(), 1);
self.import_block(rlp.as_raw()).unwrap();
self.import_block(rlp.as_raw().to_vec()).unwrap();
}
}
}
@@ -110,7 +110,7 @@ impl BlockChainClient for TestBlockChainClient {
None
}
fn import_block(&mut self, b: &[u8]) -> ImportResult {
fn import_block(&mut self, b: Bytes) -> ImportResult {
let header = Rlp::new(&b).val_at::<BlockHeader>(0);
let number: usize = header.number as usize;
if number > self.blocks.len() {
@@ -132,7 +132,7 @@ impl BlockChainClient for TestBlockChainClient {
if number == self.numbers.len() {
self.difficulty = self.difficulty + header.difficulty;
self.last_hash = header.hash();
self.blocks.insert(header.hash(), b.to_vec());
self.blocks.insert(header.hash(), b);
self.numbers.insert(number, header.hash());
let mut parent_hash = header.parent_hash;
if number > 0 {