diff --git a/polkadot/node/network/availability-distribution/src/error.rs b/polkadot/node/network/availability-distribution/src/error.rs index d3ff182b33..764b2f6493 100644 --- a/polkadot/node/network/availability-distribution/src/error.rs +++ b/polkadot/node/network/availability-distribution/src/error.rs @@ -18,6 +18,7 @@ //! Error handling related code and Error/Result definitions. use polkadot_node_network_protocol::request_response::outgoing::RequestError; +use polkadot_primitives::v1::SessionIndex; use thiserror::Error; use futures::channel::oneshot; @@ -76,8 +77,8 @@ pub enum NonFatal { QueryAvailableDataResponseChannel(#[source] oneshot::Canceled), /// We tried accessing a session that was not cached. - #[error("Session is not cached.")] - NoSuchCachedSession, + #[error("Session {missing_session} is not cached, cached sessions: {available_sessions:?}.")] + NoSuchCachedSession { available_sessions: Vec, missing_session: SessionIndex }, /// Sending request response failed (Can happen on timeouts for example). #[error("Sending a request's response failed.")] @@ -120,7 +121,7 @@ pub fn log_error(result: Result<()>, ctx: &'static str) -> std::result::Result<( match error { NonFatal::UnexpectedPoV | NonFatal::InvalidValidatorIndex | - NonFatal::NoSuchCachedSession | + NonFatal::NoSuchCachedSession { .. } | NonFatal::QueryAvailableDataResponseChannel(_) | NonFatal::QueryChunkResponseChannel(_) => tracing::warn!(target: LOG_TARGET, error = %error, ctx), diff --git a/polkadot/node/network/availability-distribution/src/requester/session_cache.rs b/polkadot/node/network/availability-distribution/src/requester/session_cache.rs index 5b87d1dcf9..1dbab38cff 100644 --- a/polkadot/node/network/availability-distribution/src/requester/session_cache.rs +++ b/polkadot/node/network/availability-distribution/src/requester/session_cache.rs @@ -144,10 +144,13 @@ impl SessionCache { /// We assume validators in a group are tried in reverse order, so the reported bad validators /// will be put at the beginning of the group. pub fn report_bad(&mut self, report: BadValidators) -> crate::Result<()> { - let session = self - .session_info_cache - .get_mut(&report.session_index) - .ok_or(NonFatal::NoSuchCachedSession)?; + let available_sessions = self.session_info_cache.iter().map(|(k, _)| *k).collect(); + let session = self.session_info_cache.get_mut(&report.session_index).ok_or( + NonFatal::NoSuchCachedSession { + available_sessions, + missing_session: report.session_index, + }, + )?; let group = session.validator_groups.get_mut(report.group_index.0 as usize).expect( "A bad validator report must contain a valid group for the reported session. qed.", );