Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Feat/new register runtx flows #52

Merged
merged 21 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ init: kill-dev install
@echo "Initializing relayer..."
./network/hermes/hermes-restore-key.sh
./network/hermes/hermes.sh
./network/hermes/start.sh

init-golang-rly: kill-dev install
@echo "Initializing both blockchains..."
Expand Down
12 changes: 3 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,9 @@ func New(
)
transferModule := transfer.NewAppModule(app.TransferKeeper)

app.ibcAccountKeeper = ibcaccountkeeper.NewKeeper(keys[ibcaccounttypes.MemStoreKey], appCodec, keys[ibcaccounttypes.StoreKey],
map[string]ibcaccounttypes.TxEncoder{
// register the tx encoder for cosmos-sdk
"cosmos-sdk": ibcaccountkeeper.SerializeCosmosTx(appCodec, interfaceRegistry),
}, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.ibcAccountKeeper = ibcaccountkeeper.NewKeeper(
keys[ibcaccounttypes.MemStoreKey], appCodec, keys[ibcaccounttypes.StoreKey],
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, scopedIbcAccountKeeper, app.Router(), app,
)
ibcAccountModule := ibcaccount.NewAppModule(app.ibcAccountKeeper)
Expand Down Expand Up @@ -620,10 +618,6 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
return paramsKeeper
}

func (app *App) OnAccountCreated(ctx sdk.Context, sourcePort, sourceChannel string, address sdk.AccAddress) {
app.interTxKeeper.OnAccountCreated(ctx, sourcePort, sourceChannel, address)
}

func (*App) OnTxSucceeded(ctx sdk.Context, sourcePort, sourceChannel string, txHash []byte, txBytes []byte) {
}

Expand Down
41 changes: 17 additions & 24 deletions network/hermes/config.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
[global]
log_level = 'info'
log_level = 'trace'
strategy = 'all'

[[chains]]
account_prefix = 'cosmos'
clock_drift = '5s'
fee_amount = 10
fee_denom = 'stake'
gas = 3000000
grpc_addr = 'http://127.0.0.1:8090'
id = 'test-1'
key_name = 'testkey'
rpc_addr = 'http://127.0.0.1:16657'
grpc_addr = 'http://127.0.0.1:8090'
websocket_addr = 'ws://127.0.0.1:16657/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
max_gas = 3000000
gas_price = { price = 0.001, denom = 'stake' }
clock_drift = '5s'
trusting_period = '14days'
websocket_addr = 'ws://127.0.0.1:16657/websocket'

[chains.trust_threshold]
denominator = '3'
numerator = '1'
trust_threshold = { numerator = '1', denominator = '3' }

[[chains]]
account_prefix = 'cosmos'
clock_drift = '5s'
fee_amount = 1000
fee_denom = 'stake'
gas = 3000000
grpc_addr = 'http://127.0.0.1:9090'
id = 'test-2'
key_name = 'testkey'
rpc_addr = 'http://127.0.0.1:26657'
grpc_addr = 'http://127.0.0.1:9090'
websocket_addr = 'ws://127.0.0.1:26657/websocket'
rpc_timeout = '10s'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
max_gas = 3000000
gas_price = { price = 0.001, denom = 'stake' }
clock_drift = '5s'
trusting_period = '14days'
websocket_addr = 'ws://127.0.0.1:26657/websocket'
trust_threshold = { numerator = '1', denominator = '3' }

[chains.trust_threshold]
denominator = '3'
numerator = '1'
9 changes: 9 additions & 0 deletions network/hermes/create-test-channel-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Start the hermes relayer in multi-paths mode
CONFIG_DIR=./network/hermes/config.toml
PORT_ID=ics27-1-0-cosmos1mjk79fjjgpplak5wq838w0yd982gzkyfrk07am
hermes -c ./network/hermes/config.toml tx raw chan-open-init test-1 test-2 connection-0 $PORT_ID ibcaccount -o ORDERED
hermes -c $CONFIG_DIR tx raw chan-open-try test-2 test-1 connection-0 ibcaccount $PORT_ID -s channel-1
hermes -c $CONFIG_DIR tx raw chan-open-ack test-1 test-2 connection-0 $PORT_ID ibcaccount -d channel-1 -s channel-1
hermes -c $CONFIG_DIR tx raw chan-open-confirm test-2 test-1 connection-0 ibcaccount $PORT_ID -d channel-1 -s channel-1
11 changes: 11 additions & 0 deletions network/hermes/create-test-channel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Start the hermes relayer in multi-paths mode
CONFIG_DIR=./network/hermes/config.toml
PORT_ID=ics27-1-0-cosmos1mjk79fjjgpplak5wq838w0yd982gzkyfrk07am
hermes -c ./network/hermes/config.toml tx raw chan-open-init test-1 test-2 connection-0 $PORT_ID ibcaccount -o ORDERED
hermes -c $CONFIG_DIR tx raw chan-open-try test-2 test-1 connection-0 ibcaccount $PORT_ID -s channel-0
hermes -c $CONFIG_DIR tx raw chan-open-ack test-1 test-2 connection-0 $PORT_ID ibcaccount -d channel-0 -s channel-0
hermes -c $CONFIG_DIR tx raw chan-open-confirm test-2 test-1 connection-0 ibcaccount $PORT_ID -d channel-0 -s channel-0


37 changes: 3 additions & 34 deletions network/hermes/hermes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,10 @@ set -e

CONFIG_DIR=./network/hermes/config.toml

### Configure clients
echo "Configuring clients..."
hermes -c $CONFIG_DIR tx raw create-client test-1 test-2
hermes -c $CONFIG_DIR tx raw create-client test-2 test-1

### Connection Handshake
### Configure the clients and connection
echo "Initiating connection handshake..."
# conn-init
hermes -c $CONFIG_DIR tx raw conn-init test-1 test-2 07-tendermint-0 07-tendermint-0
# conn-try
hermes -c $CONFIG_DIR tx raw conn-try test-2 test-1 07-tendermint-0 07-tendermint-0 -s connection-0
# conn-ack
hermes -c $CONFIG_DIR tx raw conn-ack test-1 test-2 07-tendermint-0 07-tendermint-0 -d connection-0 -s connection-0
# conn-confirm
hermes -c $CONFIG_DIR tx raw conn-confirm test-2 test-1 07-tendermint-0 07-tendermint-0 -d connection-0 -s connection-0
hermes -c $CONFIG_DIR create connection test-1 test-2

### Create an ics-27 ibcaccount channel
echo "Creating ics-27 ibcaccount channel..."
# chan-open-init
hermes -c $CONFIG_DIR tx raw chan-open-init test-1 test-2 connection-0 ibcaccount ibcaccount -o ORDERED
# chan-open-try
hermes -c $CONFIG_DIR tx raw chan-open-try test-2 test-1 connection-0 ibcaccount ibcaccount -s channel-0
# chan-open-ack
hermes -c $CONFIG_DIR tx raw chan-open-ack test-1 test-2 connection-0 ibcaccount ibcaccount -d channel-0 -s channel-0
# chan-open-confirm
hermes -c $CONFIG_DIR tx raw chan-open-confirm test-2 test-1 connection-0 ibcaccount ibcaccount -d channel-0 -s channel-0
sleep 2

### Create an ics-20 transfer channel
echo "Creating ics-20 transfer channel..."
# chan-open-init
hermes -c $CONFIG_DIR tx raw chan-open-init test-1 test-2 connection-0 transfer transfer -o UNORDERED
# chan-open-try
hermes -c $CONFIG_DIR tx raw chan-open-try test-2 test-1 connection-0 transfer transfer -s channel-1
# chan-open-ack
hermes -c $CONFIG_DIR tx raw chan-open-ack test-1 test-2 connection-0 transfer transfer -d channel-1 -s channel-1
# chan-open-confirm
hermes -c $CONFIG_DIR tx raw chan-open-confirm test-2 test-1 connection-0 transfer transfer -d channel-1 -s channel-1

4 changes: 2 additions & 2 deletions network/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ GRPCPORT_2=9090

echo "Starting $CHAINID_1 in $CHAIN_DIR..."
echo "Creating log file at $CHAIN_DIR/$CHAINID_1.log"
$BINARY start --home $CHAIN_DIR/$CHAINID_1 --pruning=nothing --grpc.address="0.0.0.0:$GRPCPORT_1" > $CHAIN_DIR/$CHAINID_1.log 2>&1 &
$BINARY start --log_level trace --log_format json --home $CHAIN_DIR/$CHAINID_1 --pruning=nothing --grpc.address="0.0.0.0:$GRPCPORT_1" > $CHAIN_DIR/$CHAINID_1.log 2>&1 &

echo "Starting $CHAINID_2 in $CHAIN_DIR..."
echo "Creating log file at $CHAIN_DIR/$CHAINID_2.log"
$BINARY start --home $CHAIN_DIR/$CHAINID_2 --pruning=nothing --grpc.address="0.0.0.0:$GRPCPORT_2" > $CHAIN_DIR/$CHAINID_2.log 2>&1 &
$BINARY start --log_level trace --log_format json --home $CHAIN_DIR/$CHAINID_2 --pruning=nothing --grpc.address="0.0.0.0:$GRPCPORT_2" > $CHAIN_DIR/$CHAINID_2.log 2>&1 &

5 changes: 1 addition & 4 deletions proto/ibc/account/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ message IBCAccount {
(gogoproto.embed) = true,
(gogoproto.moretags) = "yaml:\"base_account\""
];
string source_port = 2;
string source_channel = 3;
string destination_port = 4;
string destination_channel = 5;
string accountOwner = 2;
}
21 changes: 2 additions & 19 deletions proto/ibc/account/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ option go_package = "github.com/cosmos/interchain-accounts/x/ibc-account/types";
// Query defines the gRPC querier service.
service Query {
rpc IBCAccount(QueryIBCAccountRequest) returns (QueryIBCAccountResponse) {
option (google.api.http).get =
"/cosmos/ibc-account/v1beta1/ibc-account/{address}";
}

rpc IBCAccountFromData(QueryIBCAccountFromDataRequest)
returns (QueryIBCAccountResponse) {
option (google.api.http).get =
"/cosmos/ibc-account/v1beta1/ibc-account-from-data/{port}/{channel}/"
"{data}";
}
}

Expand All @@ -29,18 +20,10 @@ message QueryIBCAccountRequest {

// address is the address to query.
string address = 1;
}

message QueryIBCAccountFromDataRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string port = 1;
string channel = 2;
string data = 3;
string connection_id = 2;
}

message QueryIBCAccountResponse {
// account defines the account of the corresponding address.
ibc.account.IBCAccount account = 1;
string account_address = 1;
}
10 changes: 3 additions & 7 deletions proto/ibc/account/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ message IBCAccountPacketData {
Type type = 1;
bytes data = 2;
}

message IBCAccountPacketAcknowledgement {
Type type = 1;
string chainID = 2;
uint32 code = 3;
bytes data = 4;
string error = 5;

message AccountAddress {
string address = 1;
}
18 changes: 0 additions & 18 deletions proto/intertx/intertx.proto

This file was deleted.

9 changes: 3 additions & 6 deletions proto/intertx/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ message QueryIBCAccountFromAddressRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string port = 1;
string channel = 2;
bytes address = 3
bytes address = 1
[ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress"];
string connectionId = 2;
}

message QueryIBCAccountFromAddressResponse {
bytes address = 1
[ (gogoproto.casttype) =
"github.com/cosmos/cosmos-sdk/types.AccAddress"];
string address = 1;
}

27 changes: 7 additions & 20 deletions proto/intertx/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,20 @@ message MsgRegisterAccount {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// the port by which the packet will be sent
string source_port = 2 [(gogoproto.moretags) = "yaml:\"source_port\""];

// the channel by which the packet will be sent
string source_channel = 3 [(gogoproto.moretags) = "yaml:\"source_channel\""];

string owner=6;
string owner = 1;
string connectionId = 2;
}

message MsgRegisterAccountResponse {}

// MsgSend is used to send coins from an interchain account to another account on the same chain
message MsgSend {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// the port by which the packet will be sent
string chain_type = 1 [(gogoproto.moretags) = "yaml:\"chain_type\""];
string source_port = 2 [(gogoproto.moretags) = "yaml:\"source_port\""];

// the channel by which the packet will be sent
string source_channel = 3 [(gogoproto.moretags) = "yaml:\"source_channel\""];

bytes sender = 6 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
bytes to_address = 7 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
repeated cosmos.base.v1beta1.Coin amount = 8
string interchain_account = 1;
bytes owner = 2 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
string to_address = 3;
repeated cosmos.base.v1beta1.Coin amount = 4
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
string connectionId = 5;
}

// MsgSendResponse defines the Msg/Send response type.
Expand Down
26 changes: 15 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Interchain Accounts
This repo contains an ongoing refactor/update of https://github.com/chainapsis/cosmos-sdk-interchain-account which is based on the [ics-27 spec.](https://github.com/cosmos/ics/tree/master/spec/ics-027-interchain-accounts)

## Local Demo

### Setup
Expand All @@ -17,44 +15,50 @@ make install
- Install [Rust](https://www.rust-lang.org/tools/install)
- Install [Hermes](https://hermes.informal.systems/installation.html)

# Bootstrap two local chains & start the relayer with development data
# Bootstrap two local chains & create a connection using the hermes relayer
make init

# Wait for the ibc connection & channel handshake to complete and the relayer to start
```

### Send Asset Demo
### Demo

```bash
# Open a seperate terminal

# These address are defined in init.sh for development purposes
export VAL_1=cosmos1mjk79fjjgpplak5wq838w0yd982gzkyfrk07am
export VAL_2=cosmos17dtl0mjt3t77kpuhg2edqzjpszulwhgzuj9ljs

# Register an IBC Account on chain test-2
icad tx intertx register --from val1 --source-port ibcaccount --source-channel channel-0 --chain-id test-1 --gas 90000 --home ./data/test-1 --node tcp://localhost:16657 -y
icad tx intertx register --from val1 --connection-id connection-0 --chain-id test-1 --gas 150000 --home ./data/test-1 --node tcp://localhost:16657 -y

# Start the hermes relayer in the first terminal
# This will also finish the channel creation handshake signalled during the register step
make start-rly

# Get the address of interchain account
icad query intertx ibcaccount $VAL_1 ibcaccount channel-0 --node tcp://localhost:16657
# Output -> address: cosmos1pt6ar8lawmvvq5haxc3l3zhjfl04u56fs2ndh9
icad query ibcaccount address cosmos1mjk79fjjgpplak5wq838w0yd982gzkyfrk07am connection-0 --home ./data/test-2 --node tcp://localhost:26657
# Output -> account_address: cosmos1plyxrjdepap2zgqmfpzfchmklwqhchq5jrctm0

export IBC_ACCOUNT=cosmos1pt6ar8lawmvvq5haxc3l3zhjfl04u56fs2ndh9
export IBC_ACCOUNT=cosmos1plyxrjdepap2zgqmfpzfchmklwqhchq5jrctm0

# Check the interchain account's balance on test-2 chain. It should be empty.
icad q bank balances $IBC_ACCOUNT --chain-id test-2 --node tcp://localhost:26657

# Send some assets to $IBC_ACCOUNT.
icad tx bank send val2 $IBC_ACCOUNT 1000stake --chain-id test-2 --home ./data/test-2 --node tcp://localhost:26657 -y

# Check that the balance has been updated
icad q bank balances $IBC_ACCOUNT --chain-id test-2 --node tcp://localhost:26657

# Test sending assets from interchain account via ibc.
icad tx intertx send cosmos-sdk $VAL_2 500stake --source-port ibcaccount --source-channel channel-0 --chain-id test-1 --gas 90000 --home ./data/test-1 --node tcp://localhost:16657 --from val1 -y
icad tx intertx send cosmos1plyxrjdepap2zgqmfpzfchmklwqhchq5jrctm0 $VAL_2 500stake --connection-id conection-0 --chain-id test-1 --gas 90000 --home ./data/test-1 --node tcp://localhost:16657 --from val1 -y

# Wait until the relayer has relayed the packet

# Check if the balance has been changed.
# Check if the balance has been changed (it should now be 500stake)
icad q bank balances $IBC_ACCOUNT --chain-id test-2 --node tcp://localhost:26657
icad q bank balances $VAL_2 --chain-id test-2 --node tcp://localhost:26657
```

## Collaboration
Expand Down
Loading