Better error for spurious cache misses. (#4669)

Happened on Kusama for some not yet known reason.
This commit is contained in:
Robert Klotzner
2022-01-07 11:23:20 +01:00
committed by GitHub
parent c805500dfb
commit 2f1643b430
2 changed files with 11 additions and 7 deletions
@@ -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<SessionIndex>, 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),
@@ -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.",
);