Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@andresilva
Copy link
Contributor

@andresilva andresilva commented Sep 3, 2019

Currently GrandpaBlockImport tracks authority set changes in AuthoritySet, we require a justification for blocks that enact an authority set change. Additionally, the GRANDPA voter will restrict its votes to blocks that enact an authority set change. This guarantees that said blocks, if finalized, will always have a justification. Additionally, GrandpaBlockImport keeps track of consensus changes, this is any kind of changes to the client cache (e.g. a BABE epoch change), and we also require justification for those blocks (added in #3301).

The problem with the current logic is that the sync code will always make the justification requests in-order, therefore if we cannot guarantee that a justification exists for a given block, we might get stuck requesting something endlessly. This is the case with BABE epoch changes since the GRANDPA voter won't limit its votes to these blocks.

This PR changes GrandpaBlockImport to only require a justification from sync for authority set changes (not consensus changes). I started by removing all of consensus changes from GrandpaBlockImport but this is still required so that we persist a justification for blocks that enact a consensus change (so that we can later on serve it to light clients).

I also changed the logic for finalizing pending requests in sync back to what it was before #3301. Since we only request justifications that must be satisfiable then we can also make sure that we finalize the requests in-order (i.e. finalize_with_ancestors -> finalize).

@andresilva andresilva added A0-please_review Pull request needs code review. M4-core labels Sep 3, 2019
number,
)
}
self.extra_justifications.try_finalize_root((hash, number), finalization_result, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can happen if we process the notification for on_block_finalized before we actually process the import result. Either way it is fine because we also call try_finalize_root on on_block_finalized so any necessary bookkeeping is done correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@andresilva can you add this to the code?

Copy link
Contributor

Choose a reason for hiding this comment

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

@andresilva I thought this check prevents it from happening, no?

Copy link
Contributor

@Demi-Marie Demi-Marie left a comment

Choose a reason for hiding this comment

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

Can you incude the PR comment in the source code? This will be very useful for future developers.

number,
)
}
self.extra_justifications.try_finalize_root((hash, number), finalization_result, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

@andresilva can you add this to the code?


if best_finalized_number > self.best_seen_finalized_number {
match self.tree.finalize_with_ancestors(
match self.tree.finalize(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you, please, change it back to finalize_with_ancestors() for finality proofs? It isn't guaranteed that they're coming in-order. If that PR needs to be merged ASAP, just ping me - I'll create a follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

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

@andresilva @svyatonik i guess this is on-ice until this change is made?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svyatonik Doesn't it have the same guarantees as for justifications? The code that makes the requests is shared with justifications and it will request things in-order as they are "popped" from the tree. I understand that the finality proof for B might have a justification for block B+n, but for checking in the tree we will be using in B anyway right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@andresilva You're right, on_block_finalized is called for every block in finalization path => they'll be in-order anyway. But then probably we should reconsider this limitation - it could happen that we'll only receive notification for B+n, but no notification for B => we could end up with the same UnfinalizedAncestor error, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I did not remember that. Let's revert back to finalize_with_ancestors() then.

Copy link
Contributor

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

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

The only concern I have, is that the number of full nodes that could serve justifications to light clients will decrease - the nodes that have imported consensus-changes-block without justification, will never receive it, afau. But that isn't the biggest problem right now.

@rphmeier rphmeier merged commit 9b08e7f into master Sep 9, 2019
@rphmeier rphmeier deleted the andre/grandpa-remove-consensus-changes branch September 9, 2019 05:28
andresilva added a commit that referenced this pull request Sep 17, 2019
#3540)

* grandpa: don't request justification for consensus changes on full node

* sync: finalize justification/finality proof requests in-order

* sync: ignore result of try_finalize_root on justification import
Demi-Marie pushed a commit to Demi-Marie/substrate that referenced this pull request Sep 17, 2019
paritytech#3540)

* grandpa: don't request justification for consensus changes on full node

* sync: finalize justification/finality proof requests in-order

* sync: ignore result of try_finalize_root on justification import
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants