Skip to content

Commit

Permalink
Exit with an error if mappings can’t be created for the chosen block
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 24, 2024
1 parent aff971e commit 5e69ad1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@ 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() {
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);
}

if (best_block_to_archive..best_block_number)
Expand All @@ -622,6 +624,19 @@ 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
// 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

0 comments on commit 5e69ad1

Please sign in to comment.