Skip to content

Commit

Permalink
refactor: unify cosmos sdk configurations
Browse files Browse the repository at this point in the history
remove address format verifier
  • Loading branch information
gartnera committed Dec 12, 2024
1 parent 462fcea commit 60c043d
Show file tree
Hide file tree
Showing 26 changed files with 46 additions and 203 deletions.
39 changes: 2 additions & 37 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"runtime/debug"
"time"

cosmoserrors "cosmossdk.io/errors"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand All @@ -26,7 +25,6 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -145,26 +143,8 @@ func init() {
}

var (
AccountAddressPrefix = "zeta"
NodeDir = ".zetacored"
DefaultNodeHome = os.ExpandEnv("$HOME/") + NodeDir

// AddrLen is the allowed length (in bytes) for an address.
// NOTE: In the SDK, the default value is 255.
AddrLen = 20

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = AccountAddressPrefix
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Bech32PrefixAccPub = AccountAddressPrefix + sdk.PrefixPublic
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixOperator
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
Bech32PrefixConsAddr = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = AccountAddressPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
NodeDir = ".zetacored"
DefaultNodeHome = os.ExpandEnv("$HOME/") + NodeDir
)

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand Down Expand Up @@ -1037,21 +1017,6 @@ func initParamsKeeper(
return paramsKeeper
}

// VerifyAddressFormat verifies the address is compatible with ethereum
func VerifyAddressFormat(bz []byte) error {
if len(bz) == 0 {
return cosmoserrors.Wrap(sdkerrors.ErrUnknownAddress, "invalid address; cannot be empty")
}
if len(bz) != AddrLen {
return cosmoserrors.Wrapf(
sdkerrors.ErrUnknownAddress,
"invalid address length; got: %d, expect: %d", len(bz), AddrLen,
)
}

return nil
}

// SimulationManager implements the SimulationApp interface
func (app *App) SimulationManager() *module.SimulationManager {
return app.sm
Expand Down
17 changes: 0 additions & 17 deletions app/prefix.go

This file was deleted.

36 changes: 0 additions & 36 deletions cmd/cosmos.go

This file was deleted.

4 changes: 1 addition & 3 deletions cmd/zetaclientd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
"github.com/zeta-chain/node/cmd"
"github.com/zeta-chain/node/pkg/constant"
_ "github.com/zeta-chain/node/pkg/sdkconfig/default"
)

var (
Expand Down Expand Up @@ -85,8 +85,6 @@ func setupGlobalOptions() {
}

func init() {
cmd.SetupCosmosConfig()

// Setup options
setupGlobalOptions()
setupInitializeConfigOptions()
Expand Down
14 changes: 0 additions & 14 deletions cmd/zetacored/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import (
ethermint "github.com/zeta-chain/ethermint/types"
)

// SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings.
func SetBech32Prefixes(config *sdk.Config) {
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
}

const (
DisplayDenom = "zeta"
BaseDenom = "azeta"
Expand All @@ -28,10 +21,3 @@ func RegisterDenoms() {
panic(err)
}
}

// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
func SetBip44CoinType(config *sdk.Config) {
config.SetCoinType(ethermint.Bip44CoinType)
config.SetPurpose(sdk.Purpose) // Shared
config.SetFullFundraiserPath(ethermint.BIP44HDPath) // nolint: staticcheck
}
1 change: 1 addition & 0 deletions cmd/zetacored/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/zeta-chain/node/app"
cmdcfg "github.com/zeta-chain/node/cmd/zetacored/config"
_ "github.com/zeta-chain/node/pkg/sdkconfig/default"
)

func main() {
Expand Down
16 changes: 1 addition & 15 deletions cmd/zetacored/parse_genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,16 @@ import (
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/app"
zetacored "github.com/zeta-chain/node/cmd/zetacored"
_ "github.com/zeta-chain/node/pkg/sdkconfig/default"
keepertest "github.com/zeta-chain/node/testutil/keeper"
"github.com/zeta-chain/node/testutil/sample"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
emissionstypes "github.com/zeta-chain/node/x/emissions/types"
observertypes "github.com/zeta-chain/node/x/observer/types"
)

func setConfig(t *testing.T) {
defer func(t *testing.T) {
if r := recover(); r != nil {
t.Log("config is already sealed", r)
}
}(t)
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
cfg.Seal()
}
func Test_ModifyCrossChainState(t *testing.T) {
setConfig(t)
t.Run("successfully modify cross chain state to reduce data", func(t *testing.T) {
cdc := keepertest.NewCodec()
appState := sample.AppState(t)
Expand Down Expand Up @@ -64,7 +53,6 @@ func Test_ModifyCrossChainState(t *testing.T) {
}

func Test_ModifyObserverState(t *testing.T) {
setConfig(t)
t.Run("successfully modify observer state to reduce data", func(t *testing.T) {
cdc := keepertest.NewCodec()
appState := sample.AppState(t)
Expand Down Expand Up @@ -93,7 +81,6 @@ func Test_ModifyObserverState(t *testing.T) {

func Test_ImportDataIntoFile(t *testing.T) {
t.Run("successfully import data into file and modify data", func(t *testing.T) {
setConfig(t)
cdc := keepertest.NewCodec()
genDoc := sample.GenDoc(t)
importGenDoc := ImportGenDoc(t, cdc, 100)
Expand Down Expand Up @@ -133,7 +120,6 @@ func Test_ImportDataIntoFile(t *testing.T) {
})

t.Run("successfully import data into file without modifying data", func(t *testing.T) {
setConfig(t)
cdc := keepertest.NewCodec()
genDoc := sample.GenDoc(t)
importGenDoc := ImportGenDoc(t, cdc, 8)
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetacored/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/app"
_ "github.com/zeta-chain/node/pkg/sdkconfig/default"
"github.com/zeta-chain/node/testutil/sample"
)

Expand All @@ -18,7 +18,6 @@ func TestParsefileToObserverMapper(t *testing.T) {
err := os.RemoveAll(fp)
require.NoError(t, err)
}(t, file)
app.SetConfig()

observerAddress := sample.AccAddress()
commonGrantAddress := sample.AccAddress()
Expand Down
7 changes: 0 additions & 7 deletions cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -47,12 +46,6 @@ const EnvPrefix = "zetacore"
func NewRootCmd() (*cobra.Command, types.EncodingConfig) {
encodingConfig := app.MakeEncodingConfig()

cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(app.Bech32PrefixValAddr, app.Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub)
cfg.Seal()

initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config"
"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/runner"
Expand Down Expand Up @@ -46,9 +45,6 @@ func runBalances(cmd *cobra.Command, args []string) error {
// initialize logger
logger := runner.NewLogger(false, color.FgHiCyan, "")

// set config
app.SetConfig()

// initialize context
ctx, cancel := context.WithCancel(context.Background())

Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/bitcoin_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config"
"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/runner"
Expand Down Expand Up @@ -46,9 +45,6 @@ func runBitcoinAddress(cmd *cobra.Command, args []string) error {
// initialize logger
logger := runner.NewLogger(false, color.FgHiYellow, "")

// set config
app.SetConfig()

// initialize context
ctx, cancel := context.WithCancel(context.Background())

Expand Down
2 changes: 0 additions & 2 deletions cmd/zetae2e/local/get_zetaclient_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"google.golang.org/grpc/credentials/insecure"

"github.com/zeta-chain/node/pkg/rpc"
"github.com/zeta-chain/node/pkg/sdkconfig"
observertypes "github.com/zeta-chain/node/x/observer/types"
)

Expand All @@ -33,7 +32,6 @@ func NewGetZetaclientBootstrap() *cobra.Command {
}

func getZetaclientBootstrap(cmd *cobra.Command, _ []string) error {
sdkconfig.SetDefault(true)
grpcURL, _ := cmd.Flags().GetString(grpcURLFlag)
rpcClient, err := rpc.NewGRPCClients(
grpcURL,
Expand Down
3 changes: 0 additions & 3 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"

"github.com/zeta-chain/node/app"
zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config"
"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/e2etests"
Expand Down Expand Up @@ -154,8 +153,6 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
noError(utils.WaitForBlockHeight(ctx, waitForHeight, conf.RPCs.ZetaCoreRPC, logger))
}

app.SetConfig()

zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
[]string{
Expand Down
2 changes: 2 additions & 0 deletions cmd/zetae2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"

"github.com/fatih/color"

_ "github.com/zeta-chain/node/pkg/sdkconfig/default"
)

func main() {
Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config"
"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/e2etests"
Expand Down Expand Up @@ -99,9 +98,6 @@ func runE2ETest(cmd *cobra.Command, args []string) error {
conf.Contracts.ZEVM.ERC20ZRC20Addr = config.DoubleQuotedString(zrc20ContractAddress)
}

// set config
app.SetConfig()

// initialize context
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/setup_bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config"
"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/runner"
Expand Down Expand Up @@ -34,9 +33,6 @@ func runSetupBitcoin(_ *cobra.Command, args []string) error {
// initialize logger
logger := runner.NewLogger(false, color.FgHiYellow, "")

// set config
app.SetConfig()

// initialize context
ctx, cancel := context.WithCancel(context.Background())

Expand Down
4 changes: 0 additions & 4 deletions cmd/zetae2e/show_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config"
"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/runner"
Expand Down Expand Up @@ -34,9 +33,6 @@ func runShowTSS(_ *cobra.Command, args []string) error {
// initialize logger
logger := runner.NewLogger(true, color.FgHiCyan, "")

// set config
app.SetConfig()

// initialize context
ctx, cancel := context.WithCancel(context.Background())

Expand Down
Loading

0 comments on commit 60c043d

Please sign in to comment.