Skip to content

Commit

Permalink
Support shielding transfers (#28)
Browse files Browse the repository at this point in the history
* gen-ibc-shielded

* MsgTimeout and MsgAcknowledgement

* add refund flag

* add shielded_sync

* scripts for IBC rate limit

* not to use memo for shielded transfers

* add namada-stargaze-transfer test script

* remove duplicated masp tx

* for Namada query change

* update Namada rev

* Namada 0.33.0
  • Loading branch information
yito88 committed Apr 12, 2024
1 parent 3e6b7a1 commit 31e4612
Show file tree
Hide file tree
Showing 12 changed files with 1,100 additions and 371 deletions.
787 changes: 524 additions & 263 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,19 @@ default-features = false

[dependencies.namada_ibc]
git = "https://github.com/anoma/namada"
tag = "v0.31.0"
version = "0.33.0"

[dependencies.namada_parameters]
git = "https://github.com/anoma/namada"
tag = "v0.31.0"
version = "0.33.0"

[dependencies.namada_sdk]
git = "https://github.com/anoma/namada"
tag = "v0.31.0"
features = ["std"]
version = "0.33.0"

[dependencies.namada_trans_token]
git = "https://github.com/anoma/namada"
tag = "v0.31.0"
version = "0.33.0"

[dev-dependencies]
ibc-relayer-types = { version = "0.27.0", path = "../relayer-types", features = ["mocks"] }
Expand Down
33 changes: 28 additions & 5 deletions crates/relayer/src/chain/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ use ibc_relayer_types::signer::Signer;
use ibc_relayer_types::Height as ICSHeight;
use namada_ibc::storage;
use namada_parameters::{storage as param_storage, EpochDuration};
use namada_sdk::address::{Address, InternalAddress};
use namada_sdk::borsh::BorshDeserialize;
use namada_sdk::io::NullIo;
use namada_sdk::masp::fs::FsShieldedUtils;
use namada_sdk::masp::ShieldedContext;
use namada_sdk::masp::DefaultLogger;
use namada_sdk::proof_of_stake::storage_key as pos_storage_key;
use namada_sdk::proof_of_stake::OwnedPosParams;
use namada_sdk::queries::Client as SdkClient;
use namada_sdk::state::ics23_specs::ibc_proof_specs;
use namada_sdk::state::Sha256Hasher;
use namada_sdk::types::address::{Address, InternalAddress};
use namada_sdk::types::storage::{Key, KeySeg, PrefixValue};
use namada_sdk::storage::{Key, KeySeg, PrefixValue};
use namada_sdk::wallet::Store;
use namada_sdk::wallet::Wallet;
use namada_sdk::{rpc, Namada, NamadaImpl};
Expand Down Expand Up @@ -166,6 +166,24 @@ impl NamadaChain {
.parse()
.unwrap())
}

async fn shielded_sync(&self) -> Result<(), Error> {
let mut shielded = self.ctx.shielded_mut().await;
let _ = shielded.load().await;
shielded
.fetch(
self.ctx.client(),
&DefaultLogger::new(self.ctx.io()),
None,
None,
1,
&[],
&[],
)
.await
.map_err(NamadaError::namada)?;
shielded.save().await.map_err(Error::io)
}
}

impl ChainEndpoint for NamadaChain {
Expand All @@ -181,7 +199,7 @@ impl ChainEndpoint for NamadaChain {
}

fn config(&self) -> ChainConfig {
ChainConfig::CosmosSdk(self.config.clone())
ChainConfig::Namada(self.config.clone())
}

fn bootstrap(config: ChainConfig, rt: Arc<TokioRuntime>) -> Result<Self, Error> {
Expand All @@ -202,7 +220,12 @@ impl ChainEndpoint for NamadaChain {
KeyRing::new_namada(config.key_store_type, &config.id, &config.key_store_folder)
.map_err(Error::key_base)?;

let shielded_ctx = ShieldedContext::<FsShieldedUtils>::default();
let shielded_dir = dirs_next::home_dir()
.expect("No home directory")
.join(".hermes/shielded")
.join(config.id.to_string());
std::fs::create_dir_all(&shielded_dir).map_err(Error::io)?;
let shielded_ctx = FsShieldedUtils::new(shielded_dir);

let mut store = Store::default();
let key = keybase
Expand Down
4 changes: 2 additions & 2 deletions crates/relayer/src/chain/namada/key.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::any::Any;

use namada_sdk::types::address::Address;
use namada_sdk::types::key::common::SecretKey;
use namada_sdk::address::Address;
use namada_sdk::key::common::SecretKey;

use crate::config::AddressType;
use crate::keyring::errors::Error;
Expand Down
10 changes: 5 additions & 5 deletions crates/relayer/src/chain/namada/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use ibc_relayer_types::core::ics23_commitment::merkle::convert_tm_to_ics_merkle_
use ibc_relayer_types::core::ics23_commitment::merkle::MerkleProof;
use ibc_relayer_types::events::IbcEvent;
use ibc_relayer_types::Height as ICSHeight;
use namada_ibc::storage::{ibc_denom_key_prefix, is_ibc_denom_key};
use namada_ibc::storage::{ibc_trace_key_prefix, is_ibc_trace_key};
use namada_sdk::address::{Address, InternalAddress};
use namada_sdk::borsh::BorshDeserialize;
use namada_sdk::queries::{Client as SdkClient, RPC};
use namada_sdk::rpc;
use namada_sdk::types::address::{Address, InternalAddress};
use namada_sdk::types::storage::{BlockHeight, Epoch, Key, PrefixValue};
use namada_sdk::storage::{BlockHeight, Epoch, Key, PrefixValue};
use namada_sdk::Namada;
use tendermint::block::Height as TmHeight;

Expand Down Expand Up @@ -275,12 +275,12 @@ impl NamadaChain {
_ => return Err(NamadaError::denom_not_found(raw_addr).into()),
};

let prefix = ibc_denom_key_prefix(None);
let prefix = ibc_trace_key_prefix(None);
let pairs = self.query_prefix(prefix)?;
let pair = pairs
.iter()
.find(|PrefixValue { key, value: _ }| {
if let Some((_, token_hash)) = is_ibc_denom_key(key) {
if let Some((_, token_hash)) = is_ibc_trace_key(key) {
token_hash == *hash
} else {
false
Expand Down
Loading

0 comments on commit 31e4612

Please sign in to comment.