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

BEEFY: generate historical proofs #11230

Closed
wants to merge 3 commits into from

Conversation

svyatonik
Copy link
Contributor

@svyatonik svyatonik commented Apr 18, 2022

Polkadot companion: paritytech/polkadot#5334

This PR adds new MMR RPC method - mmr_generateHistoricalProof. It is quite similar to the existing mmr_generateProof method, but it has additional argument - number of MMR leaves. It may be used to generate proof using historical MMR state even using latest block state, where there are more leaves.

Where it is useful:

  1. BEEFY light client needs to import explicit commitment + leaf + leaf proof for blocks that are changing validator set. If the chain has progressed since such block, the state of validator-set-change-block may have already been discarded (unless you're using archive node, which we want to avoid) and the call of mmr_generateProof(use-state-at-validator-set-change-block) will obviously fail. We may use mmr_generateHistoricalProof(use-state-at-best-block, use-mmr-state-at-validator-set-change-block) instead - this will generate us required proof;
  2. if block B is known to the light client, then we can't simply generate some MMR-related proof using MMR state at block B+10. So e.g. to prove some storage (read: deliver message), we need to generate proof using MMR state at block B. If state is discarded, we'll need to import B+10 first => extra bridge cost.

The leaves_count argument can easily be computed by the client by assuming that there's exactly one leaf per every block starting from some beginning block (where MMR pallet has been deployed). We may read number of MMR leaves at the best_block and then compute leaves_count_at_historical_block as number_of_historical_block - (best_block_number - leaves_count_at_best_block).

@svyatonik svyatonik 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 Apr 18, 2022
@svyatonik svyatonik added the D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. label Apr 18, 2022
Comment on lines +408 to +411
fn generate_historical_proof(
leaf_index: LeafIndex,
leaves_count: LeafIndex,
) -> Result<(EncodableOpaqueLeaf, Proof<Hash>), Error>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to directly add this with support for multiple leaves at once? (see #10635)

Would the light client benefit for generating historical proofs in a batch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - I think it makes sense to add support for proving several leaves, even though we'll only be using this API to prove single leaf now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then let's probably defer this PR until #10635 is merged to reuse primitives from there && etc

@svyatonik svyatonik added A1-onice and removed A0-please_review Pull request needs code review. labels Apr 18, 2022
/// Note this method can only be used from an off-chain context
/// (Offchain Worker or Runtime API call), since it requires
/// all the leaves to be present.
/// It may return an error or panic if used incorrectly.
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO it makes sense to add an explicit error in case leaves_count > Self::mmr_leaves()

@stale
Copy link

stale bot commented May 25, 2022

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label May 25, 2022
@svyatonik svyatonik closed this May 25, 2022
@svyatonik svyatonik deleted the sv-beefy-generate-historical-proof branch May 25, 2022 05:59
@serban300 serban300 added D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit D2-breaksapi E5-breaksapi D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. and removed D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit E5-breaksapi D2-breaksapi labels Sep 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. 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. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants