Skip to content

Commit

Permalink
Merge branch 'main' into julian/remove-auth-globalConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano authored Mar 6, 2024
2 parents 8d985a5 + 41f9272 commit 86d7023
Show file tree
Hide file tree
Showing 111 changed files with 983 additions and 638 deletions.
15 changes: 14 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,20 @@ Additionally, the `appmodule.Environment` interface is introduced to fetch diffe
This should be used as an alternative to using `sdk.UnwrapContext(ctx)` to fetch the services.
It needs to be passed into a module at instantiation.

`x/circuit` is used as an example.:
`x/circuit` is used as an example:

```go
app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment((keys[circuittypes.StoreKey])), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec())
```

If your module requires a message server or query server, it should be passed in the environment as well.

```diff
-govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[govtypes.StoreKey]), app.AuthKeeper, app.BankKeeper,app.StakingKeeper, app.PoolKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String())
+govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger, runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String())
```


##### Dependency Injection

Previously `cosmossdk.io/core` held functions `Invoke`, `Provide` and `Register` were moved to `cosmossdk.io/depinject/appconfig`.
Expand Down Expand Up @@ -213,6 +221,11 @@ Group was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/group

Gov was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/gov`

Gov v1beta1 proposal handler has been changed to take in a `context.Context` instead of `sdk.Context`.
This change was made to allow legacy proposals to be compatible with server/v2.
If you wish to migrate to server/v2, you should update your proposal handler to take in a `context.Context` and use services.
On the other hand, if you wish to keep using baseapp, simply unwrap the sdk context in your proposal handler.

#### `x/mint`

Mint was spun out into its own `go.mod`. To import it use `cosmossdk.io/x/mint`
Expand Down
2 changes: 1 addition & 1 deletion client/tx/aux_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (b *AuxTxBuilder) SetExtensionOptions(extOpts ...*codectypes.Any) {
b.auxSignerData.SignDoc.BodyBytes = nil
}

// SetSignature sets the aux signer's signature.
// SetNonCriticalExtensionOptions sets the aux signer's non-critical extension options.
func (b *AuxTxBuilder) SetNonCriticalExtensionOptions(extOpts ...*codectypes.Any) {
b.checkEmptyFields()

Expand Down
1 change: 1 addition & 0 deletions client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* [#19618](https://github.com/cosmos/cosmos-sdk/pull/19618) Marshal enum as string in queries.
* [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands.
* Note, the given command must have a `client.Context` in its context.
* [#19216](https://github.com/cosmos/cosmos-sdk/pull/19216) Do not overwrite TxConfig, use directly the one provided in context. TxConfig should always be set in the `client.Context` in `root.go` of an app.
Expand Down
1 change: 1 addition & 0 deletions client/v2/autocli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protor
outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output())
encoderOptions := aminojson.EncoderOptions{
Indent: " ",
EnumAsString: true,
DoNotSortFields: true,
TypeResolver: b.TypeResolver,
FileResolver: b.FileResolver,
Expand Down
6 changes: 3 additions & 3 deletions client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ require (
gitlab.com/yawning/tuplehash v0.0.0-20230713102510-df83abbf9a02 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.20.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
Expand Down
12 changes: 6 additions & 6 deletions client/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
Expand Down Expand Up @@ -875,12 +875,12 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
12 changes: 12 additions & 0 deletions core/gas/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Service interface {

// WithBlockGasMeter returns a new context with the provided block-level gas meter.
WithBlockGasMeter(ctx context.Context, meter Meter) context.Context

GetGasConfig(ctx context.Context) GasConfig
}

// Meter represents a gas meter for modules consumption
Expand All @@ -48,3 +50,13 @@ type Meter interface {
Remaining() Gas
Limit() Gas
}

type GasConfig struct {
HasCost Gas
DeleteCost Gas
ReadCostFlat Gas
ReadCostPerByte Gas
WriteCostFlat Gas
WriteCostPerByte Gas
IterNextCostFlat Gas
}
2 changes: 1 addition & 1 deletion crypto/armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func decryptPrivKey(saltBytes, encBytes []byte, passphrase, kdf string) (privKey
key = crypto.Sha256(key) // Get 32 bytes
privKeyBytes, err = xsalsa20symmetric.DecryptSymmetric(encBytes, key)

if err == xsalsa20symmetric.ErrCiphertextDecrypt {
if errors.Is(err, xsalsa20symmetric.ErrCiphertextDecrypt) {
return privKey, sdkerrors.ErrWrongPassword
}
default:
Expand Down
3 changes: 2 additions & 1 deletion crypto/hd/hdpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/hmac"
"crypto/sha512"
"encoding/binary"
"errors"
"fmt"
"math/big"
"path/filepath"
Expand Down Expand Up @@ -88,7 +89,7 @@ func NewParamsFromPath(path string) (*BIP44Params, error) {
}

if !(change == 0 || change == 1) {
return nil, fmt.Errorf("change field can only be 0 or 1")
return nil, errors.New("change field can only be 0 or 1")
}

return &BIP44Params{
Expand Down
8 changes: 4 additions & 4 deletions crypto/keyring/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package keyring

import "github.com/cockroachdb/errors"
import "errors"

var (
// ErrUnsupportedSigningAlgo is raised when the caller tries to use a
Expand All @@ -14,8 +14,8 @@ var (
// ErrOverwriteKey is raised when a key cannot be overwritten
ErrOverwriteKey = errors.New("cannot overwrite key")
// ErrKeyAlreadyExists is raised when creating a key that already exists
ErrKeyAlreadyExists = errors.Newf("key already exists")
// ErrInvalidSignMode is raised when trying to sign with an invaled method
ErrKeyAlreadyExists = errors.New("key already exists")
// ErrInvalidSignMode is raised when trying to sign with an invalid method
ErrInvalidSignMode = errors.New("invalid sign mode, expected LEGACY_AMINO_JSON or TEXTUAL")
// ErrMaxPassPhraseAttempts is raised when the maxPassphraseEntryAttempts is reached
ErrMaxPassPhraseAttempts = errors.New("too many failed passphrase attempts")
Expand All @@ -30,7 +30,7 @@ var (
// ErrNotLedgerObj is raised when record.GetLedger() returns nil.
ErrNotLedgerObj = errors.New("not a ledger object")
// ErrLedgerInvalidSignature is raised when ledger generates an invalid signature.
ErrLedgerInvalidSignature = errors.New("Ledger generated an invalid signature. Perhaps you have multiple ledgers and need to try another one")
ErrLedgerInvalidSignature = errors.New("ledger generated an invalid signature. Perhaps you have multiple ledgers and need to try another one")
// ErrLegacyToRecord is raised when cannot be converted to a Record
ErrLegacyToRecord = errors.New("unable to convert LegacyInfo to Record")
// ErrUnknownLegacyType is raised when a LegacyInfo type is unknown.
Expand Down
10 changes: 5 additions & 5 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keyring
import (
"bufio"
"encoding/hex"
"errors"
"fmt"
"io"
"os"
Expand All @@ -11,7 +12,6 @@ import (
"strings"

"github.com/99designs/keyring"
"github.com/cockroachdb/errors"
"github.com/cosmos/go-bip39"
"golang.org/x/crypto/bcrypt"

Expand Down Expand Up @@ -435,7 +435,7 @@ func (ks keystore) SaveLedgerKey(uid string, algo SignatureAlgo, hrp string, coi

priv, _, err := ledger.NewPrivKeySecp256k1(*hdPath, hrp)
if err != nil {
return nil, errors.CombineErrors(ErrLedgerGenerateKey, err)
return nil, errorsmod.Wrap(ErrLedgerGenerateKey, err.Error())
}

return ks.writeLedgerKey(uid, priv.PubKey(), hdPath)
Expand Down Expand Up @@ -534,7 +534,7 @@ func (ks keystore) KeyByAddress(address []byte) (*Record, error) {
}

func wrapKeyNotFound(err error, msg string) error {
if err == keyring.ErrKeyNotFound {
if errors.Is(err, keyring.ErrKeyNotFound) {
return errorsmod.Wrap(sdkerrors.ErrKeyNotFound, msg)
}
return err
Expand Down Expand Up @@ -822,7 +822,7 @@ func (ks keystore) writeRecord(k *Record) error {

serializedRecord, err := ks.cdc.Marshal(k)
if err != nil {
return errors.CombineErrors(ErrUnableToSerialize, err)
return errorsmod.Wrap(ErrUnableToSerialize, err.Error())
}

item := keyring.Item{
Expand Down Expand Up @@ -977,7 +977,7 @@ func (ks keystore) migrate(key string) (*Record, error) {

serializedRecord, err := ks.cdc.Marshal(k)
if err != nil {
return nil, errors.CombineErrors(ErrUnableToSerialize, err)
return nil, errorsmod.Wrap(ErrUnableToSerialize, err.Error())
}

item = keyring.Item{
Expand Down
2 changes: 1 addition & 1 deletion crypto/keyring/keyring_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package keyring

import (
"bytes"
"errors"
"testing"

"github.com/cockroachdb/errors"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/crypto/hd"
Expand Down
4 changes: 2 additions & 2 deletions crypto/keyring/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ func TestNewAccount(t *testing.T) {
bip39Passphrease: "",
algo: hd.Secp256k1,
mnemonic: "fresh enact fresh ski large bicycle marine abandon motor end pact mixture annual elite bind fan write warrior adapt common manual cool happy dutch",
expectedErr: fmt.Errorf("Invalid byte at position"),
expectedErr: errors.New("invalid byte at position"),
},
{
name: "in memory invalid mnemonic",
Expand All @@ -1129,7 +1129,7 @@ func TestNewAccount(t *testing.T) {
bip39Passphrease: "",
algo: hd.Secp256k1,
mnemonic: "malarkey pair crucial catch public canyon evil outer stage ten gym tornado",
expectedErr: fmt.Errorf("Invalid mnemonic"),
expectedErr: errors.New("invalid mnemonic"),
},
}
for _, tt := range tests {
Expand Down
9 changes: 5 additions & 4 deletions crypto/keyring/legacy_info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keyring

import (
"errors"
"fmt"

"github.com/cosmos/cosmos-sdk/codec/legacy"
Expand Down Expand Up @@ -77,7 +78,7 @@ func (i legacyLocalInfo) GetAlgo() hd.PubKeyType {

// GetPath returns bip44 path, but not available for this type
func (i legacyLocalInfo) GetPath() (*hd.BIP44Params, error) {
return nil, fmt.Errorf("BIP44 Paths are not available for this type")
return nil, errors.New("BIP44 Paths are not available for this type")
}

// legacyLedgerInfo is the public information about a Ledger key
Expand Down Expand Up @@ -155,7 +156,7 @@ func (i legacyOfflineInfo) GetAddress() sdk.AccAddress {

// GetPath returns bip44 path, but not available for this type
func (i legacyOfflineInfo) GetPath() (*hd.BIP44Params, error) {
return nil, fmt.Errorf("BIP44 Paths are not available for this type")
return nil, errors.New("BIP44 Paths are not available for this type")
}

// Deprecated: this structure is not used anymore and it's here only to allow
Expand Down Expand Up @@ -213,7 +214,7 @@ func (i LegacyMultiInfo) GetAlgo() hd.PubKeyType {

// GetPath returns bip44 path, but not available for this type
func (i LegacyMultiInfo) GetPath() (*hd.BIP44Params, error) {
return nil, fmt.Errorf("BIP44 Paths are not available for this type")
return nil, errors.New("BIP44 Paths are not available for this type")
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
Expand Down Expand Up @@ -258,7 +259,7 @@ func privKeyFromLegacyInfo(info LegacyInfo) (cryptotypes.PrivKey, error) {
switch linfo := info.(type) {
case legacyLocalInfo:
if linfo.PrivKeyArmor == "" {
return nil, fmt.Errorf("private key not available")
return nil, errors.New("private key not available")
}
priv, err := legacy.PrivKeyFromBytes([]byte(linfo.PrivKeyArmor))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion crypto/keyring/record.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package keyring

import (
"github.com/cockroachdb/errors"
"errors"

errorsmod "cosmossdk.io/errors"

Expand Down
4 changes: 2 additions & 2 deletions crypto/keyring/signing_algorithms.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keyring
import (
"strings"

"github.com/cockroachdb/errors"
errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/crypto/hd"
)
Expand All @@ -22,7 +22,7 @@ func NewSigningAlgoFromString(str string, algoList SigningAlgoList) (SignatureAl
return algo, nil
}
}
return nil, errors.Wrap(ErrUnsupportedSigningAlgo, str)
return nil, errorsmod.Wrap(ErrUnsupportedSigningAlgo, str)
}

// SigningAlgoList is a slice of signature algorithms
Expand Down
7 changes: 4 additions & 3 deletions crypto/keys/ed25519/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ed25519
import (
"crypto/ed25519"
"crypto/subtle"
"errors"
"fmt"
"io"

Expand All @@ -14,7 +15,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

//-------------------------------------
Expand Down Expand Up @@ -102,7 +103,7 @@ func (privKey PrivKey) MarshalAmino() ([]byte, error) {
// UnmarshalAmino overrides Amino binary marshaling.
func (privKey *PrivKey) UnmarshalAmino(bz []byte) error {
if len(bz) != PrivKeySize {
return fmt.Errorf("invalid privkey size")
return errors.New("invalid privkey size")
}
privKey.Key = bz

Expand Down Expand Up @@ -211,7 +212,7 @@ func (pubKey PubKey) MarshalAmino() ([]byte, error) {
// UnmarshalAmino overrides Amino binary marshaling.
func (pubKey *PubKey) UnmarshalAmino(bz []byte) error {
if len(bz) != PubKeySize {
return errorsmod.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size")
return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "invalid pubkey size")
}
pubKey.Key = bz

Expand Down
Loading

0 comments on commit 86d7023

Please sign in to comment.