From 7ae488b2951b12b2b8b31c4a4a2b93782b86f3db Mon Sep 17 00:00:00 2001 From: Marcel Moura <5615598+marcelstanley@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:32:31 -0300 Subject: [PATCH] feat(advance-runner): log tainted session reason --- .../src/server_manager/facade.rs | 56 ++++++++++++++++++- .../advance-runner/tests/host_integration.rs | 2 +- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/offchain/advance-runner/src/server_manager/facade.rs b/offchain/advance-runner/src/server_manager/facade.rs index c37375635..8596cdbdd 100644 --- a/offchain/advance-runner/src/server_manager/facade.rs +++ b/offchain/advance-runner/src/server_manager/facade.rs @@ -180,7 +180,7 @@ impl ServerManagerFacade { ) -> Result> { 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(), @@ -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"); @@ -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, + ) { + // 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)] diff --git a/offchain/advance-runner/tests/host_integration.rs b/offchain/advance-runner/tests/host_integration.rs index 2604c3078..c1c090a07 100644 --- a/offchain/advance-runner/tests/host_integration.rs +++ b/offchain/advance-runner/tests/host_integration.rs @@ -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)]