Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a new host function for reporting fatal errors; make WASM backtraces readable when printing out errors #10741

Merged
2 changes: 1 addition & 1 deletion client/authority-discovery/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Error {
#[error("Failed to hash the authority id to be used as a dht key.")]
HashingAuthorityId(#[from] libp2p::core::multiaddr::multihash::Error),

#[error("Failed calling into the Substrate runtime.")]
#[error("Failed calling into the Substrate runtime: {0}")]
CallingRuntime(#[from] sp_blockchain::Error),

#[error("Received a dht record with a key that does not match any in-flight awaited keys.")]
Expand Down
8 changes: 4 additions & 4 deletions client/authority-discovery/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ where
Some(registry) => match Metrics::register(&registry) {
Ok(metrics) => Some(metrics),
Err(e) => {
error!(target: LOG_TARGET, "Failed to register metrics: {:?}", e);
error!(target: LOG_TARGET, "Failed to register metrics: {}", e);
None
},
},
Expand Down Expand Up @@ -242,7 +242,7 @@ where
if let Err(e) = self.publish_ext_addresses(only_if_changed).await {
error!(
target: LOG_TARGET,
"Failed to publish external addresses: {:?}", e,
"Failed to publish external addresses: {}", e,
);
}
},
Expand All @@ -251,7 +251,7 @@ where
if let Err(e) = self.refill_pending_lookups_queue().await {
error!(
target: LOG_TARGET,
"Failed to request addresses of authorities: {:?}", e,
"Failed to request addresses of authorities: {}", e,
);
}
},
Expand Down Expand Up @@ -426,7 +426,7 @@ where
metrics.handle_value_found_event_failure.inc();
}

debug!(target: LOG_TARGET, "Failed to handle Dht value found event: {:?}", e);
debug!(target: LOG_TARGET, "Failed to handle Dht value found event: {}", e);
}
},
DhtEvent::ValueNotFound(hash) => {
Expand Down
2 changes: 1 addition & 1 deletion client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ where
.expect("forwards closure result; the closure always returns Ok; qed.");
}
}) {
error!(target: "beefy", "🥩 Failed to get hash for block number {}; err: {:?}",
error!(target: "beefy", "🥩 Failed to get hash for block number {}: {}",
block_num, err);
}

Expand Down
4 changes: 2 additions & 2 deletions client/consensus/aura/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ where
let hash = block.header.hash();
let parent_hash = *block.header.parent_hash();
let authorities = authorities(self.client.as_ref(), &BlockId::Hash(parent_hash))
.map_err(|e| format!("Could not fetch authorities at {:?}: {:?}", parent_hash, e))?;
.map_err(|e| format!("Could not fetch authorities at {:?}: {}", parent_hash, e))?;

let create_inherent_data_providers = self
.create_inherent_data_providers
Expand Down Expand Up @@ -249,7 +249,7 @@ where
&BlockId::Hash(parent_hash),
|v| v >= 2,
)
.map_err(|e| format!("{:?}", e))?
.map_err(|e| e.to_string())?
{
self.check_inherents(
new_block.clone(),
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/babe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
let epoch_start = client
.runtime_api()
.current_epoch_start(&BlockId::Hash(header.hash()))
.map_err(|err| Error::StringError(format!("{:?}", err)))?;
.map_err(|err| Error::StringError(err.to_string()))?;
let epoch =
epoch_data(&shared_epoch, &client, &babe_config, *epoch_start, &select_chain)
.await?;
Expand Down Expand Up @@ -209,7 +209,7 @@ where
slot.into(),
|slot| Epoch::genesis(&babe_config, slot),
)
.map_err(|e| Error::Consensus(ConsensusError::ChainLookup(format!("{:?}", e))))?
.map_err(|e| Error::Consensus(ConsensusError::ChainLookup(e.to_string())))?
.ok_or(Error::Consensus(ConsensusError::InvalidAuthoritiesSet))
}

Expand Down
18 changes: 9 additions & 9 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub enum Error<B: BlockT> {
#[error("Multiple BABE config change digests, rejecting!")]
MultipleConfigChangeDigests,
/// Could not extract timestamp and slot
#[error("Could not extract timestamp and slot: {0:?}")]
#[error("Could not extract timestamp and slot: {0}")]
Extraction(sp_consensus::Error),
/// Could not fetch epoch
#[error("Could not fetch epoch at {0:?}")]
Expand Down Expand Up @@ -274,7 +274,7 @@ pub enum Error<B: BlockT> {
#[error("VRF verification failed: {0:?}")]
VRFVerificationFailed(SignatureError),
/// Could not fetch parent header
#[error("Could not fetch parent header: {0:?}")]
#[error("Could not fetch parent header: {0}")]
FetchParentHeader(sp_blockchain::Error),
/// Expected epoch change to happen.
#[error("Expected epoch change to happen at {0:?}, s{1}")]
Expand Down Expand Up @@ -713,7 +713,7 @@ where
parent.number().clone(),
slot,
)
.map_err(|e| ConsensusError::ChainLookup(format!("{:?}", e)))?
.map_err(|e| ConsensusError::ChainLookup(e.to_string()))?
.ok_or(sp_consensus::Error::InvalidAuthoritiesSet)
}

Expand Down Expand Up @@ -1201,7 +1201,7 @@ where
)
.await
{
warn!(target: "babe", "Error checking/reporting BABE equivocation: {:?}", err);
warn!(target: "babe", "Error checking/reporting BABE equivocation: {}", err);
}

// if the body is passed through, we need to use the runtime
Expand Down Expand Up @@ -1551,15 +1551,15 @@ where
)
.map_err(|e| {
ConsensusError::ClientImport(format!(
"Error importing epoch changes: {:?}",
"Error importing epoch changes: {}",
e
))
})?;
Ok(())
};

if let Err(e) = prune_and_import() {
debug!(target: "babe", "Failed to launch next epoch: {:?}", e);
debug!(target: "babe", "Failed to launch next epoch: {}", e);
*epoch_changes =
old_epoch_changes.expect("set `Some` above and not taken; qed");
return Err(e)
Expand Down Expand Up @@ -1590,7 +1590,7 @@ where
parent_weight
} else {
aux_schema::load_block_weight(&*self.client, last_best)
.map_err(|e| ConsensusError::ChainLookup(format!("{:?}", e)))?
.map_err(|e| ConsensusError::ChainLookup(e.to_string()))?
.ok_or_else(|| {
ConsensusError::ChainLookup(
"No block weight for parent header.".to_string(),
Expand Down Expand Up @@ -1649,7 +1649,7 @@ where
let finalized_slot = {
let finalized_header = client
.header(BlockId::Hash(info.finalized_hash))
.map_err(|e| ConsensusError::ClientImport(format!("{:?}", e)))?
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?
.expect(
"best finalized hash was given by client; finalized headers must exist in db; qed",
);
Expand All @@ -1666,7 +1666,7 @@ where
info.finalized_number,
finalized_slot,
)
.map_err(|e| ConsensusError::ClientImport(format!("{:?}", e)))?;
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?;

Ok(())
}
Expand Down
17 changes: 15 additions & 2 deletions client/consensus/common/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,34 @@ pub enum BlockImportStatus<N: std::fmt::Debug + PartialEq> {
}

/// Block import error.
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum BlockImportError {
/// Block missed header, can't be imported
#[error("block is missing a header (origin = {0:?})")]
IncompleteHeader(Option<Origin>),

/// Block verification failed, can't be imported
#[error("block verification failed (origin = {0:?}): {1}")]
VerificationFailed(Option<Origin>, String),

/// Block is known to be Bad
#[error("bad block (origin = {0:?})")]
BadBlock(Option<Origin>),

/// Parent state is missing.
#[error("block is missing parent state")]
MissingState,

/// Block has an unknown parent
#[error("block has an unknown parent")]
UnknownParent,

/// Block import has been cancelled. This can happen if the parent block fails to be imported.
#[error("import has been cancelled")]
Cancelled,

/// Other error.
#[error("consensus error: {0}")]
Other(ConsensusError),
}

Expand Down Expand Up @@ -245,7 +258,7 @@ pub(crate) async fn import_single_block_metered<
Err(BlockImportError::BadBlock(peer.clone()))
},
Err(e) => {
debug!(target: "sync", "Error importing block {}: {:?}: {:?}", number, hash, e);
debug!(target: "sync", "Error importing block {}: {:?}: {}", number, hash, e);
Err(BlockImportError::Other(e))
},
};
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/common/src/import_queue/basic_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ impl<B: BlockT> BlockImportWorker<B> {
.map_err(|e| {
debug!(
target: "sync",
"Justification import failed with {:?} for hash: {:?} number: {:?} coming from node: {:?}",
e,
"Justification import failed for hash = {:?} with number = {:?} coming from node = {:?} with error: {}",
hash,
number,
who,
e,
);
e
})
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/manual-seal/src/consensus/babe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ where
pre_digest.slot(),
)
.map_err(|e| format!("failed to fetch epoch_descriptor: {}", e))?
.ok_or_else(|| format!("{:?}", sp_consensus::Error::InvalidAuthoritiesSet))?;
.ok_or_else(|| format!("{}", sp_consensus::Error::InvalidAuthoritiesSet))?;
// drop the lock
drop(epoch_changes);

Expand Down
2 changes: 1 addition & 1 deletion client/consensus/manual-seal/src/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where

match finalizer.finalize_block(BlockId::Hash(hash), justification, true) {
Err(e) => {
log::warn!("Failed to finalize block {:?}", e);
log::warn!("Failed to finalize block {}", e);
rpc::send_result(&mut sender, Err(e.into()))
},
Ok(()) => {
Expand Down
5 changes: 4 additions & 1 deletion client/consensus/manual-seal/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ pub fn send_result<T: std::fmt::Debug>(
) {
if let Some(sender) = sender.take() {
if let Err(err) = sender.send(result) {
log::warn!("Server is shutting down: {:?}", err)
match err {
Ok(value) => log::warn!("Server is shutting down: {:?}", value),
Err(error) => log::warn!("Server is shutting down with error: {}", error),
}
}
} else {
// instant seal doesn't report errors over rpc, simply log them.
Expand Down
7 changes: 2 additions & 5 deletions client/consensus/manual-seal/src/seal_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP>(

let inherent_data = inherent_data_providers.create_inherent_data()?;

let proposer = env
.init(&parent)
.map_err(|err| Error::StringError(format!("{:?}", err)))
.await?;
let proposer = env.init(&parent).map_err(|err| Error::StringError(err.to_string())).await?;
let inherents_len = inherent_data.len();

let digest = if let Some(digest_provider) = digest_provider {
Expand All @@ -133,7 +130,7 @@ pub async fn seal_block<B, BI, SC, C, E, TP, CIDP>(
Duration::from_secs(MAX_PROPOSAL_DURATION),
None,
)
.map_err(|err| Error::StringError(format!("{:?}", err)))
.map_err(|err| Error::StringError(err.to_string()))
.await?;

if proposal.block.extrinsics().len() == inherents_len && !create_empty {
Expand Down
24 changes: 12 additions & 12 deletions client/consensus/pow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,24 @@ pub enum Error<B: BlockT> {
FailedPreliminaryVerify,
#[error("Rejecting block too far in future")]
TooFarInFuture,
#[error("Fetching best header failed using select chain: {0:?}")]
#[error("Fetching best header failed using select chain: {0}")]
BestHeaderSelectChain(ConsensusError),
#[error("Fetching best header failed: {0:?}")]
#[error("Fetching best header failed: {0}")]
BestHeader(sp_blockchain::Error),
#[error("Best header does not exist")]
NoBestHeader,
#[error("Block proposing error: {0:?}")]
#[error("Block proposing error: {0}")]
BlockProposingError(String),
#[error("Fetch best hash failed via select chain: {0:?}")]
#[error("Fetch best hash failed via select chain: {0}")]
BestHashSelectChain(ConsensusError),
#[error("Error with block built on {0:?}: {1:?}")]
#[error("Error with block built on {0:?}: {1}")]
BlockBuiltError(B::Hash, ConsensusError),
#[error("Creating inherents failed: {0}")]
CreateInherents(sp_inherents::Error),
#[error("Checking inherents failed: {0}")]
CheckInherents(sp_inherents::Error),
#[error(
"Checking inherents unknown error for identifier: {:?}",
"Checking inherents unknown error for identifier: {}",
String::from_utf8_lossy(.0)
)]
CheckInherentsUnknownError(sp_inherents::InherentIdentifier),
Expand Down Expand Up @@ -350,7 +350,7 @@ where
.select_chain
.best_chain()
.await
.map_err(|e| format!("Fetch best chain failed via select chain: {:?}", e))?;
.map_err(|e| format!("Fetch best chain failed via select chain: {}", e))?;
let best_hash = best_header.hash();

let parent_hash = *block.header.parent_hash();
Expand Down Expand Up @@ -565,7 +565,7 @@ where
warn!(
target: "pow",
"Unable to pull new block for authoring. \
Select best chain error: {:?}",
Select best chain error: {}",
err
);
continue
Expand Down Expand Up @@ -596,7 +596,7 @@ where
warn!(
target: "pow",
"Unable to propose new block for authoring. \
Fetch difficulty failed: {:?}",
Fetch difficulty failed: {}",
err,
);
continue
Expand All @@ -612,7 +612,7 @@ where
warn!(
target: "pow",
"Unable to propose new block for authoring. \
Creating inherent data providers failed: {:?}",
Creating inherent data providers failed: {}",
err,
);
continue
Expand All @@ -625,7 +625,7 @@ where
warn!(
target: "pow",
"Unable to propose new block for authoring. \
Creating inherent data failed: {:?}",
Creating inherent data failed: {}",
e,
);
continue
Expand Down Expand Up @@ -661,7 +661,7 @@ where
warn!(
target: "pow",
"Unable to propose new block for authoring. \
Creating proposal failed: {:?}",
Creating proposal failed: {}",
err,
);
continue
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/pow/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ where
Err(err) => {
warn!(
target: "pow",
"Unable to import mined block: {:?}",
"Unable to import mined block: {}",
err,
);
return false
Expand Down Expand Up @@ -238,7 +238,7 @@ where
Err(err) => {
warn!(
target: "pow",
"Unable to import mined block: {:?}",
"Unable to import mined block: {}",
err,
);
false
Expand Down
Loading