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

Check if approval voting db is empty on startup #6219

Merged
merged 3 commits into from
Oct 31, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 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,26 @@ 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 backend = OverlayedBackend::new(&backend);
sandreim marked this conversation as resolved.
Show resolved Hide resolved
let all_blocks = backend.load_all_blocks()?;
eskimor marked this conversation as resolved.
Show resolved Hide resolved

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 +752,10 @@ async fn run<B, Context>(
where
B: Backend,
{
if let Err(err) = db_sanity_check(subsystem.db, subsystem.db_config) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bail in case we can't read from the db?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could so that, it also happens later if not here.

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