mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 19:51:02 +00:00
Expunge error-chain (feat. tomaka) (#2662)
* Remove error_chain * Expunge error-chain from rpc and service. * Expunge from transaction pool. * Expunge from node/cli * Expunge from keystore. * Remove some boilerplate. * Fix remaining stuff. * Improve on deprecation message. * Fix issues. * Fix trnsaction pool tests. * Fix the rest. * Fix borked merge. * Update lock
This commit is contained in:
committed by
Gavin Wood
parent
69ffec5822
commit
c162fc5ff1
@@ -26,7 +26,7 @@ use client::blockchain::HeaderBackend;
|
||||
use client::backend::Backend;
|
||||
use client::runtime_api::ApiExt;
|
||||
use consensus_common::{
|
||||
BlockImport, Error as ConsensusError, ErrorKind as ConsensusErrorKind,
|
||||
BlockImport, Error as ConsensusError,
|
||||
ImportBlock, ImportResult, JustificationImport, well_known_cache_keys,
|
||||
SelectChain,
|
||||
};
|
||||
@@ -187,11 +187,11 @@ where
|
||||
|
||||
match maybe_change {
|
||||
Err(e) => match api.has_api_with::<GrandpaApi<Block>, _>(&at, |v| v >= 2) {
|
||||
Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()),
|
||||
Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()),
|
||||
Ok(true) => {
|
||||
// API version is high enough to support forced changes
|
||||
// but got error, so it is legitimate.
|
||||
return Err(ConsensusErrorKind::ClientImport(e.to_string()).into())
|
||||
return Err(ConsensusError::ClientImport(e.to_string()).into())
|
||||
},
|
||||
Ok(false) => {
|
||||
// API version isn't high enough to support forced changes
|
||||
@@ -216,7 +216,7 @@ where
|
||||
);
|
||||
|
||||
match maybe_change {
|
||||
Err(e) => Err(ConsensusErrorKind::ClientImport(e.to_string()).into()),
|
||||
Err(e) => Err(ConsensusError::ClientImport(e.to_string()).into()),
|
||||
Ok(Some(change)) => Ok(Some(PendingChange {
|
||||
next_authorities: change.next_authorities,
|
||||
delay: change.delay,
|
||||
@@ -301,12 +301,12 @@ where
|
||||
guard.as_mut().add_pending_change(
|
||||
change,
|
||||
&is_descendent_of,
|
||||
).map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?;
|
||||
).map_err(|e| ConsensusError::from(ConsensusError::ClientImport(e.to_string())))?;
|
||||
}
|
||||
|
||||
let applied_changes = {
|
||||
let forced_change_set = guard.as_mut().apply_forced_changes(hash, number, &is_descendent_of)
|
||||
.map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()))
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))
|
||||
.map_err(ConsensusError::from)?;
|
||||
|
||||
if let Some((median_last_finalized_number, new_set)) = forced_change_set {
|
||||
@@ -318,14 +318,14 @@ where
|
||||
// with. we use the minimum between the median and the local
|
||||
// best finalized block.
|
||||
let best_finalized_number = self.inner.backend().blockchain().info()
|
||||
.map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()))?
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?
|
||||
.finalized_number;
|
||||
|
||||
let canon_number = best_finalized_number.min(median_last_finalized_number);
|
||||
|
||||
let canon_hash =
|
||||
self.inner.backend().blockchain().header(BlockId::Number(canon_number))
|
||||
.map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()))?
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?
|
||||
.expect("the given block number is less or equal than the current best finalized number; \
|
||||
current best finalized number must exist in chain; qed.")
|
||||
.hash();
|
||||
@@ -343,7 +343,7 @@ where
|
||||
AppliedChanges::Forced(new_authorities)
|
||||
} else {
|
||||
let did_standard = guard.as_mut().enacts_standard_change(hash, number, &is_descendent_of)
|
||||
.map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()))
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))
|
||||
.map_err(ConsensusError::from)?;
|
||||
|
||||
if let Some(root) = did_standard {
|
||||
@@ -399,7 +399,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> BlockImport<Block>
|
||||
match self.inner.backend().blockchain().status(BlockId::Hash(hash)) {
|
||||
Ok(blockchain::BlockStatus::InChain) => return Ok(ImportResult::AlreadyInChain),
|
||||
Ok(blockchain::BlockStatus::Unknown) => {},
|
||||
Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()),
|
||||
Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()),
|
||||
}
|
||||
|
||||
let pending_changes = self.make_authorities_changes(&mut block, hash)?;
|
||||
@@ -420,7 +420,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> BlockImport<Block>
|
||||
Err(e) => {
|
||||
debug!(target: "afg", "Restoring old authority set after block import error: {:?}", e);
|
||||
pending_changes.revert();
|
||||
return Err(ConsensusErrorKind::ClientImport(e.to_string()).into());
|
||||
return Err(ConsensusError::ClientImport(e.to_string()).into());
|
||||
},
|
||||
}
|
||||
};
|
||||
@@ -509,7 +509,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC> BlockImport<Block>
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC>
|
||||
impl<B, E, Block: BlockT<Hash=H256>, RA, PRA, SC>
|
||||
GrandpaBlockImport<B, E, Block, RA, PRA, SC>
|
||||
{
|
||||
pub(crate) fn new(
|
||||
@@ -559,7 +559,7 @@ where
|
||||
);
|
||||
|
||||
let justification = match justification {
|
||||
Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()),
|
||||
Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()),
|
||||
Ok(justification) => justification,
|
||||
};
|
||||
|
||||
@@ -579,17 +579,17 @@ where
|
||||
command {}, signaling voter.", number, command);
|
||||
|
||||
if let Err(e) = self.send_voter_commands.unbounded_send(command) {
|
||||
return Err(ConsensusErrorKind::ClientImport(e.to_string()).into());
|
||||
return Err(ConsensusError::ClientImport(e.to_string()).into());
|
||||
}
|
||||
},
|
||||
Err(CommandOrError::Error(e)) => {
|
||||
return Err(match e {
|
||||
Error::Grandpa(error) => ConsensusErrorKind::ClientImport(error.to_string()),
|
||||
Error::Network(error) => ConsensusErrorKind::ClientImport(error),
|
||||
Error::Blockchain(error) => ConsensusErrorKind::ClientImport(error),
|
||||
Error::Client(error) => ConsensusErrorKind::ClientImport(error.to_string()),
|
||||
Error::Safety(error) => ConsensusErrorKind::ClientImport(error),
|
||||
Error::Timer(error) => ConsensusErrorKind::ClientImport(error.to_string()),
|
||||
Error::Grandpa(error) => ConsensusError::ClientImport(error.to_string()),
|
||||
Error::Network(error) => ConsensusError::ClientImport(error),
|
||||
Error::Blockchain(error) => ConsensusError::ClientImport(error),
|
||||
Error::Client(error) => ConsensusError::ClientImport(error.to_string()),
|
||||
Error::Safety(error) => ConsensusError::ClientImport(error),
|
||||
Error::Timer(error) => ConsensusError::ClientImport(error.to_string()),
|
||||
}.into());
|
||||
},
|
||||
Ok(_) => {
|
||||
|
||||
@@ -441,7 +441,7 @@ fn register_finality_tracker_inherent_data_provider<B, E, Block: BlockT<Hash=H25
|
||||
},
|
||||
}
|
||||
}))
|
||||
.map_err(|err| consensus_common::ErrorKind::InherentData(err.into()).into())
|
||||
.map_err(|err| consensus_common::Error::InherentData(err.into()))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ use parity_codec::{Encode, Decode};
|
||||
use consensus_common::{
|
||||
import_queue::{Verifier, SharedFinalityProofRequestBuilder}, well_known_cache_keys,
|
||||
BlockOrigin, BlockImport, FinalityProofImport, ImportBlock, ImportResult, ImportedAux,
|
||||
Error as ConsensusError, ErrorKind as ConsensusErrorKind, FinalityProofRequestBuilder,
|
||||
Error as ConsensusError, FinalityProofRequestBuilder,
|
||||
};
|
||||
use runtime_primitives::Justification;
|
||||
use runtime_primitives::traits::{
|
||||
@@ -119,7 +119,9 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockImport<Block>
|
||||
block: ImportBlock<Block>,
|
||||
new_cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
) -> Result<ImportResult, Self::Error> {
|
||||
do_import_block::<_, _, _, _, GrandpaJustification<Block>>(&*self.client, &mut *self.data.write(), block, new_cache)
|
||||
do_import_block::<_, _, _, _, GrandpaJustification<Block>>(
|
||||
&*self.client, &mut *self.data.write(), block, new_cache
|
||||
)
|
||||
}
|
||||
|
||||
fn check_block(
|
||||
@@ -238,7 +240,7 @@ fn do_import_block<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
let mut imported_aux = match import_result {
|
||||
Ok(ImportResult::Imported(aux)) => aux,
|
||||
Ok(r) => return Ok(r),
|
||||
Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()),
|
||||
Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()),
|
||||
};
|
||||
|
||||
match justification {
|
||||
@@ -294,12 +296,13 @@ fn do_import_finality_proof<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
authorities,
|
||||
authority_set_provider,
|
||||
finality_proof,
|
||||
).map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?;
|
||||
).map_err(|e| ConsensusError::ClientImport(e.to_string()))?;
|
||||
|
||||
// try to import all new headers
|
||||
let block_origin = BlockOrigin::NetworkBroadcast;
|
||||
for header_to_import in finality_effects.headers_to_import {
|
||||
let (block_to_import, new_authorities) = verifier.verify(block_origin, header_to_import, None, None)?;
|
||||
let (block_to_import, new_authorities) = verifier.verify(block_origin, header_to_import, None, None)
|
||||
.map_err(|e| ConsensusError::ClientImport(e))?;
|
||||
assert!(block_to_import.justification.is_none(), "We have passed None as justification to verifier.verify");
|
||||
|
||||
let mut cache = HashMap::new();
|
||||
@@ -313,7 +316,7 @@ fn do_import_finality_proof<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
let finalized_block_hash = finality_effects.block;
|
||||
let finalized_block_number = client.backend().blockchain()
|
||||
.expect_block_number_from_id(&BlockId::Hash(finality_effects.block))
|
||||
.map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?;
|
||||
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?;
|
||||
do_finalize_block(
|
||||
client,
|
||||
data,
|
||||
@@ -383,7 +386,7 @@ fn do_import_justification<B, E, Block: BlockT<Hash=H256>, RA, J>(
|
||||
hash,
|
||||
);
|
||||
|
||||
return Err(ConsensusErrorKind::ClientImport(e.to_string()).into());
|
||||
return Err(ConsensusError::ClientImport(e.to_string()).into());
|
||||
},
|
||||
Ok(justification) => {
|
||||
trace!(
|
||||
@@ -417,7 +420,7 @@ fn do_finalize_block<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
// finalize the block
|
||||
client.finalize_block(BlockId::Hash(hash), Some(justification), true).map_err(|e| {
|
||||
warn!(target: "finality", "Error applying finality to block {:?}: {:?}", (hash, number), e);
|
||||
ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string()))
|
||||
ConsensusError::ClientImport(e.to_string())
|
||||
})?;
|
||||
|
||||
// forget obsoleted consensus changes
|
||||
@@ -513,7 +516,7 @@ fn require_insert_aux<T: Encode, B, E, Block: BlockT<Hash=H256>, RA>(
|
||||
fn on_post_finalization_error(error: ClientError, value_type: &str) -> ConsensusError {
|
||||
warn!(target: "finality", "Failed to write updated {} to disk. Bailing.", value_type);
|
||||
warn!(target: "finality", "Node is in a potentially inconsistent state.");
|
||||
ConsensusError::from(ConsensusErrorKind::ClientImport(error.to_string()))
|
||||
ConsensusError::ClientImport(error.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user