Block validation
This commit is contained in:
parent
b997a61d4a
commit
61f39d68f8
@ -20,6 +20,7 @@ use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||
use ethcore::client::{BlockChainClient, BlockStatus};
|
||||
use range_collection::{RangeCollection, ToUsize, FromUsize};
|
||||
use ethcore::error::*;
|
||||
use ethcore::block::Block;
|
||||
use io::SyncIo;
|
||||
|
||||
impl ToUsize for BlockNumber {
|
||||
@ -669,6 +670,12 @@ 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;
|
||||
// Perform basic block verification
|
||||
if !Block::is_good(block_rlp.as_raw()) {
|
||||
debug!(target: "sync", "Bad block rlp {:?} : {:?}", h, block_rlp.as_raw());
|
||||
restart = true;
|
||||
break;
|
||||
}
|
||||
match io.chain().import_block(block_rlp.out()) {
|
||||
Err(ImportError::AlreadyInChain) => {
|
||||
trace!(target: "sync", "Block already in chain {:?}", h);
|
||||
|
@ -38,7 +38,11 @@ impl TestBlockChainClient {
|
||||
header.number = n as BlockNumber;
|
||||
let mut uncles = RlpStream::new_list(if empty {0} else {1});
|
||||
if !empty {
|
||||
uncles.append(&H256::from(&U256::from(n)));
|
||||
let mut uncle_header = BlockHeader::new();
|
||||
uncle_header.difficulty = From::from(n);
|
||||
uncle_header.parent_hash = self.last_hash.read().unwrap().clone();
|
||||
uncle_header.number = n as BlockNumber;
|
||||
uncles.append(&uncle_header);
|
||||
header.uncles_hash = uncles.as_raw().sha3();
|
||||
}
|
||||
let mut rlp = RlpStream::new_list(3);
|
||||
|
Loading…
Reference in New Issue
Block a user