diff --git a/Makefile b/Makefile index 88be31e15..175a2d547 100644 --- a/Makefile +++ b/Makefile @@ -197,7 +197,7 @@ proto-format: @echo "Formatting Protobuf files" @$(DOCKER) run --rm -v $(CURDIR):/workspace \ --workdir /workspace tendermintdev/docker-build-proto \ - find ./ -not -path "./third_party/*" -name "*.proto" -exec clang-format -i {} \; + $( find ./ -not -path "./third_party/*" -name "*.proto" -exec clang-format -i {} \; ) proto-lint: @echo "Linting Protobuf files" diff --git a/app/app.go b/app/app.go index 6dcd7b145..d79aa2998 100644 --- a/app/app.go +++ b/app/app.go @@ -129,6 +129,7 @@ import ( "github.com/axelarnetwork/axelar-core/x/vote" voteKeeper "github.com/axelarnetwork/axelar-core/x/vote/keeper" voteTypes "github.com/axelarnetwork/axelar-core/x/vote/types" + "github.com/axelarnetwork/utils/funcs" // Override with generated statik docs _ "github.com/axelarnetwork/axelar-core/client/docs/statik" @@ -202,6 +203,7 @@ func NewAxelarApp( loadLatest bool, skipUpgradeHeights map[int64]bool, homePath string, + wasmDir string, invCheckPeriod uint, encodingConfig axelarParams.EncodingConfig, appOpts servertypes.AppOptions, @@ -255,7 +257,22 @@ func NewAxelarApp( SetKeeper(keepers, initAxelarIBCKeeper(keepers)) if IsWasmEnabled() { - SetKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, appOpts, wasmOpts, homePath)) + if wasmDir == "" { + dbDir := cast.ToString(appOpts.Get("db_dir")) + wasmDir = filepath.Join(homePath, dbDir, "wasm") + } + + wasmPath, err := filepath.Abs(wasmDir) + if err != nil { + panic(fmt.Sprintf("failed to resolve absolute path for new wasm dir %s: %v", wasmDir, err)) + } + + // Migrate wasm dir from old path to new path + // TODO: Remove this once nodes have migrated + oldWasmDir := filepath.Join(homePath, "wasm") + funcs.MustNoErr(migrateWasmDir(oldWasmDir, wasmPath)) + + SetKeeper(keepers, initWasmKeeper(encodingConfig, keys, keepers, bApp, appOpts, wasmOpts, wasmPath)) SetKeeper(keepers, initWasmContractKeeper(keepers)) // set the contract keeper for the Ics20WasmHooks @@ -324,7 +341,7 @@ func NewAxelarApp( upgradeKeeper: *getKeeper[upgradekeeper.Keeper](keepers), } - app.setUpgradeBehaviour(configurator) + app.setUpgradeBehaviour(configurator, keepers) // initialize stores app.MountKVStores(keys) @@ -338,6 +355,10 @@ func NewAxelarApp( app.SetAnteHandler(initAnteHandlers(encodingConfig, keys, keepers, appOpts)) + // Register wasm snapshot extension for state-sync compatibility + // MUST be done before loading the version + app.registerWasmSnapshotExtension(keepers) + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) @@ -447,11 +468,60 @@ func initMessageRouter(keepers *KeeperCache) nexusTypes.MessageRouter { return messageRouter } -func (app *AxelarApp) setUpgradeBehaviour(configurator module.Configurator) { +func migrateWasmDir(oldWasmDir, newWasmDir string) error { + // If the new wasm dir exists, there's nothing to do + if _, err := os.Stat(newWasmDir); err == nil { + return nil + } + + // If the old wasm dir doesn't exist, there's nothing to do + if _, err := os.Stat(oldWasmDir); err != nil && os.IsNotExist(err) { + return nil + } + + // Move the wasm dir from old path to new path + if err := os.Rename(oldWasmDir, newWasmDir); err != nil { + return fmt.Errorf("failed to move wasm directory from %s to %s: %v", oldWasmDir, newWasmDir, err) + } + + return nil +} + +func (app *AxelarApp) registerWasmSnapshotExtension(keepers *KeeperCache) { + // Register wasm snapshot extension to enable state-sync compatibility for wasm. + // MUST be done before loading the version + // Requires the snapshot store to be created and registered as a BaseAppOption + if IsWasmEnabled() { + if manager := app.SnapshotManager(); manager != nil { + err := manager.RegisterExtensions( + wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), getKeeper[wasm.Keeper](keepers)), + ) + if err != nil { + panic(fmt.Errorf("failed to register snapshot extension: %s", err)) + } + } + } +} + +func (app *AxelarApp) setUpgradeBehaviour(configurator module.Configurator, keepers *KeeperCache) { app.upgradeKeeper.SetUpgradeHandler( upgradeName(app.Version()), func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - return app.mm.RunMigrations(ctx, configurator, fromVM) + updatedVM, err := app.mm.RunMigrations(ctx, configurator, fromVM) + if err != nil { + return updatedVM, err + } + + // TODO: remove after v35 upgrade + // Override wasm module default params + if upgradeName(app.Version()) == "v0.35" && IsWasmEnabled() { + getKeeper[wasm.Keeper](keepers).SetParams(ctx, wasmtypes.Params{ + CodeUploadAccess: wasmtypes.AllowNobody, + InstantiateDefaultPermission: wasmtypes.AccessTypeNobody, + }) + } + + return updatedVM, err }, ) @@ -1035,7 +1105,7 @@ func GetModuleBasics() module.BasicManager { } if IsWasmEnabled() { - managers = append(managers, NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{}, authtypes.NewModuleAddress(govtypes.ModuleName))) + managers = append(managers, NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{})) } if IsIBCWasmHooksEnabled() { diff --git a/app/app_test.go b/app/app_test.go index 558f4689a..a8698b0e1 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -41,6 +41,7 @@ func TestNewAxelarApp(t *testing.T) { true, nil, "", + "", 0, app.MakeEncodingConfig(), simapp.EmptyAppOptions{}, diff --git a/app/keepers.go b/app/keepers.go index 94cf736de..e8ae81af4 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -2,7 +2,6 @@ package app import ( "fmt" - "path/filepath" "reflect" "strings" @@ -162,8 +161,7 @@ func InitStakingKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, ke return &stakingK } -func initWasmKeeper(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *KeeperCache, bApp *bam.BaseApp, appOpts types.AppOptions, wasmOpts []wasm.Option, homePath string) *wasm.Keeper { - wasmDir := filepath.Join(homePath, "wasm") +func initWasmKeeper(encodingConfig axelarParams.EncodingConfig, keys map[string]*sdk.KVStoreKey, keepers *KeeperCache, bApp *bam.BaseApp, appOpts types.AppOptions, wasmOpts []wasm.Option, wasmDir string) *wasm.Keeper { wasmConfig := mustReadWasmConfig(appOpts) // The last arguments can contain custom message handlers, and custom query handlers, diff --git a/app/wasm.go b/app/wasm.go index 4ba22a2f7..d36c079e1 100644 --- a/app/wasm.go +++ b/app/wasm.go @@ -119,13 +119,11 @@ func isIBCSendPacketMsg(msg wasmvmtypes.CosmosMsg) bool { type WasmAppModuleBasicOverride struct { wasm.AppModuleBasic - uploader sdk.AccAddress } -func NewWasmAppModuleBasicOverride(wasmModule wasm.AppModuleBasic, uploader sdk.AccAddress) WasmAppModuleBasicOverride { +func NewWasmAppModuleBasicOverride(wasmModule wasm.AppModuleBasic) WasmAppModuleBasicOverride { return WasmAppModuleBasicOverride{ AppModuleBasic: wasmModule, - uploader: uploader, } } @@ -134,8 +132,8 @@ func NewWasmAppModuleBasicOverride(wasmModule wasm.AppModuleBasic, uploader sdk. func (m WasmAppModuleBasicOverride) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(&wasm.GenesisState{ Params: wasmtypes.Params{ - CodeUploadAccess: wasmtypes.AccessTypeAnyOfAddresses.With(m.uploader), - InstantiateDefaultPermission: wasmtypes.AccessTypeAnyOfAddresses, + CodeUploadAccess: wasmtypes.AllowNobody, + InstantiateDefaultPermission: wasmtypes.AccessTypeNobody, }, }) } diff --git a/app/wasm_test.go b/app/wasm_test.go index a8fbbac4b..09423ef41 100644 --- a/app/wasm_test.go +++ b/app/wasm_test.go @@ -9,7 +9,6 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/assert" @@ -242,8 +241,7 @@ func TestMsgTypeBlacklistMessenger_DispatchMsg(t *testing.T) { } func TestNewWasmAppModuleBasicOverride(t *testing.T) { - uploader := authtypes.NewModuleAddress("allowed to upload") - wasmModule := app.NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{}, uploader) + wasmModule := app.NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{}) cdc := app.MakeEncodingConfig().Codec genesis := wasmModule.DefaultGenesis(cdc) @@ -252,9 +250,8 @@ func TestNewWasmAppModuleBasicOverride(t *testing.T) { var state wasm.GenesisState assert.NoError(t, cdc.UnmarshalJSON(genesis, &state)) - assert.Equal(t, state.Params.InstantiateDefaultPermission, wasmtypes.AccessTypeAnyOfAddresses) - assert.True(t, state.Params.CodeUploadAccess.Allowed(uploader)) - assert.Len(t, state.Params.CodeUploadAccess.AllAuthorizedAddresses(), 1) + assert.Equal(t, state.Params.InstantiateDefaultPermission, wasmtypes.AccessTypeNobody) + assert.True(t, state.Params.CodeUploadAccess.Equals(wasmtypes.AllowNobody)) } func TestICSMiddleWare(t *testing.T) { diff --git a/client/docs/static/openapi/index.html b/client/docs/static/openapi/index.html index a8c87b9c6..f18f4423d 100644 --- a/client/docs/static/openapi/index.html +++ b/client/docs/static/openapi/index.html @@ -2125,7 +2125,7 @@
{- "sender": "string",
- "poll_id": "string",
- "vote": {
- "type_url": "string",
- "value": "string"
}
}