Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit with an error if mappings can’t be created for the chosen block #3242

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from all 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
19 changes: 17 additions & 2 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,18 +610,33 @@ where
// If there is no path to this block from the tip due to snap sync, we'll start archiving from
// an earlier segment, then start mapping again once archiving reaches this block.
if let Some(block_number) = create_object_mappings.block() {
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
best_block_to_archive = best_block_to_archive.min(block_number);
// There aren't any mappings in the genesis block, so starting there is pointless.
// (And causes errors on restart, because genesis block data is never stored during snap sync.)
best_block_to_archive = best_block_to_archive.min(block_number).max(1);
Comment on lines +613 to +615
Copy link
Member

Choose a reason for hiding this comment

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

Block is already constrained to be non-zero in create_object_mappings, so not sure how much this is actually needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it’s still possible due to the saturating subtraction, see my comments in this thread:
#3242 (comment)

I'll follow up with a PR for the state check.

}

if (best_block_to_archive..best_block_number)
.any(|block_number| client.hash(block_number.into()).ok().flatten().is_none())
{
// If there are blocks missing blocks between best block to archive and best block of the
// If there are blocks missing headers between best block to archive and best block of the
// blockchain it means newer block was inserted in some special way and as such is by
// definition valid, so we can simply assume that is our best block to archive instead
best_block_to_archive = best_block_number;
}

// If the user chooses an object mapping start block we don't have the data for, we can't
// create mappings for it, so the node must exit with an error.
let best_block_to_archive_hash = client
.hash(best_block_to_archive.into())?
.expect("just checked above; qed");
if client.block(best_block_to_archive_hash)?.is_none() {
let error = format!(
"Missing data for mapping block {best_block_to_archive} hash {best_block_to_archive_hash},\
try a higher block number, or wipe your node and restart with `--sync full`"
);
return Err(sp_blockchain::Error::Application(error.into()));
}

let maybe_last_archived_block = find_last_archived_block(
client,
segment_headers_store,
Expand Down
Loading