Skip to content

Commit

Permalink
some fixes on ibc (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikluke authored Aug 19, 2024
1 parent 6126768 commit 1620ea0
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 13 deletions.
154 changes: 154 additions & 0 deletions LOCAL_IBC_TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Build local image
```
make local-image
```

# Prepare networks

Change {index} to 0 or 1, depending it is 1st or 2nd node installation

0. Add chain-id param to init step in make file
```
$(V)$(SCORUMD) init --default-denom nscr local-network --chain-id scorum-{index}
```

1. Prepare fresh network genesis and config
```
make local-init
```

2. Rename test to test-local-{index}
```
mv test test-local-{index}
```

3. Start network
```
docker run -d --name test-local-{index} --rm -v ./test-local-{index}:/root/.scorum scorumd-local scorumd start --api.enable true --grpc.enable true --rpc.laddr 'tcp://0.0.0.0:26657' --grpc.address '0.0.0.0:9090'
```

4. Get container address by
```
docker network inspect bridge
```

5. Start container to interact with network
```
docker run --rm -it -v ./test-local-{index}:/root/.scorum scorumd-local /bin/sh
```

6. Create key and save mnemonic somewhere
```
scorumd keys add hermes --keyring-backend test
```

7. Mint gas to this address
```
scorumd tx scorum admin mint-gas --node 'tcp://{node-ip}:26657' --from test --keyring-backend test {hermes-key-address} 10000000000000000
```

Now we can consider network prepared


# Prepare hermes

1. Create config dir
```
mkdir test-hermes
```

2. Create hermes config file
```
nano test-hermes/config.toml
```

Put config and save it by ctrl+x.

*NOTE* Copy paste [[chains]] template. There are should be 2 [[chains]] blocks with id 'scorum-0' and 'scorum-1'
```
[global]
log_level = 'info'
[mode]
[mode.clients]
enabled = true
refresh = true
misbehaviour = true
[mode.connections]
enabled = true
[mode.channels]
enabled = true
[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = true
[telemetry]
enabled = true
host = '127.0.0.1'
port = 3001
[[chains]]
id = 'scorum-{index}'
type = "CosmosSdk"
rpc_addr = 'http://{node-ip}:26657'
grpc_addr = 'http://{node-ip}:9090'
event_source = { mode = 'push', url = 'ws://{node-ip}:26657/websocket', batch_delay = '200ms' }
rpc_timeout = '15s'
trusted_node = true
account_prefix = 'scorum'
key_name = 'hermes'
store_prefix = 'ibc'
gas_price = { price = 1, denom = 'gas' }
gas_multiplier = 1.2
default_gas = 1000000
max_gas = 10000000
max_msg_num = 30
max_tx_size = 2097152
clock_drift = '5s'
max_block_time = '30s'
trusting_period = '14days'
trust_threshold = { numerator = '2', denominator = '3' }
```

3. Start hermes container
```
docker run --rm -it -v ./test-hermes:/home/hermes/.hermes --entrypoint "/bin/bash" informalsystems/hermes:1.10.2
```

4. Add keys to hermes
```
echo "{mnemonic}" | hermes keys add --chain scorum-{index} --mnemonic-file /dev/stdin
```

5. Create channel
```
hermes create channel --a-chain scorum-0 --b-chain scorum-1 --a-port transfer --b-port transfer --new-client-connection
```

6. Start relaying
```
hermes start
```

# Test ibc
1. Run ibc transfer from *test-local-0* terminal
```
scorumd tx ibc-transfer transfer --node 'tcp://{node-ip}:26657' --from test --keyring-backend test transfer channel-0 scorum17sxdedhm47y5s9w55ng0nflyqn0w5ffxwz3cuq 1000nscr
```

2. Query balance on *test-local-1* terminal
```
scorumd --node 'tcp://{node-ip}:26657' query bank balances scorum17sxdedhm47y5s9w55ng0nflyqn0w5ffxwz3cuq
```

You must see something like
```
- amount: "1000"
denom: ibc/8529F970ED97E874805713A099E86A520D418AF2AC44335C7E1FED9D545C4020
```
24 changes: 13 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,17 @@ func New(
app.BankKeeper,
)

// create before wrappers
app.ScorumKeeper = scorumkeeper.NewKeeper(
appCodec,
keys[scorumtypes.StoreKey],
app.GetSubspace(scorumtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
)

// create keeper wrappers to mint gas
scorumWrapperAccountKeeper := scorumwrapper.NewAccountKeeper(app.AccountKeeper, app.BankKeeper, app.ScorumKeeper)
scorumWrapperBankKeeper := bankkeeper.NewBaseKeeper(
Expand Down Expand Up @@ -532,16 +543,6 @@ func New(
app.BankKeeper,
)

app.ScorumKeeper = scorumkeeper.NewKeeper(
appCodec,
keys[scorumtypes.StoreKey],
app.GetSubspace(scorumtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
)

app.AviatrixKeeper = aviatrixkeeper.NewKeeper(
appCodec,
keys[aviatrixtypes.StoreKey],
Expand Down Expand Up @@ -663,6 +664,7 @@ func New(
nftmodule.NewAppModule(appCodec, app.NftKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
ibc.NewAppModule(app.IBCKeeper),
ibctransfer.NewAppModule(app.IBCTransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
scorum.NewAppModule(appCodec, app.ScorumKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -1085,7 +1087,7 @@ func GetKeys() map[string]*storetypes.KVStoreKey {
paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey,
capabilitytypes.StoreKey, group.StoreKey, nft.StoreKey, consensusparamtypes.StoreKey,
// ibc
ibcexported.StoreKey, ibcfeetypes.StoreKey,
ibcexported.StoreKey, ibcfeetypes.StoreKey, ibctransfertypes.StoreKey,
icahosttypes.StoreKey, icacontrollertypes.StoreKey,
// scorum
scorumtypes.StoreKey, aviatrixtypes.StoreKey,
Expand Down
6 changes: 4 additions & 2 deletions x/scorum/wrapper/account_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ func NewAccountKeeper(ak accountkeeper.AccountKeeper, bk bankkeeper.Keeper, sk s

func (k AccountKeeper) SetAccount(ctx sdk.Context, acc types.AccountI) {
hasAccount := k.AccountKeeper.HasAccount(ctx, acc.GetAddress())
// must be set before minting to avoid recursion (BankKeeper calls SetAccount if it's not created yet)
k.AccountKeeper.SetAccount(ctx, acc)

if !hasAccount {
// must be set before minting to avoid recursion (BankKeeper calls SetAccount if it's not created yet)
k.AccountKeeper.SetAccount(ctx, acc)

if err := k.sk.Mint(ctx, acc.GetAddress(), sdk.NewCoin(scorumtypes.GasDenom, k.sk.GetParams(ctx).GasLimit.Int)); err != nil {
panic(fmt.Sprintf("failed to mint gas to new account: %s", err.Error()))
}
Expand Down

0 comments on commit 1620ea0

Please sign in to comment.