Check if approval voting db is empty on startup (#6219)

* Add approval voting db sanity check

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* add newline back

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

* no need for overlay to read

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
Andrei Sandu
2022-10-31 20:57:50 +01:00
committed by GitHub
parent d02d58de40
commit 351d37e324
@@ -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<dyn Database>, 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<Context: Send> ApprovalVotingSubsystem {
fn start(self, ctx: Context) -> SpawnedSubsystem {
@@ -732,6 +751,10 @@ async fn run<B, Context>(
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,