-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat(store/v2): add support for iavl/v2 #22424
Changes from 4 commits
7b89c8f
a837b9b
906144b
ee21c4a
063a18f
c3415de
56ea0e5
200f7dd
e1f0574
bb2eeec
2f7ef1e
6b19d2b
84e5b38
37147bf
7a436e8
c815594
850914e
b59fe7f
d97ad63
e8e2f1b
8b7270d
a912d0f
f557fdd
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package iavlv2 | ||
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. Could you please add the tree test like iavl v1? 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. I implemented the tests, skipping snaphots for now. It needs to be filled out but that can be done in parallel with the performance tests I'm now doing. |
||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/cosmos/iavl/v2" | ||
ics23 "github.com/cosmos/ics23/go" | ||
|
||
"cosmossdk.io/store/v2" | ||
"cosmossdk.io/store/v2/commitment" | ||
) | ||
|
||
var ( | ||
_ commitment.Tree = (*Tree)(nil) | ||
_ store.PausablePruner = (*Tree)(nil) | ||
) | ||
|
||
type Tree struct { | ||
tree *iavl.Tree | ||
} | ||
|
||
func NewTree(treeOptions iavl.TreeOptions, dbOptions iavl.SqliteDbOptions, pool *iavl.NodePool) (*Tree, error) { | ||
sql, err := iavl.NewSqliteDb(pool, dbOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tree := iavl.NewTree(sql, pool, treeOptions) | ||
return &Tree{tree: tree}, nil | ||
} | ||
|
||
func (t Tree) Set(key, value []byte) error { | ||
_, err := t.tree.Set(key, value) | ||
return err | ||
} | ||
kocubinski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func (t Tree) Remove(key []byte) error { | ||
_, _, err := t.tree.Remove(key) | ||
return err | ||
} | ||
|
||
func (t Tree) GetLatestVersion() (uint64, error) { | ||
return uint64(t.tree.Version()), nil | ||
} | ||
|
||
func (t Tree) Hash() []byte { | ||
return t.tree.Hash() | ||
} | ||
|
||
func (t Tree) Version() uint64 { | ||
return uint64(t.tree.Version()) | ||
} | ||
|
||
func (t Tree) LoadVersion(version uint64) error { | ||
// TODO fix this in iavl v2 | ||
kocubinski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if version == 0 { | ||
return nil | ||
} | ||
return t.tree.LoadVersion(int64(version)) | ||
} | ||
|
||
func (t Tree) Commit() ([]byte, uint64, error) { | ||
h, v, err := t.tree.SaveVersion() | ||
return h, uint64(v), err | ||
} | ||
|
||
func (t Tree) SetInitialVersion(version uint64) error { | ||
t.tree.SetShouldCheckpoint() | ||
return t.tree.SetInitialVersion(int64(version)) | ||
} | ||
|
||
func (t Tree) GetProof(version uint64, key []byte) (*ics23.CommitmentProof, error) { | ||
return t.tree.GetProof(int64(version), key) | ||
} | ||
|
||
func (t Tree) Get(version uint64, key []byte) ([]byte, error) { | ||
if int64(version) != t.tree.Version() { | ||
return nil, fmt.Errorf("loading past version not yet supported") | ||
} | ||
return t.tree.Get(key) | ||
} | ||
kocubinski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func (t Tree) Export(version uint64) (commitment.Exporter, error) { | ||
return nil, errors.New("snapshot import/export not yet supported") | ||
} | ||
|
||
func (t Tree) Import(version uint64) (commitment.Importer, error) { | ||
return nil, errors.New("snapshot import/export not yet supported") | ||
} | ||
|
||
func (t Tree) Close() error { | ||
return t.tree.Close() | ||
} | ||
|
||
func (t Tree) Prune(version uint64) error { | ||
return t.tree.DeleteVersionsTo(int64(version)) | ||
} | ||
|
||
// PausePruning is unnecessary in IAVL v2 due to the advanced pruning mechanism | ||
func (t Tree) PausePruning(bool) {} | ||
kocubinski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func (t *Tree) WorkingHash() []byte { | ||
return t.tree.Hash() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,16 @@ require ( | |
cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 | ||
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 | ||
cosmossdk.io/log v1.4.1 | ||
github.com/bvinc/go-sqlite-lite v0.6.1 | ||
github.com/cockroachdb/pebble v1.1.0 | ||
github.com/cosmos/cosmos-proto v1.0.0-beta.5 | ||
github.com/cosmos/gogoproto v1.7.0 | ||
github.com/cosmos/iavl v1.0.0-beta.1.0.20240813194616-eb5078efcf9e | ||
github.com/cosmos/iavl v1.3.0 | ||
github.com/cosmos/iavl/v2 v2.0.0-20241029195051-d3ac274b6b58 | ||
github.com/cosmos/ics23/go v0.11.0 | ||
github.com/google/btree v1.1.2 | ||
github.com/google/btree v1.1.3 | ||
github.com/hashicorp/go-metrics v0.5.3 | ||
github.com/linxGnu/grocksdb v1.9.3 | ||
github.com/mattn/go-sqlite3 v1.14.22 | ||
github.com/spf13/cast v1.7.0 | ||
github.com/stretchr/testify v1.9.0 | ||
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d | ||
|
@@ -26,13 +27,15 @@ require ( | |
require ( | ||
cosmossdk.io/schema v0.3.0 // indirect | ||
github.com/DataDog/zstd v1.5.5 // indirect | ||
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
github.com/cockroachdb/errors v1.11.1 // indirect | ||
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect | ||
github.com/cockroachdb/redact v1.1.5 // indirect | ||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/dustin/go-humanize v1.0.1 // indirect | ||
github.com/emicklei/dot v1.6.2 // indirect | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/getsentry/sentry-go v0.27.0 // indirect | ||
|
@@ -43,6 +46,7 @@ require ( | |
github.com/hashicorp/go-uuid v1.0.1 // indirect | ||
github.com/hashicorp/golang-lru v1.0.2 // indirect | ||
github.com/klauspost/compress v1.17.9 // indirect | ||
github.com/kocubinski/costor-api v1.1.1 // indirect | ||
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. 💡 Codebase verification Remove unused indirect dependency costor-api The 🔗 Analysis chainVerify necessity of costor-api dependency The addition of 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for usage of costor-api in the codebase
rg "github.com/kocubinski/costor-api" --type go
# Check if it's a transitive dependency
go mod graph | rg "costor-api"
Length of output: 171 Script: #!/bin/bash
# Search for any imports or usage of costor
rg -i "costor" --type go -A 3
# Find all Go files and check their content for costor
fd -e go -x cat {} | rg -i "costor" -A 3
# Look for any references to costor in the entire codebase
rg -i "costor" -A 3
Length of output: 913 |
||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
|
@@ -64,3 +68,5 @@ require ( | |
google.golang.org/protobuf v1.35.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) | ||
|
||
replace cosmossdk.io/core => ../../core | ||
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. 💡 Codebase verification Replace directive in store/v2/go.mod is inconsistent with other modules The analysis shows that while many modules depend on
🔗 Analysis chainVerify consistency of local replace directive The replace directive for the core module is using a relative path. Let's verify this is consistent with other modules. Let me generate additional scripts to verify the consistency of replace directives across the codebase. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check replace directives in other go.mod files
fd -e mod -x sh -c 'echo "=== {} ===" && cat {} | rg "^replace cosmossdk.io/core"'
Length of output: 1630 Script: #!/bin/bash
# Check all replace directives in store/v2/go.mod
echo "=== Replace directives in store/v2/go.mod ==="
cat store/v2/go.mod | rg "^replace"
# Check if core module is imported in store/v2/go.mod
echo -e "\n=== Core module import in store/v2/go.mod ==="
cat store/v2/go.mod | rg "cosmossdk.io/core"
# Check if other modules that import core have similar replace directives
echo -e "\n=== Modules importing core ==="
rg "cosmossdk.io/core" -g 'go.mod'
Length of output: 5949 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Consider using a more actively maintained SQLite library
The current choice of
github.com/bvinc/go-sqlite-lite v0.6.1
raises several concerns:Consider evaluating alternative SQLite libraries with explicit locking mechanisms that are actively maintained, such as:
modernc.org/sqlite
github.com/glebarez/go-sqlite
🔗 Analysis chain
Verify the SQLite library migration.
The addition of
github.com/bvinc/go-sqlite-lite v0.6.1
aligns with the PR objective to migrate frommattn/go-sqlite3
. However, let's verify if v0.6.1 is the latest stable version and if there are any known issues.Let me gather more information about the issues and the repository activity.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 355
Script:
Length of output: 2015
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a fair point, but I personally favor how
bvinc/go-sqlite-lite
is a very minimal wrapper around the original libc API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kocubinski, understood. Thank you for explaining your preference for
bvinc/go-sqlite-lite
due to its minimal wrapper around the original libc API. I'll keep this in mind for future reviews.✏️ Learnings added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modernc.org/sqlite could be a good fit since it's a pure go implementation (won't conflict with iavl/v2) and maybe even more performant than the C one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kocubinski, that's a great point. Modernc.org/sqlite, being a pure Go implementation, could indeed avoid conflicts with iavl/v2 and potentially offer better performance.
From the information gathered:
It seems like a promising alternative worth evaluating. Let me know if you need any assistance with this.
🔗 Analysis chain
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 2119
✏️ Learnings added