From 4ed64b999e950166fdff13277031309bb9727e81 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 25 Nov 2024 13:07:03 +1000 Subject: [PATCH 1/2] Handle state missing edge case when setting custom mapping height --- crates/sc-consensus-subspace/src/archiver.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/sc-consensus-subspace/src/archiver.rs b/crates/sc-consensus-subspace/src/archiver.rs index 8ffefd987f..104e6e6c07 100644 --- a/crates/sc-consensus-subspace/src/archiver.rs +++ b/crates/sc-consensus-subspace/src/archiver.rs @@ -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},\ 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()) + .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, From 46ed466f4afb8147088c8b027afc901e01fabbab Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 25 Nov 2024 13:10:29 +1000 Subject: [PATCH 2/2] Fix missing space in error log --- crates/sc-consensus-subspace/src/archiver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sc-consensus-subspace/src/archiver.rs b/crates/sc-consensus-subspace/src/archiver.rs index 104e6e6c07..075fabc162 100644 --- a/crates/sc-consensus-subspace/src/archiver.rs +++ b/crates/sc-consensus-subspace/src/archiver.rs @@ -637,7 +637,7 @@ where .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},\ + "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()));