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

Feat/send inter tx #27

Merged
merged 10 commits into from
Mar 26, 2021
Merged

Feat/send inter tx #27

merged 10 commits into from
Mar 26, 2021

Conversation

seantking
Copy link
Contributor

@seantking seantking commented Mar 23, 2021

Description
Adding the send command to the inter-tx module. We should now have a basic flow for registering an account and sending tokens with the registered interchain account.

I also updated the register command to use flags for source port and source channel as well as some general cleanup.

I have removed timeouts as user input and hardcoded a max int64 timeout period. (This should probably be lowered to something like 4 weeks).

I added a command in the Makefile to clear previous data & spin up both test chains & relayer in one command for convenience.

init: kill-dev install 
	@echo "Initializing both blockchains..."
	./network/init.sh
	@echo "Initializing relayer..." 
	./network/relayer/interchain-acc-config/rly.sh

How to run

# These address are defined in init.sh for development purposes
VAL_1=cosmos1mjk79fjjgpplak5wq838w0yd982gzkyfrk07am
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

# Get the address of interchain account
icad query intertx ibcaccount $VAL_1 ibcaccount channel-0 --node tcp://localhost:16657
# Output -> address: cosmos1pt6ar8lawmvvq5haxc3l3zhjfl04u56fs2ndh9

IBC_ACCOUNT=cosmos1pt6ar8lawmvvq5haxc3l3zhjfl04u56fs2ndh9

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

# 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

# Test sending assets on intetchain 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

# Wait until the relayer has relayed the packet

# Check if the balance has been changed.
icad q bank balances $IBC_ACCOUNT --chain-id test-2
icad q bank balances $VAL_2 --chain-id test-2

@seantking seantking force-pushed the feat/send-inter-tx branch 2 times, most recently from 42a0f18 to d68d5c4 Compare March 23, 2021 23:51
@seantking seantking marked this pull request as ready for review March 24, 2021 05:32
Copy link
Contributor

@defihyung defihyung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @seantking! The testing environment is smooth.
I left some nitpick comments below.

In regards of comments, what do you think about documenting go code as godoc suggests?

The convention is simple: to document a type, variable, constant, function, or even a package, write a regular comment directly preceding its declaration, with no intervening blank line. Godoc will then present that comment as text alongside the item it documents.......

readme.md Outdated
# 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

# Test sending assets on intetchain account via ibc.
Copy link
Contributor

@defihyung defihyung Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

little typo in this comment. intetchain should be interchain. Other than that, it is all good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -30,20 +31,29 @@ func (k msgServer) Register(
// check if an account is already registered
_, err = k.GetIBCAccount(ctx, msg.SourcePort, msg.SourceChannel, acc)
if err == nil {
return &types.MsgRegisterAccountResponse{}, fmt.Errorf("Interchain account is already registered for this account")
err = fmt.Errorf("Interchain account is already registered for this account")
return &types.MsgRegisterAccountResponse{}, sdkerrors.Wrap(err, err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registering an IBC Account on chain test-2 with the same source-port and source-channel returns codespace undefined and code 1. How about handling this with sdkerrors.Wrap(types.ErrIAAccountNotExist, acc.String())?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, do you know what IA stand for? interchain account?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All errors need to be registered otherwise the error message gets wiped downstream. The first error cannot begin with 1 either. Usually these errors are registered in errors.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this thanks

rm -rf ./data
-@killall icad 2>/dev/null
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why switch the order? is there a chance that the process starts writing to that location again and you need to delete all over again?

Copy link
Contributor Author

@seantking seantking Mar 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this line was throwing an error if there were no icad processes running. I'm silencing the error now with the - and the 2>/dev/null but this is the reason.

readme.md Show resolved Hide resolved
@@ -16,24 +16,40 @@ https://github.com/cosmos/relayer.git
cd relayer
make install

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 10 has old repo name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

# Use relayer to link the chains
make start-rly
# Bootstrap two local chains & start the relayer with development data
make init
```

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Wait til you see the chains linked with the clients, connections and channels created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, although slightly differently. Good idea.


# Check if the balance has been changed.
icad q bank balances $IBC_ACCOUNT --chain-id test-2
icad q bank balances $VAL_2 --chain-id test-2
```

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TA DAAAAAA

@defihyung
Copy link
Contributor

Another feedback I had was to change the module name to github.com/cosmos/interchain-account since the repo is moved. This requires to update all proto files and imports inside both modules. It can be handled with another PR.

// TODO: Add timeout height and timestamp
timeoutHeight := clienttypes.Height{
RevisionNumber: 2,
RevisionHeight: ^uint64(0),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colin-axner did you say that I can set RevisionHeight to 0 to stop timeoutHeight from being used as a timeout? I was getting a relayer error when I did this.

I'm not sure what the best practice is here. @AdityaSripal maybe you have some thoughts also? 🙌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm updated

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Did a quick pass and will look over any files I missed later this week. Left mostly code convention suggestions

x/ibc-account/keeper/relay.go Outdated Show resolved Hide resolved
x/ibc-account/keeper/relay.go Outdated Show resolved Hide resolved
x/ibc-account/keeper/relay.go Show resolved Hide resolved
x/inter-tx/types/codec.go Outdated Show resolved Hide resolved
x/inter-tx/types/msgs.go Outdated Show resolved Hide resolved
x/inter-tx/types/msgs.go Outdated Show resolved Hide resolved
x/inter-tx/types/msgs.go Outdated Show resolved Hide resolved
proto/intertx/tx.proto Outdated Show resolved Hide resolved
@@ -30,20 +31,29 @@ func (k msgServer) Register(
// check if an account is already registered
_, err = k.GetIBCAccount(ctx, msg.SourcePort, msg.SourceChannel, acc)
if err == nil {
return &types.MsgRegisterAccountResponse{}, fmt.Errorf("Interchain account is already registered for this account")
err = fmt.Errorf("Interchain account is already registered for this account")
return &types.MsgRegisterAccountResponse{}, sdkerrors.Wrap(err, err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All errors need to be registered otherwise the error message gets wiped downstream. The first error cannot begin with 1 either. Usually these errors are registered in errors.go

proto/intertx/tx.proto Show resolved Hide resolved
@seantking
Copy link
Contributor Author

Great work @seantking! The testing environment is smooth.
I left some nitpick comments below.

In regards of comments, what do you think about documenting go code as godoc suggests?

The convention is simple: to document a type, variable, constant, function, or even a package, write a regular comment directly preceding its declaration, with no intervening blank line. Godoc will then present that comment as text alongside the item it documents.......

Good call re: Godoc. I have updated most of the functions in the inter-tx module to follow this standard. What do you think?

@seantking seantking force-pushed the feat/send-inter-tx branch from d342e1e to 2dd27d8 Compare March 25, 2021 16:37
@seantking seantking force-pushed the feat/send-inter-tx branch from 2dd27d8 to 1fdd98a Compare March 25, 2021 16:43
Copy link
Contributor

@defihyung defihyung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@seantking seantking merged commit 890f9dd into master Mar 26, 2021
@seantking seantking deleted the feat/send-inter-tx branch March 26, 2021 15:56
Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout approach here looks good to me 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants