Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented 'keys add' and 'keys list' commmands #408

Merged
merged 30 commits into from
Nov 24, 2020
Merged

Conversation

andynog
Copy link
Contributor

@andynog andynog commented Nov 19, 2020

Closes: #363

Description

This PR includes the implementation of the keys add and keys list commands on the relayer. Changes:

  • Removed all the -k parameter from the tx commands. So not key_seed.json file needs to be specified for a tx raw command
  • Refactored keybase logic to simplify methods, it has now the chain config so most parameters are used from the config
  • Implemented a keys add command. Basically this adds the key_seed.json file on a folder $HOME/.rrly. The file will be saved with the key_name parameter specified in the config (e.g. testkey.json).
  • The key file is stored un-encrypted for now. No integration at this time with an OS keyring that would safely store the file. Once the keyring logic is properly implemented then this file can be properly stored in a secure way. For now, the purpose is just to simplify the logic for the tx raw commands.
  • Added instructions on relayer-cli README.md file
  • Also implemented a keys list command that can be used to list the key configured for a chain

For contributor use:

  • Updated the Unreleased section of CHANGELOG.md with the issue.
  • If applicable: Unit tests written, added test to CI.
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments.
  • Re-reviewed Files changed in the Github PR explorer.

- Added a new test keyring backend to support adding keys to file system (under home folder)
- Refactored logic to add key to be part of the keystore and not the command
- Switched the keybase on a chain to use the test keyring
- Key seed file is saved in the test keystore default folder (/home/andy/.rrly)
- Clean up remaining key_seed flag for tx cmds
- Refactored keybase to include chain config
- Refactoring keyring methods to use chain config
- Logic to use configured key to sign tx
@andynog andynog added I: CLI Internal: related to the relayer's CLI I: logic Internal: related to the relaying logic labels Nov 19, 2020
@andynog andynog requested review from romac and ancazamfir November 19, 2020 22:34
@codecov-io
Copy link

codecov-io commented Nov 19, 2020

Codecov Report

Merging #408 (ac6e485) into master (b1b37f5) will increase coverage by 23.0%.
The diff coverage is 67.5%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #408      +/-   ##
=========================================
+ Coverage    13.6%   36.7%   +23.0%     
=========================================
  Files          69     154      +85     
  Lines        3752   11089    +7337     
  Branches     1374    4124    +2750     
=========================================
+ Hits          513    4072    +3559     
- Misses       2618    6360    +3742     
- Partials      621     657      +36     
Impacted Files Coverage Δ
modules/src/events.rs 0.0% <0.0%> (ø)
modules/src/ics02_client/events.rs 0.0% <ø> (ø)
modules/src/ics02_client/msgs.rs 0.0% <0.0%> (ø)
modules/src/ics02_client/raw.rs 0.0% <0.0%> (ø)
modules/src/ics03_connection/error.rs 13.6% <0.0%> (-19.7%) ⬇️
modules/src/ics04_channel/error.rs 75.0% <ø> (+50.0%) ⬆️
modules/src/ics04_channel/msgs/chan_open_try.rs 67.0% <ø> (ø)
modules/src/ics04_channel/msgs/recv_packet.rs 63.5% <ø> (ø)
modules/src/ics04_channel/msgs/timeout.rs 69.2% <ø> (ø)
modules/src/ics04_channel/packet.rs 70.4% <ø> (+70.4%) ⬆️
... and 282 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f71413...d3ed4da. Read the comment docs.

Copy link
Member

@romac romac left a comment

Choose a reason for hiding this comment

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

Looks good, aside from some minor remarks. Thanks :)

@@ -121,7 +121,7 @@ mod tests {
#[test]
fn parse_channel_query_end_parameters() {
let default_params = QueryChannelEndCmd {
chain_id: Some("ibc0".to_string().parse().unwrap()),
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't implement this as part of my issue, maybe something merged from master? Maybe @ancazamfir knows ?

@@ -3,12 +3,13 @@ timeout = '10s'
strategy = 'naive'

[[chains]]
id = 'ibc0'
id = 'ibc-0'
Copy link
Member

Choose a reason for hiding this comment

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

Is this change needed because the identifiers of the chains spawned by the Go relayer setup scripts have changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they changed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, i don't understand why this needs change. We are still on stargate-4. This change is coming in stargate-5.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want me to change this back to ibc0 ?

relayer/src/keyring/store.rs Outdated Show resolved Hide resolved
MemoryKeyStore { store: BTreeMap<Address, KeyEntry> },
MemoryKeyStore {
store: BTreeMap<String, String>,
chain_config: ChainConfig,
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to full chain config here? Can we instead just store the data that's actually needed from it (eg. the key 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.

Actually I had it before with key name and chain id but it made calling the functions more complex and thought that this way was cleaner and also if we need more params in the config here in the future this would make it simpler to implement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I couldn't find a good pattern here. Ideally this is used as a property of the chain (keybase) so if the config could be "passed down" into the keybase then this chain_config property would not be needed.

@andynog
Copy link
Contributor Author

andynog commented Nov 20, 2020

I noticed that with other PRs merged to master this PR got broken again, I will fix this one again so it can be merged

Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Found some issues while testing. I can only submit transactions on one chain (ibc0 of stargate-4/ gaia setup with Go relayer). For the other one the account is not recognized. Not sure why, will try to debug.
Also not sure why the protos had changed compared with master.

@@ -3,12 +3,13 @@ timeout = '10s'
strategy = 'naive'

[[chains]]
id = 'ibc0'
id = 'ibc-0'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, i don't understand why this needs change. We are still on stargate-4. This change is coming in stargate-5.

@andynog
Copy link
Contributor Author

andynog commented Nov 20, 2020

Found some issues while testing. I can only submit transactions on one chain (ibc0 of stargate-4/ gaia setup with Go relayer). For the other one the account is not recognized. Not sure why, will try to debug.
Also not sure why the protos had changed compared with master.

I've changed to ibc-0 because I was testing against the latest Go relayer release that now is on https://github.com/cosmos/relayer. For some reason their scripts to start two chains changed the chain-id to ibc-0. But if we are not using that to test then we can revert back to ibc0.

Concerning the transactions, please make sure you add the right key for each chain. So you should have a key_seed.json for each chain, after you add them you should see something like this under your $HOME/.rrly folder

$tree $HOME/.rrly
$HOME/.rrly/
└── keys
    ├── ibc-0
    │   └── keyring-test
    │       └── testkey.json
    └── ibc-1
        └── keyring-test
            └── testkey.json

But each testkey.json should have different contents. You can verify by doing:

relayer -c relayer-cli/tests/fixtures/two_chains.toml keys list ibc-0
keys list result:  "chain: ibc-0 -> testkey (cosmos1hkza0857rpkfl4uvwptv87he5t7f9g5v5yel7r)"
relayer -c ./relayer-cli/tests/fixtures/two_chains.toml keys list ibc-1
keys list result:  "chain: ibc-1 -> testkey (cosmos1hud8teqlrzw6zstnz3vf2qns547enm26ul22fw)"

which should display different addresses. Then the transactions should be signed with the key for the chain (right now there's no way to use more than one key per chain). If you have the right setup and still not working then might be a bug in the logic.

Concerning the proto changes, as far as I remember I didn't change them, might be changes once I've merged the latest master into this branch.

@ancazamfir
Copy link
Collaborator

Concerning the transactions, please make sure you add the right key for each chain. So you should have a key_seed.json for each chain, after you add them you should see something like this under your $HOME/.rrly folder

yes, I did that. All accounts and keys seem fine and I doubled checked they are the same as the ones from the Go relayer seed files. Does this work for you? Having both chains accepting transactions?

@ancazamfir
Copy link
Collaborator

I've changed to ibc-0 because I was testing against the latest Go relayer release that now is on https://github.com/cosmos/relayer. For some reason their scripts to start two chains changed the chain-id to ibc-0. But if we are not using that to test then we can revert back to ibc0.

Yes but for the latest (stargate-5) we need a number of changes in ibc-rs and tendermint-rs (I made changes for this on anca/stargate-5 on both). With current we cannot do proper client, connection and channel handshakes. IIRC only ConnOpenInit works.

@ancazamfir
Copy link
Collaborator

Concerning the transactions, please make sure you add the right key for each chain. So you should have a key_seed.json for each chain, after you add them you should see something like this under your $HOME/.rrly folder

yes, I did that. All accounts and keys seem fine and I doubled checked they are the same as the ones from the Go relayer seed files. Does this work for you? Having both chains accepting transactions?

I figured what went wrong. From previous testing I had some sections [[chains.peers.light_clients]] in the config file and for ibc1 one of the client peers was configured with the port of ibc0. This caused the transaction to be sent to ibc0. I will still have to investigate why, as the rpc address was correctly configured and the light clients are not currently started with the CLIs.
The good news is that your changes work, I tested almost all CLIs. The problem is that master is now broken after the upgrade to tokio 0.3 (compiles but CLIs are broken) so we should fix that before we merge your PR.

Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Looks great! All commands work without the key seed file option, which is great! Thanks a lot Andy, let's merge this today.

@romac romac merged commit a3303c3 into master Nov 24, 2020
@romac romac deleted the andy/add-key-cmd branch November 24, 2020 10:53
adizere pushed a commit that referenced this pull request Nov 27, 2020
* Added logic to generate GRPC client from cosmos.auth proto (#337)

* Adding logic to use GRPC client (#337)

* Grpc client connection retrieves account sequence (#337)

* Removed the account sequence flag from the tx raw commands (#337)

* Removed instructions to query and specify account sequence from tx raw command (#337)

* Logic to fetch GRPC endpoint address from config (#337)

* Fixing tests (#361)

* Logic to use the address from the key seed (#337)

* Added boilerplate code for a keys add command to the relayer (#363)

* Removing key flag from tx cmds

* Adding logic to get key specified in the config

* Logic to get the key specified in the config (#363)

* Removed the -k flag from the tx raw commands (#363)

* More logic to add key command (#363)

* key add command for memory store working (#363)

* Added logic to persist key seed in 'home' folder (#363)

* Changes implemented (#363):
- Added a new test keyring backend to support adding keys to file system (under home folder)
- Refactored logic to add key to be part of the keystore and not the command
- Switched the keybase on a chain to use the test keyring
- Key seed file is saved in the test keystore default folder (/home/andy/.rrly)

* Logic to use the key_name parameter from the config to add key. Removed name parameter from keys add cmd (#363)

* Changed the logic to get the key from the test keyring file store (#363)

* Implemented changes: (#363)
- Clean up remaining key_seed flag for tx cmds
- Refactored keybase to include chain config
- Refactoring keyring methods to use chain config
- Logic to use configured key to sign tx

* Updated the README instructions (#363)

* Disable the 'keys restore' command for now (#363)

* Added 'keys list' command to show key added on a chain (#363)

* Added entry for issue #363 (PR #408)

* Refactored the bound variables to use the full name per comment suggestion (#408)

* Move key retrieval, memo and timeout height inside send_tx

* Add the client creation, connection and channel handshake

* remove sleeps

* More error handling, cleanup

* Macro for channel CLIs

* Macro for connection CLIs

* Where src/dst make no sense rename to a/b, also fix a few bugs after last commits

* cleanup

* cargo fmt

* Use Romain's skip-verif until backwards verification is done

* fix CLI bugs

Co-authored-by: Andy Nogueira <me@andynogueira.dev>
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
* Added logic to generate GRPC client from cosmos.auth proto (#337)

* Adding logic to use GRPC client (#337)

* Grpc client connection retrieves account sequence (#337)

* Removed the account sequence flag from the tx raw commands (#337)

* Removed instructions to query and specify account sequence from tx raw command (#337)

* Logic to fetch GRPC endpoint address from config (#337)

* Fixing tests (informalsystems#361)

* Logic to use the address from the key seed (#337)

* Added boilerplate code for a keys add command to the relayer (informalsystems#363)

* Removing key flag from tx cmds

* Adding logic to get key specified in the config

* Logic to get the key specified in the config (informalsystems#363)

* Removed the -k flag from the tx raw commands (informalsystems#363)

* More logic to add key command (informalsystems#363)

* key add command for memory store working (informalsystems#363)

* Added logic to persist key seed in 'home' folder (informalsystems#363)

* Changes implemented (informalsystems#363):
- Added a new test keyring backend to support adding keys to file system (under home folder)
- Refactored logic to add key to be part of the keystore and not the command
- Switched the keybase on a chain to use the test keyring
- Key seed file is saved in the test keystore default folder (/home/andy/.rrly)

* Logic to use the key_name parameter from the config to add key. Removed name parameter from keys add cmd (informalsystems#363)

* Changed the logic to get the key from the test keyring file store (informalsystems#363)

* Implemented changes: (informalsystems#363)
- Clean up remaining key_seed flag for tx cmds
- Refactored keybase to include chain config
- Refactoring keyring methods to use chain config
- Logic to use configured key to sign tx

* Updated the README instructions (informalsystems#363)

* Disable the 'keys restore' command for now (informalsystems#363)

* Added 'keys list' command to show key added on a chain (informalsystems#363)

* Added entry for issue informalsystems#363 (PR informalsystems#408)

* Refactored the bound variables to use the full name per comment suggestion (informalsystems#408)

* Move key retrieval, memo and timeout height inside send_tx

Co-authored-by: Anca Zamfir <zamfiranca@gmail.com>
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
* Added logic to generate GRPC client from cosmos.auth proto (#337)

* Adding logic to use GRPC client (#337)

* Grpc client connection retrieves account sequence (#337)

* Removed the account sequence flag from the tx raw commands (#337)

* Removed instructions to query and specify account sequence from tx raw command (#337)

* Logic to fetch GRPC endpoint address from config (#337)

* Fixing tests (informalsystems#361)

* Logic to use the address from the key seed (#337)

* Added boilerplate code for a keys add command to the relayer (informalsystems#363)

* Removing key flag from tx cmds

* Adding logic to get key specified in the config

* Logic to get the key specified in the config (informalsystems#363)

* Removed the -k flag from the tx raw commands (informalsystems#363)

* More logic to add key command (informalsystems#363)

* key add command for memory store working (informalsystems#363)

* Added logic to persist key seed in 'home' folder (informalsystems#363)

* Changes implemented (informalsystems#363):
- Added a new test keyring backend to support adding keys to file system (under home folder)
- Refactored logic to add key to be part of the keystore and not the command
- Switched the keybase on a chain to use the test keyring
- Key seed file is saved in the test keystore default folder (/home/andy/.rrly)

* Logic to use the key_name parameter from the config to add key. Removed name parameter from keys add cmd (informalsystems#363)

* Changed the logic to get the key from the test keyring file store (informalsystems#363)

* Implemented changes: (informalsystems#363)
- Clean up remaining key_seed flag for tx cmds
- Refactored keybase to include chain config
- Refactoring keyring methods to use chain config
- Logic to use configured key to sign tx

* Updated the README instructions (informalsystems#363)

* Disable the 'keys restore' command for now (informalsystems#363)

* Added 'keys list' command to show key added on a chain (informalsystems#363)

* Added entry for issue informalsystems#363 (PR informalsystems#408)

* Refactored the bound variables to use the full name per comment suggestion (informalsystems#408)

* Move key retrieval, memo and timeout height inside send_tx

* Add the client creation, connection and channel handshake

* remove sleeps

* More error handling, cleanup

* Macro for channel CLIs

* Macro for connection CLIs

* Where src/dst make no sense rename to a/b, also fix a few bugs after last commits

* cleanup

* cargo fmt

* Use Romain's skip-verif until backwards verification is done

* fix CLI bugs

Co-authored-by: Andy Nogueira <me@andynogueira.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: CLI Internal: related to the relayer's CLI I: logic Internal: related to the relaying logic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command to add a key to a configured chain in the relayer
4 participants