Skip to content

Commit

Permalink
fix(x/tx): default to using gogoproto.HybridResolver wherever possible (
Browse files Browse the repository at this point in the history
#19845)

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
  • Loading branch information
aaronc and tac0turtle authored Mar 25, 2024
1 parent ea7bdd1 commit adc3432
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 23 deletions.
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
16 changes: 10 additions & 6 deletions x/tx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Improvments

* [#19845](https://github.com/cosmos/cosmos-sdk/pull/19845) Use hybrid resolver instead of only protov2 registry

## v0.13.1

### Features
Expand Down Expand Up @@ -113,18 +117,18 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* [#15871](https://github.com/cosmos/cosmos-sdk/pull/15871)
* `HandlerMap` now has a `DefaultMode()` getter method
* Textual types use `signing.ProtoFileResolver` instead of `protoregistry.Files`
* `HandlerMap` now has a `DefaultMode()` getter method
* Textual types use `signing.ProtoFileResolver` instead of `protoregistry.Files`

## v0.6.0

### API Breaking

* [#15709](https://github.com/cosmos/cosmos-sdk/pull/15709):
* `GetSignersContext` has been renamed to `signing.Context`
* `GetSigners` now returns `[][]byte` instead of `[]string`
* `GetSignersOptions` has been renamed to `signing.Options` and requires `address.Codec`s for account and validator addresses
* `GetSignersOptions.ProtoFiles` has been renamed to `signing.Options.FileResolver`
* `GetSignersContext` has been renamed to `signing.Context`
* `GetSigners` now returns `[][]byte` instead of `[]string`
* `GetSignersOptions` has been renamed to `signing.Options` and requires `address.Codec`s for account and validator addresses
* `GetSignersOptions.ProtoFiles` has been renamed to `signing.Options.FileResolver`

### Bug Fixes

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

0 comments on commit adc3432

Please sign in to comment.