pokt-network / smt

A Go library that implements a Sparse Merkle Trie for a key-value map.
https://pkg.go.dev/github.com/pokt-network/smt
Other
16 stars 4 forks source link

feat: Add MultiStore SMT manager #17

Closed h5law closed 1 year ago

h5law commented 1 year ago

Description

This PR introduces the new MultiStore SMT manager. This enables the management of numerous SMTs under a single overarching tree.

The MultiStore acts as a wrapper around an SMT that includes the name and root hash of the trees it manages. The Store interface is a wrapper around a single SMT which tracks the MultiStore it is a part of and overwrites the SMT's Commit method to not only commit the Store's changes to the database but also update the MultiStore with the name and root hash of the Store's tree.

This is useful in areas where a single tree / root hash is needed but different SMT's are desired: for example in a blockchain setting this could replace the root tree and each of the trees it manages could track the transactions, accounts etc. It would also be useful for an implementation of the IBC specification where the MultiStore would represent the IBC store as a whole with each Store representing a single ICS component such as the ICS-02 store or the ICS-03 store.

Summary generated by Reviewpad on 31 Jul 23 12:52 UTC

This pull request introduces significant changes to several files related to the MultiStore functionality. Here is a summary of the changes:

  1. multi_test.go: The file now includes test functions and helper functions for testing the MultiStore functionality. The test functions cover various operations such as adding a store, inserting a pre-existing store, getting a store, removing a store, performing store operations, committing changes, and generating proofs. Additionally, a helper function customStoreCreator is added.

  2. multi.go: This file implements the MultiStore interface and its associated functions. The multi struct represents a collection of multiple stores and implements methods such as AddStore, InsertStore, GetStore, RemoveStore, Commit, Root, Prove, and Spec. The store struct represents an individual store within the MultiStore, maintaining a reference to the parent MultiStore and implementing a Commit method that updates the multi-store with the latest root hash.

  3. MultiStore.md: The Markdown file provides an overview of the MultiStore interface and its functionalities. It explains how the MultiStore manages multiple stores and describes the operations available for managing stores and trees. It also introduces the Store type, which is a wrapper around an SMT and includes a Commit method to update the multi-store with the root hash of the store. Additionally, it discusses the TreeSpec type, which specifies the hashing functions and maximum depth of the tree.

These changes significantly enhance the functionality and usage of the MultiStore concept, allowing for better management and manipulation of multiple stores within the system.

Type of change

Please mark the relevant option(s):

List of changes

Testing

Required Checklist

If Applicable Checklist

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 83.82% and project coverage change: -0.20% :warning:

Comparison is base (f5ef955) 86.93% compared to head (4784998) 86.73%. Report is 1 commits behind head on main.

:exclamation: Current head 4784998 differs from pull request most recent head 95e930f. Consider uploading reports for the commit 95e930f to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #17 +/- ## ========================================== - Coverage 86.93% 86.73% -0.20% ========================================== Files 8 9 +1 Lines 995 1063 +68 ========================================== + Hits 865 922 +57 - Misses 94 101 +7 - Partials 36 40 +4 ``` | [Files Changed](https://app.codecov.io/gh/pokt-network/smt/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pokt-network) | Coverage Δ | | |---|---|---| | [types.go](https://app.codecov.io/gh/pokt-network/smt/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pokt-network#diff-dHlwZXMuZ28=) | `93.02% <ø> (ø)` | | | [multi.go](https://app.codecov.io/gh/pokt-network/smt/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pokt-network#diff-bXVsdGkuZ28=) | `83.82% <83.82%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

h5law commented 1 year ago

Closing this as the MultiStore is not longer a priority.

For future reference this should be rescoped to allow the SMT to preform silimar functions to the IAVL+ tree in the context of the CommitMultiStore etc used in the cosmos-sdk [1]. Enabling the correct features for this to be plugged in place of the IAVL+ tree will be a win.

[1] https://docs.cosmos.network/v0.45/core/store.html#commitmultistore