From 384f5fe9448ab354524841bda1268b898e42c3ac 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 ++++++++++++++++++- offchain/inspect-server/src/inspect.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/inspect-server/src/inspect.rs b/offchain/inspect-server/src/inspect.rs index 8948d5c0d..f1d5e85a3 100644 --- a/offchain/inspect-server/src/inspect.rs +++ b/offchain/inspect-server/src/inspect.rs @@ -79,7 +79,7 @@ async fn handle_inspect( let endpoint = format!("http://{}", address); while let Some(request) = inspect_rx.recv().await { match ServerManagerClient::connect(endpoint.clone()).await { - Err(e) => { +v Err(e) => { respond( request.response_tx, Err(InspectError::FailedToConnect {