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

Fixes to make hermes work with non-gaiad custom chains (e.g. starport) #753

Merged
merged 3 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

- [ibc-relayer]
- Replaced `rust-crypto` & `bitcoin-wallet` deprecated dependencies ([#352])
- Fix for hard-coded account number ([#752])
- Fix for chains that don't have `cosmos` account prefix ([#416])

- [ibc-relayer-cli]
- Hermes guide: improved installation guideline ([#672])
Expand All @@ -58,6 +60,7 @@
- [nothing yet]

[#352]: https://github.com/informalsystems/ibc-rs/issues/352
[#416]: https://github.com/informalsystems/ibc-rs/issues/416
[#561]: https://github.com/informalsystems/ibc-rs/issues/561
[#599]: https://github.com/informalsystems/ibc-rs/issues/599
[#630]: https://github.com/informalsystems/ibc-rs/issues/630
Expand All @@ -69,6 +72,7 @@
[#700]: https://github.com/informalsystems/ibc-rs/pull/700
[#702]: https://github.com/informalsystems/ibc-rs/issues/702
[#740]: https://github.com/informalsystems/ibc-rs/issues/740
[#752]: https://github.com/informalsystems/ibc-rs/issues/752

## v0.1.1
*February 17, 2021*
Expand Down
8 changes: 6 additions & 2 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ impl CosmosSdkChain {
let mut pk_buf = Vec::new();
prost::Message::encode(&key.public_key.public_key.to_bytes(), &mut pk_buf).unwrap();

crate::time!("PK {:?}", hex::encode(key.public_key.public_key.to_bytes()));

// Create a MsgSend proto Any message
let pk_any = Any {
type_url: "/cosmos.crypto.secp256k1.PubKey".to_string(),
Expand All @@ -181,7 +183,7 @@ impl CosmosSdkChain {
// Gas Fee
let coin = Coin {
denom: "stake".to_string(),
amount: "1000".to_string(),
amount: "10000".to_string(),
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 supposed to stay hardcoded forever or do we eventually want to make this configurable/dynamic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@romac I believe this should be dynamic, we can have a default value but should allow the value to be passed as a parameter, I had opened a separate issue for that #754

};

let fee = Some(Fee {
Expand All @@ -204,7 +206,7 @@ impl CosmosSdkChain {
body_bytes: body_buf.clone(),
auth_info_bytes: auth_buf.clone(),
chain_id: self.config.clone().id.to_string(),
account_number: 0,
account_number: acct_response.account_number,
};

// A protobuf serialization of a SignDoc
Expand All @@ -223,6 +225,8 @@ impl CosmosSdkChain {
let mut txraw_buf = Vec::new();
prost::Message::encode(&tx_raw, &mut txraw_buf).unwrap();

crate::time!("TxRAW {:?}", hex::encode(txraw_buf.clone()));

let response = self
.block_on(broadcast_tx_commit(self, txraw_buf))
.map_err(|e| Kind::Rpc(self.config.rpc_addr.clone()).context(e))?;
Expand Down
51 changes: 36 additions & 15 deletions relayer/src/keyring/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ pub enum StoreBackend {

pub trait KeyRingOperations: Sized {
fn init(backend: StoreBackend, chain_config: ChainConfig) -> Result<KeyRing, Error>;
fn key_from_seed_file(&self, key_file_content: &str) -> Result<KeyEntry, Error>;
fn key_from_mnemonic(&self, mnemonic_words: &str) -> Result<KeyEntry, Error>;
fn key_from_seed_file(
&self,
key_file_content: &str,
chain_config: &ChainConfig,
) -> Result<KeyEntry, Error>;
fn key_from_mnemonic(
&self,
mnemonic_words: &str,
chain_config: &ChainConfig,
) -> Result<KeyEntry, Error>;
fn get_key(&self) -> Result<KeyEntry, Error>;
fn add_key(&self, key_contents: &str) -> Result<(), Error>;
fn sign_msg(&self, msg: Vec<u8>) -> Vec<u8>;
Expand Down Expand Up @@ -97,7 +105,11 @@ impl KeyRingOperations for KeyRing {
}

/// Get key from seed file
fn key_from_seed_file(&self, key_file_content: &str) -> Result<KeyEntry, Error> {
fn key_from_seed_file(
&self,
key_file_content: &str,
chain_config: &ChainConfig,
) -> Result<KeyEntry, Error> {
let key_json: Value =
serde_json::from_str(key_file_content).map_err(|e| Kind::InvalidKey.context(e))?;

Expand All @@ -111,7 +123,7 @@ impl KeyRingOperations for KeyRing {
match mnemonic {
Some(v) => {
key = self
.key_from_mnemonic(v)
.key_from_mnemonic(v, chain_config)
.map_err(|e| Kind::InvalidMnemonic.context(e))?;
Ok(key)
}
Expand All @@ -127,7 +139,11 @@ impl KeyRingOperations for KeyRing {
}

/// Add a key entry in the store using a mnemonic.
fn key_from_mnemonic(&self, mnemonic_words: &str) -> Result<KeyEntry, Error> {
fn key_from_mnemonic(
&self,
mnemonic_words: &str,
chain_config: &ChainConfig,
) -> Result<KeyEntry, Error> {
let mnemonic = Mnemonic::from_phrase(mnemonic_words, Language::English)
.map_err(|e| Kind::InvalidMnemonic.context(e))?;
let seed = Seed::new(&mnemonic, "");
Expand All @@ -145,8 +161,12 @@ impl KeyRingOperations for KeyRing {
let address = get_address(public_key);

// Get Bech32 account
let account = bech32::encode("cosmos", address.to_base32(), Variant::Bech32)
.map_err(|e| Kind::Bech32Account.context(e))?;
let account = bech32::encode(
chain_config.account_prefix.as_str(),
address.to_base32(),
Variant::Bech32,
)
.map_err(|e| Kind::Bech32Account.context(e))?;

let key = KeyEntry {
public_key,
Expand All @@ -171,9 +191,10 @@ impl KeyRingOperations for KeyRing {
let key_content = store.get(chain_config.key_name.as_str());
match key_content {
Some(k) => {
let key_entry = self.key_from_seed_file(k).map_err(|_| {
Kind::KeyStoreOperation.context("failed to get key entry")
})?;
let key_entry =
self.key_from_seed_file(k, chain_config).map_err(|_| {
Kind::KeyStoreOperation.context("failed to get key entry")
})?;
Ok(key_entry)
}
None => Err(Kind::InvalidKey.into()),
Expand All @@ -200,11 +221,11 @@ impl KeyRingOperations for KeyRing {
let mut file_contents = String::new();
file.read_to_string(&mut file_contents)
.map_err(|_| Kind::KeyStoreOperation.context("cannot ready key file"))?;
let key_entry =
self.key_from_seed_file(file_contents.as_str())
.map_err(|_| {
Kind::KeyStoreOperation.context("error getting key from file")
})?;
let key_entry = self
.key_from_seed_file(file_contents.as_str(), chain_config)
.map_err(|_| {
Kind::KeyStoreOperation.context("error getting key from file")
})?;
Ok(key_entry)
} else {
Err(Kind::KeyStoreOperation
Expand Down
4 changes: 3 additions & 1 deletion relayer/src/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ pub fn add_key(opts: KeysAddOptions) -> Result<String, Error> {
.map_err(|_| Kind::KeyBase.context("error reading the key file"))?;

// Check if it's a valid Key seed file
let key_entry = chain.keybase().key_from_seed_file(&key_contents);
let key_entry = chain
.keybase()
.key_from_seed_file(&key_contents, chain.config());

match key_entry {
Ok(k) => {
Expand Down