Skip to content

Commit

Permalink
feat: add hub genesis module (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 authored Apr 6, 2024
1 parent eab8283 commit 73b3ceb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 22 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,26 @@ export DENOM="urax"
export MONIKER="$ROLLAPP_CHAIN_ID-sequencer"
```

if you want to change the max wasm size:
And initialize the rollapp:

```shell
export MAX_WASM_SIZE=YOUR_MAX_WASM_SIZE
sh scripts/init.sh
```

And initialize the rollapp:
You can find out in <https://github.com/CosmWasm/wasmd#compile-time-parameters> that:

There are a few variables was allow blockchains to customize at compile time. If you build your own chain and import x/wasm, you can adjust a few items via module parameters, but a few others did not fit in that, as they need to be used by stateless ValidateBasic(). Thus, we made them as flags and set them in start.go so that they can be overridden on your custom chain.

```shell
sh scripts/init.sh
rollappd start --max-label-size 64 --max-wasm-size 2048000 --max-wasm-proposal-size 2048000
```

Those flags are optional, the default value was set as:

```go
wasmtypes.MaxLabelSize = 128
wasmtypes.MaxWasmSize = 819200
wasmtypes.MaxProposalWasmSize = 3145728
```

### Download cw20-ics20 smartcontract
Expand Down
31 changes: 22 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -82,6 +81,10 @@ import (
epochskeeper "github.com/dymensionxyz/dymension-rdk/x/epochs/keeper"
epochstypes "github.com/dymensionxyz/dymension-rdk/x/epochs/types"

hubgenesis "github.com/dymensionxyz/dymension-rdk/x/hub-genesis"
hubgenkeeper "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/keeper"
hubgentypes "github.com/dymensionxyz/dymension-rdk/x/hub-genesis/types"

ibctransfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
Expand Down Expand Up @@ -127,7 +130,7 @@ var (
minttypes.StoreKey, distrtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey,
ibchost.StoreKey, upgradetypes.StoreKey,
epochstypes.StoreKey,
epochstypes.StoreKey, hubgentypes.StoreKey,
ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
wasmtypes.StoreKey,
}
Expand Down Expand Up @@ -170,6 +173,7 @@ var (
ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
vesting.AppModuleBasic{},
hubgenesis.AppModuleBasic{},
wasm.AppModuleBasic{},
)

Expand All @@ -183,6 +187,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasmtypes.ModuleName: {authtypes.Burner},
hubgentypes.ModuleName: {authtypes.Burner},
}
)

Expand Down Expand Up @@ -227,6 +232,7 @@ type App struct {
EpochsKeeper epochskeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
HubGenesisKeeper hubgenkeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
Expand Down Expand Up @@ -285,13 +291,6 @@ func NewRollapp(
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

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)
wasmtypes.MaxProposalWasmSize = int(val)
}

// load state streaming if enabled
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, keys); err != nil {
panic("failed to load state streaming services: " + err.Error())
Expand Down Expand Up @@ -437,6 +436,15 @@ func NewRollapp(
)
transferIBCModule := ibctransfer.NewIBCModule(app.TransferKeeper)

app.HubGenesisKeeper = hubgenkeeper.NewKeeper(
appCodec,
keys[hubgentypes.StoreKey],
app.GetSubspace(hubgentypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
app.BankKeeper,
app.AccountKeeper,
)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand Down Expand Up @@ -504,6 +512,7 @@ func NewRollapp(
ibc.NewAppModule(app.IBCKeeper),
ibctransfer.NewAppModule(app.TransferKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
hubgenesis.NewAppModule(appCodec, app.HubGenesisKeeper, app.AccountKeeper),
}

app.mm = module.NewManager(modules...)
Expand All @@ -529,6 +538,7 @@ func NewRollapp(
genutiltypes.ModuleName,
epochstypes.ModuleName,
paramstypes.ModuleName,
hubgentypes.ModuleName,
wasm.ModuleName,
}
app.mm.SetOrderBeginBlockers(beginBlockersList...)
Expand All @@ -549,6 +559,7 @@ func NewRollapp(
upgradetypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
hubgentypes.ModuleName,
wasm.ModuleName,
}
app.mm.SetOrderEndBlockers(endBlockersList...)
Expand All @@ -575,6 +586,7 @@ func NewRollapp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
ibctransfertypes.ModuleName,
hubgentypes.ModuleName,
wasm.ModuleName,
}
app.mm.SetOrderInitGenesis(initGenesisList...)
Expand Down Expand Up @@ -903,6 +915,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable())
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(hubgentypes.ModuleName)

paramsKeeper.Subspace(wasmtypes.ModuleName)
return paramsKeeper
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/bcdevtools/block-explorer-rpc-cosmos v1.0.2
github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.0.2
github.com/cosmos/cosmos-sdk v0.46.15
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/cosmos/ibc-go/v6 v6.3.0
github.com/dymensionxyz/dymension-rdk v1.2.0-beta
github.com/dymensionxyz/dymint v1.0.1-alpha
github.com/ethereum/go-ethereum v1.12.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU=
github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-go/v6 v6.2.1 h1:NiaDXTRhKwf3n9kELD4VRIe5zby1yk1jBvaz9tXTQ6k=
github.com/cosmos/ibc-go/v6 v6.2.1/go.mod h1:XLsARy4Y7+GtAqzMcxNdlQf6lx+ti1e8KcMGv5NIK7A=
github.com/cosmos/ibc-go/v6 v6.3.0 h1:2EkkqDEd9hTQvzB/BsPhYZsu7T/dzAVA8+VD2UuJLSQ=
github.com/cosmos/ibc-go/v6 v6.3.0/go.mod h1:Dm14j9s094bGyCEE8W4fD+2t8IneHv+cz+80Mvwjr1w=
github.com/cosmos/interchain-accounts v0.4.3 h1:WedxEa/Hj/2GY7AF6CafkEPJ/Z9rhl3rT1mRwNHsdts=
github.com/cosmos/interchain-accounts v0.4.3/go.mod h1:qibHB6y/R2YsuuZdamI2BcIUBPMyhyELDWAr8Nk8x4g=
github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw=
Expand Down
28 changes: 22 additions & 6 deletions rollappd/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ package cmd
import (
"context"
"fmt"
"net"
"net/http"
"os"
"runtime/pprof"
"strconv"
"time"

berpc "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc"
berpcbackend "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/backend"
berpccfg "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/config"
Expand All @@ -13,12 +20,6 @@ import (
rawbeapi "github.com/dymensionxyz/rollapp-wasm/ra_wasm_be_rpc/namespaces/raw"
"github.com/ethereum/go-ethereum/rpc"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"net"
"net/http"
"os"
"runtime/pprof"
"strconv"
"time"

"github.com/spf13/cobra"
"github.com/tendermint/tendermint/node"
Expand All @@ -41,6 +42,8 @@ import (
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

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

"github.com/dymensionxyz/dymension-rdk/utils"
rdklogger "github.com/dymensionxyz/dymension-rdk/utils/logger"
dymintconf "github.com/dymensionxyz/dymint/config"
Expand Down Expand Up @@ -72,6 +75,11 @@ const (
FlagDisableIAVLFastNode = "iavl-disable-fastnode"
FlagIAVLLazyLoading = "iavl-lazy-loading"

// wasm max bytes flags
FlagMaxLabelSize = "max-label-size"
FlagMaxWasmSize = "max-wasm-size"
FlagMaxProposalWasmSize = "max-proposal-wasm-size"

// state sync-related flags
FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval"
FlagStateSyncSnapshotKeepRecent = "state-sync.snapshot-keep-recent"
Expand Down Expand Up @@ -194,6 +202,10 @@ which accepts a path for the resulting pprof file.
cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks")
cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks")

cmd.Flags().Int(FlagMaxLabelSize, 128, "Maximum wasm label size")
cmd.Flags().Int(FlagMaxWasmSize, 819200, "Maximum wasm size")
cmd.Flags().Int(FlagMaxProposalWasmSize, 3145728, "Maximum wasm proposal size")

cmd.Flags().Bool(FlagAPIEnable, false, "Define if the API server should be enabled")
cmd.Flags().Bool(FlagAPISwagger, false, "Define if swagger documentation should automatically be registered (Note: the API must also be enabled)")
cmd.Flags().String(FlagAPIAddress, serverconfig.DefaultAPIAddress, "the API server address to listen on")
Expand Down Expand Up @@ -231,6 +243,10 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, nodeConfig *d
}
defer db.Close()

wasmtypes.MaxLabelSize = ctx.Viper.GetInt(FlagMaxLabelSize)
wasmtypes.MaxWasmSize = ctx.Viper.GetInt(FlagMaxWasmSize)
wasmtypes.MaxProposalWasmSize = ctx.Viper.GetInt(FlagMaxProposalWasmSize)

traceWriterFile := ctx.Viper.GetString(flagTraceStore)
traceWriter, err := utils.OpenTraceWriter(traceWriterFile)
if err != nil {
Expand Down

0 comments on commit 73b3ceb

Please sign in to comment.