fix bad-block reporting no reason (#9638)
This commit is contained in:
parent
4c2301fdf6
commit
8875dccd11
@ -294,7 +294,6 @@ impl Importer {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let raw = block.bytes.clone();
|
|
||||||
match self.check_and_lock_block(block, client) {
|
match self.check_and_lock_block(block, client) {
|
||||||
Ok(closed_block) => {
|
Ok(closed_block) => {
|
||||||
if self.engine.is_proposal(&header) {
|
if self.engine.is_proposal(&header) {
|
||||||
@ -312,8 +311,8 @@ impl Importer {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.bad_blocks.report(raw, format!("{:?}", err));
|
self.bad_blocks.report(bytes, format!("{:?}", err));
|
||||||
invalid_blocks.insert(header.hash());
|
invalid_blocks.insert(hash);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -354,7 +353,7 @@ impl Importer {
|
|||||||
imported
|
imported
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_and_lock_block(&self, block: PreverifiedBlock, client: &Client) -> Result<LockedBlock, ()> {
|
fn check_and_lock_block(&self, block: PreverifiedBlock, client: &Client) -> EthcoreResult<LockedBlock> {
|
||||||
let engine = &*self.engine;
|
let engine = &*self.engine;
|
||||||
let header = block.header.clone();
|
let header = block.header.clone();
|
||||||
|
|
||||||
@ -362,7 +361,7 @@ impl Importer {
|
|||||||
let best_block_number = client.chain.read().best_block_number();
|
let best_block_number = client.chain.read().best_block_number();
|
||||||
if client.pruning_info().earliest_state > header.number() {
|
if client.pruning_info().earliest_state > header.number() {
|
||||||
warn!(target: "client", "Block import failed for #{} ({})\nBlock is ancient (current best block: #{}).", header.number(), header.hash(), best_block_number);
|
warn!(target: "client", "Block import failed for #{} ({})\nBlock is ancient (current best block: #{}).", header.number(), header.hash(), best_block_number);
|
||||||
return Err(());
|
bail!("Block is ancient");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if parent is in chain
|
// Check if parent is in chain
|
||||||
@ -370,7 +369,7 @@ impl Importer {
|
|||||||
Some(h) => h,
|
Some(h) => h,
|
||||||
None => {
|
None => {
|
||||||
warn!(target: "client", "Block import failed for #{} ({}): Parent not found ({}) ", header.number(), header.hash(), header.parent_hash());
|
warn!(target: "client", "Block import failed for #{} ({}): Parent not found ({}) ", header.number(), header.hash(), header.parent_hash());
|
||||||
return Err(());
|
bail!("Parent not found");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -389,13 +388,13 @@ impl Importer {
|
|||||||
|
|
||||||
if let Err(e) = verify_family_result {
|
if let Err(e) = verify_family_result {
|
||||||
warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||||
return Err(());
|
bail!(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
let verify_external_result = self.verifier.verify_block_external(&header, engine);
|
let verify_external_result = self.verifier.verify_block_external(&header, engine);
|
||||||
if let Err(e) = verify_external_result {
|
if let Err(e) = verify_external_result {
|
||||||
warn!(target: "client", "Stage 4 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
warn!(target: "client", "Stage 4 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||||
return Err(());
|
bail!(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enact Verified Block
|
// Enact Verified Block
|
||||||
@ -415,9 +414,13 @@ impl Importer {
|
|||||||
&mut chain.ancestry_with_metadata_iter(*header.parent_hash()),
|
&mut chain.ancestry_with_metadata_iter(*header.parent_hash()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut locked_block = enact_result.map_err(|e| {
|
let mut locked_block = match enact_result {
|
||||||
warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
Ok(b) => b,
|
||||||
})?;
|
Err(e) => {
|
||||||
|
warn!(target: "client", "Block import failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||||
|
bail!(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Strip receipts for blocks before validate_receipts_transition,
|
// Strip receipts for blocks before validate_receipts_transition,
|
||||||
// if the expected receipts root header does not match.
|
// if the expected receipts root header does not match.
|
||||||
@ -431,7 +434,7 @@ impl Importer {
|
|||||||
// Final Verification
|
// Final Verification
|
||||||
if let Err(e) = self.verifier.verify_block_final(&header, locked_block.block().header()) {
|
if let Err(e) = self.verifier.verify_block_final(&header, locked_block.block().header()) {
|
||||||
warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
|
||||||
return Err(());
|
bail!(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(locked_block)
|
Ok(locked_block)
|
||||||
@ -441,7 +444,7 @@ impl Importer {
|
|||||||
///
|
///
|
||||||
/// The block is guaranteed to be the next best blocks in the
|
/// The block is guaranteed to be the next best blocks in the
|
||||||
/// first block sequence. Does no sealing or transaction validation.
|
/// first block sequence. Does no sealing or transaction validation.
|
||||||
fn import_old_block(&self, unverified: Unverified, receipts_bytes: &[u8], db: &KeyValueDB, chain: &BlockChain) -> Result<(), ::error::Error> {
|
fn import_old_block(&self, unverified: Unverified, receipts_bytes: &[u8], db: &KeyValueDB, chain: &BlockChain) -> EthcoreResult<()> {
|
||||||
let receipts = ::rlp::decode_list(receipts_bytes);
|
let receipts = ::rlp::decode_list(receipts_bytes);
|
||||||
let _import_lock = self.import_lock.lock();
|
let _import_lock = self.import_lock.lock();
|
||||||
|
|
||||||
|
@ -465,19 +465,19 @@ impl<K: Kind> VerificationQueue<K> {
|
|||||||
|
|
||||||
/// Add a block to the queue.
|
/// Add a block to the queue.
|
||||||
pub fn import(&self, input: K::Input) -> EthcoreResult<H256> {
|
pub fn import(&self, input: K::Input) -> EthcoreResult<H256> {
|
||||||
let h = input.hash();
|
let hash = input.hash();
|
||||||
{
|
{
|
||||||
if self.processing.read().contains_key(&h) {
|
if self.processing.read().contains_key(&hash) {
|
||||||
bail!(ErrorKind::Import(ImportErrorKind::AlreadyQueued));
|
bail!(ErrorKind::Import(ImportErrorKind::AlreadyQueued));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bad = self.verification.bad.lock();
|
let mut bad = self.verification.bad.lock();
|
||||||
if bad.contains(&h) {
|
if bad.contains(&hash) {
|
||||||
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
|
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
|
||||||
}
|
}
|
||||||
|
|
||||||
if bad.contains(&input.parent_hash()) {
|
if bad.contains(&input.parent_hash()) {
|
||||||
bad.insert(h.clone());
|
bad.insert(hash);
|
||||||
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
|
bail!(ErrorKind::Import(ImportErrorKind::KnownBad));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -486,21 +486,21 @@ impl<K: Kind> VerificationQueue<K> {
|
|||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
self.verification.sizes.unverified.fetch_add(item.heap_size_of_children(), AtomicOrdering::SeqCst);
|
self.verification.sizes.unverified.fetch_add(item.heap_size_of_children(), AtomicOrdering::SeqCst);
|
||||||
|
|
||||||
self.processing.write().insert(h.clone(), item.difficulty());
|
self.processing.write().insert(hash, item.difficulty());
|
||||||
{
|
{
|
||||||
let mut td = self.total_difficulty.write();
|
let mut td = self.total_difficulty.write();
|
||||||
*td = *td + item.difficulty();
|
*td = *td + item.difficulty();
|
||||||
}
|
}
|
||||||
self.verification.unverified.lock().push_back(item);
|
self.verification.unverified.lock().push_back(item);
|
||||||
self.more_to_verify.notify_all();
|
self.more_to_verify.notify_all();
|
||||||
Ok(h)
|
Ok(hash)
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
match err {
|
match err {
|
||||||
// Don't mark future blocks as bad.
|
// Don't mark future blocks as bad.
|
||||||
Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {},
|
Error(ErrorKind::Block(BlockError::TemporarilyInvalid(_)), _) => {},
|
||||||
_ => {
|
_ => {
|
||||||
self.verification.bad.lock().insert(h.clone());
|
self.verification.bad.lock().insert(hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err)
|
Err(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user