Skip to content

Commit

Permalink
Merge pull request #2178 from subspace/support-early-archiver-restart…
Browse files Browse the repository at this point in the history
…s-reorgs

Support early archiver restarts/reorgs
  • Loading branch information
nazar-pc authored Oct 30, 2023
2 parents f8386a5 + 0e7a271 commit 63e1e29
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,32 @@ where

let last_archived_block_encoded = encode_block(last_archived_block);

Archiver::with_initial_state(
let archiver = Archiver::with_initial_state(
subspace_link.kzg().clone(),
last_segment_header,
&last_archived_block_encoded,
block_object_mappings,
)
.expect("Incorrect parameters for archiver")
.expect("Incorrect parameters for archiver");

// Due to sync from DSN it is possible that the very first segment header is known even
// though only genesis block exists, in this case there is nothing else left to archive
// and we need to insert segment header to be included in the block 1 explicitly here or
// else it'll be missing and block import will fail.
//
// Checking for segment index instead of best block number ensures we support
// hypothetical reorgs of the early blocks within confirmation depth distance from
// genesis.
if last_segment_header.segment_index() == SegmentIndex::ZERO {
// Set list of expected segment headers for the block where we expect segment
// header extrinsic to be included
subspace_link
.segment_headers
.lock()
.put(One::one(), vec![last_segment_header]);
}

archiver
} else {
info!(target: "subspace", "Starting archiving from genesis");

Expand Down

0 comments on commit 63e1e29

Please sign in to comment.