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,