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

grandpa: avoid importing unnecessary justifications #14423

Merged
merged 7 commits into from
Jul 17, 2023

Conversation

andresilva
Copy link
Contributor

@andresilva andresilva commented Jun 20, 2023

When importing a block if it includes a GRANDPA justification we will always process it. If a peer is serving us justifications for every block then we will invariably verify them and import them which can lead to a significant slowdown in block import speed. We don't need justifications for every block and therefore this is wasteful. After this PR we will only import GRANDPA justifications every 512 blocks (besides the mandatory ones, i.e. when authorities change).

Fixes problems like paritytech/polkadot-sdk#13.

polkadot companion: paritytech/polkadot#7484

@andresilva andresilva added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Jun 20, 2023
@andresilva andresilva requested a review from a team June 20, 2023 18:09
@skunert
Copy link
Contributor

skunert commented Jun 21, 2023

This will solve the slow import issue when syncing with nodes that are sending more justifications as expected.

However its a bit different than what we discussed earlier, correct? Since JUSTIFICATION_IMPORT_PERIOD and the config are separate, this will even help nodes that have justification_period set to 1. I think previously we had discussed using the configured justification_period for import too.

@davxy
Copy link
Member

davxy commented Jun 21, 2023

Another option could be to add another parameter in the GrandpaParams.
Something like separating justification_import_period and justification_production_period.
As another tweak, both may also be defined as Options. If one is None => Use a default const value (like 512)
Just to not have the import period as a constant while the production a non constant.

(feel free to ignore... this is just an opinionated nit 😃)

@davxy davxy requested a review from a team June 21, 2023 15:40
@andresilva
Copy link
Contributor Author

andresilva commented Jun 27, 2023

The GrandpaParams is only used when running a validator, whereas in this case the configuration needs to be passed to the GrandpaBlockImport when setting up the pipeline (which in service is also done beforehand). The reason I didn't add a parameter there to configure this was to avoid having a breaking change that will need to be handled by everyone when setting up the service. I can add the parameter though (I was a bit lazy and didn't want to deal with this).

@bkchr
Copy link
Member

bkchr commented Jun 27, 2023

I would probably go with the parameter, to make it configurable like we have for the creation.

@andresilva
Copy link
Contributor Author

Updated to make the justification import period configurable.

@jasl
Copy link
Contributor

jasl commented Jul 11, 2023

A dumb question: what if justification_import_period can not exact division justification_generation_period?

@andresilva
Copy link
Contributor Author

@jasl Both options will be used independently. justification_generation_period will be used when following the GRANDPA protocol (i.e. when fully synced) to create justifications from commits at the end of the round, e.g. if it is set to 1 then the node will create and persist a justification for all the GRANDPA rounds. justification_import_period will be used when importing blocks that may come with a justification attached (usually only during initial sync), e.g. if it is set to 1 then it will always import the justifications that are served with the block. If you set justification_generation_period to 1 then when you are serving blocks for someone else to sync they will always have a justification attached (not necessarily always due to the way GRANDPA works), but on the other side if that node has justification_import_period set to e.g. 512 it will discard those justifications and only import them every 512 blocks.

@jasl
Copy link
Contributor

jasl commented Jul 13, 2023

@jasl Both options will be used independently. justification_generation_period will be used when following the GRANDPA protocol (i.e. when fully synced) to create justifications from commits at the end of the round, e.g. if it is set to 1 then the node will create and persist a justification for all the GRANDPA rounds. justification_import_period will be used when importing blocks that may come with a justification attached (usually only during initial sync), e.g. if it is set to 1 then it will always import the justifications that are served with the block. If you set justification_generation_period to 1 then when you are serving blocks for someone else to sync they will always have a justification attached (not necessarily always due to the way GRANDPA works), but on the other side if that node has justification_import_period set to e.g. 512 it will discard those justifications and only import them every 512 blocks.

So in our case, we could set justification_generation_period to 1 but set justification_import_period to 512 to mitigate our problem and keep the current behavior?

@andresilva
Copy link
Contributor Author

@jasl Yes, that would work for your own node to generate as much justifications as possible while not affecting other nodes on the network, i.e. those nodes would ignore those justifications when doing initial sync.

@andresilva
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Error: Github API says paritytech/polkadot#7484 is not mergeable

@paritytech paritytech deleted a comment from paritytech-processbot bot Jul 17, 2023
@bkchr
Copy link
Member

bkchr commented Jul 17, 2023

bot merge force

@paritytech-processbot paritytech-processbot bot merged commit 08f5857 into master Jul 17, 2023
3 checks passed
@paritytech-processbot paritytech-processbot bot deleted the andre/ignore-unnecessary-justifications branch July 17, 2023 17:38
jasl added a commit to Phala-Network/khala-parachain that referenced this pull request Jul 17, 2023
jasl added a commit to Phala-Network/khala-parachain that referenced this pull request Jul 18, 2023
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
* grandpa: avoid importing unnecessary justifications

* grandpa: make justification_import_period configurable

* grandpa: keep the first justification

* grandpa: add test for justification import period

* grandpa: fix test
crystalin pushed a commit to moonbeam-foundation/substrate that referenced this pull request Jul 19, 2023
* grandpa: avoid importing unnecessary justifications

* grandpa: make justification_import_period configurable

* grandpa: keep the first justification

* grandpa: add test for justification import period

* grandpa: fix test
Ank4n pushed a commit that referenced this pull request Jul 22, 2023
* grandpa: avoid importing unnecessary justifications

* grandpa: make justification_import_period configurable

* grandpa: keep the first justification

* grandpa: add test for justification import period

* grandpa: fix test
jasl added a commit to Phala-Network/khala-parachain that referenced this pull request Jul 27, 2023
Agusrodri pushed a commit to moonbeam-foundation/substrate that referenced this pull request Aug 15, 2023
* grandpa: avoid importing unnecessary justifications

* grandpa: make justification_import_period configurable

* grandpa: keep the first justification

* grandpa: add test for justification import period

* grandpa: fix test
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. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants