Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request paritytech#139 from subspace/restart-fixes
Browse files Browse the repository at this point in the history
Fixes for 2 issues related to node restarts
  • Loading branch information
nazar-pc committed Nov 17, 2021
2 parents 4c598db + 212f854 commit 9d5e015
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
29 changes: 21 additions & 8 deletions crates/sc-consensus-subspace/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,17 @@ pub fn start_subspace_archiver<Block: BlockT, Client>(
.recorded_history_segment_size(&genesis_block_id)
.expect("Failed to get `recorded_history_segment_size` from runtime API");

let mut archiver = if let Some(last_root_block) = find_last_root_block(client.as_ref()) {
let maybe_last_root_block = find_last_root_block(client.as_ref()).and_then(|last_root_block| {
// At least one non-genesis block needs to be archived for restarts
// TODO: This check can be removed when we no longer have pre-genesis objects
if last_root_block.last_archived_block().number == 0 {
None
} else {
Some(last_root_block)
}
});

let mut archiver = if let Some(last_root_block) = maybe_last_root_block {
// Continuing from existing initial state
let last_archived_block_number = last_root_block.last_archived_block().number;
info!(
Expand Down Expand Up @@ -221,20 +231,23 @@ pub fn start_subspace_archiver<Block: BlockT, Client>(
block_to_archive,
encoded_block.len() as f32 / 1024.0
);

// These archived segments were processed before, thus do not need to be sent to
// farmers
let new_root_blocks = archiver
let new_root_blocks: Vec<RootBlock> = archiver
.add_block(encoded_block, block_object_mapping)
.into_iter()
.map(|archived_segment| archived_segment.root_block)
.collect();

// Set list of expected root blocks for the block where we expect root block
// extrinsic to be included
subspace_link.root_blocks.lock().put(
(block_to_archive + confirmation_depth_k + 1).into(),
new_root_blocks,
);
if !new_root_blocks.is_empty() {
// Set list of expected root blocks for the block where we expect root block
// extrinsic to be included
subspace_link.root_blocks.lock().put(
(block_to_archive + confirmation_depth_k + 1).into(),
new_root_blocks,
);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-archiving/src/archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ impl BlockArchiver {
mut object_mapping: BlockObjectMapping,
) -> Result<Self, ArchiverInstantiationError> {
if root_block.last_archived_block() == INITIAL_LAST_ARCHIVED_BLOCK {
// TODO: This check can be removed when we no longer have pre-genesis objects
return Err(ArchiverInstantiationError::NoBlocksInvalidInitialState);
}

Expand Down

0 comments on commit 9d5e015

Please sign in to comment.