Skip to content

Commit

Permalink
Merge pull request #453 from ComposableFi/dz/15
Browse files Browse the repository at this point in the history
allow devnet with custom key gov
  • Loading branch information
dzmitry-lahoda authored Feb 28, 2024
2 parents 9e38eda + d4add98 commit 47f7112
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func NewComposableApp(
encodingConfig EncodingConfig,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
devnetGov *string,
baseAppOptions ...func(*baseapp.BaseApp),
) *ComposableApp {
appCodec := encodingConfig.Codec
Expand Down Expand Up @@ -286,6 +287,7 @@ func NewComposableApp(
homePath,
appOpts,
wasmOpts,
devnetGov,
)

transferModule := transfer.NewAppModule(app.TransferKeeper)
Expand Down
1 change: 1 addition & 0 deletions app/helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func setup(withGenesis bool, invCheckPeriod uint, opts ...wasmkeeper.Option) (*c
encCdc,
EmptyAppOptions{},
opts,
nil,
)
if withGenesis {
return app, composable.NewDefaultGenesisState()
Expand Down
6 changes: 5 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
homePath string,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
devnetGov *string,
) {
// add keepers
appKeepers.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -228,6 +229,9 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
)

govModuleAuthority := authtypes.NewModuleAddress(govtypes.ModuleName).String()
if devnetGov != nil {
govModuleAuthority = *devnetGov
}

appKeepers.Wasm08Keeper = wasmclientkeeper.NewKeeper(appCodec, appKeepers.keys[wasm08types.StoreKey], govModuleAuthority, homePath, &appKeepers.IBCKeeper.ClientKeeper)

Expand Down Expand Up @@ -322,7 +326,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
wasmDir,
wasmConfig,
availableCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModuleAuthority,
wasmOpts...,
)

Expand Down
1 change: 1 addition & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func setup(tb testing.TB, withGenesis bool, invCheckPeriod uint) (*ComposableApp
MakeEncodingConfig(),
EmptyBaseAppOptions{},
wasmOpts,
nil,
baseAppOpts...)
if withGenesis {
return app, NewDefaultGenesisState()
Expand Down
19 changes: 16 additions & 3 deletions cmd/centaurid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import (
"github.com/cometbft/cometbft/libs/log"
)

const (
// if set, than uses specific key for governance instead of default (default is production; this override for local devtest)
flagDevnetGov = "devnet-gov"
)

var ChainID string

// NewRootCmd creates a new root command for simd. It is called once in the
Expand Down Expand Up @@ -72,7 +77,6 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) {
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}

customAppTemplate, customAppConfig := initAppConfig()

customTMConfig := initTendermintConfig()
Expand Down Expand Up @@ -182,8 +186,8 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
// this line is used by starport scaffolding # stargate/root/commands
)

a := appCreator{encodingConfig}
server.AddCommands(rootCmd, app.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags)
appCreator := appCreator{encodingConfig}
server.AddCommands(rootCmd, app.DefaultNodeHome, appCreator.newApp, appCreator.appExport, addModuleInitFlags)

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
Expand All @@ -196,6 +200,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
startCmd.Flags().String(flagDevnetGov, "", "Sets the devnet governance key (if not set, uses the default production key)")
// this line is used by starport scaffolding # stargate/root/initFlags
}

Expand Down Expand Up @@ -265,6 +270,11 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
skipUpgradeHeights[h] = true
}

var devnetGov *string
devnetGovOption, _ := appOpts.Get(flagDevnetGov).(string)
if devnetGovOption != "" {
devnetGov = &devnetGovOption
}
baseappOptions := server.DefaultBaseappOptions(appOpts)

var emptyWasmOpts []wasmkeeper.Option
Expand All @@ -277,6 +287,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
// this line is used by starport scaffolding # stargate/root/appArgument
appOpts,
emptyWasmOpts,
devnetGov,
baseappOptions...,
)

Expand Down Expand Up @@ -308,6 +319,7 @@ func (a appCreator) appExport(
a.encCfg,
appOpts,
emptyWasmOpts,
nil,
)

if err := anApp.LoadHeight(height); err != nil {
Expand All @@ -325,6 +337,7 @@ func (a appCreator) appExport(
a.encCfg,
appOpts,
emptyWasmOpts,
nil,
)
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/centaurid/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import (
"path/filepath"

"github.com/CosmWasm/wasmd/app"

tmconfig "github.com/cometbft/cometbft/config"
tmos "github.com/cometbft/cometbft/libs/os"
tmrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/types"
tmtime "github.com/cometbft/cometbft/types/time"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -36,6 +30,12 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

tmconfig "github.com/cometbft/cometbft/config"
tmos "github.com/cometbft/cometbft/libs/os"
tmrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/types"
tmtime "github.com/cometbft/cometbft/types/time"
)

var (
Expand Down
7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@
gci
gnumake
go
delve
golangci-lint
gomod2nix
gotools
libwasmvm
];
};
};

packages = {
packages = rec {
centaurid = buildGoApplication rec {
pname = "centaurid";
version = "v7.0.0";
Expand All @@ -66,7 +68,8 @@
-X github.com/cosmos/cosmos-sdk/version.Name=centauri -X github.com/cosmos/cosmos-sdk/version.AppName=${pname} -X github.com/cosmos/cosmos-sdk/version.Version=${version} -X github.com/cosmos/cosmos-sdk/version.Commit=${self.rev or self.dirtyRev or "dirty"} -X github.com/cometbft/cometbft/version.TMCoreSemVer=v0.37.2
'';
};
default = pkgs.writeShellApplication {
default = ci;
ci = pkgs.writeShellApplication {
name = "ci";
text = ''
go get mvdan.cc/gofumpt
Expand Down
11 changes: 10 additions & 1 deletion x/transfermiddleware/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,16 @@ func (k Keeper) HasAllowRlyAddress(ctx sdk.Context, rlyAddress string) bool {
store := ctx.KVStore(k.storeKey)
key := types.GetKeyByRlyAddress(rlyAddress)

return store.Has(key)
if store.Has(key) {
return true
}

prefixStore := prefix.NewStore(store, types.KeyRlyAddress)
iter := prefixStore.Iterator(nil, nil)
defer iter.Close()

// there are not records => so it is permissionless
return !iter.Valid()
}

func (k Keeper) IterateAllowRlyAddress(ctx sdk.Context, cb func(rlyAddress string) (stop bool)) {
Expand Down
2 changes: 1 addition & 1 deletion x/transfermiddleware/types/parachain_token_info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 47f7112

Please sign in to comment.