Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 54c2d61

Browse files
tomusdrwsorpaas
authored andcommitted
Make sure to not mark block header hash as invalid if only the body is wrong. (#11356)
* Patch invalid transaction root. * Add raw hash to bad and include fix for uncles too. * Fix submodules.
1 parent 29ebddc commit 54c2d61

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

ethcore/src/verification/queue/kind.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ pub use self::headers::Headers;
2727

2828
/// Something which can produce a hash and a parent hash.
2929
pub trait BlockLike {
30-
/// Get the hash of this item.
30+
/// Get the hash of this item - i.e. the header hash.
3131
fn hash(&self) -> H256;
3232

33+
/// Get a raw hash of this item - i.e. the hash of the RLP representation.
34+
fn raw_hash(&self) -> H256;
35+
3336
/// Get the hash of this item's parent.
3437
fn parent_hash(&self) -> H256;
3538

@@ -160,6 +163,10 @@ pub mod blocks {
160163
self.header.hash()
161164
}
162165

166+
fn raw_hash(&self) -> H256 {
167+
hash::keccak(&self.bytes)
168+
}
169+
163170
fn parent_hash(&self) -> H256 {
164171
self.header.parent_hash().clone()
165172
}
@@ -174,6 +181,10 @@ pub mod blocks {
174181
self.header.hash()
175182
}
176183

184+
fn raw_hash(&self) -> H256 {
185+
hash::keccak(&self.bytes)
186+
}
187+
177188
fn parent_hash(&self) -> H256 {
178189
self.header.parent_hash().clone()
179190
}
@@ -197,6 +208,7 @@ pub mod headers {
197208

198209
impl BlockLike for Header {
199210
fn hash(&self) -> H256 { self.hash() }
211+
fn raw_hash(&self) -> H256 { self.hash() }
200212
fn parent_hash(&self) -> H256 { self.parent_hash().clone() }
201213
fn difficulty(&self) -> U256 { self.difficulty().clone() }
202214
}

ethcore/src/verification/queue/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,14 @@ impl<K: Kind> VerificationQueue<K> {
472472
/// Add a block to the queue.
473473
pub fn import(&self, input: K::Input) -> Result<H256, (K::Input, Error)> {
474474
let hash = input.hash();
475+
let raw_hash = input.raw_hash();
475476
{
476477
if self.processing.read().contains_key(&hash) {
477478
bail!((input, ErrorKind::Import(ImportErrorKind::AlreadyQueued).into()));
478479
}
479480

480481
let mut bad = self.verification.bad.lock();
481-
if bad.contains(&hash) {
482+
if bad.contains(&hash) || bad.contains(&raw_hash) {
482483
bail!((input, ErrorKind::Import(ImportErrorKind::KnownBad).into()));
483484
}
484485

@@ -505,6 +506,16 @@ impl<K: Kind> VerificationQueue<K> {
505506
match err {
506507
// Don't mark future blocks as bad.
507508
Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {},
509+
// If the transaction root or uncles hash is invalid, it doesn't necessarily mean
510+
// that the header is invalid. We might have just received a malformed block body,
511+
// so we shouldn't put the header hash to `bad`.
512+
//
513+
// We still put the entire `Item` hash to bad, so that we can early reject
514+
// the items that are malformed.
515+
Error(ErrorKind::Block(BlockError::InvalidTransactionsRoot(_)), _) |
516+
Error(ErrorKind::Block(BlockError::InvalidUnclesHash(_)), _) => {
517+
self.verification.bad.lock().insert(raw_hash);
518+
},
508519
_ => {
509520
self.verification.bad.lock().insert(hash);
510521
}

0 commit comments

Comments
 (0)