Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ntauri into dung/keepers-refactor
  • Loading branch information
dungnt0210 committed Jul 12, 2023
2 parents 8ec2fb1 + f76b2cb commit 25b0ca3
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 26 deletions.
61 changes: 55 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package app

import (
"fmt"
"io"
"os"
"path/filepath"
"strings"

nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/consensus"
tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
wasm "github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm"
wasmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/types"
wasm08 "github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm"
wasm08types "github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -98,6 +100,10 @@ import (
minttypes "github.com/notional-labs/centauri/v3/x/mint/types"

ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

const (
Expand All @@ -106,6 +112,33 @@ const (
ForkHeight = 244008
)

var (
// If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals.
ProposalsEnabled = "false"
// If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""
)

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into wasmd app.
func GetEnabledProposals() []wasm.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasm.EnableAllProposals
}
return wasm.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
return proposals
}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand Down Expand Up @@ -155,6 +188,7 @@ var (
vesting.AppModuleBasic{},
tendermint.AppModuleBasic{},
mint.AppModuleBasic{},
wasm08.AppModuleBasic{},
wasm.AppModuleBasic{},
router.AppModuleBasic{},
transfermiddleware.AppModuleBasic{},
Expand Down Expand Up @@ -218,11 +252,13 @@ func NewCentauriApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
enabledProposals []wasm.ProposalType,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig EncodingConfig,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *CentauriApp {
appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -299,7 +335,8 @@ func NewCentauriApp(
transferModule,
icqModule,
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
wasm.NewAppModule(app.Wasm08Keeper),
wasm08.NewAppModule(app.Wasm08Keeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
routerModule,
transfermiddlewareModule,
alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -333,7 +370,8 @@ func NewCentauriApp(
group.ModuleName,
paramstypes.ModuleName,
consensusparamtypes.ModuleName,
wasmtypes.ModuleName,
wasm08types.ModuleName,
wasm.ModuleName,
alliancemoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)
Expand Down Expand Up @@ -361,7 +399,8 @@ func NewCentauriApp(
ibctransfertypes.ModuleName,
icqtypes.ModuleName,
consensusparamtypes.ModuleName,
wasmtypes.ModuleName,
wasm08types.ModuleName,
wasm.ModuleName,
alliancemoduletypes.ModuleName,
)

Expand Down Expand Up @@ -393,7 +432,8 @@ func NewCentauriApp(
feegrant.ModuleName,
group.ModuleName,
consensusparamtypes.ModuleName,
wasmtypes.ModuleName,
wasm08types.ModuleName,
wasm.ModuleName,
alliancemoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)
Expand Down Expand Up @@ -447,6 +487,15 @@ func NewCentauriApp(
))
app.SetEndBlocker(app.EndBlocker)

if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
}
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down
7 changes: 5 additions & 2 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"
"time"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -61,7 +63,6 @@ func NewContextForApp(app centauri.CentauriApp) sdk.Context {

func Setup(t *testing.T, isCheckTx bool, invCheckPeriod uint) *centauri.CentauriApp {
t.Helper()

app, genesisState := setup(!isCheckTx, invCheckPeriod)
if !isCheckTx {
// InitChain must be called to stop deliverState from being nil
Expand All @@ -81,19 +82,21 @@ func Setup(t *testing.T, isCheckTx bool, invCheckPeriod uint) *centauri.Centauri
return app
}

func setup(withGenesis bool, invCheckPeriod uint) (*centauri.CentauriApp, centauri.GenesisState) {
func setup(withGenesis bool, invCheckPeriod uint, opts ...wasm.Option) (*centauri.CentauriApp, centauri.GenesisState) {
db := dbm.NewMemDB()
encCdc := centauri.MakeEncodingConfig()
app := centauri.NewCentauriApp(
log.NewNopLogger(),
db,
nil,
true,
wasmtypes.EnableAllProposals,
map[int64]bool{},
centauri.DefaultNodeHome,
invCheckPeriod,
encCdc,
EmptyAppOptions{},
opts,
)
if withGenesis {
return app, centauri.NewDefaultGenesisState()
Expand Down
9 changes: 8 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
minttypes "github.com/notional-labs/centauri/v3/x/mint/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

// DefaultConsensusParams defines the default Tendermint consensus params used in
Expand Down Expand Up @@ -68,14 +71,18 @@ func setup(tb testing.TB, withGenesis bool, invCheckPeriod uint) (*CentauriApp,
baseAppOpts := []func(*baseapp.BaseApp){baseapp.SetSnapshot(snapshotStore, types.SnapshotOptions{
KeepRecent: 2,
})}
var wasmOpts []wasm.Option
db := dbm.NewMemDB()
app := NewCentauriApp(
log.NewNopLogger(),
db, nil, true, map[int64]bool{},
db, nil, true,
wasmtypes.EnableAllProposals,
map[int64]bool{},
nodeHome,
invCheckPeriod,
MakeEncodingConfig(),
EmptyBaseAppOptions{},
wasmOpts,
baseAppOpts...)
if withGenesis {
return app, NewDefaultGenesisState()
Expand Down
14 changes: 14 additions & 0 deletions app/wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app

// AllCapabilities returns all capabilities available with the current wasmvm
// See https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md
// This functionality is going to be moved upstream: https://github.com/CosmWasm/wasmvm/issues/425
func AllCapabilities() []string {
return []string{
"iterator",
"staking",
"stargate",
"cosmwasm_1_1",
"cosmwasm_1_2",
}
}
55 changes: 55 additions & 0 deletions cmd/centaurid/cmd/bech32_convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"github.com/cosmos/cosmos-sdk/types/bech32"

"github.com/spf13/cobra"
)

var flagBech32Prefix = "prefix"

// AddBech32ConvertCommand returns bech32-convert cobra Command.
func AddBech32ConvertCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "bech32-convert [address]",
Short: "Convert any bech32 string to the centauri prefix",
Long: `Convert any bech32 string to the centauri prefix
Example:
centaurid debug bech32-convert akash1a6zlyvpnksx8wr6wz8wemur2xe8zyh0ytz6d88
centaurid debug bech32-convert stride1673f0t8p893rqyqe420mgwwz92ac4qv6synvx2 --prefix osmo
`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
bech32prefix, err := cmd.Flags().GetString(flagBech32Prefix)
if err != nil {
return err
}

_, bz, err := bech32.DecodeAndConvert(args[0])
if err != nil {
return err
}

bech32Addr, err := bech32.ConvertAndEncode(bech32prefix, bz)
if err != nil {
panic(err)
}

cmd.Println(bech32Addr)

return nil
},
}

cmd.Flags().StringP(flagBech32Prefix, "p", "centauri", "Bech32 Prefix to encode to")

return cmd
}

// addDebugCommands injects custom debug commands into another command as children.
func addDebugCommands(cmd *cobra.Command) *cobra.Command {
cmd.AddCommand(AddBech32ConvertCommand())
return cmd
}
13 changes: 12 additions & 1 deletion cmd/centaurid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"

"github.com/CosmWasm/wasmd/x/wasm"
dbm "github.com/cometbft/cometbft-db"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -176,6 +177,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
addDebugCommands(debug.Cmd()),
debug.Cmd(),
config.Cmd(),
CovertPrefixAddr(),
Expand Down Expand Up @@ -267,13 +269,17 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a

baseappOptions := server.DefaultBaseappOptions(appOpts)

var emptyWasmOpts []wasm.Option
newApp := app.NewCentauriApp(
logger, db, traceStore, true, skipUpgradeHeights,
logger, db, traceStore, true,
app.GetEnabledProposals(),
skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
a.encCfg,
// this line is used by starport scaffolding # stargate/root/appArgument
appOpts,
emptyWasmOpts,
baseappOptions...,
)

Expand All @@ -291,18 +297,21 @@ func (a appCreator) appExport(
if !ok || homePath == "" {
return servertypes.ExportedApp{}, errors.New("application home not set")
}
var emptyWasmOpts []wasm.Option

if height != -1 {
anApp = app.NewCentauriApp(
logger,
db,
traceStore,
false,
app.GetEnabledProposals(),
map[int64]bool{},
homePath,
uint(1),
a.encCfg,
appOpts,
emptyWasmOpts,
)

if err := anApp.LoadHeight(height); err != nil {
Expand All @@ -314,11 +323,13 @@ func (a appCreator) appExport(
db,
traceStore,
true,
app.GetEnabledProposals(),
map[int64]bool{},
homePath,
uint(1),
a.encCfg,
appOpts,
emptyWasmOpts,
)
}

Expand Down
Loading

0 comments on commit 25b0ca3

Please sign in to comment.