substrate icon indicating copy to clipboard operation
substrate copied to clipboard

MMR: scope storing full subtrees in offchain db

Open serban300 opened this issue 3 years ago • 1 comments

Derived from: #12864

Now we are saving each MMR node by their position in the MMR. Another option would be to save each subtree by the block that introduced it (this would save multiple nodes at once). For example

For the tree:

  2  
 / \    
1   3

we are now saving the data for each node at the following keys:

1_[genesis_hash]
2_[block_1_hash]
3_[block_1_hash]

The other option would be to save:

1_[genesis_hash] -> the subtree containing node 1 (the subtree added by block 1)
2_[block_1_hash] -> the subtree containing nodes 2 and 3 (the subtree added by block 2)

This could have a couple of advantages:

  • less writes to the DB => more efficient on-chain processing
  • faster time for generating proofs (because of hot cache hits)
  • the mmr client gadget code would get more sipler because:
    • we wouldn't need to handle node indexes and leaf indexes
    • we wouldn't need to handle pallet resets

However, I'm not sure this would be compatible with MMBs. It might sense to look at this optimization after switching to MMBs.

PoC: https://github.com/serban300/substrate/tree/mmr_subtree

serban300 avatar Dec 22 '22 07:12 serban300

Is this still relevant? @serban300 @acatangiu ?

EmmanuellNorbertTulbure avatar Aug 25 '23 06:08 EmmanuellNorbertTulbure