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

Commit fe2f6ca

Browse files
debrisAndronik Ordian
authored andcommitted
fix bad-block reporting no reason (#9638)
1 parent d9acc1b commit fe2f6ca

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

ethcore/src/client/client.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ impl Importer {
296296
continue;
297297
}
298298

299-
let raw = block.bytes.clone();
300299
match self.check_and_lock_block(block, client) {
301300
Ok(closed_block) => {
302301
if self.engine.is_proposal(&header) {
@@ -314,8 +313,8 @@ impl Importer {
314313
}
315314
},
316315
Err(err) => {
317-
self.bad_blocks.report(raw, format!("{:?}", err));
318-
invalid_blocks.insert(header.hash());
316+
self.bad_blocks.report(bytes, format!("{:?}", err));
317+
invalid_blocks.insert(hash);
319318
},
320319
}
321320
}
@@ -356,23 +355,23 @@ impl Importer {
356355
imported
357356
}
358357

359-
fn check_and_lock_block(&self, block: PreverifiedBlock, client: &Client) -> Result<LockedBlock, ()> {
358+
fn check_and_lock_block(&self, block: PreverifiedBlock, client: &Client) -> EthcoreResult<LockedBlock> {
360359
let engine = &*self.engine;
361360
let header = block.header.clone();
362361

363362
// Check the block isn't so old we won't be able to enact it.
364363
let best_block_number = client.chain.read().best_block_number();
365364
if client.pruning_info().earliest_state > header.number() {
366365
warn!(target: "client", "Block import failed for #{} ({})\nBlock is ancient (current best block: #{}).", header.number(), header.hash(), best_block_number);
367-
return Err(());
366+
bail!("Block is ancient");
368367
}
369368

370369
// Check if parent is in chain
371370
let parent = match client.block_header_decoded(BlockId::Hash(*header.parent_hash())) {
372371
Some(h) => h,
373372
None => {
374373
warn!(target: "client", "Block import failed for #{} ({}): Parent not found ({}) ", header.number(), header.hash(), header.parent_hash());
375-
return Err(());
374+
bail!("Parent not found");
376375
}
377376
};
378377

@@ -391,13 +390,13 @@ impl Importer {
391390

392391
if let Err(e) = verify_family_result {
393392
warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
394-
return Err(());
393+
bail!(e);
395394
};
396395

397396
let verify_external_result = self.verifier.verify_block_external(&header, engine);
398397
if let Err(e) = verify_external_result {
399398
warn!(target: "client", "Stage 4 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
400-
return Err(());
399+
bail!(e);
401400
};
402401

403402
// Enact Verified Block
@@ -417,9 +416,13 @@ impl Importer {
417416
&mut chain.ancestry_with_metadata_iter(*header.parent_hash()),
418417
);
419418

420-
let mut locked_block = enact_result.map_err(|e| {
421-
warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
422-
})?;
419+
let mut locked_block = match enact_result {
420+
Ok(b) => b,
421+
Err(e) => {
422+
warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
423+
bail!(e);
424+
}
425+
};
423426

424427
// Strip receipts for blocks before validate_receipts_transition,
425428
// if the expected receipts root header does not match.
@@ -433,7 +436,7 @@ impl Importer {
433436
// Final Verification
434437
if let Err(e) = self.verifier.verify_block_final(&header, locked_block.block().header()) {
435438
warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
436-
return Err(());
439+
bail!(e);
437440
}
438441

439442
Ok(locked_block)
@@ -443,7 +446,7 @@ impl Importer {
443446
///
444447
/// The block is guaranteed to be the next best blocks in the
445448
/// first block sequence. Does no sealing or transaction validation.
446-
fn import_old_block(&self, unverified: Unverified, receipts_bytes: &[u8], db: &KeyValueDB, chain: &BlockChain) -> Result<(), ::error::Error> {
449+
fn import_old_block(&self, unverified: Unverified, receipts_bytes: &[u8], db: &KeyValueDB, chain: &BlockChain) -> EthcoreResult<()> {
447450
let receipts = ::rlp::decode_list(receipts_bytes);
448451
let _import_lock = self.import_lock.lock();
449452

ethcore/src/verification/queue/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,19 +465,19 @@ impl<K: Kind> VerificationQueue<K> {
465465

466466
/// Add a block to the queue.
467467
pub fn import(&self, input: K::Input) -> ImportResult {
468-
let h = input.hash();
468+
let hash = input.hash();
469469
{
470-
if self.processing.read().contains_key(&h) {
470+
if self.processing.read().contains_key(&hash) {
471471
bail!(ErrorKind::Import(ImportErrorKind::AlreadyQueued));
472472
}
473473

474474
let mut bad = self.verification.bad.lock();
475-
if bad.contains(&h) {
475+
if bad.contains(&hash) {
476476
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
477477
}
478478

479479
if bad.contains(&input.parent_hash()) {
480-
bad.insert(h.clone());
480+
bad.insert(hash);
481481
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
482482
}
483483
}
@@ -486,21 +486,21 @@ impl<K: Kind> VerificationQueue<K> {
486486
Ok(item) => {
487487
self.verification.sizes.unverified.fetch_add(item.heap_size_of_children(), AtomicOrdering::SeqCst);
488488

489-
self.processing.write().insert(h.clone(), item.difficulty());
489+
self.processing.write().insert(hash, item.difficulty());
490490
{
491491
let mut td = self.total_difficulty.write();
492492
*td = *td + item.difficulty();
493493
}
494494
self.verification.unverified.lock().push_back(item);
495495
self.more_to_verify.notify_all();
496-
Ok(h)
496+
Ok(hash)
497497
},
498498
Err(err) => {
499499
match err {
500500
// Don't mark future blocks as bad.
501501
Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {},
502502
_ => {
503-
self.verification.bad.lock().insert(h.clone());
503+
self.verification.bad.lock().insert(hash);
504504
}
505505
}
506506
Err(err)

0 commit comments

Comments
 (0)