From 7ea92dee255517b57ae6b188d15ba7fc05b510d3 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Thu, 28 Nov 2024 06:06:00 +0200 Subject: [PATCH] Fix fresh node start with Snap sync failing --- crates/sc-consensus-subspace/src/archiver.rs | 42 ++++++++++++-------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/crates/sc-consensus-subspace/src/archiver.rs b/crates/sc-consensus-subspace/src/archiver.rs index 075fabc162..ba7a860c29 100644 --- a/crates/sc-consensus-subspace/src/archiver.rs +++ b/crates/sc-consensus-subspace/src/archiver.rs @@ -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,