Skip to content

Commit

Permalink
Merge pull request #4386 from oasisprotocol/kostko/fix/rt-propagate-t…
Browse files Browse the repository at this point in the history
…x-panics

runtime: Propagate panics during transaction/local RPC/policy dispatch
  • Loading branch information
kostko authored Dec 3, 2021
2 parents 9816de7 + 8fc7e21 commit c660d0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changelog/4386.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runtime: Propagate panics during transaction/local RPC/policy dispatch

A panic during transaction/local RPC/policy dispatch signals a serious
problem so it should be propagated and the runtime should crash to force
state reset.
18 changes: 16 additions & 2 deletions runtime/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ impl Dispatcher {
inputs: TxnBatch,
state: TxDispatchState,
) -> Result<Body, Error> {
// Make sure to abort the process on panic during transaction processing as that indicates
// a serious problem and should make sure to clean up the process.
let _guard = AbortOnPanic;

debug!(self.logger, "Received transaction batch request";
"state_root" => ?state.header.state_root,
"round" => state.header.round + 1,
Expand Down Expand Up @@ -721,7 +725,8 @@ impl Dispatcher {
)
}
})
.await?
.await
.unwrap() // Propagate panics during transaction dispatch.
}

async fn dispatch_rpc(
Expand Down Expand Up @@ -841,6 +846,10 @@ impl Dispatcher {
ctx: Context,
request: Vec<u8>,
) -> Result<Body, Error> {
// Make sure to abort the process on panic during local RPC processing as that indicates a
// serious problem and should make sure to clean up the process.
let _guard = AbortOnPanic;

debug!(self.logger, "Received local RPC call request");

let req: RpcRequest = cbor::from_slice(&request)
Expand Down Expand Up @@ -869,7 +878,8 @@ impl Dispatcher {
let response = cbor::to_vec(response);
Ok(Body::RuntimeLocalRPCCallResponse { response })
})
.await?
.await
.unwrap() // Propagate panics during local RPC dispatch.
}

fn handle_km_policy_update(
Expand All @@ -878,6 +888,10 @@ impl Dispatcher {
_ctx: Context,
signed_policy_raw: Vec<u8>,
) -> Result<Body, Error> {
// Make sure to abort the process on panic during policy processing as that indicates a
// serious problem and should make sure to clean up the process.
let _guard = AbortOnPanic;

debug!(self.logger, "Received km policy update request");
rpc_dispatcher.handle_km_policy_update(signed_policy_raw);
debug!(self.logger, "KM policy update request complete");
Expand Down

0 comments on commit c660d0c

Please sign in to comment.