From 0bc8fddc19a628fd304a170c6a5f3c1cdd771b72 Mon Sep 17 00:00:00 2001 From: Andrei Sandu <54316454+sandreim@users.noreply.github.com> Date: Mon, 31 Oct 2022 20:57:50 +0100 Subject: [PATCH] Check if approval voting db is empty on startup (#6219) * Add approval voting db sanity check Signed-off-by: Andrei Sandu * add newline back Signed-off-by: Andrei Sandu * no need for overlay to read Signed-off-by: Andrei Sandu Signed-off-by: Andrei Sandu --- node/core/approval-voting/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/node/core/approval-voting/src/lib.rs b/node/core/approval-voting/src/lib.rs index cff420fa46b6..e9757071f15e 100644 --- a/node/core/approval-voting/src/lib.rs +++ b/node/core/approval-voting/src/lib.rs @@ -378,6 +378,25 @@ impl ApprovalVotingSubsystem { } } +// Checks and logs approval vote db state. It is perfectly normal to start with an +// empty approval vote DB if we changed DB type or the node will sync from scratch. +fn db_sanity_check(db: Arc, config: DatabaseConfig) -> SubsystemResult<()> { + let backend = DbBackend::new(db, config); + let all_blocks = backend.load_all_blocks()?; + + if all_blocks.is_empty() { + gum::info!(target: LOG_TARGET, "Starting with an empty approval vote DB.",); + } else { + gum::debug!( + target: LOG_TARGET, + "Starting with {} blocks in approval vote DB.", + all_blocks.len() + ); + } + + Ok(()) +} + #[overseer::subsystem(ApprovalVoting, error = SubsystemError, prefix = self::overseer)] impl ApprovalVotingSubsystem { fn start(self, ctx: Context) -> SpawnedSubsystem { @@ -732,6 +751,10 @@ async fn run( where B: Backend, { + if let Err(err) = db_sanity_check(subsystem.db, subsystem.db_config) { + gum::warn!(target: LOG_TARGET, ?err, "Could not run approval vote DB sanity check"); + } + let mut state = State { session_window: None, keystore: subsystem.keystore,