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

refactor!: mv AddressCodecs aliases from runtime -> core #19747

Merged
merged 5 commits into from
Mar 14, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (types) [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) and [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) All genesis interfaces now don't take `codec.JsonCodec`.
* Every module has the codec already, passing it created an unneeded dependency.
* Additionally, to reflect this change, the module manager does not take a codec either.
* (runtime) [#19747](https://github.com/cosmos/cosmos-sdk/pull/19747) `runtime.ValidatorAddressCodec` and `runtime.ConsensusAddressCodec` have been moved to `core`.

### Client Breaking Changes

Expand Down
5 changes: 2 additions & 3 deletions baseapp/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -47,8 +46,8 @@ func makeMinimalConfig() depinject.Config {
var (
mempoolOpt = baseapp.SetMempool(mempool.NewSenderNonceMempool())
addressCodec = func() address.Codec { return addresscodec.NewBech32Codec("cosmos") }
validatorAddressCodec = func() runtime.ValidatorAddressCodec { return addresscodec.NewBech32Codec("cosmosvaloper") }
consensusAddressCodec = func() runtime.ConsensusAddressCodec { return addresscodec.NewBech32Codec("cosmosvalcons") }
validatorAddressCodec = func() address.ValidatorAddressCodec { return addresscodec.NewBech32Codec("cosmosvaloper") }
consensusAddressCodec = func() address.ConsensusAddressCodec { return addresscodec.NewBech32Codec("cosmosvalcons") }
)

return depinject.Configs(
Expand Down
6 changes: 2 additions & 4 deletions client/v2/autocli/flag/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"cosmossdk.io/client/v2/internal/flags"
"cosmossdk.io/client/v2/internal/util"
"cosmossdk.io/core/address"

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

const (
Expand Down Expand Up @@ -55,8 +53,8 @@ type Builder struct {

// Address Codecs are the address codecs to use for client/v2.
AddressCodec address.Codec
ValidatorAddressCodec runtime.ValidatorAddressCodec
ConsensusAddressCodec runtime.ConsensusAddressCodec
ValidatorAddressCodec address.ValidatorAddressCodec
ConsensusAddressCodec address.ConsensusAddressCodec
}

func (b *Builder) init() {
Expand Down
8 changes: 8 additions & 0 deletions core/address/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ type Codec interface {
// BytesToString encodes bytes to text
BytesToString(bz []byte) (string, error)
}

type (
// ValidatorAddressCodec is an alias for address.Codec for validator addresses.
ValidatorAddressCodec Codec

// ConsensusAddressCodec is an alias for address.Codec for validator consensus addresses.
ConsensusAddressCodec Codec
)
5 changes: 2 additions & 3 deletions crypto/armor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/xsalsa20symmetric"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -84,8 +83,8 @@ func TestArmorUnarmorPubKey(t *testing.T) {
configurator.NewAppConfig(),
depinject.Supply(log.NewNopLogger(),
func() address.Codec { return addresscodec.NewBech32Codec("cosmos") },
func() runtime.ValidatorAddressCodec { return addresscodec.NewBech32Codec("cosmosvaloper") },
func() runtime.ConsensusAddressCodec { return addresscodec.NewBech32Codec("cosmosvalcons") },
func() address.ValidatorAddressCodec { return addresscodec.NewBech32Codec("cosmosvaloper") },
func() address.ConsensusAddressCodec { return addresscodec.NewBech32Codec("cosmosvalcons") },
),
), &cdc)
require.NoError(t, err)
Expand Down
5 changes: 2 additions & 3 deletions crypto/keys/multisig/multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
Expand Down Expand Up @@ -363,8 +362,8 @@ func TestDisplay(t *testing.T) {
configurator.NewAppConfig(),
depinject.Supply(log.NewNopLogger(),
func() address.Codec { return addresscodec.NewBech32Codec("cosmos") },
func() runtime.ValidatorAddressCodec { return addresscodec.NewBech32Codec("cosmosvaloper") },
func() runtime.ConsensusAddressCodec { return addresscodec.NewBech32Codec("cosmosvalcons") },
func() address.ValidatorAddressCodec { return addresscodec.NewBech32Codec("cosmosvaloper") },
func() address.ConsensusAddressCodec { return addresscodec.NewBech32Codec("cosmosvalcons") },
),
), &cdc)
require.NoError(err)
Expand Down
18 changes: 5 additions & 13 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func SetupAppBuilder(inputs AppInputs) {
app.ModuleManager.RegisterLegacyAminoCodec(inputs.LegacyAmino)
}

func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec ValidatorAddressCodec, customGetSigners []signing.CustomGetSigner) (codectypes.InterfaceRegistry, error) {
func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec address.ValidatorAddressCodec, customGetSigners []signing.CustomGetSigner) (codectypes.InterfaceRegistry, error) {
signingOptions := signing.Options{
AddressCodec: addressCodec,
ValidatorAddressCodec: validatorAddressCodec,
Expand Down Expand Up @@ -245,28 +245,20 @@ func ProvideAppVersionModifier(app *AppBuilder) baseapp.AppVersionModifier {
return app.app
}

type (
// ValidatorAddressCodec is an alias for address.Codec for validator addresses.
ValidatorAddressCodec address.Codec

// ConsensusAddressCodec is an alias for address.Codec for validator consensus addresses.
ConsensusAddressCodec address.Codec
)

type AddressCodecInputs struct {
depinject.In

AuthConfig *authmodulev1.Module `optional:"true"`
StakingConfig *stakingmodulev1.Module `optional:"true"`

AddressCodecFactory func() address.Codec `optional:"true"`
ValidatorAddressCodecFactory func() ValidatorAddressCodec `optional:"true"`
ConsensusAddressCodecFactory func() ConsensusAddressCodec `optional:"true"`
AddressCodecFactory func() address.Codec `optional:"true"`
ValidatorAddressCodecFactory func() address.ValidatorAddressCodec `optional:"true"`
ConsensusAddressCodecFactory func() address.ConsensusAddressCodec `optional:"true"`
}

// ProvideAddressCodec provides an address.Codec to the container for any
// modules that want to do address string <> bytes conversion.
func ProvideAddressCodec(in AddressCodecInputs) (address.Codec, ValidatorAddressCodec, ConsensusAddressCodec) {
func ProvideAddressCodec(in AddressCodecInputs) (address.Codec, address.ValidatorAddressCodec, address.ConsensusAddressCodec) {
if in.AddressCodecFactory != nil && in.ValidatorAddressCodecFactory != nil && in.ConsensusAddressCodecFactory != nil {
return in.AddressCodecFactory(), in.ValidatorAddressCodecFactory(), in.ConsensusAddressCodecFactory()
}
Expand Down
9 changes: 4 additions & 5 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"cosmossdk.io/x/upgrade"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil/mock"
"github.com/cosmos/cosmos-sdk/testutil/network"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
Expand Down Expand Up @@ -313,8 +312,8 @@ func (c customAddressCodec) BytesToString(bz []byte) (string, error) {

func TestAddressCodecFactory(t *testing.T) {
var addrCodec address.Codec
var valAddressCodec runtime.ValidatorAddressCodec
var consAddressCodec runtime.ConsensusAddressCodec
var valAddressCodec address.ValidatorAddressCodec
var consAddressCodec address.ConsensusAddressCodec

err := depinject.Inject(
depinject.Configs(
Expand All @@ -340,8 +339,8 @@ func TestAddressCodecFactory(t *testing.T) {
depinject.Supply(
log.NewNopLogger(),
func() address.Codec { return customAddressCodec{} },
func() runtime.ValidatorAddressCodec { return customAddressCodec{} },
func() runtime.ConsensusAddressCodec { return customAddressCodec{} },
func() address.ValidatorAddressCodec { return customAddressCodec{} },
func() address.ConsensusAddressCodec { return customAddressCodec{} },
),
),
&addrCodec, &valAddressCodec, &consAddressCodec)
Expand Down
5 changes: 2 additions & 3 deletions simapp/simd/cmd/root_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -103,8 +102,8 @@ func ProvideClientContext(
txConfigOpts tx.ConfigOptions,
legacyAmino *codec.LegacyAmino,
addressCodec address.Codec,
validatorAddressCodec runtime.ValidatorAddressCodec,
consensusAddressCodec runtime.ConsensusAddressCodec,
validatorAddressCodec address.ValidatorAddressCodec,
consensusAddressCodec address.ConsensusAddressCodec,
authConfig *authv1.Module,
stakingConfig *stakingv1.Module,
) client.Context {
Expand Down
6 changes: 3 additions & 3 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"

"cosmossdk.io/core/address"
cmtconfig "github.com/cometbft/cometbft/config"
cmttime "github.com/cometbft/cometbft/types/time"
"github.com/spf13/cobra"
Expand All @@ -26,7 +27,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/testutil"
Expand Down Expand Up @@ -209,7 +209,7 @@ func initTestnetFiles(
nodeConfig *cmtconfig.Config,
mm *module.Manager,
genBalIterator banktypes.GenesisBalancesIterator,
valAddrCodec runtime.ValidatorAddressCodec,
valAddrCodec address.ValidatorAddressCodec,
args initArgs,
) error {
if args.chainID == "" {
Expand Down Expand Up @@ -417,7 +417,7 @@ func initGenFiles(
func collectGenFiles(
clientCtx client.Context, nodeConfig *cmtconfig.Config, chainID string,
nodeIDs []string, valPubKeys []cryptotypes.PubKey, numValidators int,
outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator, valAddrCodec runtime.ValidatorAddressCodec,
outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator, valAddrCodec address.ValidatorAddressCodec,
) error {
var appState json.RawMessage
genTime := cmttime.Now()
Expand Down
8 changes: 4 additions & 4 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ type Config struct {

// Address codecs
AddressCodec address.Codec // address codec
ValidatorAddressCodec runtime.ValidatorAddressCodec // validator address codec
ConsensusAddressCodec runtime.ConsensusAddressCodec // consensus address codec
ValidatorAddressCodec address.ValidatorAddressCodec // validator address codec
ConsensusAddressCodec address.ConsensusAddressCodec // consensus address codec
}

// DefaultConfig returns a sane default configuration suitable for nearly all
Expand Down Expand Up @@ -185,8 +185,8 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) {
cdc codec.Codec
interfaceRegistry codectypes.InterfaceRegistry
addressCodec address.Codec
validatorAddressCodec runtime.ValidatorAddressCodec
consensusAddressCodec runtime.ConsensusAddressCodec
validatorAddressCodec address.ValidatorAddressCodec
consensusAddressCodec address.ConsensusAddressCodec
)

if err := depinject.Inject(
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/config/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ModuleInputs struct {

Config *txconfigv1.Config
AddressCodec address.Codec
ValidatorAddressCodec runtime.ValidatorAddressCodec
ValidatorAddressCodec address.ValidatorAddressCodec
Codec codec.Codec
ProtoFileResolver txsigning.ProtoFileResolver
// BankKeeper is the expected bank keeper to be passed to AnteHandlers
Expand Down
4 changes: 2 additions & 2 deletions x/genutil/client/cli/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"encoding/json"
"path/filepath"

"cosmossdk.io/core/address"
"github.com/spf13/cobra"

"cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
Expand All @@ -18,7 +18,7 @@ import (
const flagGenTxDir = "gentx-dir"

// CollectGenTxsCmd - return the cobra command to collect genesis transactions
func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator types.MessageValidator, valAddrCodec runtime.ValidatorAddressCodec) *cobra.Command {
func CollectGenTxsCmd(genBalIterator types.GenesisBalancesIterator, validator types.MessageValidator, valAddrCodec address.ValidatorAddressCodec) *cobra.Command {
cmd := &cobra.Command{
Use: "collect-gentxs",
Short: "Collect genesis txs and output a genesis.json file",
Expand Down
6 changes: 3 additions & 3 deletions x/genutil/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import (
"sort"
"strings"

"cosmossdk.io/core/address"
cfg "github.com/cometbft/cometbft/config"

bankexported "cosmossdk.io/x/bank/exported"
stakingtypes "cosmossdk.io/x/staking/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdkruntime "github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)

// GenAppStateFromConfig gets the genesis app state from the config
func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodingConfig,
config *cfg.Config, initCfg types.InitConfig, genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator,
validator types.MessageValidator, valAddrCodec sdkruntime.ValidatorAddressCodec,
validator types.MessageValidator, valAddrCodec address.ValidatorAddressCodec,
) (appState json.RawMessage, err error) {
// process genesis transactions, else create default genesis.json
appGenTxs, persistentPeers, err := CollectTxs(
Expand Down Expand Up @@ -68,7 +68,7 @@ func GenAppStateFromConfig(cdc codec.JSONCodec, txEncodingConfig client.TxEncodi
// the list of appGenTxs, and persistent peers required to generate genesis.json.
func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string,
genesis *types.AppGenesis, genBalIterator types.GenesisBalancesIterator,
validator types.MessageValidator, valAddrCodec sdkruntime.ValidatorAddressCodec,
validator types.MessageValidator, valAddrCodec address.ValidatorAddressCodec,
) (appGenTxs []sdk.Tx, persistentPeers string, err error) {
// prepare a map of all balances in genesis state to then validate
// against the validators addresses
Expand Down
6 changes: 3 additions & 3 deletions x/staking/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"sort"

"cosmossdk.io/core/address"
"golang.org/x/exp/maps"

modulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
Expand All @@ -16,7 +17,6 @@ import (
"cosmossdk.io/x/staking/types"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
Expand All @@ -38,8 +38,8 @@ type ModuleInputs struct {
depinject.In

Config *modulev1.Module
ValidatorAddressCodec runtime.ValidatorAddressCodec
ConsensusAddressCodec runtime.ConsensusAddressCodec
ValidatorAddressCodec address.ValidatorAddressCodec
ConsensusAddressCodec address.ConsensusAddressCodec
AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
Cdc codec.Codec
Expand Down
Loading