Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve snap sync #2972

Merged
merged 3 commits into from
Aug 14, 2024
Merged

Improve snap sync #2972

merged 3 commits into from
Aug 14, 2024

Conversation

nazar-pc
Copy link
Member

This simple change ensures that the first imported block is finalized and allows to finalize all other blocks afterwards successfully.

Code contributor checklist:

Base automatically changed from update-substrate to main August 14, 2024 07:48
@shamil-gadelshin
Copy link
Contributor

When I set pub(crate) const FINALIZATION_DEPTH_IN_SEGMENTS: SegmentIndex = SegmentIndex::new(0); and manually set snap_sync target block to some value (e.g.:1000000) should I get blocks of the first couple of segments finalized?

@nazar-pc
Copy link
Member Author

You will not get any finalization during sync because the whole archiving process is skipped for already archived blocks and finalization is only called from there.

To re-enable archiving of already archived history you'll have to do something like this:

diff --git a/crates/sc-consensus-subspace/src/archiver.rs b/crates/sc-consensus-subspace/src/archiver.rs
--- a/crates/sc-consensus-subspace/src/archiver.rs	(revision 51c4da575186f81c98b550ad92bcc6a7ba8fffe4)
+++ b/crates/sc-consensus-subspace/src/archiver.rs	(date 1723552439720)
@@ -845,7 +845,7 @@
                 "Checking if block needs to be skipped"
             );
             if best_archived_block_number >= block_number_to_archive
-                || last_archived_block_number > block_number_to_archive
+            // || last_archived_block_number > block_number_to_archive
             {
                 // This block was already archived, skip
                 debug!(
@@ -958,6 +958,13 @@
         block_number_to_archive, block_hash_to_archive
     );
 

But then you don't need to modify sync target or archiving depth at all if you want to just verify finalization, something like this is sufficient:

diff --git a/crates/sc-consensus-subspace/src/archiver.rs b/crates/sc-consensus-subspace/src/archiver.rs
--- a/crates/sc-consensus-subspace/src/archiver.rs	(revision 51c4da575186f81c98b550ad92bcc6a7ba8fffe4)
+++ b/crates/sc-consensus-subspace/src/archiver.rs	(date 1723552439720)
@@ -845,7 +845,7 @@
                 "Checking if block needs to be skipped"
             );
             if best_archived_block_number >= block_number_to_archive
-                || last_archived_block_number > block_number_to_archive
+            // || last_archived_block_number > block_number_to_archive
             {
                 // This block was already archived, skip
                 debug!(
@@ -958,6 +958,13 @@
         block_number_to_archive, block_hash_to_archive
     );
 
+    finalize_block(
+        client,
+        None,
+        *block.block.header().parent_hash(),
+        *block.block.header().number() - One::one(),
+    );
+
     if parent_block_hash != best_archived_block_hash {
         let error = format!(
             "Attempt to switch to a different fork beyond archiving depth, \

Copy link
Contributor

@shamil-gadelshin shamil-gadelshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well!

@nazar-pc nazar-pc added this pull request to the merge queue Aug 14, 2024
@nazar-pc
Copy link
Member Author

I'll submit a patch that will warn and suggest users to wipe the database separately (if we can't transparently fix it before then)

Merged via the queue into main with commit 124c045 Aug 14, 2024
9 checks passed
@nazar-pc nazar-pc deleted the improve-snap-sync branch August 14, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants