Skip to content

Commit

Permalink
feat(advance-runner): log tainted session reason
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstanley committed Aug 22, 2024
1 parent 72e340c commit 7ae488b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
56 changes: 54 additions & 2 deletions offchain/advance-runner/src/server_manager/facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl ServerManagerFacade {
) -> Result<Vec<RollupsOutput>> {
tracing::trace!("sending advance-state input to server-manager");

grpc_call!(self, advance_state, {
let response = grpc_call!(self, advance_state, {
let input_metadata = InputMetadata {
msg_sender: Some(Address {
data: (*input_metadata.msg_sender.inner()).into(),
Expand All @@ -197,7 +197,9 @@ impl ServerManagerFacade {
input_metadata: Some(input_metadata),
input_payload: input_payload.clone(),
}
})?;
});

self.handle_advance_state_error(response).await;

tracing::trace!("waiting until the input is processed");

Expand Down Expand Up @@ -271,6 +273,56 @@ impl ServerManagerFacade {
Ok(outputs)
}

/// Handle response to advance-state request
#[tracing::instrument(level = "trace", skip_all)]
async fn handle_advance_state_error(
&mut self,
response: Result<grpc_interfaces::cartesi_machine::Void>,
) {
// Capture server-manager error for advance-state request
// to try to get the reason for a possible tainted session error.
if response.is_err() {
match response.unwrap_err() {
ServerManagerError::MethodCallError {
method: _,
request_id: _,
source,
} => {
// Original error message to be reported by default.
let mut message = source.message().to_string();
// The server-manager signals with code Dataloss when the session has been previously tainted.
if source.code() == tonic::Code::DataLoss {
// Recover the tainted session reason from the session's status.
// If not available, log the original error message.
let status_response = grpc_call!(
self,
get_session_status,
GetSessionStatusRequest {
session_id: self.config.session_id.clone(),
}
);

if status_response.is_err() {
match status_response.unwrap_err() {
ServerManagerError::MethodCallError {
method: _,
request_id: _,
source,
} => {
message = format!("Server manager session was tainted: {} ({})", source.code(), source.message());
}
_ => {}
}
} else {
}
}
tracing::error!(message);
}
_ => {}
}
}
}

/// Send a finish-epoch request to the server-manager
/// Return the epoch claim and the proofs
#[tracing::instrument(level = "trace", skip_all)]
Expand Down
2 changes: 1 addition & 1 deletion offchain/advance-runner/tests/host_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async fn advance_runner_fails_when_inputs_has_wrong_epoch() {

tracing::info!("waiting for the advance_runner to exit with error");
let err = state.advance_runner.wait_err().await;
assert!(format!("{:?}", err).contains("incorrect active epoch index"));
assert!(format!("{:?}", err).contains("unknown epoch index"));
}

#[test_log::test(tokio::test)]
Expand Down

0 comments on commit 7ae488b

Please sign in to comment.