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

fix(x/tx): default to using gogoproto.HybridResolver wherever possible #19845

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions store/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ type Reader interface {
//
// Note: <key> is safe to modify and read after calling Get.
// The returned byte slice is safe to read, but cannot be modified.
Get(storeKey []byte, key []byte) ([]byte, error)
Get(storeKey, key []byte) ([]byte, error)
}

// Writer wraps the Set method of a backing data store.
type Writer interface {
// Set inserts the given value into the key-value data store.
//
// Note: <key, value> are safe to modify and read after calling Set.
Set(storeKey []byte, key, value []byte) error
Set(storeKey, key, value []byte) error

// Delete removes the key from the backing key-value data store.
//
// Note: <key> is safe to modify and read after calling Delete.
Delete(storeKey []byte, key []byte) error
Delete(storeKey, key []byte) error
}

// Database contains all the methods required to allow handling different
Expand Down
3 changes: 2 additions & 1 deletion store/internal/encoding/changeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package encoding
import (
"testing"

corestore "cosmossdk.io/core/store"
"github.com/stretchr/testify/require"

corestore "cosmossdk.io/core/store"
)

func TestChangesetMarshal(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions store/storage/pebbledb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func (b *Batch) set(storeKey []byte, tombstone uint64, key, value []byte) error
return nil
}

func (b *Batch) Set(storeKey []byte, key, value []byte) error {
func (b *Batch) Set(storeKey, key, value []byte) error {
return b.set(storeKey, 0, key, value)
}

func (b *Batch) Delete(storeKey []byte, key []byte) error {
func (b *Batch) Delete(storeKey, key []byte) error {
return b.set(storeKey, b.version, key, []byte(tombstoneVal))
}

Expand Down
4 changes: 2 additions & 2 deletions store/storage/pebbledb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func storePrefix(storeKey []byte) []byte {
return append([]byte(StorePrefixTpl), storeKey...)
}

func prependStoreKey(storeKey []byte, key []byte) []byte {
func prependStoreKey(storeKey, key []byte) []byte {
return append(storePrefix(storeKey), key...)
}

Expand Down Expand Up @@ -362,7 +362,7 @@ func valTombstoned(value []byte) bool {
return true
}

func getMVCCSlice(db *pebble.DB, storeKey []byte, key []byte, version uint64) ([]byte, error) {
func getMVCCSlice(db *pebble.DB, storeKey, key []byte, version uint64) ([]byte, error) {
// end domain is exclusive, so we need to increment the version by 1
if version < math.MaxUint64 {
version++
Expand Down
4 changes: 2 additions & 2 deletions store/storage/sqlite/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ func (b *Batch) Reset() error {
return nil
}

func (b *Batch) Set(storeKey []byte, key, value []byte) error {
func (b *Batch) Set(storeKey, key, value []byte) error {
b.size += len(key) + len(value)
b.ops = append(b.ops, batchOp{action: batchActionSet, storeKey: storeKey, key: key, value: value})
return nil
}

func (b *Batch) Delete(storeKey []byte, key []byte) error {
func (b *Batch) Delete(storeKey, key []byte) error {
b.size += len(key)
b.ops = append(b.ops, batchOp{action: batchActionDel, storeKey: storeKey, key: key})
return nil
Expand Down
4 changes: 1 addition & 3 deletions store/storage/sqlite/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
"cosmossdk.io/store/v2/storage"
)

var (
storeKey1 = []byte("store1")
)
var storeKey1 = []byte("store1")

func TestStorageTestSuite(t *testing.T) {
s := &storage.StorageTestSuite{
Expand Down
3 changes: 2 additions & 1 deletion x/tx/signing/aminojson/aminojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/reflect/protoregistry"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
Expand All @@ -31,7 +32,7 @@ type SignModeHandlerOptions struct {
func NewSignModeHandler(options SignModeHandlerOptions) *SignModeHandler {
h := &SignModeHandler{}
if options.FileResolver == nil {
h.fileResolver = protoregistry.GlobalFiles
h.fileResolver = gogoproto.HybridResolver
} else {
h.fileResolver = options.FileResolver
}
Expand Down
3 changes: 2 additions & 1 deletion x/tx/signing/aminojson/json_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"sort"

gogoproto "github.com/cosmos/gogoproto/proto"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
Expand Down Expand Up @@ -55,7 +56,7 @@ type Encoder struct {
// rules.
func NewEncoder(options EncoderOptions) Encoder {
if options.FileResolver == nil {
options.FileResolver = protoregistry.GlobalFiles
options.FileResolver = gogoproto.HybridResolver
}
if options.TypeResolver == nil {
options.TypeResolver = protoregistry.GlobalTypes
Expand Down
3 changes: 2 additions & 1 deletion x/tx/signing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

cosmos_proto "github.com/cosmos/cosmos-proto"
gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protodesc"
"google.golang.org/protobuf/reflect/protoreflect"
Expand Down Expand Up @@ -79,7 +80,7 @@ type ProtoFileResolver interface {
func NewContext(options Options) (*Context, error) {
protoFiles := options.FileResolver
if protoFiles == nil {
protoFiles = protoregistry.GlobalFiles
protoFiles = gogoproto.HybridResolver
}

protoTypes := options.TypeResolver
Expand Down
3 changes: 2 additions & 1 deletion x/tx/signing/textual/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"

cosmos_proto "github.com/cosmos/cosmos-proto"
gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
Expand Down Expand Up @@ -71,7 +72,7 @@ func NewSignModeHandler(o SignModeOptions) (*SignModeHandler, error) {
return nil, errors.New("coinMetadataQuerier must be non-empty")
}
if o.FileResolver == nil {
o.FileResolver = protoregistry.GlobalFiles
o.FileResolver = gogoproto.HybridResolver
}
if o.TypeResolver == nil {
o.TypeResolver = protoregistry.GlobalTypes
Expand Down
Loading