Skip to content

Enable non-sequential block finalization.#21

Closed
shamil-gadelshin wants to merge 1 commit intosubspace-v6from
finalization2
Closed

Enable non-sequential block finalization.#21
shamil-gadelshin wants to merge 1 commit intosubspace-v6from
finalization2

Conversation

@shamil-gadelshin
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

self.backend.blockchain().clear_block_gap()
}

fn finalize_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()> {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

nazar-pc commented Aug 9, 2024

Also I think by sequential you actually meant contiguous

Copy link
Copy Markdown
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)?;
}

self.backend.blockchain().clear_block_gap()
}

fn finalize_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()> {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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