Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Check if approval voting db is empty on startup (#6219)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
sandreim authored Oct 31, 2022
1 parent 5d05f2a commit 0bc8fdd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0bc8fdd

Please sign in to comment.