From a78d48f35de10857f07995c1de1a7c2440827da2 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Fri, 3 May 2024 18:06:54 +0300 Subject: [PATCH 1/7] feat: integrate cosmwasm --- app/ante.go | 79 ++++++++++++++++ app/app.go | 68 ++++++++++++-- app/app_test.go | 2 + app/keepers/keepers.go | 179 ++++++++++++++++++++++++++++++++---- app/keepers/keys.go | 10 +- app/modules.go | 65 +++++++++---- app/prefix.go | 4 + app/sim_test.go | 3 + app/upgrades/v9/consts.go | 8 ++ app/upgrades/v9/upgrades.go | 11 +++ cmd/sged/cmd/root.go | 45 ++++++++- go.mod | 17 +++- go.sum | 22 +++-- testutil/network/network.go | 3 + testutil/simapp/simapp.go | 4 + 15 files changed, 464 insertions(+), 56 deletions(-) create mode 100644 app/ante.go diff --git a/app/ante.go b/app/ante.go new file mode 100644 index 00000000..7f4afcaf --- /dev/null +++ b/app/ante.go @@ -0,0 +1,79 @@ +package app + +import ( + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + + ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + + errorsmod "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/codec" + 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/x/auth/ante" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" +) + +// HandlerOptions extends the SDK's AnteHandler options by requiring the IBC +// channel keeper and a BankKeeper with an added method for fee sharing. +type HandlerOptions struct { + ante.HandlerOptions + + GovKeeper govkeeper.Keeper + IBCKeeper *ibckeeper.Keeper + BankKeeper bankkeeper.Keeper + TxCounterStoreKey storetypes.StoreKey + WasmConfig wasmtypes.WasmConfig + Cdc codec.BinaryCodec + + StakingKeeper stakingkeeper.Keeper +} + +// NewAnteHandler returns an AnteHandler that checks and increments sequence +// numbers, checks signatures & account numbers, and deducts fees from the first +// signer. +func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { + if options.AccountKeeper == nil { + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") + } + + if options.BankKeeper == nil { + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder") + } + + if options.SignModeHandler == nil { + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + } + + sigGasConsumer := options.SigGasConsumer + if sigGasConsumer == nil { + sigGasConsumer = ante.DefaultSigVerificationGasConsumer + } + + anteDecorators := []sdk.AnteDecorator{ + // GlobalFee query params for minimum fee + ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), + wasmkeeper.NewCountTXDecorator(options.TxCounterStoreKey), + ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), + ante.NewValidateBasicDecorator(), + ante.NewTxTimeoutHeightDecorator(), + ante.NewValidateMemoDecorator(options.AccountKeeper), + ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), + + // SetPubKeyDecorator must be called before all signature verification decorators + ante.NewSetPubKeyDecorator(options.AccountKeeper), + ante.NewValidateSigCountDecorator(options.AccountKeeper), + ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), + ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), + ante.NewIncrementSequenceDecorator(options.AccountKeeper), + ibcante.NewRedundantRelayDecorator(options.IBCKeeper), + } + + return sdk.ChainAnteDecorators(anteDecorators...), nil +} diff --git a/app/app.go b/app/app.go index 1ddcab96..778721eb 100644 --- a/app/app.go +++ b/app/app.go @@ -6,12 +6,14 @@ import ( "net/http" "os" "path/filepath" + "strconv" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmjson "github.com/cometbft/cometbft/libs/json" "github.com/cometbft/cometbft/libs/log" tmos "github.com/cometbft/cometbft/libs/os" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" @@ -42,8 +44,13 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + wasmlckeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" ibcclientHandler "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" + wasm "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/sge-network/sge/app/keepers" sgeappparams "github.com/sge-network/sge/app/params" "github.com/sge-network/sge/app/upgrades" @@ -137,6 +144,7 @@ func NewSgeApp( invCheckPeriod uint, encodingConfig sgeappparams.EncodingConfig, appOpts servertypes.AppOptions, + wasmOpts []wasmkeeper.Option, baseAppOptions ...func(*baseapp.BaseApp), ) *SgeApp { appCodec := encodingConfig.Marshaler @@ -170,9 +178,16 @@ func NewSgeApp( skipUpgradeHeights, homePath, invCheckPeriod, + wasmOpts, appOpts, ) + if maxSize := os.Getenv("MAX_WASM_SIZE"); maxSize != "" { + // https://github.com/CosmWasm/wasmd#compile-time-parameters + val, _ := strconv.ParseInt(maxSize, 10, 32) + wasmtypes.MaxWasmSize = int(val) + } + // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment // we prefer to be more strict in what arguments the modules expect. skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) @@ -214,6 +229,11 @@ func NewSgeApp( } reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc) + wasmConfig, err := wasm.ReadWasmConfig(appOpts) + if err != nil { + panic("error while reading wasm config: " + err.Error()) + } + // create the simulation manager and define the order of the modules for deterministic simulations // // NOTE: this is not required apps that don't use the simulator for fuzz testing @@ -231,13 +251,24 @@ func NewSgeApp( // initialize BaseApp app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) - anteHandler, err := ante.NewAnteHandler( - ante.HandlerOptions{ - AccountKeeper: app.AccountKeeper, - BankKeeper: app.BankKeeper, - FeegrantKeeper: app.FeeGrantKeeper, - SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + anteHandler, err := NewAnteHandler( + HandlerOptions{ + HandlerOptions: ante.HandlerOptions{ + AccountKeeper: app.AppKeepers.AccountKeeper, + BankKeeper: app.AppKeepers.BankKeeper, + FeegrantKeeper: app.AppKeepers.FeeGrantKeeper, + SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + + GovKeeper: *app.AppKeepers.GovKeeper, + IBCKeeper: app.AppKeepers.IBCKeeper, + BankKeeper: app.AppKeepers.BankKeeper, + TxCounterStoreKey: app.AppKeepers.GetKey(wasmtypes.StoreKey), + WasmConfig: wasmConfig, + Cdc: appCodec, + + StakingKeeper: *app.AppKeepers.StakingKeeper, }, ) if err != nil { @@ -246,6 +277,17 @@ func NewSgeApp( app.SetAnteHandler(anteHandler) app.SetEndBlocker(app.EndBlocker) + if manager := app.SnapshotManager(); manager != nil { + err = manager.RegisterExtensions( + wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmKeeper), + // https://github.com/cosmos/ibc-go/pull/5439 + wasmlckeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmClientKeeper), + ) + if err != nil { + panic("failed to register snapshot extension: " + err.Error()) + } + } + app.setupUpgradeHandlers() app.setupUpgradeStoreLoaders() @@ -253,6 +295,18 @@ func NewSgeApp( if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) } + ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) + + // https://github.com/cosmos/ibc-go/pull/5439 + if err := wasmlckeeper.InitializePinnedCodes(ctx, appCodec); err != nil { + tmos.Exit(fmt.Sprintf("wasmlckeeper failed initialize pinned codes %s", err)) + } + + if err := app.AppKeepers.WasmKeeper.InitializePinnedCodes(ctx); err != nil { + tmos.Exit(fmt.Sprintf("app.AppKeepers.WasmKeeper failed initialize pinned codes %s", err)) + } + + app.AppKeepers.CapabilityKeeper.Seal() } return app diff --git a/app/app_test.go b/app/app_test.go index 34e8609c..71adb6a6 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -3,6 +3,7 @@ package app_test import ( "testing" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" tmdb "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -24,6 +25,7 @@ func TestApp(t *testing.T) { 0, encCdc, simtestutil.EmptyAppOptions{}, + []wasmkeeper.Option{}, ) } require.NotPanics(t, panicFunc) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 6c25193b..21a65cb8 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -1,10 +1,16 @@ package keepers import ( + "fmt" + "path" + "path/filepath" + "strings" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" servertypes "github.com/cosmos/cosmos-sdk/server/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" @@ -24,6 +30,7 @@ import ( feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" @@ -38,16 +45,19 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" - ibc "github.com/cosmos/ibc-go/v7/modules/core" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" // ibc-go + ibc_hooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7" + ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/keeper" + ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" + wasmlckeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller" icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" @@ -56,15 +66,28 @@ import ( "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v7/modules/core" ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ibcporttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" - mintkeeper "github.com/sge-network/sge/x/mint/keeper" - minttypes "github.com/sge-network/sge/x/mint/types" + + // cosmwasm + + wasmapp "github.com/CosmWasm/wasmd/app" + "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + wasmvm "github.com/CosmWasm/wasmvm" // sge + mintkeeper "github.com/sge-network/sge/x/mint/keeper" + minttypes "github.com/sge-network/sge/x/mint/types" + betmodule "github.com/sge-network/sge/x/bet" betmodulekeeper "github.com/sge-network/sge/x/bet/keeper" betmoduletypes "github.com/sge-network/sge/x/bet/types" @@ -97,6 +120,8 @@ import ( _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) +var wasmCapabilities = strings.Join(wasmapp.AllCapabilities(), ",") + type AppKeepers struct { // keys to access the substores keys map[string]*storetypes.KVStoreKey @@ -121,6 +146,12 @@ type AppKeepers struct { GroupKeeper groupkeeper.Keeper ConsensusParamsKeeper consensusparamkeeper.Keeper + //// CosmWasm keepers \\\\ + ContractKeeper wasmtypes.ContractOpsKeeper + WasmClientKeeper wasmlckeeper.Keeper + WasmKeeper wasmkeeper.Keeper + ScopedWasmKeeper capabilitykeeper.ScopedKeeper + //// SGE keepers \\\\ BetKeeper *betmodulekeeper.Keeper MarketKeeper *marketmodulekeeper.Keeper @@ -150,6 +181,7 @@ type AppKeepers struct { // IBC Keepers IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly IBCFeeKeeper ibcfeekeeper.Keeper + IBCHooksKeeper *ibchookskeeper.Keeper ICAControllerKeeper icacontrollerkeeper.Keeper ICAHostKeeper icahostkeeper.Keeper @@ -158,6 +190,9 @@ type AppKeepers struct { ICAModule ica.AppModule TransferModule transfer.AppModule IBCFeeModule ibcfee.AppModule + + Ics20WasmHooks *ibc_hooks.WasmHooks + HooksICS4Wrapper ibc_hooks.ICS4Middleware } func NewAppKeeper( @@ -168,7 +203,8 @@ func NewAppKeeper( skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, - _ servertypes.AppOptions, + wasmOpts []wasmkeeper.Option, + appOpts servertypes.AppOptions, ) AppKeepers { appKeepers := AppKeepers{} // Set keys KVStoreKey, TransientStoreKey, MemoryStoreKey @@ -196,17 +232,10 @@ func NewAppKeeper( // grant capabilities for the ibc and ibc-transfer modules appKeepers.ScopedIBCKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) - appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule( - ibctransfertypes.ModuleName, - ) - appKeepers.ScopedICAControllerKeeper = appKeepers.CapabilityKeeper.ScopeToModule( - icacontrollertypes.SubModuleName, - ) - appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule( - icahosttypes.SubModuleName, - ) - - appKeepers.CapabilityKeeper.Seal() + appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + appKeepers.ScopedICAControllerKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName) + appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) + appKeepers.ScopedWasmKeeper = appKeepers.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName) // add keepers appKeepers.CrisisKeeper = crisiskeeper.NewKeeper( @@ -342,6 +371,20 @@ func NewAppKeeper( ) appKeepers.GovKeeper.SetLegacyRouter(govRouter) + // Configure the hooks keeper + hooksKeeper := ibchookskeeper.NewKeeper( + appKeepers.keys[ibchookstypes.StoreKey], + ) + appKeepers.IBCHooksKeeper = &hooksKeeper + + junoPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix() + wasmHooks := ibc_hooks.NewWasmHooks(appKeepers.IBCHooksKeeper, &appKeepers.WasmKeeper, junoPrefix) // The contract keeper needs to be set later + appKeepers.Ics20WasmHooks = &wasmHooks + appKeepers.HooksICS4Wrapper = ibc_hooks.NewICS4Middleware( + appKeepers.IBCKeeper.ChannelKeeper, + appKeepers.Ics20WasmHooks, + ) + // IBC Fee Module keeper appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper( appCodec, @@ -395,6 +438,101 @@ func NewAppKeeper( appKeepers.SlashingKeeper, ) + dataDir := filepath.Join(homePath, "data") + + wasmConfig, err := wasm.ReadWasmConfig(appOpts) + if err != nil { + panic("error while reading wasm config: " + err.Error()) + } + + // Stargate Queries + acceptedStargateQueries := wasmkeeper.AcceptedStargateQueries{ + // ibc + "/ibc.core.client.v1.Query/ClientState": &ibcclienttypes.QueryClientStateResponse{}, + "/ibc.core.client.v1.Query/ConsensusState": &ibcclienttypes.QueryConsensusStateResponse{}, + "/ibc.core.connection.v1.Query/Connection": &ibcconnectiontypes.QueryConnectionResponse{}, + + // governance + "/cosmos.gov.v1beta1.Query/Vote": &govv1.QueryVoteResponse{}, + + // distribution + "/cosmos.distribution.v1beta1.Query/DelegationRewards": &distrtypes.QueryDelegationRewardsResponse{}, + + // staking + "/cosmos.staking.v1beta1.Query/Delegation": &stakingtypes.QueryDelegationResponse{}, + "/cosmos.staking.v1beta1.Query/Redelegations": &stakingtypes.QueryRedelegationsResponse{}, + "/cosmos.staking.v1beta1.Query/UnbondingDelegation": &stakingtypes.QueryUnbondingDelegationResponse{}, + "/cosmos.staking.v1beta1.Query/Validator": &stakingtypes.QueryValidatorResponse{}, + "/cosmos.staking.v1beta1.Query/Params": &stakingtypes.QueryParamsResponse{}, + "/cosmos.staking.v1beta1.Query/Pool": &stakingtypes.QueryPoolResponse{}, + } + + querierOpts := wasmkeeper.WithQueryPlugins( + &wasmkeeper.QueryPlugins{ + Stargate: wasmkeeper.AcceptListStargateQuerier(acceptedStargateQueries, bApp.GRPCQueryRouter(), appCodec), + }) + wasmOpts = append(wasmOpts, querierOpts) + + mainWasmer, err := wasmvm.NewVM(path.Join(dataDir, "wasm"), wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) + if err != nil { + panic(fmt.Sprintf("failed to create juno wasm vm: %s", err)) + } + + lcWasmer, err := wasmvm.NewVM(filepath.Join(dataDir, "light-client-wasm"), wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) + if err != nil { + panic(fmt.Sprintf("failed to create juno wasm vm for 08-wasm: %s", err)) + } + + appKeepers.WasmKeeper = wasmkeeper.NewKeeper( + appCodec, + appKeepers.keys[wasmtypes.StoreKey], + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.StakingKeeper, + distrkeeper.NewQuerier(appKeepers.DistrKeeper), + appKeepers.IBCFeeKeeper, + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + appKeepers.ScopedWasmKeeper, + appKeepers.TransferKeeper, + bApp.MsgServiceRouter(), + bApp.GRPCQueryRouter(), + dataDir, + wasmConfig, + wasmCapabilities, + govModAddress, + append(wasmOpts, wasmkeeper.WithWasmEngine(mainWasmer))..., + ) + + // 08-wasm light client + accepted := make([]string, 0) + for k := range acceptedStargateQueries { + accepted = append(accepted, k) + } + + wasmLightClientQuerier := wasmlctypes.QueryPlugins{ + // Custom: MyCustomQueryPlugin(), + // `myAcceptList` is a `[]string` containing the list of gRPC query paths that the chain wants to allow for the `08-wasm` module to query. + // These queries must be registered in the chain's gRPC query router, be deterministic, and track their gas usage. + // The `AcceptListStargateQuerier` function will return a query plugin that will only allow queries for the paths in the `myAcceptList`. + // The query responses are encoded in protobuf unlike the implementation in `x/wasm`. + Stargate: wasmlctypes.AcceptListStargateQuerier(accepted), + } + + appKeepers.WasmClientKeeper = wasmlckeeper.NewKeeperWithVM( + appCodec, + appKeepers.keys[wasmlctypes.StoreKey], + appKeepers.IBCKeeper.ClientKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + lcWasmer, + bApp.GRPCQueryRouter(), + wasmlckeeper.WithQueryPlugins(&wasmLightClientQuerier), + ) + + // set the contract keeper for the Ics20WasmHooks + appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(&appKeepers.WasmKeeper) + appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper + // // SGE keepers \\\\ appKeepers.OrderbookKeeper = orderbookmodulekeeper.NewKeeper( @@ -545,11 +683,17 @@ func NewAppKeeper( icaHostStack = icahost.NewIBCModule(appKeepers.ICAHostKeeper) icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, appKeepers.IBCFeeKeeper) + // Create fee enabled wasm ibc Stack + var wasmStack porttypes.IBCModule + wasmStack = wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCFeeKeeper) + wasmStack = ibcfee.NewIBCMiddleware(wasmStack, appKeepers.IBCFeeKeeper) + // Create static IBC router, add transfer route, then set and seal it ibcRouter := ibcporttypes.NewRouter() ibcRouter.AddRoute(icacontrollertypes.SubModuleName, icaControllerStack) ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostStack) ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) + ibcRouter.AddRoute(wasmtypes.ModuleName, wasmStack) appKeepers.IBCKeeper.SetRouter(ibcRouter) @@ -589,6 +733,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, paramsKeeper.Subspace(housemoduletypes.ModuleName) paramsKeeper.Subspace(rewardmoduletypes.ModuleName) paramsKeeper.Subspace(subaccountmoduletypes.ModuleName) + paramsKeeper.Subspace(wasmtypes.ModuleName) return paramsKeeper } diff --git a/app/keepers/keys.go b/app/keepers/keys.go index e729f34f..b4d80fd8 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -18,12 +18,19 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + // ibc-go + ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + // cosmwasm + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + betmoduletypes "github.com/sge-network/sge/x/bet/types" housemoduletypes "github.com/sge-network/sge/x/house/types" marketmoduletypes "github.com/sge-network/sge/x/market/types" @@ -50,7 +57,8 @@ func (appKeepers *AppKeepers) GenerateKeys() { minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, group.StoreKey, - ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, + wasmtypes.StoreKey, wasmlctypes.StoreKey, + ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, ibchookstypes.StoreKey, orderbookmoduletypes.StoreKey, betmoduletypes.StoreKey, marketmoduletypes.StoreKey, diff --git a/app/modules.go b/app/modules.go index 1337f532..b552dc72 100644 --- a/app/modules.go +++ b/app/modules.go @@ -13,6 +13,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/capability" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" "github.com/cosmos/cosmos-sdk/x/crisis" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distr "github.com/cosmos/cosmos-sdk/x/distribution" @@ -35,6 +36,10 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" + wasmlc "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" + wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" @@ -44,6 +49,9 @@ import ( ibc "github.com/cosmos/ibc-go/v7/modules/core" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + wasm "github.com/CosmWasm/wasmd/x/wasm" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + sgeappparams "github.com/sge-network/sge/app/params" betmodule "github.com/sge-network/sge/x/bet" betmoduletypes "github.com/sge-network/sge/x/bet/types" @@ -57,11 +65,10 @@ import ( orderbookmoduletypes "github.com/sge-network/sge/x/orderbook/types" ovmmodule "github.com/sge-network/sge/x/ovm" ovmmoduletypes "github.com/sge-network/sge/x/ovm/types" - subaccountmodule "github.com/sge-network/sge/x/subaccount" - subaccounttypes "github.com/sge-network/sge/x/subaccount/types" - rewardmodule "github.com/sge-network/sge/x/reward" rewardmoduletypes "github.com/sge-network/sge/x/reward/types" + subaccountmodule "github.com/sge-network/sge/x/subaccount" + subaccounttypes "github.com/sge-network/sge/x/subaccount/types" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -81,6 +88,9 @@ var mAccPerms = map[string][]string{ ibcfeetypes.ModuleName: nil, icatypes.ModuleName: nil, + // cosmwasm + wasmtypes.ModuleName: {}, + // sge betmoduletypes.BetFeeCollectorFunder{}.GetModuleAcc(): nil, housemoduletypes.HouseFeeCollectorFunder{}.GetModuleAcc(): nil, @@ -103,16 +113,19 @@ var ModuleBasics = module.NewBasicManager( params.AppModuleBasic{}, crisis.AppModuleBasic{}, slashing.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, feegrantmodule.AppModuleBasic{}, authzmodule.AppModuleBasic{}, + vesting.AppModuleBasic{}, groupmodule.AppModuleBasic{}, + + wasm.AppModuleBasic{}, ibc.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, transfer.AppModuleBasic{}, - vesting.AppModuleBasic{}, ica.AppModuleBasic{}, ibcfee.AppModuleBasic{}, + wasmlc.AppModuleBasic{}, // sge betmodule.AppModuleBasic{}, @@ -184,12 +197,13 @@ func appModules( app.BankKeeper, app.interfaceRegistry, ), + wasm.NewAppModule(appCodec, &app.AppKeepers.WasmKeeper, app.AppKeepers.StakingKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), app.IBCModule, params.NewAppModule(app.ParamsKeeper), app.TransferModule, app.IBCFeeModule, app.ICAModule, - + wasmlc.NewAppModule(app.AppKeepers.WasmClientKeeper), app.BetModule, app.MarketModule, app.OrderbookModule, @@ -255,6 +269,7 @@ func simulationModules( app.BankKeeper, app.interfaceRegistry, ), + wasm.NewAppModule(appCodec, &app.AppKeepers.WasmKeeper, app.AppKeepers.StakingKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), app.IBCModule, app.TransferModule, @@ -277,8 +292,6 @@ func orderBeginBlockers() []string { slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, - ibctransfertypes.ModuleName, - ibcexported.ModuleName, authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, @@ -289,8 +302,14 @@ func orderBeginBlockers() []string { group.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, - icatypes.ModuleName, + consensusparamtypes.ModuleName, + ibctransfertypes.ModuleName, + ibcexported.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, + wasmtypes.ModuleName, + ibchookstypes.ModuleName, + wasmlctypes.ModuleName, betmoduletypes.ModuleName, marketmoduletypes.ModuleName, orderbookmoduletypes.ModuleName, @@ -306,8 +325,6 @@ func orderEndBlockers() []string { crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName, - ibcexported.ModuleName, - ibctransfertypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, @@ -322,8 +339,14 @@ func orderEndBlockers() []string { paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - icatypes.ModuleName, + consensusparamtypes.ModuleName, + ibcexported.ModuleName, + ibctransfertypes.ModuleName, ibcfeetypes.ModuleName, + icatypes.ModuleName, + wasmtypes.ModuleName, + ibchookstypes.ModuleName, + wasmlctypes.ModuleName, betmoduletypes.ModuleName, marketmoduletypes.ModuleName, orderbookmoduletypes.ModuleName, @@ -344,19 +367,23 @@ func orderInitBlockers() []string { slashingtypes.ModuleName, govtypes.ModuleName, mintmoduletypes.ModuleName, - ibcexported.ModuleName, + crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, group.ModuleName, - crisistypes.ModuleName, + vestingtypes.ModuleName, + feegrant.ModuleName, + consensusparamtypes.ModuleName, ibctransfertypes.ModuleName, + ibcexported.ModuleName, icatypes.ModuleName, ibcfeetypes.ModuleName, - paramstypes.ModuleName, - upgradetypes.ModuleName, - vestingtypes.ModuleName, + wasmtypes.ModuleName, + wasmlctypes.ModuleName, + ibchookstypes.ModuleName, betmoduletypes.ModuleName, marketmoduletypes.ModuleName, orderbookmoduletypes.ModuleName, diff --git a/app/prefix.go b/app/prefix.go index bf8413fb..bf7d304f 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -4,6 +4,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/sge-network/sge/app/keepers" "github.com/sge-network/sge/app/params" ) @@ -28,6 +30,8 @@ func SetConfig() { config.SetBech32PrefixForValidator(ValidatorAddressPrefix, ValidatorPubKeyPrefix) config.SetBech32PrefixForConsensusNode(ConsNodeAddressPrefix, ConsNodePubKeyPrefix) + config.SetAddressVerifier(wasmtypes.VerifyAddressLen()) + err := sdk.RegisterDenom(params.HumanCoinUnit, sdkmath.LegacyOneDec()) if err != nil { panic(err) diff --git a/app/sim_test.go b/app/sim_test.go index 5bbb725e..e38bb02a 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -6,6 +6,7 @@ import ( "os" "testing" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" dbm "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" "github.com/cometbft/cometbft/libs/rand" @@ -61,6 +62,7 @@ func BenchmarkFullAppSimulation(b *testing.B) { simcli.FlagPeriodValue, app.MakeEncodingConfig(), simtestutil.EmptyAppOptions{}, + []wasmkeeper.Option{}, interBlockCacheOpt(), ) @@ -139,6 +141,7 @@ func TestAppStateDeterminism(t *testing.T) { simcli.FlagPeriodValue, app.MakeEncodingConfig(), simtestutil.EmptyAppOptions{}, + []wasmkeeper.Option{}, interBlockCacheOpt(), ) diff --git a/app/upgrades/v9/consts.go b/app/upgrades/v9/consts.go index c2544d24..a61e07e2 100644 --- a/app/upgrades/v9/consts.go +++ b/app/upgrades/v9/consts.go @@ -5,6 +5,11 @@ import ( consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + "github.com/sge-network/sge/app/upgrades" ) @@ -18,6 +23,9 @@ var Upgrade = upgrades.Upgrade{ Added: []string{ crisistypes.ModuleName, consensustypes.ModuleName, + ibchookstypes.StoreKey, + wasmtypes.ModuleName, + wasmlctypes.ModuleName, }, Deleted: []string{}, }, diff --git a/app/upgrades/v9/upgrades.go b/app/upgrades/v9/upgrades.go index 039c542f..902bd6f5 100644 --- a/app/upgrades/v9/upgrades.go +++ b/app/upgrades/v9/upgrades.go @@ -1,6 +1,8 @@ package v9 import ( + "fmt" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,11 +18,14 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" exported "github.com/cosmos/ibc-go/v7/modules/core/exported" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/sge-network/sge/app/keepers" betmoduletypes "github.com/sge-network/sge/x/bet/types" housemoduletypes "github.com/sge-network/sge/x/house/types" @@ -72,6 +77,10 @@ func CreateUpgradeHandler( case icacontrollertypes.SubModuleName: keyTable = icacontrollertypes.ParamKeyTable() + // wasm + case wasmtypes.ModuleName: + keyTable = wasmtypes.ParamKeyTable() //nolint:staticcheck + // sge modules case betmoduletypes.ModuleName: keyTable = betmoduletypes.ParamKeyTable() @@ -92,6 +101,7 @@ func CreateUpgradeHandler( } if !subspace.HasKeyTable() { + fmt.Println(subspace.Name()) subspace.WithKeyTable(keyTable) } } @@ -105,6 +115,7 @@ func CreateUpgradeHandler( // explicitly update the IBC 02-client params, adding the localhost client type params := k.IBCKeeper.ClientKeeper.GetParams(ctx) params.AllowedClients = append(params.AllowedClients, exported.Localhost) + params.AllowedClients = append(params.AllowedClients, wasmlctypes.Wasm) k.IBCKeeper.ClientKeeper.SetParams(ctx, params) // update gov params to use a 20% initial deposit ratio, allowing us to remote the ante handler diff --git a/cmd/sged/cmd/root.go b/cmd/sged/cmd/root.go index f16a0b09..16ed8b8e 100644 --- a/cmd/sged/cmd/root.go +++ b/cmd/sged/cmd/root.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" + "github.com/prometheus/client_golang/prometheus" "github.com/spf13/cast" "github.com/spf13/cobra" @@ -23,6 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" + serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/snapshots" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" @@ -36,6 +38,10 @@ import ( genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + wasm "github.com/CosmWasm/wasmd/x/wasm" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/app/params" ) @@ -75,7 +81,9 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { return err } - return server.InterceptConfigsPreRunHandler(cmd, "", nil, tmcfg.DefaultConfig()) + customAppTemplate, customAppConfig := initAppConfig() + + return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, tmcfg.DefaultConfig()) }, } @@ -84,6 +92,30 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { return rootCmd, encodingConfig } +// initAppConfig helps to override default appConfig template and configs. +// return "", nil if no custom configuration is required for the application. +func initAppConfig() (string, interface{}) { + type CustomAppConfig struct { + serverconfig.Config + + Wasm wasmtypes.WasmConfig `mapstructure:"wasm"` + } + + // Optionally allow the chain developer to overwrite the SDK's default + // server config. + srvCfg := serverconfig.DefaultConfig() + // srvCfg.MinGasPrices = "0ujuno,0ujunox" // GlobalFee handles + + customAppConfig := CustomAppConfig{ + Config: *srvCfg, + Wasm: wasmtypes.DefaultWasmConfig(), + } + + customAppTemplate := serverconfig.DefaultConfigTemplate + wasmtypes.DefaultConfigTemplate() + + return customAppTemplate, customAppConfig +} + func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { cfg := sdk.GetConfig() cfg.Seal() @@ -122,6 +154,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { func addModuleInitFlags(startCmd *cobra.Command) { crisis.AddModuleInitFlags(startCmd) + wasm.AddModuleInitFlags(startCmd) } func queryCommand() *cobra.Command { @@ -220,6 +253,11 @@ func newApp( panic(err) } + var wasmOpts []wasmkeeper.Option + if cast.ToBool(appOpts.Get("telemetry.enabled")) { + wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer)) + } + return app.NewSgeApp( logger, db, @@ -230,6 +268,7 @@ func newApp( cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), app.MakeEncodingConfig(), // Ideally, we would reuse the one created by NewRootCmd. appOpts, + wasmOpts, baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))), @@ -261,6 +300,7 @@ func createSimappAndExport( encCfg := app.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry) var sgeApp *app.SgeApp + var emptyWasmOpts []wasmkeeper.Option if height != -1 { sgeApp = app.NewSgeApp( logger, @@ -272,13 +312,14 @@ func createSimappAndExport( cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encCfg, appOpts, + emptyWasmOpts, ) if err := sgeApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - sgeApp = app.NewSgeApp(logger, db, traceStore, true, map[int64]bool{}, "", cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encCfg, appOpts) + sgeApp = app.NewSgeApp(logger, db, traceStore, true, map[int64]bool{}, "", cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encCfg, appOpts, emptyWasmOpts) } return sgeApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) diff --git a/go.mod b/go.mod index 66945ebe..0e2311a2 100644 --- a/go.mod +++ b/go.mod @@ -7,11 +7,15 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 cosmossdk.io/simapp v0.0.0-20230831152633-2e9e5d6eea24 + github.com/CosmWasm/wasmd v0.45.0 + github.com/CosmWasm/wasmvm v1.5.2 github.com/cometbft/cometbft v0.37.5 github.com/cometbft/cometbft-db v0.8.0 github.com/cosmos/cosmos-proto v1.0.0-beta.4 github.com/cosmos/cosmos-sdk v0.47.8 github.com/cosmos/gogoproto v1.4.10 + github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad + github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/golang-jwt/jwt/v4 v4.5.0 @@ -22,6 +26,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 github.com/mrz1836/go-sanitize v1.3.1 + github.com/prometheus/client_golang v1.16.0 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 @@ -64,14 +69,14 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.36.0 // indirect - cosmossdk.io/core v0.5.1 // indirect + cosmossdk.io/core v0.6.1 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/tools/rosetta v0.2.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/4meepo/tagalign v1.3.3 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect - github.com/99designs/keyring v1.2.1 // indirect + github.com/99designs/keyring v1.2.2 // indirect github.com/Antonboom/errname v0.1.12 // indirect github.com/Antonboom/nilnil v0.1.7 // indirect github.com/Antonboom/testifylint v0.2.3 // indirect @@ -127,6 +132,7 @@ require ( github.com/dgraph-io/badger/v2 v2.2007.4 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect + github.com/docker/distribution v2.8.2+incompatible // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/dvsekhvalnov/jose2go v1.6.0 // indirect github.com/esimonov/ifshort v1.0.4 // indirect @@ -172,6 +178,7 @@ require ( github.com/golangci/revgrep v0.5.2 // indirect github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/google/gofuzz v1.2.0 // indirect github.com/google/orderedcode v0.0.1 // indirect github.com/google/s2a-go v0.1.7 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect @@ -245,14 +252,14 @@ require ( github.com/nishanths/predeclared v0.2.2 // indirect github.com/nunnatsa/ginkgolinter v0.14.1 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/polyfloyd/go-errorlint v1.4.5 // indirect - github.com/prometheus/client_golang v1.14.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.42.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect + github.com/prometheus/procfs v0.10.1 // indirect github.com/quasilyte/go-ruleguard v0.4.0 // indirect github.com/quasilyte/gogrep v0.5.0 // indirect github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect @@ -342,6 +349,8 @@ replace ( // cosmos keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 + github.com/CosmWasm/wasmd => github.com/sge-network/wasmd v0.0.0-20240503124041-93276618b032 + github.com/cosmos/cosmos-sdk => github.com/sge-network/cosmos-sdk v0.47.9-0.20240409081440-054c8c413d45 // support concurrency for iavl diff --git a/go.sum b/go.sum index 95719994..79ed5035 100644 --- a/go.sum +++ b/go.sum @@ -194,8 +194,8 @@ cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoIS collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE= cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= -cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI= -cosmossdk.io/core v0.5.1/go.mod h1:KZtwHCLjcFuo0nmDc24Xy6CRNEL9Vl/MeimQ2aC7NLE= +cosmossdk.io/core v0.6.1 h1:OBy7TI2W+/gyn2z40vVvruK3di+cAluinA6cybFbE7s= +cosmossdk.io/core v0.6.1/go.mod h1:g3MMBCBXtxbDWBURDVnJE7XML4BG5qENhs0gzkcpuFA= cosmossdk.io/depinject v1.0.0-alpha.4 h1:PLNp8ZYAMPTUKyG9IK2hsbciDWqna2z1Wsl98okJopc= cosmossdk.io/depinject v1.0.0-alpha.4/go.mod h1:HeDk7IkR5ckZ3lMGs/o91AVUc7E596vMaOmslGFM3yU= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= @@ -235,6 +235,8 @@ github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8 github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= +github.com/CosmWasm/wasmvm v1.5.2 h1:+pKB1Mz9GZVt1vadxB+EDdD1FOz3dMNjIKq/58/lrag= +github.com/CosmWasm/wasmvm v1.5.2/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= @@ -469,6 +471,10 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg= github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= +github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad h1:ozJyL/gd3hXYQodS7EESUQgu+1CeJ9nvb9sfHufmsjI= +github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad/go.mod h1:JwHFbo1oX/ht4fPpnPvmhZr+dCkYK1Vihw+vZE9umR4= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5 h1:sMoHjep+KInjMrppNCEutMVm1p8nI9WhKCuMQ+EcUHw= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5/go.mod h1:VR2Hg2i/X1bafbmmNsV2Khwsg0PzNeuWoVKmSN5dAwo= github.com/cosmos/ibc-go/v7 v7.4.0 h1:8FqYMptvksgMvlbN4UW9jFxTXzsPyfAzEZurujXac8M= github.com/cosmos/ibc-go/v7 v7.4.0/go.mod h1:L/KaEhzV5TGUCTfGysVgMBQtl5Dm7hHitfpk+GIeoAo= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= @@ -526,6 +532,8 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= +github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= @@ -1267,8 +1275,8 @@ github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= +github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -1297,8 +1305,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= +github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/quasilyte/go-ruleguard v0.4.0 h1:DyM6r+TKL+xbKB4Nm7Afd1IQh9kEUKQs2pboWGKtvQo= github.com/quasilyte/go-ruleguard v0.4.0/go.mod h1:Eu76Z/R8IXtViWUIHkE3p8gdH3/PKk1eh3YGfaEof10= @@ -1362,6 +1370,8 @@ github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sge-network/cosmos-sdk v0.47.9-0.20240409081440-054c8c413d45 h1:gdXKc/Y7QTsuDsoC/S3R/LdXAxazOFzjxNoiJmpFaYE= github.com/sge-network/cosmos-sdk v0.47.9-0.20240409081440-054c8c413d45/go.mod h1:WjqTUUHJnaRjkgJbP2aQ1F+9pxDpLsOBpfuP2S0W+Ck= +github.com/sge-network/wasmd v0.0.0-20240503124041-93276618b032 h1:h36Vah9OlpBhVFxAEwo9cSRLhX1vhN5f4Q4Hue2BKXw= +github.com/sge-network/wasmd v0.0.0-20240503124041-93276618b032/go.mod h1:uQOWQUhJrZpsroGkmunpIJfj4tY9NIZWDVw1f42hjtI= github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU= github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= diff --git a/testutil/network/network.go b/testutil/network/network.go index 291f0317..25d8893f 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -17,6 +17,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/sge-network/sge/app" ) @@ -73,6 +75,7 @@ func DefaultConfig() network.Config { 0, encoding, simtestutil.EmptyAppOptions{}, + []wasmkeeper.Option{}, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), baseapp.SetChainID(chainID), diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index eafaa75c..8f68e3dd 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -24,6 +24,9 @@ import ( stakingKeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/sge-network/sge/app" "github.com/sge-network/sge/app/params" "github.com/sge-network/sge/utils" @@ -56,6 +59,7 @@ func setup(withGenesis bool, invCheckPeriod uint) (*TestApp, app.GenesisState) { invCheckPeriod, encCdc, simtestutil.EmptyAppOptions{}, + []wasmkeeper.Option{}, ) if withGenesis { return &TestApp{SgeApp: *appInstance}, app.NewDefaultGenesisState() From 5b16f7d01d0aace4bcfaf92ad76508a2ec38fbda Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Mon, 6 May 2024 14:38:18 +0300 Subject: [PATCH 2/7] refactor: replace wasmd build --- app/keepers/keepers.go | 8 ++++---- cmd/sged/cmd/root.go | 1 - go.mod | 4 ++-- go.sum | 8 ++++---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 21a65cb8..99af60b0 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -377,8 +377,8 @@ func NewAppKeeper( ) appKeepers.IBCHooksKeeper = &hooksKeeper - junoPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix() - wasmHooks := ibc_hooks.NewWasmHooks(appKeepers.IBCHooksKeeper, &appKeepers.WasmKeeper, junoPrefix) // The contract keeper needs to be set later + sgePrefix := sdk.GetConfig().GetBech32AccountAddrPrefix() + wasmHooks := ibc_hooks.NewWasmHooks(appKeepers.IBCHooksKeeper, &appKeepers.WasmKeeper, sgePrefix) // The contract keeper needs to be set later appKeepers.Ics20WasmHooks = &wasmHooks appKeepers.HooksICS4Wrapper = ibc_hooks.NewICS4Middleware( appKeepers.IBCKeeper.ChannelKeeper, @@ -475,12 +475,12 @@ func NewAppKeeper( mainWasmer, err := wasmvm.NewVM(path.Join(dataDir, "wasm"), wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) if err != nil { - panic(fmt.Sprintf("failed to create juno wasm vm: %s", err)) + panic(fmt.Sprintf("failed to create sge wasm vm: %s", err)) } lcWasmer, err := wasmvm.NewVM(filepath.Join(dataDir, "light-client-wasm"), wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) if err != nil { - panic(fmt.Sprintf("failed to create juno wasm vm for 08-wasm: %s", err)) + panic(fmt.Sprintf("failed to create sge wasm vm for 08-wasm: %s", err)) } appKeepers.WasmKeeper = wasmkeeper.NewKeeper( diff --git a/cmd/sged/cmd/root.go b/cmd/sged/cmd/root.go index 16ed8b8e..f61b4c0a 100644 --- a/cmd/sged/cmd/root.go +++ b/cmd/sged/cmd/root.go @@ -104,7 +104,6 @@ func initAppConfig() (string, interface{}) { // Optionally allow the chain developer to overwrite the SDK's default // server config. srvCfg := serverconfig.DefaultConfig() - // srvCfg.MinGasPrices = "0ujuno,0ujunox" // GlobalFee handles customAppConfig := CustomAppConfig{ Config: *srvCfg, diff --git a/go.mod b/go.mod index 0e2311a2..939a77a7 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/cosmos/cosmos-sdk v0.47.8 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad - github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5 + github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/golang-jwt/jwt/v4 v4.5.0 @@ -349,7 +349,7 @@ replace ( // cosmos keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 - github.com/CosmWasm/wasmd => github.com/sge-network/wasmd v0.0.0-20240503124041-93276618b032 + github.com/CosmWasm/wasmd => github.com/sge-network/wasmd v0.0.0-20240506113624-5ccb26abde7a github.com/cosmos/cosmos-sdk => github.com/sge-network/cosmos-sdk v0.47.9-0.20240409081440-054c8c413d45 diff --git a/go.sum b/go.sum index 79ed5035..289bc8eb 100644 --- a/go.sum +++ b/go.sum @@ -473,8 +473,8 @@ github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg= github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad h1:ozJyL/gd3hXYQodS7EESUQgu+1CeJ9nvb9sfHufmsjI= github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad/go.mod h1:JwHFbo1oX/ht4fPpnPvmhZr+dCkYK1Vihw+vZE9umR4= -github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5 h1:sMoHjep+KInjMrppNCEutMVm1p8nI9WhKCuMQ+EcUHw= -github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5/go.mod h1:VR2Hg2i/X1bafbmmNsV2Khwsg0PzNeuWoVKmSN5dAwo= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1 h1:fCtG9qasnNzhgxGR1jM9eBufZ5WQVpy0KdaOpKRfg8Y= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1/go.mod h1:h114vYKBtI5zKBeSyr8y5JZ8ZtpQJInO4TYww2IQr6o= github.com/cosmos/ibc-go/v7 v7.4.0 h1:8FqYMptvksgMvlbN4UW9jFxTXzsPyfAzEZurujXac8M= github.com/cosmos/ibc-go/v7 v7.4.0/go.mod h1:L/KaEhzV5TGUCTfGysVgMBQtl5Dm7hHitfpk+GIeoAo= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= @@ -1370,8 +1370,8 @@ github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sge-network/cosmos-sdk v0.47.9-0.20240409081440-054c8c413d45 h1:gdXKc/Y7QTsuDsoC/S3R/LdXAxazOFzjxNoiJmpFaYE= github.com/sge-network/cosmos-sdk v0.47.9-0.20240409081440-054c8c413d45/go.mod h1:WjqTUUHJnaRjkgJbP2aQ1F+9pxDpLsOBpfuP2S0W+Ck= -github.com/sge-network/wasmd v0.0.0-20240503124041-93276618b032 h1:h36Vah9OlpBhVFxAEwo9cSRLhX1vhN5f4Q4Hue2BKXw= -github.com/sge-network/wasmd v0.0.0-20240503124041-93276618b032/go.mod h1:uQOWQUhJrZpsroGkmunpIJfj4tY9NIZWDVw1f42hjtI= +github.com/sge-network/wasmd v0.0.0-20240506113624-5ccb26abde7a h1:cg3upuH1sZBjFKY2p7qgE9LTtGt2ccH8vucTGMWquSo= +github.com/sge-network/wasmd v0.0.0-20240506113624-5ccb26abde7a/go.mod h1:uQOWQUhJrZpsroGkmunpIJfj4tY9NIZWDVw1f42hjtI= github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU= github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= From 951bc19124916ad7ce61fe114eb4fbca28da7755 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Mon, 6 May 2024 16:58:37 +0300 Subject: [PATCH 3/7] lint: multi import ibcport --- app/keepers/keepers.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 99af60b0..c8503e0b 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -71,7 +71,6 @@ import ( ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ibcporttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" - porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" @@ -684,7 +683,7 @@ func NewAppKeeper( icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, appKeepers.IBCFeeKeeper) // Create fee enabled wasm ibc Stack - var wasmStack porttypes.IBCModule + var wasmStack ibcporttypes.IBCModule wasmStack = wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCFeeKeeper) wasmStack = ibcfee.NewIBCMiddleware(wasmStack, appKeepers.IBCFeeKeeper) From 2247acca829e5d63d4d86cea67f9036a42d4520b Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Tue, 7 May 2024 15:13:53 +0300 Subject: [PATCH 4/7] fix: remove manual cosmvm generate --- Dockerfile | 75 +++++++++++++++++++++++++++++++ Makefile | 19 ++++++++ app/app.go | 6 +-- app/keepers/keepers.go | 88 +++++++------------------------------ app/keepers/keys.go | 4 +- app/modules.go | 14 +++--- app/upgrades/v9/consts.go | 4 +- app/upgrades/v9/upgrades.go | 4 +- cmd/sged/cmd/root.go | 33 ++++++-------- go.mod | 2 +- 10 files changed, 140 insertions(+), 109 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..d0f3ac19 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,75 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION="1.22" +ARG RUNNER_IMAGE="gcr.io/distroless/static-debian11" +ARG BUILD_TAGS="netgo,ledger,muslc" + +# -------------------------------------------------------- +# Builder +# -------------------------------------------------------- + +FROM golang:${GO_VERSION}-alpine3.19 as builder + +ARG GIT_VERSION +ARG GIT_COMMIT +ARG BUILD_TAGS + +RUN apk add --no-cache \ + ca-certificates \ + build-base \ + linux-headers + +# Download go dependencies +WORKDIR /sge +COPY go.mod go.sum ./ +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + go mod download + +# Cosmwasm - Download correct libwasmvm version +RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | sed 's/.* //') && \ + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.a \ + -O /lib/libwasmvm_muslc.a && \ + # verify checksum + wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \ + sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$ARCH | cut -d ' ' -f 1) + +# Copy the remaining files +COPY . . + +# Build sged binary +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/root/go/pkg/mod \ + GOWORK=off go build \ + -mod=readonly \ + -tags "netgo,ledger,muslc" \ + -ldflags \ + "-X github.com/cosmos/cosmos-sdk/version.Name="sge" \ + -X github.com/cosmos/cosmos-sdk/version.AppName="sged" \ + -X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \ + -X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \ + -X github.com/cosmos/cosmos-sdk/version.BuildTags=${BUILD_TAGS} \ + -w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \ + -trimpath \ + -o /sge/build/sged \ + /sge/cmd/sged/main.go + +# -------------------------------------------------------- +# Runner +# -------------------------------------------------------- + +FROM ${RUNNER_IMAGE} + +COPY --from=builder /sge/build/sged /bin/sged + +ENV HOME /sge +WORKDIR $HOME + +EXPOSE 26656 +EXPOSE 26657 +EXPOSE 1317 +# Note: uncomment the line below if you need pprof in localsge +# We disable it by default in out main Dockerfile for security reasons +# EXPOSE 6060 + +ENTRYPOINT ["sged"] diff --git a/Makefile b/Makefile index b3ba976b..40823969 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ ifeq (,$(VERSION)) endif endif +GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2) PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') LEDGER_ENABLED ?= true SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') @@ -131,6 +132,24 @@ $(BUILD_TARGETS): check_version go.sum $(BUILDDIR)/ $(BUILDDIR)/: mkdir -p $(BUILDDIR)/ +build-reproducible-amd64: go.sum + mkdir -p $(BUILDDIR) + $(DOCKER) buildx create --name sgebuilder --node sgebinary || true + $(DOCKER) buildx use sgebuilder + $(DOCKER) buildx build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + --build-arg RUNNER_IMAGE=alpine:3.19 \ + --platform linux/amd64 \ + -t sge:local-amd64 \ + --load \ + -f Dockerfile . + $(DOCKER) rm -f sgebinary || true + $(DOCKER) create -ti --name sgebinary sge:local-amd64 + $(DOCKER) cp sgebinary:/bin/sged $(BUILDDIR)/sged-linux-amd64 + $(DOCKER) rm -f sgebinary + build-linux: go.sum LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build diff --git a/app/app.go b/app/app.go index 778721eb..3c123e09 100644 --- a/app/app.go +++ b/app/app.go @@ -44,7 +44,7 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - wasmlckeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" ibcclientHandler "github.com/cosmos/ibc-go/v7/modules/core/02-client/client" wasm "github.com/CosmWasm/wasmd/x/wasm" @@ -281,7 +281,7 @@ func NewSgeApp( err = manager.RegisterExtensions( wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmKeeper), // https://github.com/cosmos/ibc-go/pull/5439 - wasmlckeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmClientKeeper), + ibcwasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmClientKeeper), ) if err != nil { panic("failed to register snapshot extension: " + err.Error()) @@ -298,7 +298,7 @@ func NewSgeApp( ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{}) // https://github.com/cosmos/ibc-go/pull/5439 - if err := wasmlckeeper.InitializePinnedCodes(ctx, appCodec); err != nil { + if err := ibcwasmkeeper.InitializePinnedCodes(ctx, appCodec); err != nil { tmos.Exit(fmt.Sprintf("wasmlckeeper failed initialize pinned codes %s", err)) } diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index c8503e0b..d91f016c 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -1,10 +1,7 @@ package keepers import ( - "fmt" - "path" "path/filepath" - "strings" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -30,7 +27,6 @@ import ( feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" @@ -51,8 +47,8 @@ import ( ibc_hooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7" ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/keeper" ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" - wasmlckeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" - wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + ibcwasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller" icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" @@ -69,18 +65,14 @@ import ( ibc "github.com/cosmos/ibc-go/v7/modules/core" ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client" ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - ibcconnectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" ibcporttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" // cosmwasm - - wasmapp "github.com/CosmWasm/wasmd/app" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvm "github.com/CosmWasm/wasmvm" // sge @@ -119,8 +111,6 @@ import ( _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) -var wasmCapabilities = strings.Join(wasmapp.AllCapabilities(), ",") - type AppKeepers struct { // keys to access the substores keys map[string]*storetypes.KVStoreKey @@ -147,7 +137,7 @@ type AppKeepers struct { //// CosmWasm keepers \\\\ ContractKeeper wasmtypes.ContractOpsKeeper - WasmClientKeeper wasmlckeeper.Keeper + WasmClientKeeper ibcwasmkeeper.Keeper WasmKeeper wasmkeeper.Keeper ScopedWasmKeeper capabilitykeeper.ScopedKeeper @@ -437,50 +427,20 @@ func NewAppKeeper( appKeepers.SlashingKeeper, ) - dataDir := filepath.Join(homePath, "data") - + wasmDir := filepath.Join(homePath, "cwvm") wasmConfig, err := wasm.ReadWasmConfig(appOpts) if err != nil { panic("error while reading wasm config: " + err.Error()) } - // Stargate Queries - acceptedStargateQueries := wasmkeeper.AcceptedStargateQueries{ - // ibc - "/ibc.core.client.v1.Query/ClientState": &ibcclienttypes.QueryClientStateResponse{}, - "/ibc.core.client.v1.Query/ConsensusState": &ibcclienttypes.QueryConsensusStateResponse{}, - "/ibc.core.connection.v1.Query/Connection": &ibcconnectiontypes.QueryConnectionResponse{}, - - // governance - "/cosmos.gov.v1beta1.Query/Vote": &govv1.QueryVoteResponse{}, - - // distribution - "/cosmos.distribution.v1beta1.Query/DelegationRewards": &distrtypes.QueryDelegationRewardsResponse{}, - - // staking - "/cosmos.staking.v1beta1.Query/Delegation": &stakingtypes.QueryDelegationResponse{}, - "/cosmos.staking.v1beta1.Query/Redelegations": &stakingtypes.QueryRedelegationsResponse{}, - "/cosmos.staking.v1beta1.Query/UnbondingDelegation": &stakingtypes.QueryUnbondingDelegationResponse{}, - "/cosmos.staking.v1beta1.Query/Validator": &stakingtypes.QueryValidatorResponse{}, - "/cosmos.staking.v1beta1.Query/Params": &stakingtypes.QueryParamsResponse{}, - "/cosmos.staking.v1beta1.Query/Pool": &stakingtypes.QueryPoolResponse{}, - } - - querierOpts := wasmkeeper.WithQueryPlugins( - &wasmkeeper.QueryPlugins{ - Stargate: wasmkeeper.AcceptListStargateQuerier(acceptedStargateQueries, bApp.GRPCQueryRouter(), appCodec), - }) - wasmOpts = append(wasmOpts, querierOpts) - - mainWasmer, err := wasmvm.NewVM(path.Join(dataDir, "wasm"), wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) - if err != nil { - panic(fmt.Sprintf("failed to create sge wasm vm: %s", err)) - } + ibcWasmConfig := + ibcwasmtypes.WasmConfig{ + DataDir: filepath.Join(wasmDir, "ibc_08-wasm"), + SupportedCapabilities: "iterator,stargate,abort", + ContractDebugMode: false, + } - lcWasmer, err := wasmvm.NewVM(filepath.Join(dataDir, "light-client-wasm"), wasmCapabilities, 32, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) - if err != nil { - panic(fmt.Sprintf("failed to create sge wasm vm for 08-wasm: %s", err)) - } + wasmCapabilities := "iterator,staking,stargate" appKeepers.WasmKeeper = wasmkeeper.NewKeeper( appCodec, @@ -496,36 +456,20 @@ func NewAppKeeper( appKeepers.TransferKeeper, bApp.MsgServiceRouter(), bApp.GRPCQueryRouter(), - dataDir, + wasmDir, wasmConfig, wasmCapabilities, govModAddress, - append(wasmOpts, wasmkeeper.WithWasmEngine(mainWasmer))..., + wasmOpts..., ) - // 08-wasm light client - accepted := make([]string, 0) - for k := range acceptedStargateQueries { - accepted = append(accepted, k) - } - - wasmLightClientQuerier := wasmlctypes.QueryPlugins{ - // Custom: MyCustomQueryPlugin(), - // `myAcceptList` is a `[]string` containing the list of gRPC query paths that the chain wants to allow for the `08-wasm` module to query. - // These queries must be registered in the chain's gRPC query router, be deterministic, and track their gas usage. - // The `AcceptListStargateQuerier` function will return a query plugin that will only allow queries for the paths in the `myAcceptList`. - // The query responses are encoded in protobuf unlike the implementation in `x/wasm`. - Stargate: wasmlctypes.AcceptListStargateQuerier(accepted), - } - - appKeepers.WasmClientKeeper = wasmlckeeper.NewKeeperWithVM( + appKeepers.WasmClientKeeper = ibcwasmkeeper.NewKeeperWithConfig( appCodec, - appKeepers.keys[wasmlctypes.StoreKey], + appKeepers.keys[ibcwasmtypes.StoreKey], appKeepers.IBCKeeper.ClientKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), - lcWasmer, + ibcWasmConfig, bApp.GRPCQueryRouter(), - wasmlckeeper.WithQueryPlugins(&wasmLightClientQuerier), ) // set the contract keeper for the Ics20WasmHooks diff --git a/app/keepers/keys.go b/app/keepers/keys.go index b4d80fd8..4f24e08f 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -21,6 +21,7 @@ import ( // ibc-go ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" @@ -29,7 +30,6 @@ import ( // cosmwasm wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" betmoduletypes "github.com/sge-network/sge/x/bet/types" housemoduletypes "github.com/sge-network/sge/x/house/types" @@ -57,7 +57,7 @@ func (appKeepers *AppKeepers) GenerateKeys() { minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, group.StoreKey, - wasmtypes.StoreKey, wasmlctypes.StoreKey, + wasmtypes.StoreKey, ibcwasmtypes.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey, icacontrollertypes.StoreKey, icahosttypes.StoreKey, ibchookstypes.StoreKey, orderbookmoduletypes.StoreKey, betmoduletypes.StoreKey, diff --git a/app/modules.go b/app/modules.go index b552dc72..a4fdaa1c 100644 --- a/app/modules.go +++ b/app/modules.go @@ -38,8 +38,8 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" - wasmlc "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" - wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + ibcwasmmodule "github.com/cosmos/ibc-go/modules/light-clients/08-wasm" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee" @@ -125,7 +125,7 @@ var ModuleBasics = module.NewBasicManager( transfer.AppModuleBasic{}, ica.AppModuleBasic{}, ibcfee.AppModuleBasic{}, - wasmlc.AppModuleBasic{}, + ibcwasmmodule.AppModuleBasic{}, // sge betmodule.AppModuleBasic{}, @@ -203,7 +203,7 @@ func appModules( app.TransferModule, app.IBCFeeModule, app.ICAModule, - wasmlc.NewAppModule(app.AppKeepers.WasmClientKeeper), + ibcwasmmodule.NewAppModule(app.AppKeepers.WasmClientKeeper), app.BetModule, app.MarketModule, app.OrderbookModule, @@ -309,7 +309,7 @@ func orderBeginBlockers() []string { icatypes.ModuleName, wasmtypes.ModuleName, ibchookstypes.ModuleName, - wasmlctypes.ModuleName, + ibcwasmtypes.ModuleName, betmoduletypes.ModuleName, marketmoduletypes.ModuleName, orderbookmoduletypes.ModuleName, @@ -346,7 +346,7 @@ func orderEndBlockers() []string { icatypes.ModuleName, wasmtypes.ModuleName, ibchookstypes.ModuleName, - wasmlctypes.ModuleName, + ibcwasmtypes.ModuleName, betmoduletypes.ModuleName, marketmoduletypes.ModuleName, orderbookmoduletypes.ModuleName, @@ -382,7 +382,7 @@ func orderInitBlockers() []string { icatypes.ModuleName, ibcfeetypes.ModuleName, wasmtypes.ModuleName, - wasmlctypes.ModuleName, + ibcwasmtypes.ModuleName, ibchookstypes.ModuleName, betmoduletypes.ModuleName, marketmoduletypes.ModuleName, diff --git a/app/upgrades/v9/consts.go b/app/upgrades/v9/consts.go index a61e07e2..915ed4f3 100644 --- a/app/upgrades/v9/consts.go +++ b/app/upgrades/v9/consts.go @@ -6,9 +6,9 @@ import ( crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" "github.com/sge-network/sge/app/upgrades" ) @@ -25,7 +25,7 @@ var Upgrade = upgrades.Upgrade{ consensustypes.ModuleName, ibchookstypes.StoreKey, wasmtypes.ModuleName, - wasmlctypes.ModuleName, + ibcwasmtypes.ModuleName, }, Deleted: []string{}, }, diff --git a/app/upgrades/v9/upgrades.go b/app/upgrades/v9/upgrades.go index 902bd6f5..8308f03b 100644 --- a/app/upgrades/v9/upgrades.go +++ b/app/upgrades/v9/upgrades.go @@ -18,7 +18,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" @@ -115,7 +115,7 @@ func CreateUpgradeHandler( // explicitly update the IBC 02-client params, adding the localhost client type params := k.IBCKeeper.ClientKeeper.GetParams(ctx) params.AllowedClients = append(params.AllowedClients, exported.Localhost) - params.AllowedClients = append(params.AllowedClients, wasmlctypes.Wasm) + params.AllowedClients = append(params.AllowedClients, ibcwasmtypes.Wasm) k.IBCKeeper.ClientKeeper.SetParams(ctx, params) // update gov params to use a 20% initial deposit ratio, allowing us to remote the ante handler diff --git a/cmd/sged/cmd/root.go b/cmd/sged/cmd/root.go index f61b4c0a..798db623 100644 --- a/cmd/sged/cmd/root.go +++ b/cmd/sged/cmd/root.go @@ -300,26 +300,19 @@ func createSimappAndExport( encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry) var sgeApp *app.SgeApp var emptyWasmOpts []wasmkeeper.Option - if height != -1 { - sgeApp = app.NewSgeApp( - logger, - db, - traceStore, - false, - map[int64]bool{}, - "", - cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), - encCfg, - appOpts, - emptyWasmOpts, - ) - - if err := sgeApp.LoadHeight(height); err != nil { - return servertypes.ExportedApp{}, err - } - } else { - sgeApp = app.NewSgeApp(logger, db, traceStore, true, map[int64]bool{}, "", cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encCfg, appOpts, emptyWasmOpts) - } + loadLatest := height == -1 + sgeApp = app.NewSgeApp( + logger, + db, + traceStore, + loadLatest, + map[int64]bool{}, + cast.ToString(appOpts.Get(flags.FlagHome)), + cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), + encCfg, + appOpts, + emptyWasmOpts, + ) return sgeApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) } diff --git a/go.mod b/go.mod index 939a77a7..9b006d01 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( cosmossdk.io/math v1.3.0 cosmossdk.io/simapp v0.0.0-20230831152633-2e9e5d6eea24 github.com/CosmWasm/wasmd v0.45.0 - github.com/CosmWasm/wasmvm v1.5.2 github.com/cometbft/cometbft v0.37.5 github.com/cometbft/cometbft-db v0.8.0 github.com/cosmos/cosmos-proto v1.0.0-beta.4 @@ -82,6 +81,7 @@ require ( github.com/Antonboom/testifylint v0.2.3 // indirect github.com/BurntSushi/toml v1.3.2 // indirect github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect + github.com/CosmWasm/wasmvm v1.5.2 // indirect github.com/GaijinEntertainment/go-exhaustruct/v3 v3.1.0 // indirect github.com/Masterminds/semver v1.5.0 // indirect github.com/OpenPeeDeeP/depguard/v2 v2.1.0 // indirect From 9fddde1b2d54dea1b04ea1a4dde351c735bd9a03 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 8 May 2024 12:51:20 +0300 Subject: [PATCH 5/7] downgrade: alpine to 3.18 prevent sigabort error --- Dockerfile | 2 +- Makefile | 2 +- proto/Dockerfile | 2 +- proto/buf.lock | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0f3ac19..0ae6b491 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ ARG BUILD_TAGS="netgo,ledger,muslc" # Builder # -------------------------------------------------------- -FROM golang:${GO_VERSION}-alpine3.19 as builder +FROM golang:${GO_VERSION}-alpine3.18 as builder ARG GIT_VERSION ARG GIT_COMMIT diff --git a/Makefile b/Makefile index 40823969..31e9a316 100644 --- a/Makefile +++ b/Makefile @@ -140,7 +140,7 @@ build-reproducible-amd64: go.sum --build-arg GO_VERSION=$(GO_VERSION) \ --build-arg GIT_VERSION=$(VERSION) \ --build-arg GIT_COMMIT=$(COMMIT) \ - --build-arg RUNNER_IMAGE=alpine:3.19 \ + --build-arg RUNNER_IMAGE=alpine:3.18 \ --platform linux/amd64 \ -t sge:local-amd64 \ --load \ diff --git a/proto/Dockerfile b/proto/Dockerfile index 0de9948c..3ff044e3 100644 --- a/proto/Dockerfile +++ b/proto/Dockerfile @@ -3,7 +3,7 @@ FROM bufbuild/buf:1.9.0 as BUILDER -FROM golang:1.22-alpine +FROM golang:1.22-alpine3.18 RUN apk add --no-cache \ diff --git a/proto/buf.lock b/proto/buf.lock index 07312228..83c7a202 100644 --- a/proto/buf.lock +++ b/proto/buf.lock @@ -19,7 +19,7 @@ deps: - remote: buf.build owner: googleapis repository: googleapis - commit: 4ed3bc159a8b4ac68fe253218760d035 + commit: 1f6ed065c9f04b5cb843d6e7603d6454 digest: shake256:7149cf5e9955c692d381e557830555d4e93f205a0f1b8e2dfdae46d029369aa3fc1980e35df0d310f7cc3b622f93e19ad276769a283a967dd3065ddfd3a40e13 - remote: buf.build owner: protocolbuffers From 9e34176e5006f505e10efa552375f6ee31f487e6 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 8 May 2024 13:21:14 +0300 Subject: [PATCH 6/7] lint: gofumpt --- app/keepers/keepers.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index d91f016c..ed642a07 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -433,12 +433,11 @@ func NewAppKeeper( panic("error while reading wasm config: " + err.Error()) } - ibcWasmConfig := - ibcwasmtypes.WasmConfig{ - DataDir: filepath.Join(wasmDir, "ibc_08-wasm"), - SupportedCapabilities: "iterator,stargate,abort", - ContractDebugMode: false, - } + ibcWasmConfig := ibcwasmtypes.WasmConfig{ + DataDir: filepath.Join(wasmDir, "ibc_08-wasm"), + SupportedCapabilities: "iterator,stargate,abort", + ContractDebugMode: false, + } wasmCapabilities := "iterator,staking,stargate" From 2d05591a93d94265a67fc399425a8861b72cbefe Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 8 May 2024 14:03:48 +0300 Subject: [PATCH 7/7] feat: cross compile wasm ibc compatibility --- .github/workflows/test.yml | 56 ++++++++++++++++++++++++++++---------- Makefile | 20 ++++++++++++++ go.mod | 2 +- go.sum | 4 +-- 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cdcbba2e..5b9fe851 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,24 +27,52 @@ jobs: key: ${{ runner.os }}-go-tparse-binary build: + name: sged-${{ matrix.targetos }}-${{ matrix.arch }} runs-on: ubuntu-latest + strategy: matrix: - go-arch: ["amd64", "arm", "arm64"] + arch: [amd64, arm64] + targetos: [darwin, linux] + include: + - targetos: darwin + arch: arm64 + steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v5 - with: - go-version: 1.22 - - uses: technote-space/get-diff-action@v4 - id: git_diff + - name: Check out repository code + uses: actions/checkout@v4 + - name: Get git diff + uses: technote-space/get-diff-action@v6.1.2 with: PATTERNS: | - **/**.go + **/**.wasm + !tests/** + **/**.go !**/*_test.go go.mod go.sum - - name: Build - run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make build + Makefile + .github/workflows/build.yml + - name: 🐿 Setup Golang + uses: actions/setup-go@v5 + if: env.GIT_DIFF + with: + go-version-file: go.mod + env: + GOOS: ${{ matrix.targetos }} + GOARCH: ${{ matrix.arch }} + - name: Download Dependencies + if: env.GIT_DIFF + run: go mod download + - name: Build sged + if: env.GIT_DIFF + run: | + GOWRK=off go build cmd/sged/main.go + - name: Upload sged artifact + if: env.GIT_DIFF + uses: actions/upload-artifact@v3 + with: + name: sged-${{ matrix.targetos }}-${{ matrix.arch }} + path: cmd/sged/sged split-test-files: runs-on: ubuntu-latest @@ -52,7 +80,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version: 1.22 - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Create a file with all the pkgs run: go list ./... > pkgs.txt - name: Split pkgs into 4 files @@ -83,7 +111,7 @@ jobs: matrix: part: ["00", "01", "02", "03"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: 1.22 @@ -110,7 +138,7 @@ jobs: runs-on: ubuntu-latest needs: tests steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: technote-space/get-diff-action@v4 with: PATTERNS: | @@ -161,7 +189,7 @@ jobs: matrix: part: ["00", "01", "02", "03"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: 1.22 diff --git a/Makefile b/Makefile index 31e9a316..1d89bef5 100644 --- a/Makefile +++ b/Makefile @@ -132,6 +132,8 @@ $(BUILD_TARGETS): check_version go.sum $(BUILDDIR)/ $(BUILDDIR)/: mkdir -p $(BUILDDIR)/ +build-reproducible: build-reproducible-amd64 build-reproducible-arm64 + build-reproducible-amd64: go.sum mkdir -p $(BUILDDIR) $(DOCKER) buildx create --name sgebuilder --node sgebinary || true @@ -150,6 +152,24 @@ build-reproducible-amd64: go.sum $(DOCKER) cp sgebinary:/bin/sged $(BUILDDIR)/sged-linux-amd64 $(DOCKER) rm -f sgebinary +build-reproducible-arm64: go.sum + mkdir -p $(BUILDDIR) + $(DOCKER) buildx create --name sgebuilder || true + $(DOCKER) buildx use sgebuilder + $(DOCKER) buildx build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --build-arg GIT_VERSION=$(VERSION) \ + --build-arg GIT_COMMIT=$(COMMIT) \ + --build-arg RUNNER_IMAGE=alpine:3.18 \ + --platform linux/arm64 \ + -t sge:local-arm64 \ + --load \ + -f Dockerfile . + $(DOCKER) rm -f sgebinary || true + $(DOCKER) create -ti --name sgebinary sge:local-arm64 + $(DOCKER) cp sgebinary:/bin/sged $(BUILDDIR)/sged-linux-arm64 + $(DOCKER) rm -f sgebinary + build-linux: go.sum LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build diff --git a/go.mod b/go.mod index 9b006d01..44044b6d 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/cosmos/cosmos-sdk v0.47.8 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad - github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1 + github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/golang-jwt/jwt/v4 v4.5.0 diff --git a/go.sum b/go.sum index 289bc8eb..459ce2ea 100644 --- a/go.sum +++ b/go.sum @@ -473,8 +473,8 @@ github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg= github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad h1:ozJyL/gd3hXYQodS7EESUQgu+1CeJ9nvb9sfHufmsjI= github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20240502201956-e9b46e4bf0ad/go.mod h1:JwHFbo1oX/ht4fPpnPvmhZr+dCkYK1Vihw+vZE9umR4= -github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1 h1:fCtG9qasnNzhgxGR1jM9eBufZ5WQVpy0KdaOpKRfg8Y= -github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092633-b306e7a706e1/go.mod h1:h114vYKBtI5zKBeSyr8y5JZ8ZtpQJInO4TYww2IQr6o= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5 h1:sMoHjep+KInjMrppNCEutMVm1p8nI9WhKCuMQ+EcUHw= +github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-ibc-go-v7.3-wasmvm-v1.5/go.mod h1:VR2Hg2i/X1bafbmmNsV2Khwsg0PzNeuWoVKmSN5dAwo= github.com/cosmos/ibc-go/v7 v7.4.0 h1:8FqYMptvksgMvlbN4UW9jFxTXzsPyfAzEZurujXac8M= github.com/cosmos/ibc-go/v7 v7.4.0/go.mod h1:L/KaEhzV5TGUCTfGysVgMBQtl5Dm7hHitfpk+GIeoAo= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=