-
Notifications
You must be signed in to change notification settings - Fork 2.6k
pallet-mmr: improve offchain storage, relax LeafData requirements #11799
Comments
Will pick this up on monday |
Doing this will normally require an offchain database migration for any runtime deploying #11594 (Rococo runtime >= 9260). Right now though, |
Hi, I've gone ahead to make the changes suggested in the Issue spec. I haven't updated the tests yet, but I'll do that over the next few days. I've opened a draft PR here. |
Do you need any help here? |
Hi @acatangiu. |
Unfortunately Closing the issue as "Not possible". |
Issue
PR #11594 introduced fork-resistant offchain storage for MMR leaves.
Leaves are now saved offchain using
(parent_hash, pos)
-based key to be fork-resistant and later canonicalized topos
-based key.Relying on
(parent_hash, pos)
-based keys means that conflicts could now only happen on 1-block deep forks, where two forks with identical line of ancestors compete to write at the same offchain key. This introduced a requirement on theLeafData
to only reference data coming from ancestor blocks, so in the corner case above, the conflicting writes end up writing same values anyway.While the current behavior works for
polkadot/kusama
BEEFY+MMR deployment, I think we can improve and eliminate theLeafData
requirement shown above.Proposed solution
Leaves are added to the MMR offchain storage by runtime during
pallet_mmr::<Pallet as Hooks>::on_initialize(BlockNumber)
here using indexing API. At that timeblock_hash
is unavailable (block is still under construction) so we're usingparent_hash
-based key instead to uniquely identify this leaf in offchain db (only it's not unique for 1-block deep forks, ergo theLeafData
limitation).Idea is to drop using the indexing API and instead store the new leaf in a placeholder
Pallet::NewLeaf
runtime storage item, and have the offchain worker function move/copy the leaf to offchain db after the block is built and truly unique(block_hash, pos)
is available to be used as offchain key.The same
Pallet::NewLeaf
storage is reused for temporarily holding the new leaf at every block.The text was updated successfully, but these errors were encountered: