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 state missing for chosen mapping block #3252

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: 15 additions & 4 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,18 +630,29 @@ where
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
// If the user chooses an object mapping start block we don't have data or state 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 Some(best_block_data) = client.block(best_block_to_archive_hash)? else {
let error = format!(
"Missing data for mapping block {best_block_to_archive} hash {best_block_to_archive_hash},\
"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()));
}
};

// Similarly, state can be pruned, even if the data is present.
client
.runtime_api()
.extract_block_object_mapping(*best_block_data.block.header().parent_hash(), best_block_data.block.clone())
Copy link
Member

Choose a reason for hiding this comment

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

We already have hash conveniently stored in a variable, no need to re-calculate it again:

Suggested change
.extract_block_object_mapping(*best_block_data.block.header().parent_hash(), best_block_data.block.clone())
.extract_block_object_mapping(best_block_to_archive_hash, best_block_data.block.clone())

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically it’s the hash if the block itself, not the parent block hash?
But in this case, if we haven’t pruned the parent block, we definitely haven’t pruned the block itself.

Copy link
Member

Choose a reason for hiding this comment

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

I see, I was not reading it correct and you're correct that this change is not equivalent.

.map_err(|error| {
sp_blockchain::Error::Application(
format!("Missing state for mapping block {best_block_to_archive} hash {best_block_to_archive_hash}: {error}, \
try a higher block number, or wipe your node and restart with `--sync full`").into(),
)
})?;

let maybe_last_archived_block = find_last_archived_block(
client,
Expand Down
Loading