parent
23a23e7a18
commit
5bd6b208af
@ -28,9 +28,12 @@ pub use self::headers::Headers;
|
|||||||
|
|
||||||
/// Something which can produce a hash and a parent hash.
|
/// Something which can produce a hash and a parent hash.
|
||||||
pub trait BlockLike {
|
pub trait BlockLike {
|
||||||
/// Get the hash of this item.
|
/// Get the hash of this item - i.e. the header hash.
|
||||||
fn hash(&self) -> H256;
|
fn hash(&self) -> H256;
|
||||||
|
|
||||||
|
/// Get a raw hash of this item - i.e. the hash of the RLP representation.
|
||||||
|
fn raw_hash(&self) -> H256;
|
||||||
|
|
||||||
/// Get the hash of this item's parent.
|
/// Get the hash of this item's parent.
|
||||||
fn parent_hash(&self) -> H256;
|
fn parent_hash(&self) -> H256;
|
||||||
|
|
||||||
@ -119,6 +122,10 @@ pub mod blocks {
|
|||||||
self.header.hash()
|
self.header.hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn raw_hash(&self) -> H256 {
|
||||||
|
keccak_hash::keccak(&self.bytes)
|
||||||
|
}
|
||||||
|
|
||||||
fn parent_hash(&self) -> H256 {
|
fn parent_hash(&self) -> H256 {
|
||||||
self.header.parent_hash().clone()
|
self.header.parent_hash().clone()
|
||||||
}
|
}
|
||||||
@ -133,6 +140,10 @@ pub mod blocks {
|
|||||||
self.header.hash()
|
self.header.hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn raw_hash(&self) -> H256 {
|
||||||
|
keccak_hash::keccak(&self.bytes)
|
||||||
|
}
|
||||||
|
|
||||||
fn parent_hash(&self) -> H256 {
|
fn parent_hash(&self) -> H256 {
|
||||||
self.header.parent_hash().clone()
|
self.header.parent_hash().clone()
|
||||||
}
|
}
|
||||||
@ -158,6 +169,7 @@ pub mod headers {
|
|||||||
|
|
||||||
impl BlockLike for Header {
|
impl BlockLike for Header {
|
||||||
fn hash(&self) -> H256 { self.hash() }
|
fn hash(&self) -> H256 { self.hash() }
|
||||||
|
fn raw_hash(&self) -> H256 { self.hash() }
|
||||||
fn parent_hash(&self) -> H256 { self.parent_hash().clone() }
|
fn parent_hash(&self) -> H256 { self.parent_hash().clone() }
|
||||||
fn difficulty(&self) -> U256 { self.difficulty().clone() }
|
fn difficulty(&self) -> U256 { self.difficulty().clone() }
|
||||||
}
|
}
|
||||||
|
@ -469,13 +469,14 @@ impl<K: Kind, C> VerificationQueue<K, C> {
|
|||||||
/// Add a block to the queue.
|
/// Add a block to the queue.
|
||||||
pub fn import(&self, input: K::Input) -> Result<H256, (K::Input, Error)> {
|
pub fn import(&self, input: K::Input) -> Result<H256, (K::Input, Error)> {
|
||||||
let hash = input.hash();
|
let hash = input.hash();
|
||||||
|
let raw_hash = input.raw_hash();
|
||||||
{
|
{
|
||||||
if self.processing.read().contains_key(&hash) {
|
if self.processing.read().contains_key(&hash) {
|
||||||
return Err((input, Error::Import(ImportError::AlreadyQueued).into()));
|
return Err((input, Error::Import(ImportError::AlreadyQueued).into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bad = self.verification.bad.lock();
|
let mut bad = self.verification.bad.lock();
|
||||||
if bad.contains(&hash) {
|
if bad.contains(&hash) || bad.contains(&raw_hash) {
|
||||||
return Err((input, Error::Import(ImportError::KnownBad).into()));
|
return Err((input, Error::Import(ImportError::KnownBad).into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,6 +503,16 @@ impl<K: Kind, C> VerificationQueue<K, C> {
|
|||||||
match err {
|
match err {
|
||||||
// Don't mark future blocks as bad.
|
// Don't mark future blocks as bad.
|
||||||
Error::Block(BlockError::TemporarilyInvalid(_)) => {},
|
Error::Block(BlockError::TemporarilyInvalid(_)) => {},
|
||||||
|
// If the transaction root or uncles hash is invalid, it doesn't necessarily mean
|
||||||
|
// that the header is invalid. We might have just received a malformed block body,
|
||||||
|
// so we shouldn't put the header hash to `bad`.
|
||||||
|
//
|
||||||
|
// We still put the entire `Item` hash to bad, so that we can early reject
|
||||||
|
// the items that are malformed.
|
||||||
|
Error::Block(BlockError::InvalidTransactionsRoot(_)) |
|
||||||
|
Error::Block(BlockError::InvalidUnclesHash(_)) => {
|
||||||
|
self.verification.bad.lock().insert(raw_hash);
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
self.verification.bad.lock().insert(hash);
|
self.verification.bad.lock().insert(hash);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user