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

* Add a new host function for reporting fatal errors

* Fix one of the wasmtime executor tests

* Have `#[runtime_interface(wasm_only)]` actually mean WASM-only, and not no_std-only

* Print out errors through `Display` instead of `Debug`

* Switch one more trait to require `Error` for its error instead of only `Debug`

* Align to review comments
This commit is contained in:
Koute
2022-02-09 18:12:55 +09:00
committed by GitHub
parent bd261d57c4
commit 9a31b2c341
68 changed files with 554 additions and 249 deletions
@@ -100,7 +100,7 @@ where
// previously we only supported at most one pending change per fork
&|_, _| Ok(false),
) {
warn!(target: "afg", "Error migrating pending authority set change: {:?}.", err);
warn!(target: "afg", "Error migrating pending authority set change: {}", err);
warn!(target: "afg", "Node is in a potentially inconsistent state.");
}
}
@@ -609,7 +609,7 @@ where
let tree_route = match tree_route_res {
Ok(tree_route) => tree_route,
Err(e) => {
debug!(target: "afg", "Encountered error computing ancestry between block {:?} and base {:?}: {:?}",
debug!(target: "afg", "Encountered error computing ancestry between block {:?} and base {:?}: {}",
block, base, e);
return Err(GrandpaError::NotDescendent)
@@ -1098,7 +1098,7 @@ where
) {
warn!(target: "afg", "Detected prevote equivocation in the finality worker: {:?}", equivocation);
if let Err(err) = self.report_equivocation(equivocation.into()) {
warn!(target: "afg", "Error reporting prevote equivocation: {:?}", err);
warn!(target: "afg", "Error reporting prevote equivocation: {}", err);
}
}
@@ -1109,7 +1109,7 @@ where
) {
warn!(target: "afg", "Detected precommit equivocation in the finality worker: {:?}", equivocation);
if let Err(err) = self.report_equivocation(equivocation.into()) {
warn!(target: "afg", "Error reporting precommit equivocation: {:?}", err);
warn!(target: "afg", "Error reporting precommit equivocation: {}", err);
}
}
}
@@ -1224,7 +1224,7 @@ where
.or_else(|| Some((target_header.hash(), *target_header.number())))
},
Err(e) => {
warn!(target: "afg", "Encountered error finding best chain containing {:?}: {:?}", block, e);
warn!(target: "afg", "Encountered error finding best chain containing {:?}: {}", block, e);
None
},
};
@@ -1293,7 +1293,7 @@ where
) {
if let Some(sender) = justification_sender {
if let Err(err) = sender.notify(justification) {
warn!(target: "afg", "Error creating justification for subscriber: {:?}", err);
warn!(target: "afg", "Error creating justification for subscriber: {}", err);
}
}
}
@@ -1344,7 +1344,7 @@ where
client
.apply_finality(import_op, BlockId::Hash(hash), persisted_justification, true)
.map_err(|e| {
warn!(target: "afg", "Error applying finality to block {:?}: {:?}", (hash, number), e);
warn!(target: "afg", "Error applying finality to block {:?}: {}", (hash, number), e);
e
})?;
@@ -598,7 +598,7 @@ where
Err(e) => {
debug!(
target: "afg",
"Restoring old authority set after block import error: {:?}",
"Restoring old authority set after block import error: {}",
e,
);
pending_changes.revert();
@@ -663,8 +663,12 @@ where
import_res.unwrap_or_else(|err| {
if needs_justification {
debug!(target: "afg", "Imported block #{} that enacts authority set change with \
invalid justification: {:?}, requesting justification from peers.", number, err);
debug!(
target: "afg",
"Requesting justification from peers due to imported block #{} that enacts authority set change with invalid justification: {}",
number,
err
);
imported_aux.bad_justification = true;
imported_aux.needs_justification = true;
}
+19 -4
View File
@@ -275,23 +275,38 @@ impl Config {
}
/// Errors that can occur while voting in GRANDPA.
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// An error within grandpa.
#[error("grandpa error: {0}")]
Grandpa(GrandpaError),
/// A network error.
#[error("network error: {0}")]
Network(String),
/// A blockchain error.
#[error("blockchain error: {0}")]
Blockchain(String),
/// Could not complete a round on disk.
#[error("could not complete a round on disk: {0}")]
Client(ClientError),
/// Could not sign outgoing message
#[error("could not sign outgoing message: {0}")]
Signing(String),
/// An invariant has been violated (e.g. not finalizing pending change blocks in-order)
#[error("safety invariant has been violated: {0}")]
Safety(String),
/// A timer failed to fire.
#[error("a timer failed to fire: {0}")]
Timer(io::Error),
/// A runtime api request failed.
#[error("runtime API request failed: {0}")]
RuntimeApi(sp_api::ApiError),
}
@@ -322,7 +337,7 @@ where
{
fn block_number(&self, hash: Block::Hash) -> Result<Option<NumberFor<Block>>, Error> {
self.block_number_from_id(&BlockId::Hash(hash))
.map_err(|e| Error::Blockchain(format!("{:?}", e)))
.map_err(|e| Error::Blockchain(e.to_string()))
}
}
@@ -459,7 +474,7 @@ impl<H: fmt::Debug, N: fmt::Debug> ::std::error::Error for CommandOrError<H, N>
impl<H, N> fmt::Display for CommandOrError<H, N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
CommandOrError::Error(ref e) => write!(f, "{:?}", e),
CommandOrError::Error(ref e) => write!(f, "{}", e),
CommandOrError::VoterCommand(ref cmd) => write!(f, "{}", cmd),
}
}
@@ -838,7 +853,7 @@ where
Ok(()) => error!(target: "afg",
"GRANDPA voter future has concluded naturally, this should be unreachable."
),
Err(e) => error!(target: "afg", "GRANDPA voter error: {:?}", e),
Err(e) => error!(target: "afg", "GRANDPA voter error: {}", e),
});
// Make sure that `telemetry_task` doesn't accidentally finish and kill grandpa.
@@ -203,7 +203,7 @@ where
);
let observer_work = observer_work.map_ok(|_| ()).map_err(|e| {
warn!("GRANDPA Observer failed: {:?}", e);
warn!("GRANDPA Observer failed: {}", e);
});
Ok(observer_work.map(drop))