-
Notifications
You must be signed in to change notification settings - Fork 33
[Persistence] TreeStore Refactor #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4de90bd
0fa3984
377ea5c
afbbcfd
25af7d4
68bc5f0
0878e89
428a71a
35632f1
141ab33
d0511c5
d74032d
1b277ce
3d5701d
5a26797
61936e9
905bcc6
9403106
a34ff05
52172a0
e3a3081
b3371d2
70537ca
b83e7ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,10 @@ | ||
| package persistence | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "runtime/debug" | ||
|
|
||
| "github.com/pokt-network/pocket/persistence/types" | ||
| "github.com/pokt-network/pocket/shared/messaging" | ||
| "github.com/pokt-network/smt" | ||
| ) | ||
|
|
||
| // A list of functions to clear data from the DB not associated with protocol actors | ||
|
|
@@ -118,16 +116,5 @@ func (p *PostgresContext) clearAllSQLState() error { | |
| } | ||
|
|
||
| func (p *PostgresContext) clearAllTreeState() error { | ||
| for treeType := merkleTree(0); treeType < numMerkleTrees; treeType++ { | ||
| nodeStore := p.stateTrees.nodeStores[treeType] | ||
|
|
||
| if err := nodeStore.ClearAll(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Needed in order to make sure the root is re-set correctly after clearing | ||
| p.stateTrees.merkleTrees[treeType] = smt.NewSparseMerkleTree(nodeStore, sha256.New()) | ||
| } | ||
|
|
||
| return nil | ||
| return p.stateTrees.DebugClearAll() | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code patch provided removes some imports and modifies the clearAllTreeState function. Here's a brief review:
Potential risks or suggestions for improvement:
Overall, the code change appears to streamline the process of clearing trees, potentially improving maintainability. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "github.com/pokt-network/pocket/logger" | ||
| "github.com/pokt-network/pocket/persistence/blockstore" | ||
| "github.com/pokt-network/pocket/persistence/indexer" | ||
| "github.com/pokt-network/pocket/persistence/trees" | ||
| "github.com/pokt-network/pocket/runtime/configs" | ||
| "github.com/pokt-network/pocket/runtime/genesis" | ||
| "github.com/pokt-network/pocket/shared/modules" | ||
|
|
@@ -36,13 +37,14 @@ type persistenceModule struct { | |
| // A key-value store mapping heights to blocks. Needed for block synchronization. | ||
| blockStore blockstore.BlockStore | ||
|
|
||
| // A tx indexer (i.e. key-value store) mapping transaction hashes to transactions. Needed for | ||
| // avoiding tx replays attacks, and is also used as the backing database for the transaction | ||
| // tx merkle tree. | ||
| // txIndexer is a key-value store mapping transaction hashes to `IndexedTransaction` protos. | ||
| // It is needed to avoid tx replay attacks and for business logic around transaction validation. | ||
| // IMPORTANT: It doubles as the data store for the transaction tree in state tree set. | ||
| txIndexer indexer.TxIndexer | ||
|
|
||
| // A list of all the merkle trees maintained by the persistence module that roll up into the state commitment. | ||
| stateTrees *stateTrees | ||
| // stateTrees manages all of the merkle trees maintained by the | ||
| // persistence module that roll up into the state commitment. | ||
| stateTrees modules.TreeStore | ||
|
|
||
| // Only one write context is allowed at a time | ||
| writeContext *PostgresContext | ||
|
|
@@ -102,7 +104,8 @@ func (*persistenceModule) Create(bus modules.Bus, options ...modules.ModuleOptio | |
| return nil, err | ||
| } | ||
|
|
||
| stateTrees, err := newStateTrees(persistenceCfg.TreesStoreDir) | ||
| // TECHDEBT (#808): Make TreeStore into a full Module | ||
| stateTrees, err := trees.NewStateTrees(persistenceCfg.TreesStoreDir) | ||
dylanlott marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -234,6 +237,10 @@ func (m *persistenceModule) GetTxIndexer() indexer.TxIndexer { | |
| return m.txIndexer | ||
| } | ||
|
|
||
| func (m *persistenceModule) GetTreeStore() modules.TreeStore { | ||
| return m.stateTrees | ||
| } | ||
|
|
||
| func (m *persistenceModule) GetNetworkID() string { | ||
| return m.networkId | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, the code patch seems to make reasonable updates to the persistenceModule struct and its functions. However, below are a few suggestions that might improve maintainability and reduce risks:
Remember that these suggestions only serve as general guidelines. To ensure the stability of your project, you should always have a thorough understanding of the entire codebase and perform proper risk assessment for potential bugs or issues. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # SQL Package | ||
|
|
||
| The SQL package is a library of functions that all take a `pgx.Tx` as an argument and execute SQL queries on it. | ||
|
|
||
| - GetAccountsUpdated | ||
| - GetActors | ||
| - GetTransactions | ||
| - GetPools | ||
| - GetAccounts | ||
| - GetFlags | ||
| - GetParams | ||
|
|
||
| These functions are meant to abstract away the SQL row and error handling for components of the persistence package. | ||
|
|
||
| GetActors is used to get each of the actor types in the system: Applications, Validators, Watchers, and Servicers. | ||
|
|
||
| ## Why a whole package? | ||
|
|
||
| If the SQL handling lives in the persistence package, the package submodules will run into import cycle errors when attempting to use the SQL handlers. Putting the SQL helpers into a package inside persistence avoids the import cycle. | ||
|
|
||
| ```mermaid | ||
| flowchart TD | ||
| subgraph pers[persistence] | ||
| subgraph p[ without sql package - import cycle error ] | ||
| persistenceContext1[PersistenceContext] | ||
| treeStore1[TreeStore] | ||
| treeStore1 -- Tx --> persistenceContext1 | ||
| persistenceContext1 -- Tx --> treeStore1 | ||
| end | ||
| subgraph p2[ with sql package - refactored ] | ||
| persistenceContext -- Tx --> sql | ||
| treeStore2 -- Tx --> sql | ||
| end | ||
| end | ||
| ``` | ||
|
Comment on lines
+21
to
+35
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Olshansk the import cycle issue is described here.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||

Uh oh!
There was an error while loading. Please reload this page.