Skip to content
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

chore: cleanup v2 #922

Open
wants to merge 2 commits into
base: release/v2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '^1.20.0'
go-version: "^1.21.0"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.2
version: v1.55.2
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ format:

# look into .golangci.yml for enabling / disabling linters
golangci_lint_cmd=golangci-lint
golangci_version=v1.51.2
golangci_version=v1.55.2

lint:
@echo "--> Running linter"
Expand Down
2 changes: 1 addition & 1 deletion cmd/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func latestCommand() *cobra.Command {
if err != nil {
return err
}
tree := iavl.NewTree(sql, pool, iavl.TreeOptions{})
tree := iavl.NewTree(sql, iavl.TreeOptions{})
if err = tree.LoadVersion(version); err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import (
)

func main() {
root, err := RootCommand()
if err != nil {
os.Exit(1)
}

root := RootCommand()
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)

Expand All @@ -35,6 +31,5 @@ func main() {

if err := root.ExecuteContext(ctx); err != nil {
fmt.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

func RootCommand() (*cobra.Command, error) {
func RootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "iavl",
Short: "benchmark cosmos/iavl",
Expand All @@ -20,5 +20,5 @@ func RootCommand() (*cobra.Command, error) {
scan.Command(),
latestCommand(),
)
return cmd, nil
return cmd
}
4 changes: 2 additions & 2 deletions cmd/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func rootsCommand() *cobra.Command {
}
cmd.Flags().StringVar(&dbPath, "db", "", "path to sqlite db")
cmd.Flags().Int64Var(&version, "version", 0, "version to query")
cmd.MarkFlagRequired("db")
cmd.MarkFlagRequired("version")
_ = cmd.MarkFlagRequired("db")
_ = cmd.MarkFlagRequired("version")
return cmd
}
2 changes: 1 addition & 1 deletion cmd/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Command() *cobra.Command {
if err != nil {
return err
}
tree := iavl.NewTree(sql, pool, iavl.TreeOptions{})
tree := iavl.NewTree(sql, iavl.TreeOptions{})
if err = tree.LoadVersion(version); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cosmos/iavl/v2

go 1.18
go 1.21

require (
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kocubinski/costor-api v1.1.1 h1:sgfJA7T/8IfZ59zxiMrED0xdjerAFuPNBTqyO90GiEE=
github.com/kocubinski/costor-api v1.1.1/go.mod h1:ESMBMDkKfN+9vvvhhNVdKLhbOmzI3O/i16iXvRM9Tuc=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
Expand All @@ -51,6 +54,7 @@ github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
Expand All @@ -77,5 +81,6 @@ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 3 additions & 5 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Test_Iterator(t *testing.T) {
sql, err := iavl.NewInMemorySqliteDb(pool)
require.NoError(t, err)

tree := iavl.NewTree(sql, pool, iavl.TreeOptions{StateStorage: false})
tree := iavl.NewTree(sql, iavl.TreeOptions{StateStorage: false})
set := func(key string, value string) {
_, err := tree.Set([]byte(key), []byte(value))
require.NoError(t, err)
Expand Down Expand Up @@ -208,7 +208,6 @@ func Test_Iterator(t *testing.T) {
if cnt == 0 {
require.Equal(t, tc.expectedStart, itr.Key())
}
//fmt.Printf("%s %s\n", itr.Key(), itr.Value())
require.NoError(t, itr.Error())
cnt++
}
Expand All @@ -226,7 +225,7 @@ func Test_IteratorTree(t *testing.T) {
sql, err := iavl.NewSqliteDb(pool, iavl.SqliteDbOptions{Path: tmpDir})
require.NoError(t, err)

tree := iavl.NewTree(sql, pool, iavl.TreeOptions{StateStorage: true})
tree := iavl.NewTree(sql, iavl.TreeOptions{StateStorage: true})
set := func(key string, value string) {
_, err := tree.Set([]byte(key), []byte(value))
require.NoError(t, err)
Expand All @@ -241,7 +240,7 @@ func Test_IteratorTree(t *testing.T) {

_, version, err := tree.SaveVersion()
require.NoError(t, err)
tree = iavl.NewTree(sql, pool, iavl.TreeOptions{StateStorage: true})
tree = iavl.NewTree(sql, iavl.TreeOptions{StateStorage: true})
require.NoError(t, tree.LoadVersion(version))
cases := []struct {
name string
Expand Down Expand Up @@ -304,5 +303,4 @@ func Test_IteratorTree(t *testing.T) {
require.NoError(t, itr.Close())
})
}

}
12 changes: 5 additions & 7 deletions multitree.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ImportMultiTree(pool *NodePool, version int64, path string, treeOpts TreeOp
return nil, err
}
go func(p string) {
tree := NewTree(sql, pool, mt.treeOpts)
tree := NewTree(sql, mt.treeOpts)
importErr := tree.LoadSnapshot(version, PreOrder)

if importErr != nil {
Expand Down Expand Up @@ -94,7 +94,7 @@ func (mt *MultiTree) MountTree(storeKey string) error {
if err != nil {
return err
}
tree := NewTree(sql, mt.pool, mt.treeOpts)
tree := NewTree(sql, mt.treeOpts)
mt.Trees[storeKey] = tree
return nil
}
Expand All @@ -113,7 +113,7 @@ func (mt *MultiTree) MountTrees() error {
if err != nil {
return err
}
tree := NewTree(sql, mt.pool, mt.treeOpts)
tree := NewTree(sql, mt.treeOpts)
mt.Trees[prefix] = tree
}
return nil
Expand Down Expand Up @@ -230,10 +230,8 @@ func (mt *MultiTree) SnapshotConcurrently() error {
// https://github.com/cosmos/cosmos-sdk/blob/80dd55f79bba8ab675610019a5764470a3e2fef9/store/types/commit_info.go#L30
// it used in testing. App chains should use the store hashing code referenced above instead.
func (mt *MultiTree) Hash() []byte {
var (
storeKeys []string
hashes []byte
)
storeKeys := make([]string, len(mt.Trees))
hashes := make([]byte, 0)
for k := range mt.Trees {
storeKeys = append(storeKeys, k)
}
Expand Down
11 changes: 5 additions & 6 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ type Node struct {
rightNode *Node
subtreeHeight int8

dirty bool
evict bool
poolId uint64
dirty bool
evict bool
}

func (node *Node) String() string {
return fmt.Sprintf("Node{hash: %x, nodeKey: %s, leftNodeKey: %v, rightNodeKey: %v, size: %d, subtreeHeight: %d, poolId: %d}",
node.hash, node.nodeKey, node.leftNodeKey, node.rightNodeKey, node.size, node.subtreeHeight, node.poolId)
return fmt.Sprintf("Node{hash: %x, nodeKey: %s, leftNodeKey: %v, rightNodeKey: %v, size: %d, subtreeHeight: %d}",
node.hash, node.nodeKey, node.leftNodeKey, node.rightNodeKey, node.size, node.subtreeHeight)
}

func (node *Node) isLeaf() bool {
Expand Down Expand Up @@ -341,7 +340,7 @@ var (

// Computes the hash of the node without computing its descendants. Must be
// called on nodes which have descendant node hashes already computed.
func (node *Node) _hash() []byte {
func (node *Node) _hash() []byte { // nolint: unparam
if node.hash != nil {
return node.hash
}
Expand Down
17 changes: 1 addition & 16 deletions pool.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package iavl

import (
"math"
"sync"
)

type NodePool struct {
syncPool *sync.Pool

free chan int
nodes []Node

poolId uint64
Comment on lines -11 to -14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the reason for this removal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see any usage of it, only sync.Pool

}

func NewNodePool() *NodePool {
Expand All @@ -21,20 +15,12 @@ func NewNodePool() *NodePool {
return &Node{}
},
},
free: make(chan int, 1000),
}
return np
}

func (np *NodePool) Get() *Node {
if np.poolId == math.MaxUint64 {
np.poolId = 1
} else {
np.poolId++
}
n := np.syncPool.Get().(*Node)
n.poolId = np.poolId
return n
return np.syncPool.Get().(*Node)
}

func (np *NodePool) Put(node *Node) {
Expand All @@ -51,6 +37,5 @@ func (np *NodePool) Put(node *Node) {
node.dirty = false
node.evict = false

node.poolId = 0
np.syncPool.Put(node)
}
4 changes: 2 additions & 2 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
func TestNodePool_Get(t *testing.T) {
pool := NewNodePool()
node := pool.Get()
require.Equal(t, []byte(nil), node.key)
node.key = []byte("hello")
require.Equal(t, node.key, pool.nodes[node.poolId].key)
pool.Put(node)
require.Equal(t, []byte(nil), pool.nodes[node.poolId].key)
require.Equal(t, []byte(nil), pool.Get().key)
}
3 changes: 2 additions & 1 deletion snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ func (sql *SqliteDb) WriteSnapshot(
return nil, err
}

var versions []int64
versions := make([]int64, len(uniqueVersions))
for v := range uniqueVersions {
versions = append(versions, v)
}
fmt.Printf("snapshot %d: %d versions\n", version, len(versions))

if err = sql.SaveRoot(version, root, true); err != nil {
return nil, err
Expand Down
14 changes: 7 additions & 7 deletions sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ func NewSqliteDb(pool *NodePool, opts SqliteDbOptions) (*SqliteDb, error) {
}

if !api.IsFileExistent(opts.Path) {
err := os.MkdirAll(opts.Path, 0755)
if err != nil {
if err := os.MkdirAll(opts.Path, 0o755); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -226,6 +225,10 @@ CREATE INDEX leaf_orphan_idx ON leaf_orphan (at);`)
return nil
}

func (sql *SqliteDb) getPool() *NodePool {
return sql.pool
}

func (sql *SqliteDb) resetWriteConn() (err error) {
if sql.treeWrite != nil {
err = sql.treeWrite.Close()
Expand Down Expand Up @@ -501,7 +504,7 @@ func (sql *SqliteDb) LoadRoot(version int64) (*Node, error) {

// lastCheckpoint fetches the last checkpoint version from the shard table previous to the loaded root's version.
// a return value of zero and nil error indicates no checkpoint was found.
func (sql *SqliteDb) lastCheckpoint(treeVersion int64) (checkpointVersion int64, err error) {
func (sql *SqliteDb) lastCheckpoint(treeVersion int64) (checkpointVersion int64, err error) { // nolint: unused
conn, err := sqlite3.Open(sql.opts.treeConnectionString())
if err != nil {
return 0, err
Expand Down Expand Up @@ -556,7 +559,6 @@ func (sql *SqliteDb) loadCheckpointRange() (*VersionRange, error) {
}
if err = versionRange.Add(version); err != nil {
return nil, err

}
}
if err = q.Close(); err != nil {
Expand Down Expand Up @@ -826,8 +828,6 @@ func (sql *SqliteDb) Revert(version int) error {
return err
}
}
} else {

}
return nil
}
Expand All @@ -840,7 +840,7 @@ func (sql *SqliteDb) GetLatestLeaf(key []byte) ([]byte, error) {
return nil, err
}
}
defer sql.queryLatest.Reset()
defer sql.queryLatest.Reset() //nolint:errcheck

if err := sql.queryLatest.Bind(key); err != nil {
return nil, err
Expand Down
Loading
Loading