From 06cac8034d96d1292615bfcfb6b6a531499de2ba Mon Sep 17 00:00:00 2001 From: Marcel Moura <5615598+marcelstanley@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:28:06 -0300 Subject: [PATCH] fixup! feat(advance-runner): log tainted session reason --- .../src/server_manager/facade.rs | 57 +++++++++++++++---- .../advance-runner/tests/host_integration.rs | 2 +- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/offchain/advance-runner/src/server_manager/facade.rs b/offchain/advance-runner/src/server_manager/facade.rs index 8596cdbdd..5ebe0bcc0 100644 --- a/offchain/advance-runner/src/server_manager/facade.rs +++ b/offchain/advance-runner/src/server_manager/facade.rs @@ -199,7 +199,7 @@ impl ServerManagerFacade { } }); - self.handle_advance_state_error(response).await; + self.handle_advance_state_error(response).await?; tracing::trace!("waiting until the input is processed"); @@ -278,14 +278,18 @@ impl ServerManagerFacade { 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() { + ) -> Result<()> { + if response.is_ok() { + Ok(()) + } else { + // Capture server-manager error for advance-state request + // to try to get the reason for a possible tainted session error. + let err = response.unwrap_err(); + + let err: ServerManagerError = match err { ServerManagerError::MethodCallError { - method: _, - request_id: _, + method, + request_id, source, } => { // Original error message to be reported by default. @@ -309,17 +313,34 @@ impl ServerManagerFacade { request_id: _, source, } => { - message = format!("Server manager session was tainted: {} ({})", source.code(), source.message()); + tracing::error!( + "get-session-status error: {:?}", + source.message() + ); } _ => {} } } else { + let status_response = status_response.unwrap(); + let taint_status = + status_response.taint_status.clone(); + if let Some(taint_status) = taint_status { + message = format!("Server manager session was tainted: {} ({})", + taint_status.error_code, + taint_status.error_message); + tracing::error!(message); + } } } - tracing::error!(message); + ServerManagerError::MethodCallError { + method, + request_id, + source: tonic::Status::new(source.code(), message), + } } - _ => {} - } + _ => err, + }; + Err(err) } } @@ -421,3 +442,15 @@ impl ServerManagerFacade { Err(ServerManagerError::PendingInputsExceededError {}) } } + +#[tracing::instrument(level = "trace", skip_all)] +fn get_advance_state_error_message(err: &ServerManagerError) -> Option { + match err { + ServerManagerError::MethodCallError { + method: _, + request_id: _, + source, + } => Some(source.message().to_string()), + _ => None, + } +} diff --git a/offchain/advance-runner/tests/host_integration.rs b/offchain/advance-runner/tests/host_integration.rs index c1c090a07..2604c3078 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("unknown epoch index")); + assert!(format!("{:?}", err).contains("incorrect active epoch index")); } #[test_log::test(tokio::test)]