From 5e69ad1bf0ed92a48afbac4f3059e10875d52bfc Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 20 Nov 2024 08:39:47 +1000 Subject: [PATCH 1/2] =?UTF-8?q?Exit=20with=20an=20error=20if=20mappings=20?= =?UTF-8?q?can=E2=80=99t=20be=20created=20for=20the=20chosen=20block?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/sc-consensus-subspace/src/archiver.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/sc-consensus-subspace/src/archiver.rs b/crates/sc-consensus-subspace/src/archiver.rs index 967bcf6f9b..9af46807e2 100644 --- a/crates/sc-consensus-subspace/src/archiver.rs +++ b/crates/sc-consensus-subspace/src/archiver.rs @@ -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) @@ -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, From 47c241bb94b4458443bba08d8cc22cd92d7de265 Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 25 Nov 2024 08:50:58 +1000 Subject: [PATCH 2/2] Fix comment typo --- 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 9af46807e2..5c507f6675 100644 --- a/crates/sc-consensus-subspace/src/archiver.rs +++ b/crates/sc-consensus-subspace/src/archiver.rs @@ -618,7 +618,7 @@ where if (best_block_to_archive..best_block_number) .any(|block_number| client.hash(block_number.into()).ok().flatten().is_none()) { - // If there are blocks missing blocks between best block to archive and best block of the + // If there are blocks missing headers between best block to archive and best block of the // blockchain it means newer block was inserted in some special way and as such is by // definition valid, so we can simply assume that is our best block to archive instead best_block_to_archive = best_block_number;