Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang authored Dec 15, 2024
2 parents bb624b8 + d89d5d2 commit d550dcf
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 39 deletions.
3 changes: 2 additions & 1 deletion benchmarks/cosmos-exim/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -128,7 +129,7 @@ func runExport(dbPath string) (int64, map[string][]*iavl.ExportNode, error) {
defer exporter.Close()
for {
node, err := exporter.Next()
if err == iavl.ErrorExportDone {
if errors.Is(err, iavl.ErrorExportDone) {
break
} else if err != nil {
return 0, nil, err
Expand Down
3 changes: 2 additions & 1 deletion cmd/iaviewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -67,7 +68,7 @@ func OpenDB(dir string) (corestore.KVStoreWithBatch, error) {
case strings.HasSuffix(dir, ".db/"):
dir = dir[:len(dir)-4]
default:
return nil, fmt.Errorf("database directory must end with .db")
return nil, errors.New("database directory must end with .db")
}

dir, err := filepath.Abs(dir)
Expand Down
9 changes: 5 additions & 4 deletions export_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package iavl

import (
"errors"
"math"
"math/rand"
"testing"
Expand Down Expand Up @@ -180,7 +181,7 @@ func TestExporter(t *testing.T) {
defer exporter.Close()
for {
node, err := exporter.Next()
if err == ErrorExportDone {
if errors.Is(err, ErrorExportDone) {
break
}
require.NoError(t, err)
Expand Down Expand Up @@ -215,7 +216,7 @@ func TestExporterCompress(t *testing.T) {
exporter := NewCompressExporter(innerExporter)
for {
node, err := exporter.Next()
if err == ErrorExportDone {
if errors.Is(err, ErrorExportDone) {
break
}
require.NoError(t, err)
Expand Down Expand Up @@ -266,7 +267,7 @@ func TestExporter_Import(t *testing.T) {

for {
item, err := exporter.Next()
if err == ErrorExportDone {
if errors.Is(err, ErrorExportDone) {
err = innerImporter.Commit()
require.NoError(t, err)
break
Expand Down Expand Up @@ -365,7 +366,7 @@ func BenchmarkExport(b *testing.B) {
require.NoError(b, err)
for {
_, err := exporter.Next()
if err == ErrorExportDone {
if errors.Is(err, ErrorExportDone) {
break
} else if err != nil {
b.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.23.1
require (
cosmossdk.io/core v1.0.0-alpha.6
github.com/cosmos/ics23/go v0.11.0
github.com/emicklei/dot v1.6.3
github.com/emicklei/dot v1.6.4
github.com/gogo/protobuf v1.3.2
github.com/google/btree v1.1.3
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIG
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/dot v1.6.3 h1:MW9eLeJWaN+QZVSPlrargGd/l92IA6d4fmo39/YD2cQ=
github.com/emicklei/dot v1.6.3/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
github.com/emicklei/dot v1.6.4 h1:cG9ycT67d9Yw22G+mAb4XiuUz6E6H1S0zePp/5Cwe/c=
github.com/emicklei/dot v1.6.4/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
Expand Down
5 changes: 3 additions & 2 deletions import_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package iavl

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -43,7 +44,7 @@ func ExampleImporter() {
for {
var node *ExportNode
node, err = exporter.Next()
if err == ErrorExportDone {
if errors.Is(err, ErrorExportDone) {
break
} else if err != nil {
panic(err)
Expand Down Expand Up @@ -247,7 +248,7 @@ func benchmarkImport(b *testing.B, nodes int) {
require.NoError(b, err)
for {
item, err := exporter.Next()
if err == ErrorExportDone {
if errors.Is(err, ErrorExportDone) {
break
} else if err != nil {
b.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Encode32BytesHash(w io.Writer, bz []byte) error {
return err
}

// encodeBytesSlice length-prefixes the byte slice and returns it.
// EncodeBytesSlice length-prefixes the byte slice and returns it.
func EncodeBytesSlice(bz []byte) ([]byte, error) {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
Expand All @@ -127,7 +127,7 @@ func EncodeBytesSlice(bz []byte) ([]byte, error) {
return bytesCopy, err
}

// encodeBytesSize returns the byte size of the given slice including length-prefixing.
// EncodeBytesSize returns the byte size of the given slice including length-prefixing.
func EncodeBytesSize(bz []byte) int {
return EncodeUvarintSize(uint64(len(bz))) + len(bz)
}
Expand Down
6 changes: 3 additions & 3 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func (tree *MutableTree) LoadVersion(targetVersion int64) (int64, error) {
return latestVersion, nil
}

// loadVersionForOverwriting attempts to load a tree at a previously committed
// LoadVersionForOverwriting attempts to load a tree at a previously committed
// version, or the latest version below it. Any versions greater than targetVersion will be deleted.
func (tree *MutableTree) LoadVersionForOverwriting(targetVersion int64) error {
if _, err := tree.LoadVersion(targetVersion); err != nil {
Expand Down Expand Up @@ -960,7 +960,7 @@ func (tree *MutableTree) rotateLeft(node *Node) (*Node, error) {
// TODO: optimize balance & rotate
func (tree *MutableTree) balance(node *Node) (newSelf *Node, err error) {
if node.nodeKey != nil {
return nil, fmt.Errorf("unexpected balance() call on persisted node")
return nil, errors.New("unexpected balance() call on persisted node")
}
balance, err := node.calcBalance(tree.ImmutableTree)
if err != nil {
Expand Down Expand Up @@ -1084,7 +1084,7 @@ func (tree *MutableTree) saveNewNodes(version int64) error {
func (tree *MutableTree) SaveChangeSet(cs *ChangeSet) (int64, error) {
// if the tree has uncommitted changes, return error
if tree.root != nil && tree.root.nodeKey == nil {
return 0, fmt.Errorf("cannot save changeset with uncommitted changes")
return 0, errors.New("cannot save changeset with uncommitted changes")
}
for _, pair := range cs.Pairs {
if pair.Delete {
Expand Down
2 changes: 1 addition & 1 deletion mutable_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestIterateConcurrency(t *testing.T) {
wg.Wait()
}

// TestConcurrency throws "fatal error: concurrent map iteration and map write" and
// TestIteratorConcurrency throws "fatal error: concurrent map iteration and map write" and
// also sometimes "fatal error: concurrent map writes" when fast node is enabled
func TestIteratorConcurrency(t *testing.T) {
if testing.Short() {
Expand Down
6 changes: 3 additions & 3 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (ndb *nodeDB) GetFastNode(key []byte) (*fastnode.Node, error) {
defer ndb.mtx.Unlock()

if len(key) == 0 {
return nil, fmt.Errorf("nodeDB.GetFastNode() requires key, len(key) equals 0")
return nil, errors.New("nodeDB.GetFastNode() requires key, len(key) equals 0")
}

if cachedFastNode := ndb.fastNodeCache.Get(key); cachedFastNode != nil {
Expand Down Expand Up @@ -360,7 +360,7 @@ func (ndb *nodeDB) shouldForceFastStorageUpgrade() (bool, error) {
// saveFastNodeUnlocked saves a FastNode to disk.
func (ndb *nodeDB) saveFastNodeUnlocked(node *fastnode.Node, shouldAddToCache bool) error {
if node.GetKey() == nil {
return fmt.Errorf("cannot have FastNode with a nil value for key")
return errors.New("cannot have FastNode with a nil value for key")
}

// Save node bytes to db.
Expand Down Expand Up @@ -1339,4 +1339,4 @@ func (ndb *nodeDB) String() (string, error) {
return "-" + "\n" + buf.String() + "-", nil
}

var ErrNodeMissingNodeKey = fmt.Errorf("node does not have a nodeKey")
var ErrNodeMissingNodeKey = errors.New("node does not have a nodeKey")
2 changes: 1 addition & 1 deletion nodedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func TestTraverseNodes(t *testing.T) {
return err
}
if actualNode.String() != node.String() {
return fmt.Errorf("found unexpected node")
return errors.New("found unexpected node")
}
count++
return nil
Expand Down
6 changes: 3 additions & 3 deletions proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ var bufPool = &sync.Pool{

var (
// ErrInvalidProof is returned by Verify when a proof cannot be validated.
ErrInvalidProof = fmt.Errorf("invalid proof")
ErrInvalidProof = errors.New("invalid proof")

// ErrInvalidInputs is returned when the inputs passed to the function are invalid.
ErrInvalidInputs = fmt.Errorf("invalid inputs")
ErrInvalidInputs = errors.New("invalid inputs")

// ErrInvalidRoot is returned when the root passed in does not match the proof's.
ErrInvalidRoot = fmt.Errorf("invalid root")
ErrInvalidRoot = errors.New("invalid root")
)

//----------------------------------------
Expand Down
7 changes: 3 additions & 4 deletions proof_ics23.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package iavl

import (
"encoding/binary"
"fmt"

"errors"
ics23 "github.com/cosmos/ics23/go"
)

Expand Down Expand Up @@ -48,7 +47,7 @@ func (t *ImmutableTree) GetNonMembershipProof(key []byte) (*ics23.CommitmentProo
}

if val != nil {
return nil, fmt.Errorf("cannot create NonExistanceProof when Key in State")
return nil, errors.New("cannot create NonExistanceProof when Key in State")
}

nonexist := &ics23.NonExistenceProof{
Expand Down Expand Up @@ -177,7 +176,7 @@ func convertVarIntToBytes(orig int64, buf [binary.MaxVarintLen64]byte) []byte {
// GetProof gets the proof for the given key.
func (t *ImmutableTree) GetProof(key []byte) (*ics23.CommitmentProof, error) {
if t.root == nil {
return nil, fmt.Errorf("cannot generate the proof with nil root")
return nil, errors.New("cannot generate the proof with nil root")
}

exist, err := t.Has(key)
Expand Down
6 changes: 4 additions & 2 deletions v2/export.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package iavl

import "fmt"
import (
"errors"
)

// TraverseOrderType is the type of the order in which the tree is traversed.
type TraverseOrderType uint8
Expand Down Expand Up @@ -98,4 +100,4 @@ func (e *Exporter) Next() (*SnapshotNode, error) {
}
}

var ErrorExportDone = fmt.Errorf("export done")
var ErrorExportDone = errors.New("export done")
4 changes: 2 additions & 2 deletions v2/internal/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func EncodeBytes(w io.Writer, bz []byte) error {
return err
}

// encodeBytesSlice length-prefixes the byte slice and returns it.
// EncodeBytesSlice length-prefixes the byte slice and returns it.
func EncodeBytesSlice(bz []byte) ([]byte, error) {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
Expand All @@ -111,7 +111,7 @@ func EncodeBytesSlice(bz []byte) ([]byte, error) {
return bytesCopy, err
}

// encodeBytesSize returns the byte size of the given slice including length-prefixing.
// EncodeBytesSize returns the byte size of the given slice including length-prefixing.
func EncodeBytesSize(bz []byte) int {
return EncodeUvarintSize(uint64(len(bz))) + len(bz)
}
Expand Down
3 changes: 2 additions & 1 deletion v2/migrate/v0/migrate_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v0

import (
"bytes"
"errors"
"fmt"
"sync"

Expand Down Expand Up @@ -111,7 +112,7 @@ func latestVersionCommand() *cobra.Command {
return err
}
if set && version == -1 {
return fmt.Errorf("version must be set")
return errors.New("version must be set")
}
if set {

Expand Down
6 changes: 3 additions & 3 deletions v2/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (node *Node) right(t *Tree) *Node {
// getLeftNode will never be called on leaf nodes. all tree nodes have 2 children.
func (node *Node) getLeftNode(t *Tree) (*Node, error) {
if node.isLeaf() {
return nil, fmt.Errorf("leaf node has no left node")
return nil, errors.New("leaf node has no left node")
}
if node.leftNode != nil {
return node.leftNode, nil
Expand All @@ -117,7 +117,7 @@ func (node *Node) getLeftNode(t *Tree) (*Node, error) {

func (node *Node) getRightNode(t *Tree) (*Node, error) {
if node.isLeaf() {
return nil, fmt.Errorf("leaf node has no right node")
return nil, errors.New("leaf node has no right node")
}
if node.rightNode != nil {
return node.rightNode, nil
Expand Down Expand Up @@ -158,7 +158,7 @@ func maxInt8(a, b int8) int8 {
// TODO: optimize balance & rotate
func (tree *Tree) balance(node *Node) (newSelf *Node, err error) {
if node.hash != nil {
return nil, fmt.Errorf("unexpected balance() call on persisted node")
return nil, errors.New("unexpected balance() call on persisted node")
}
balance, err := node.calcBalance(tree)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion v2/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package iavl

import (
"bytes"
"errors"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -99,7 +100,7 @@ func (opts SqliteDbOptions) EstimateMmapSize() (uint64, error) {
return 0, err
}
if !hasRow {
return 0, fmt.Errorf("no row")
return 0, errors.New("no row")
}
var leafSize int64
err = q.Scan(&leafSize)
Expand Down
3 changes: 2 additions & 1 deletion v2/sqlite_metadata.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package iavl

import (
"errors"
"fmt"
"os"
"sync"
Expand All @@ -19,7 +20,7 @@ type SqliteKVStore struct {

func NewSqliteKVStore(opts SqliteDbOptions) (kv *SqliteKVStore, err error) {
if opts.Path == "" {
return nil, fmt.Errorf("path cannot be empty")
return nil, errors.New("path cannot be empty")
}
if opts.WalSize == 0 {
opts.WalSize = 50 * 1024 * 1024
Expand Down
3 changes: 2 additions & 1 deletion v2/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/sha256"
"errors"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -102,7 +103,7 @@ func NewTree(sql *SqliteDb, pool *NodePool, opts TreeOptions) *Tree {

func (tree *Tree) LoadVersion(version int64) (err error) {
if tree.sql == nil {
return fmt.Errorf("sql is nil")
return errors.New("sql is nil")
}

tree.workingBytes = 0
Expand Down

0 comments on commit d550dcf

Please sign in to comment.