Skip to content

Pallet-MMR should use custom block_hash getter instead of using frame_system::block_hash for non-canonicalised blocks #4062

Closed
@vedhavyas

Description

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Motivation

Currently pallet_mmr uses frame_system::block_hash to get the hash of a given block number while constructing the non-canonicalised keys. This works fine with Polkadot and other blockchains where finality is quicker. Currently, polkadot stores 4096 number of block hashes on the runtime and before the block_hashes are pruned, the blocks are already finalized.

At subspace, we do not have a quick finality and we cannot put a static number at which we can gaurantee block finalization happens. With this context, when an MMR proof is being verified, if the particular block is not canonicalised yet, it will look at frame_system::block_hashes but by then our runtime already prunes the block hash due to frame_system::Config::BlockHashCount and the storage returns an Default value for the Hash since the frame_system::block_hash is a ValueQuery. With the default value given, the MMR proof verification fails on our end.

Request

pallet_mmr should ideally define a custom getter to fetch the block_hash instead of directly using the frame_system. This will provide the projects using the pallet_mmr can impl the custom getter to fetch the said block_hash.

For polkadot and likes, the impl will just wrap frame_system::block_hashes function and should not change anything while Subspace and other project can impl custom logic to fetch the correct block_hash for a given non-canonicalised block number.

Solution

Solution would be introduce a new type for pallet_mmr::Config that can fetch block_hash for a given block_number

Are you willing to help with this request?

Yes!

Metadata

Assignees

No one assigned

    Labels

    I10-unconfirmedIssue might be valid, but it's not yet known.I5-enhancementAn additional feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions