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

Enable non-sequential block finalization. #21

Closed
wants to merge 1 commit into from

Conversation

shamil-gadelshin
Copy link
Member

This PR prepares the polkadot-sdk for enabling non-sequential block finalization in subspace blockchain.

During the snap-sync the code invokes apply_finality method which implies sequential block order and fails otherwise. Additionally, the recently modified displaced_leaves_after_finalizing tries to find the parent header of the last finalized block and fails after snap-sync(that block is the first available block inserted by the newly added finalize_block API and contains no parent header in blockchain db).

The proposed changes export finalize_block API that enables block finalization by disabling sequential block order check, also, the changes soften the error handling for displaced_leaves_after_finalizing and allows it to continue after accessing non-existent block header.

Copy link
Member

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

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

I hate to sound like a broken record in every PR of this kind, but have you discussed this with upstream, is there an open discussion and/or PR there?

We need a generic solution here, not hacks on top of hacks. paritytech#5119 looks like a related discussion. IMO we should implement and submit an upstream fix for a situation like this.

Ok(header) => header,
Err(_) => {
debug!("Can't find obtain header metatadata: {parent:?}");
break;
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we never remove one of the blocks from the database?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I understand the code correctly we skip only a missing block.

@@ -128,6 +128,10 @@ where
fn clear_block_gap(&self) -> sp_blockchain::Result<()> {
self.backend.blockchain().clear_block_gap()
}

fn finalize_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

There is already apply_finality in Substrate, why do we have to add another API on top of this instead of fixing the API we already have?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, apply_finality relies on the tree_route which demands existing headers from the genesis in our case. Changing the method seems much more invasive than preparing conditions for its correct work - I'm open to suggestions here though.

@nazar-pc
Copy link
Member

nazar-pc commented Aug 9, 2024

Also I think by sequential you actually meant contiguous

Copy link
Member Author

@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.

I hate to sound like a broken record in every PR of this kind, but have you discussed this with upstream, is there an open discussion and/or PR there?

We need a generic solution here, not hacks on top of hacks. paritytech#5119 looks like a related discussion. IMO we should implement and submit an upstream fix for a situation like this.

I intended to send upstream displaced_leaves_after_finalizing change part indeed. I wanted to validate the whole solution before posting it upstream because you authored one of the changed part.
The bug seems rather serious so I wanted to have the fix first and start a long discussion with Parity later.

Also I think by sequential you actually meant contiguous

I meant this snippet:

if ensure_sequential_finalization {
	self.ensure_sequential_finalization(header, last_finalized)?;
}

@@ -128,6 +128,10 @@ where
fn clear_block_gap(&self) -> sp_blockchain::Result<()> {
self.backend.blockchain().clear_block_gap()
}

fn finalize_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, apply_finality relies on the tree_route which demands existing headers from the genesis in our case. Changing the method seems much more invasive than preparing conditions for its correct work - I'm open to suggestions here though.

Ok(header) => header,
Err(_) => {
debug!("Can't find obtain header metatadata: {parent:?}");
break;
Copy link
Member Author

Choose a reason for hiding this comment

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

If I understand the code correctly we skip only a missing block.

@nazar-pc
Copy link
Member

nazar-pc commented Aug 9, 2024

I wanted to validate the whole solution before posting it upstream because you authored one of the changed part.

Upstream has actually changed things further since, so if you have patches, you should probably build them against upstream, add corresponding tests and open PR upstream. We can then backport it based on feedback and timeline.

The bug seems rather serious so I wanted to have the fix first and start a long discussion with Parity later.

I'm convinced discussion should start as soon as you identify what the problem is. Meaning at the very beginning, not at the end of the process.

I meant this snippet:

I see, maybe code should support such finalization then, why is it required to be sequential?

@shamil-gadelshin
Copy link
Member Author

There is an easier way to do that: autonomys/subspace#2972 with the combination of the upstream fixes in displaced_leaves_after_finalizing

@nazar-pc nazar-pc deleted the finalization2 branch August 14, 2024 08:56
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