Skip to content

Commit

Permalink
Fix fresh node start with Snap sync failing
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Nov 28, 2024
1 parent f4a19dd commit 7ea92de
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,28 +631,38 @@ where
}

// 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");
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}, \
try a higher block number, or wipe your node and restart with `--sync full`"
// create mappings for it, so the node must exit with an error
if create_object_mappings.is_enabled() {
let best_block_to_archive_hash = client
.hash(best_block_to_archive.into())?
.expect("just checked above; qed");
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}, try a higher block number, or wipe your node and \
restart with `--sync full`"
);
return Err(sp_blockchain::Error::Application(error.into()));
};
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())
// 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(),
)
.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(),
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

0 comments on commit 7ea92de

Please sign in to comment.