Skip to content

Commit

Permalink
feat(genesis bridge): genesis transfers (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt authored Jun 25, 2024
1 parent dad400c commit f0e0909
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 274 deletions.
105 changes: 31 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It uses Cosmos-SDK's [simapp](https://github.com/cosmos/cosmos-sdk/tree/main/sim

## Overview

**Note**: Requires [Go 1.22.1](https://go.dev/dl/)
**Note**: Requires [Go 1.22.1](https://go.dev/dl/). Requires [Dasel](https://formulae.brew.sh/formula/dasel) and [JQ](https://formulae.brew.sh/formula/jq).

## Installing / Getting started

Expand All @@ -25,24 +25,35 @@ Build and install the ```rollapp-evm``` binary:
```shell
export BECH32_PREFIX=ethm
make install BECH32_PREFIX=$BECH32_PREFIX
export EXECUTABLE="rollapp-evm"
```

### Initial configuration

export the following variables:

```shell
export EXECUTABLE="rollapp-evm"
export BECH32_PREFIX="ethm"
export ROLLAPP_CHAIN_ID="rollappevm_1234-1"
export KEY_NAME_ROLLAPP="rol-user"
export BASE_DENOM="arax"
export DENOM=$(echo "$BASE_DENOM" | sed 's/^.//')
export MONIKER="$ROLLAPP_CHAIN_ID-sequencer"

export ROLLAPP_HOME_DIR="$HOME/.rollapp_evm"
export ROLLAPP_SETTLEMENT_INIT_DIR_PATH="${ROLLAPP_HOME_DIR}/init"
export SKIP_EVM_BASE_FEE=true # optional, removes fees on the rollapp
export SKIP_EVM_BASE_FEE=true # optional, disables rollapp fees

$EXECUTABLE config keyring-backend test

# (if running hub too)
export HUB_KEY_WITH_FUNDS="hub-user"
export HUB_RPC_ENDPOINT="localhost"
export HUB_RPC_PORT="36657" # default: 36657
export HUB_RPC_URL="http://${HUB_RPC_ENDPOINT}:${HUB_RPC_PORT}"
export HUB_CHAIN_ID="dymension_100-1"

dymd config chain-id "${HUB_CHAIN_ID}"
dymd config node "${HUB_RPC_URL}"
dymd config keyring-backend test
```

And initialize the rollapp:
Expand All @@ -54,33 +65,20 @@ sh scripts/init.sh
### Run rollapp

```shell
rollapp-evm start
$EXECUTABLE start
```

You should have a running local rollapp!

## Run a rollapp with a settlement node
## Run a settlement node too

### Run local dymension hub node

Follow the instructions on [Dymension Hub docs](https://docs.dymension.xyz/develop/get-started/run-base-layers) to run local dymension hub node

all scripts are adjusted to use local hub node that's hosted on the default port `localhost:36657`.

configuration with a remote hub node is also supported, the following variables must be set:

```shell
export HUB_RPC_ENDPOINT="localhost"
export HUB_RPC_PORT="36657" # default: 36657

export HUB_RPC_URL="http://${HUB_RPC_ENDPOINT}:${HUB_RPC_PORT}"
export HUB_CHAIN_ID="dymension_100-1"

dymd config chain-id ${HUB_CHAIN_ID}
dymd config node ${HUB_RPC_URL}

export HUB_KEY_WITH_FUNDS="hub-user" # This key should exist on the keyring-backend test
```
configuration with a remote hub node is also supported. Configure env vars above appropriately (RPC_URL)

### Create sequencer keys

Expand Down Expand Up @@ -144,20 +142,13 @@ sh scripts/settlement/register_sequencer_to_hub.sh

Modify `dymint.toml` in the chain directory (`~/.rollapp_evm/config`)

linux:

```shell
sed -i 's/settlement_layer.*/settlement_layer = "dymension"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml
sed -i '/node_address =/c\node_address = '\"$HUB_RPC_URL\" "${ROLLAPP_HOME_DIR}/config/dymint.toml"
sed -i '/rollapp_id =/c\rollapp_id = '\"$ROLLAPP_CHAIN_ID\" "${ROLLAPP_HOME_DIR}/config/dymint.toml"
```

mac:

```shell
sed -i '' 's/settlement_layer.*/settlement_layer = "dymension"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml
sed -i '' 's|node_address =.*|node_address = '\"$HUB_RPC_URL\"'|' "${ROLLAPP_HOME_DIR}/config/dymint.toml"
sed -i '' 's|rollapp_id =.*|rollapp_id = '\"$ROLLAPP_CHAIN_ID\"'|' "${ROLLAPP_HOME_DIR}/config/dymint.toml"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "settlement_layer" -v "dymension"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "node_address" -v "$HUB_RPC_URL"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "rollapp_id" -v "$ROLLAPP_CHAIN_ID"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "max_idle_time" -v "2s" # may want to change to something longer after setup (see below)
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "max_proof_time" -v "1s"
dasel put -f "${ROLLAPP_HOME_DIR}"/config/app.toml "minimum-gas-prices" -v "1arax"
```

### Update the Genesis file to include the denommetadata, genesis accounts, module account and elevated accounts
Expand All @@ -169,32 +160,18 @@ sh scripts/update_genesis_file.sh
Validate genesis file:

```shell
rollapp-evm validate-genesis
$EXECUTABLE validate-genesis
```

```shell
# this script automatically adds 2 vesting accounts, adjust the timestampts to your liking or skip this step
# this script automatically adds 2 vesting accounts, adjust the timestamps to your liking or skip this step
sh scripts/add_vesting_accounts_to_genesis_file.sh
```

### Change to 3s block time for ibc connection initialization

Linux:

```shell
sed -i 's/empty_blocks_max_time = "1h0m0s"/empty_blocks_max_time = "3s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml
```

Mac:

```shell
sed -i '' 's/empty_blocks_max_time = "1h0m0s"/empty_blocks_max_time = "3s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml
```

### Run rollapp locally

```shell
rollapp-evm start
$EXECUTABLE start --log_level=debug
```

## Setup IBC between rollapp and local dymension hub node
Expand Down Expand Up @@ -222,25 +199,19 @@ After successful run, the new established channels will be shown
Stop the rollapp:

```shell
kill $(pgrep rollapp-evm)
kill $(pgrep $EXECUTABLE)
```

Linux:

```shell
sed -i 's/empty_blocks_max_time = "3s"/empty_blocks_max_time = "3600s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml
```

Mac:

```shell
sed -i '' 's/empty_blocks_max_time = "3s"/empty_blocks_max_time = "3600s"/' ${ROLLAPP_HOME_DIR}/config/dymint.toml
dasel put -f "${ROLLAPP_HOME_DIR}"/config/dymint.toml "max_idle_time" -v "1h"
```

Start the rollapp:

```shell
rollapp-evm start
$EXECUTABLE start
```

### run the relayer
Expand All @@ -249,20 +220,6 @@ rollapp-evm start
rly start hub-rollapp
```

### Trigger genesis events

Trigger the genesis events on the rollapp

```shell
sh ./scripts/trigger_rollapp_genesis_event.sh
```

Trigger the genesis events on the hub

```shell
sh ./scripts/settlement/trigger_hub_genesis_event.sh
```

## Developers guide

For support, join our [Discord](http://discord.gg/dymension) community and find us in the Developer section.
Expand Down
2 changes: 2 additions & 0 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
sdkvestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
conntypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types"
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
cosmosante "github.com/evmos/evmos/v12/app/ante/cosmos"
evmante "github.com/evmos/evmos/v12/app/ante/evm"
Expand Down Expand Up @@ -43,6 +44,7 @@ func cosmosHandler(options HandlerOptions, sigChecker sdk.AnteDecorator) sdk.Ant
cosmosante.NewRejectMessagesDecorator(
[]string{
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&conntypes.MsgConnectionOpenInit{}), // don't let any connection open from the Rollapp side (it's still possible from the other side)
},
),
cosmosante.NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field
Expand Down
60 changes: 17 additions & 43 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ import (
distr "github.com/dymensionxyz/dymension-rdk/x/dist"
distrkeeper "github.com/dymensionxyz/dymension-rdk/x/dist/keeper"

"github.com/dymensionxyz/dymension-rdk/x/denommetadata"
denommetadatamodulekeeper "github.com/dymensionxyz/dymension-rdk/x/denommetadata/keeper"
denommetadatamoduletypes "github.com/dymensionxyz/dymension-rdk/x/denommetadata/types"
"github.com/evmos/evmos/v12/ethereum/eip712"
ethermint "github.com/evmos/evmos/v12/types"
"github.com/evmos/evmos/v12/x/claims"
Expand Down Expand Up @@ -167,7 +164,6 @@ var (
// evmos keys
erc20types.StoreKey,
claimstypes.StoreKey,
denommetadatamoduletypes.StoreKey,
}
)

Expand Down Expand Up @@ -222,24 +218,22 @@ var (
erc20.AppModuleBasic{},
transfer.AppModuleBasic{AppModuleBasic: &ibctransfer.AppModuleBasic{}},
claims.AppModuleBasic{},
denommetadata.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
authz.ModuleName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
erc20types.ModuleName: {authtypes.Minter, authtypes.Burner},
claimstypes.ModuleName: nil,
hubgentypes.ModuleName: {authtypes.Burner},
denommetadatamoduletypes.ModuleName: nil,
authtypes.FeeCollectorName: nil,
authz.ModuleName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
erc20types.ModuleName: {authtypes.Minter, authtypes.Burner},
claimstypes.ModuleName: nil,
hubgentypes.ModuleName: {authtypes.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -315,8 +309,6 @@ type App struct {
Erc20Keeper erc20keeper.Keeper
ClaimsKeeper *claimskeeper.Keeper

DenomMetadataKeeper denommetadatamodulekeeper.Keeper

// mm is the module manager
mm *module.Manager

Expand Down Expand Up @@ -541,10 +533,6 @@ func NewRollapp(
),
)

denomMetadataHooks := denommetadatamoduletypes.NewMultiDenommetadataHooks(
erc20keeper.NewERC20ContractRegistrationHook(app.Erc20Keeper),
)

app.TransferKeeper = transferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.ClaimsKeeper, // ICS4 Wrapper: claims IBC middleware
Expand All @@ -553,21 +541,10 @@ func NewRollapp(
app.Erc20Keeper, // Add ERC20 Keeper for ERC20 transfers
)

app.DenomMetadataKeeper = denommetadatamodulekeeper.NewKeeper(
appCodec,
keys[denommetadatamoduletypes.StoreKey],
app.BankKeeper,
app.TransferKeeper,
denomMetadataHooks,
app.GetSubspace(denommetadatamoduletypes.ModuleName),
)

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

Expand Down Expand Up @@ -615,7 +592,7 @@ func NewRollapp(
params.NewAppModule(app.ParamsKeeper),
ibc.NewAppModule(app.IBCKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
hubgenesis.NewAppModule(appCodec, app.HubGenesisKeeper, app.AccountKeeper),
hubgenesis.NewAppModule(appCodec, app.HubGenesisKeeper),

// Ethermint app modules
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)),
Expand All @@ -624,7 +601,6 @@ func NewRollapp(
transferModule,
erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper, app.GetSubspace(erc20types.ModuleName)),
claims.NewAppModule(appCodec, *app.ClaimsKeeper, app.GetSubspace(claimstypes.ModuleName)),
denommetadata.NewAppModule(app.DenomMetadataKeeper, app.BankKeeper),
}

app.mm = module.NewManager(modules...)
Expand Down Expand Up @@ -657,7 +633,6 @@ func NewRollapp(
epochstypes.ModuleName,
paramstypes.ModuleName,
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
}
app.mm.SetOrderBeginBlockers(beginBlockersList...)

Expand All @@ -684,7 +659,6 @@ func NewRollapp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
}
app.mm.SetOrderEndBlockers(endBlockersList...)

Expand Down Expand Up @@ -718,7 +692,6 @@ func NewRollapp(
ibctransfertypes.ModuleName,
feegrant.ModuleName,
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
}
app.mm.SetOrderInitGenesis(initGenesisList...)

Expand Down Expand Up @@ -761,13 +734,15 @@ func NewRollapp(
encodingConfig.TxConfig,
maxGasWanted,
func(ctx sdk.Context, accAddr sdk.AccAddress, perm string) bool {
return true
/*
TODO:
We had a plan to use the sequencers module to manager permissions, but that idea was changed
For now, we just assume the only account with permission is the denom one
We will eventually replace with something more substantial
TODO:
The denom one was ripped out https://github.com/dymensionxyz/dymension-rdk/pull/433/files#diff-2caeed9462180cba822eeaff485f2bb87c9c9464040fb65f0f5dcac66fb0e18fL58-L67
*/
return app.DenomMetadataKeeper.IsAddressPermissioned(ctx, accAddr.String())
},
app.AccountKeeper,
app.StakingKeeper,
Expand Down Expand Up @@ -992,7 +967,7 @@ func (app *App) GetStakingKeeper() ibctestingtypes.StakingKeeper {
return app.StakingKeeper
}

// GetStakingKeeper implements the TestingApp interface.
// GetStakingKeeperSDK implements the TestingApp interface.
func (app *App) GetStakingKeeperSDK() stakingkeeper.Keeper {
return app.StakingKeeper
}
Expand Down Expand Up @@ -1055,7 +1030,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// evmos subspaces
paramsKeeper.Subspace(erc20types.ModuleName)
paramsKeeper.Subspace(claimstypes.ModuleName)
paramsKeeper.Subspace(denommetadatamoduletypes.ModuleName)

return paramsKeeper
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rollappd/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, nodeConfig *d
grpcAddress := fmt.Sprintf("127.0.0.1:%s", port)

// If grpc is enabled, configure grpc client for grpc gateway.
grpcClient, err := grpc.Dial(
grpcClient, err := grpc.NewClient(
grpcAddress,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(
Expand Down
Loading

0 comments on commit f0e0909

Please sign in to comment.