Skip to content

Commit

Permalink
Merge branch 'main' into lucas/pagination-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslopezf authored May 15, 2024
2 parents 3a29a8b + 080229f commit 500b11c
Show file tree
Hide file tree
Showing 97 changed files with 391 additions and 356 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### API Breaking Changes

* (types)[#20369](https://github.com/cosmos/cosmos-sdk/pull/20369) The signature of `HasAminoCodec` has changed to accept a `core/legacy.Amino` interface instead of `codec.LegacyAmino`.
* (x/simulation)[#20056](https://github.com/cosmos/cosmos-sdk/pull/20056) `SimulateFromSeed` now takes an address codec as argument.
* (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`.
* (x/genutil) [#19926](https://github.com/cosmos/cosmos-sdk/pull/19926) Removal of the Address.String() method and related changes:
Expand Down
7 changes: 7 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ The signature of the extension interface `HasRegisterInterfaces` has been change
+func (AppModule) RegisterInterfaces(registry registry.InterfaceRegistrar) {
```

The signature of the extension interface `HasAminoCodec` has been changed to accept a `cosmossdk.io/core/legacy.Amino` instead of a `codec.LegacyAmino`. Modules should update their `HasAminoCodec` implementation to accept a `cosmossdk.io/core/legacy.Amino` interface.

```diff
-func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
+func (AppModule) RegisterLegacyAminoCodec(cdc legacy.Amino) {
```

##### Simulation

`MsgSimulatorFn` has been updated to return an error. Its context argument has been removed, and an address.Codec has
Expand Down
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package baseapp

import (
"context"
"errors"
"fmt"
"sort"
"strings"
"time"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cosmos/gogoproto/proto"
Expand Down
2 changes: 1 addition & 1 deletion baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package baseapp
import (
"bytes"
"context"
"errors"
"fmt"
"slices"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
cryptoenc "github.com/cometbft/cometbft/crypto/encoding"
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package baseapp

import (
"context"
"errors"
"fmt"
"math"
"sort"
"strconv"
"sync"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/crypto/tmhash"
Expand Down
2 changes: 1 addition & 1 deletion client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package client
import (
"context"
"crypto/tls"
"errors"
"fmt"
"slices"
"strings"

"github.com/cockroachdb/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"google.golang.org/grpc"
Expand Down
2 changes: 1 addition & 1 deletion client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package client

import (
"context"
"errors"
"fmt"
"strings"

"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
rpcclient "github.com/cometbft/cometbft/rpc/client"
"google.golang.org/grpc/codes"
Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/flag/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"encoding/base64"
"encoding/hex"
"errors"
"os"

"github.com/cockroachdb/errors"
"google.golang.org/protobuf/reflect/protoreflect"
)

Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/flag/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package flag

import (
"context"
"errors"
"fmt"
"strings"

"github.com/cockroachdb/errors"
"github.com/spf13/pflag"
"google.golang.org/protobuf/reflect/protoreflect"

Expand Down
5 changes: 2 additions & 3 deletions client/v2/autocli/flag/maps/generic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package maps

import (
"fmt"
"strings"

"github.com/cockroachdb/errors"
)

type genericMapValueOptions[K comparable, V any] struct {
Expand Down Expand Up @@ -31,7 +30,7 @@ func (gm *genericMapValue[K, V]) Set(val string) error {
for _, pair := range ss {
kv := strings.SplitN(pair, "=", 2)
if len(kv) != 2 {
return errors.Errorf("%s must be formatted as key=value", pair)
return fmt.Errorf("%s must be formatted as key=value", pair)
}
key, err := gm.Options.keyParser(kv[0])
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions client/v2/autocli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/cockroachdb/errors"
gogoproto "github.com/cosmos/gogoproto/proto"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -69,7 +68,7 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc

descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service))
if err != nil {
return errors.Errorf("can't find service %s: %v", cmdDescriptor.Service, err)
return fmt.Errorf("can't find service %s: %w", cmdDescriptor.Service, err)
}
service := descriptor.(protoreflect.ServiceDescriptor)
methods := service.Methods()
Expand Down
4 changes: 2 additions & 2 deletions client/v2/autocli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/math"
"cosmossdk.io/x/tx/signing/aminojson"
"github.com/cockroachdb/errors"

"github.com/spf13/cobra"
"google.golang.org/protobuf/reflect/protoreflect"

Expand Down Expand Up @@ -62,7 +62,7 @@ func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *aut

descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service))
if err != nil {
return errors.Errorf("can't find service %s: %v", cmdDescriptor.Service, err)
return fmt.Errorf("can't find service %s: %w", cmdDescriptor.Service, err)
}

service := descriptor.(protoreflect.ServiceDescriptor)
Expand Down
2 changes: 1 addition & 1 deletion client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a
cosmossdk.io/x/tx v0.13.3
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.11.1
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.51.0
github.com/manifoldco/promptui v0.9.0 // indirect
Expand Down
25 changes: 18 additions & 7 deletions codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
cmttypes "github.com/cometbft/cometbft/types"
"github.com/tendermint/go-amino"

"cosmossdk.io/core/legacy"

"github.com/cosmos/cosmos-sdk/codec/types"
)

Expand All @@ -23,15 +25,17 @@ func (cdc *LegacyAmino) Seal() {
cdc.Amino.Seal()
}

var _ legacy.Amino = &LegacyAmino{}

func NewLegacyAmino() *LegacyAmino {
return &LegacyAmino{amino.NewCodec()}
}

// RegisterEvidences registers CometBFT evidence types with the provided Amino
// codec.
func RegisterEvidences(cdc *LegacyAmino) {
cdc.Amino.RegisterInterface((*cmttypes.Evidence)(nil), nil)
cdc.Amino.RegisterConcrete(&cmttypes.DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence", nil)
func RegisterEvidences(cdc legacy.Amino) {
cdc.RegisterInterface((*cmttypes.Evidence)(nil), nil)
cdc.RegisterConcrete(&cmttypes.DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence")
}

// MarshalJSONIndent provides a utility for indented JSON encoding of an object
Expand Down Expand Up @@ -175,12 +179,19 @@ func (*LegacyAmino) UnpackAny(*types.Any, interface{}) error {
return errors.New("AminoCodec can't handle unpack protobuf Any's")
}

func (cdc *LegacyAmino) RegisterInterface(ptr interface{}, iopts *amino.InterfaceOptions) {
cdc.Amino.RegisterInterface(ptr, iopts)
func (cdc *LegacyAmino) RegisterInterface(ptr interface{}, iopts *legacy.InterfaceOptions) {
if iopts == nil {
cdc.Amino.RegisterInterface(ptr, nil)
} else {
cdc.Amino.RegisterInterface(ptr, &amino.InterfaceOptions{
Priority: iopts.Priority,
AlwaysDisambiguate: iopts.AlwaysDisambiguate,
})
}
}

func (cdc *LegacyAmino) RegisterConcrete(o interface{}, name string, copts *amino.ConcreteOptions) {
cdc.Amino.RegisterConcrete(o, name, copts)
func (cdc *LegacyAmino) RegisterConcrete(o interface{}, name string) {
cdc.Amino.RegisterConcrete(o, name, nil)
}

func (cdc *LegacyAmino) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func createTestCodec() *codec.LegacyAmino {
cdc.RegisterInterface((*testdata.Animal)(nil), nil)
// NOTE: since we unmarshal interface using pointers, we need to register a pointer
// types here.
cdc.RegisterConcrete(&testdata.Dog{}, "testdata/Dog", nil)
cdc.RegisterConcrete(&testdata.Cat{}, "testdata/Cat", nil)
cdc.RegisterConcrete(&testdata.Dog{}, "testdata/Dog")
cdc.RegisterConcrete(&testdata.Cat{}, "testdata/Cat")

return cdc
}
Expand Down
47 changes: 47 additions & 0 deletions codec/depinject.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package codec

import (
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/core/address"
"cosmossdk.io/core/legacy"
"cosmossdk.io/x/tx/signing"

"github.com/cosmos/cosmos-sdk/codec/types"
)

func ProvideInterfaceRegistry(
addressCodec address.Codec,
validatorAddressCodec address.ValidatorAddressCodec,
customGetSigners []signing.CustomGetSigner,
) (types.InterfaceRegistry, error) {
signingOptions := signing.Options{
AddressCodec: addressCodec,
ValidatorAddressCodec: validatorAddressCodec,
}
for _, signer := range customGetSigners {
signingOptions.DefineCustomGetSigners(signer.MsgType, signer.Fn)
}

interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signingOptions,
})
if err != nil {
return nil, err
}

if err := interfaceRegistry.SigningContext().Validate(); err != nil {
return nil, err
}

return interfaceRegistry, nil
}

func ProvideLegacyAmino() legacy.Amino {
return NewLegacyAmino()
}

func ProvideProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec {
return NewProtoCodec(interfaceRegistry)
}
7 changes: 4 additions & 3 deletions codec/legacy/amino_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package legacy
import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
"cosmossdk.io/core/legacy"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// RegisterAminoMsg first checks that the msgName is <40 chars
// (else this would break ledger nano signing: https://github.com/cosmos/cosmos-sdk/issues/10870),
// then registers the concrete msg type with amino.
func RegisterAminoMsg(cdc *codec.LegacyAmino, msg sdk.Msg, msgName string) {
func RegisterAminoMsg(cdc legacy.Amino, msg sdk.Msg, msgName string) {
if len(msgName) > 39 {
panic(fmt.Errorf("msg name %s is too long to be registered with amino", msgName))
}
cdc.RegisterConcrete(msg, msgName, nil)
cdc.RegisterConcrete(msg, msgName)
}
14 changes: 14 additions & 0 deletions core/legacy/amino.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package legacy

type Amino interface {
// RegisterInterface registers an interface and its concrete type with the Amino codec.
RegisterInterface(interfacePtr any, iopts *InterfaceOptions)

// RegisterConcrete registers a concrete type with the Amino codec.
RegisterConcrete(cdcType interface{}, name string)
}

type InterfaceOptions struct {
Priority []string // Disamb priority.
AlwaysDisambiguate bool // If true, include disamb for all types.
}
19 changes: 10 additions & 9 deletions crypto/codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package codec
import (
"github.com/cometbft/cometbft/crypto/sr25519"

"github.com/cosmos/cosmos-sdk/codec"
"cosmossdk.io/core/legacy"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand All @@ -12,22 +13,22 @@ import (

// RegisterCrypto registers all crypto dependency types with the provided Amino
// codec.
func RegisterCrypto(cdc *codec.LegacyAmino) {
func RegisterCrypto(cdc legacy.Amino) {
cdc.RegisterInterface((*cryptotypes.PubKey)(nil), nil)
cdc.RegisterConcrete(sr25519.PubKey{},
sr25519.PubKeyName, nil)
sr25519.PubKeyName)
cdc.RegisterConcrete(&ed25519.PubKey{},
ed25519.PubKeyName, nil)
ed25519.PubKeyName)
cdc.RegisterConcrete(&secp256k1.PubKey{},
secp256k1.PubKeyName, nil)
secp256k1.PubKeyName)
cdc.RegisterConcrete(&kmultisig.LegacyAminoPubKey{},
kmultisig.PubKeyAminoRoute, nil)
kmultisig.PubKeyAminoRoute)

cdc.RegisterInterface((*cryptotypes.PrivKey)(nil), nil)
cdc.RegisterConcrete(sr25519.PrivKey{},
sr25519.PrivKeyName, nil)
sr25519.PrivKeyName)
cdc.RegisterConcrete(&ed25519.PrivKey{},
ed25519.PrivKeyName, nil)
ed25519.PrivKeyName)
cdc.RegisterConcrete(&secp256k1.PrivKey{},
secp256k1.PrivKeyName, nil)
secp256k1.PrivKeyName)
}
10 changes: 5 additions & 5 deletions crypto/keyring/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ func init() {
// RegisterLegacyAminoCodec registers concrete types and interfaces on the given codec.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterInterface((*LegacyInfo)(nil), nil)
cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params", nil)
cdc.RegisterConcrete(legacyLocalInfo{}, "crypto/keys/localInfo", nil)
cdc.RegisterConcrete(legacyLedgerInfo{}, "crypto/keys/ledgerInfo", nil)
cdc.RegisterConcrete(legacyOfflineInfo{}, "crypto/keys/offlineInfo", nil)
cdc.RegisterConcrete(LegacyMultiInfo{}, "crypto/keys/multiInfo", nil)
cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params")
cdc.RegisterConcrete(legacyLocalInfo{}, "crypto/keys/localInfo")
cdc.RegisterConcrete(legacyLedgerInfo{}, "crypto/keys/ledgerInfo")
cdc.RegisterConcrete(legacyOfflineInfo{}, "crypto/keys/offlineInfo")
cdc.RegisterConcrete(LegacyMultiInfo{}, "crypto/keys/multiInfo")
}
8 changes: 4 additions & 4 deletions crypto/keys/multisig/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ var AminoCdc = codec.NewLegacyAmino()
func init() {
AminoCdc.RegisterInterface((*cryptotypes.PubKey)(nil), nil)
AminoCdc.RegisterConcrete(ed25519.PubKey{},
ed25519.PubKeyName, nil)
ed25519.PubKeyName)
AminoCdc.RegisterConcrete(sr25519.PubKey{},
sr25519.PubKeyName, nil)
sr25519.PubKeyName)
AminoCdc.RegisterConcrete(&secp256k1.PubKey{},
secp256k1.PubKeyName, nil)
secp256k1.PubKeyName)
AminoCdc.RegisterConcrete(&LegacyAminoPubKey{},
PubKeyAminoRoute, nil)
PubKeyAminoRoute)
}
Loading

0 comments on commit 500b11c

Please sign in to comment.