diff --git a/.changelog/unreleased/improvements/1168-pbkdf-iterations.md b/.changelog/unreleased/improvements/1168-pbkdf-iterations.md new file mode 100644 index 0000000000..417e0f8af8 --- /dev/null +++ b/.changelog/unreleased/improvements/1168-pbkdf-iterations.md @@ -0,0 +1,2 @@ +- Wallet: Increase the number of iterations used for keys encryption to the + recommended value. ([#1168](https://github.com/anoma/anoma/issues/1168)) \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index eb732583ef..187901f491 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,10 +92,10 @@ dependencies = [ "ferveo-common", "group-threshold-cryptography", "hex", - "ibc 0.12.0 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5)", - "ibc 0.12.0 (git+https://github.com/heliaxdev/ibc-rs?rev=30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc)", - "ibc-proto 0.16.0 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5)", - "ibc-proto 0.16.0 (git+https://github.com/heliaxdev/ibc-rs?rev=30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc)", + "ibc 0.14.0 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_abcipp_rebase_master)", + "ibc 0.14.0 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5)", + "ibc-proto 0.17.1 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_abcipp_rebase_master)", + "ibc-proto 0.17.1 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5)", "ics23", "itertools 0.10.3", "loupe", @@ -2847,13 +2847,13 @@ dependencies = [ [[package]] name = "ibc" -version = "0.12.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.14.0" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_abcipp_rebase_master#646a80823dd073e86edb7e9f98fc00787f7530e3" dependencies = [ "bytes 1.1.0", "derive_more", "flex-error", - "ibc-proto 0.16.0 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5)", + "ibc-proto 0.17.1 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_abcipp_rebase_master)", "ics23", "num-traits 0.2.15", "prost 0.9.0", @@ -2864,23 +2864,23 @@ dependencies = [ "serde_json", "sha2 0.10.2", "subtle-encoding", - "tendermint 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", - "tendermint-light-client-verifier 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", - "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", - "tendermint-testgen 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", + "tendermint 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", + "tendermint-light-client-verifier 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", + "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", + "tendermint-testgen 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", "time 0.3.9", "tracing 0.1.35", ] [[package]] name = "ibc" -version = "0.12.0" -source = "git+https://github.com/heliaxdev/ibc-rs?rev=30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc#30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc" +version = "0.14.0" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ "bytes 1.1.0", "derive_more", "flex-error", - "ibc-proto 0.16.0 (git+https://github.com/heliaxdev/ibc-rs?rev=30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc)", + "ibc-proto 0.17.1 (git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5)", "ics23", "num-traits 0.2.15", "prost 0.9.0", @@ -2891,45 +2891,45 @@ dependencies = [ "serde_json", "sha2 0.10.2", "subtle-encoding", - "tendermint 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", - "tendermint-light-client-verifier 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", - "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", - "tendermint-testgen 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", + "tendermint 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", + "tendermint-light-client-verifier 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", + "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", + "tendermint-testgen 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", "time 0.3.9", "tracing 0.1.35", ] [[package]] name = "ibc-proto" -version = "0.16.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.17.1" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_abcipp_rebase_master#646a80823dd073e86edb7e9f98fc00787f7530e3" dependencies = [ + "base64 0.13.0", "bytes 1.1.0", "prost 0.9.0", "prost-types 0.9.0", "serde 1.0.137", - "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", - "tonic", + "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", ] [[package]] name = "ibc-proto" -version = "0.16.0" -source = "git+https://github.com/heliaxdev/ibc-rs?rev=30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc#30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc" +version = "0.17.1" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ + "base64 0.13.0", "bytes 1.1.0", "prost 0.9.0", "prost-types 0.9.0", "serde 1.0.137", - "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?rev=95c52476bc37927218374f94ac8e2a19bd35bec9)", - "tonic", + "tendermint-proto 0.23.5 (git+https://github.com/heliaxdev/tendermint-rs?branch=yuji/rebase_v0.23.5)", ] [[package]] name = "ics23" -version = "0.6.7" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce15e4758c46a0453bdf4b3b1dfcce70c43f79d1943c2ee0635b77eb2e7aa233" +checksum = "9d454cc0a22bd556cc3d3c69f9d75a392a36244634840697a4b9eb81bc5c8ae0" dependencies = [ "anyhow", "bytes 1.1.0", @@ -6206,7 +6206,7 @@ checksum = "35391ea974fa5ee869cb094d5b437688fbf3d8127d64d1b9fed5822a1ed39b12" [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/prost-0.9#be4b2293558361df2f452c60a3e90c6b5e52e225" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/ics23_0.7#b0ca0dc2fbb46b0e38da4b1eaf70b5ef27538554" dependencies = [ "blake2b-rs", "borsh", diff --git a/apps/Cargo.toml b/apps/Cargo.toml index 1ed0366a7d..fce5e195b8 100644 --- a/apps/Cargo.toml +++ b/apps/Cargo.toml @@ -118,7 +118,7 @@ serde_json = {version = "1.0.62", features = ["raw_value"]} serde_regex = "1.1.0" sha2 = "0.9.3" signal-hook = "0.3.9" -sparse-merkle-tree = {git = "https://github.com/heliaxdev/sparse-merkle-tree", branch = "yuji/prost-0.9", features = ["borsh"]} +sparse-merkle-tree = {git = "https://github.com/heliaxdev/sparse-merkle-tree", branch = "yuji/ics23_0.7", features = ["borsh"]} # sysinfo with disabled multithread feature sysinfo = {version = "=0.21.1", default-features = false} tar = "0.4.37" @@ -140,7 +140,7 @@ tower = "0.4" # with a patch for https://github.com/penumbra-zone/tower-abci/issues/7. tower-abci = {git = "https://github.com/heliaxdev/tower-abci", rev = "f6463388fc319b6e210503b43b3aecf6faf6b200", optional = true} tower-abci-old = {package = "tower-abci", git = "https://github.com/heliaxdev/tower-abci", branch = "yuji/rebase_v0.23.5_tracing", optional = true} -tracing = "0.1.30" +tracing = "0.1.34" tracing-log = "0.1.2" tracing-subscriber = {version = "0.3.7", features = ["env-filter"]} websocket = "0.26.2" diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index d131c4c230..d2731ac0c0 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -1469,6 +1469,7 @@ pub mod args { const SOURCE: Arg = arg("source"); const SOURCE_OPT: ArgOpt = SOURCE.opt(); const STORAGE_KEY: Arg = arg("storage-key"); + const SUB_PREFIX: ArgOpt = arg_opt("sub-prefix"); const TARGET: Arg = arg("target"); const TO_STDOUT: ArgFlag = flag("stdout"); const TOKEN_OPT: ArgOpt = TOKEN.opt(); @@ -1614,6 +1615,8 @@ pub mod args { pub target: WalletAddress, /// Transferred token address pub token: WalletAddress, + /// Transferred token sub prefix + pub sub_prefix: Option, /// Transferred token amount pub amount: token::Amount, } @@ -1624,12 +1627,14 @@ pub mod args { let source = SOURCE.parse(matches); let target = TARGET.parse(matches); let token = TOKEN.parse(matches); + let sub_prefix = SUB_PREFIX.parse(matches); let amount = AMOUNT.parse(matches); Self { tx, source, target, token, + sub_prefix, amount, } } @@ -1642,6 +1647,7 @@ pub mod args { )) .arg(TARGET.def().about("The target account address.")) .arg(TOKEN.def().about("The transfer token.")) + .arg(SUB_PREFIX.def().about("The token's sub prefix.")) .arg(AMOUNT.def().about("The amount to transfer in decimal.")) } } @@ -2182,6 +2188,8 @@ pub mod args { pub owner: Option, /// Address of a token pub token: Option, + /// Sub prefix of an account + pub sub_prefix: Option, } impl Args for QueryBalance { @@ -2189,10 +2197,12 @@ pub mod args { let query = Query::parse(matches); let owner = OWNER.parse(matches); let token = TOKEN_OPT.parse(matches); + let sub_prefix = SUB_PREFIX.parse(matches); Self { query, owner, token, + sub_prefix, } } @@ -2208,6 +2218,11 @@ pub mod args { .def() .about("The token's address whose balance to query."), ) + .arg( + SUB_PREFIX.def().about( + "The token's sub prefix whose balance to query.", + ), + ) } } diff --git a/apps/src/lib/client/rpc.rs b/apps/src/lib/client/rpc.rs index d85ff0b7c0..322860bee6 100644 --- a/apps/src/lib/client/rpc.rs +++ b/apps/src/lib/client/rpc.rs @@ -22,7 +22,7 @@ use anoma::types::governance::{ OfflineProposal, OfflineVote, ProposalVote, TallyResult, }; use anoma::types::key::*; -use anoma::types::storage::{Epoch, PrefixValue}; +use anoma::types::storage::{Epoch, Key, KeySeg, PrefixValue}; use anoma::types::token::{balance_key, Amount}; use anoma::types::{address, storage, token}; use async_std::fs::{self}; @@ -118,15 +118,29 @@ pub async fn query_balance(ctx: Context, args: args::QueryBalance) { (Some(token), Some(owner)) => { let token = ctx.get(&token); let owner = ctx.get(&owner); - let key = token::balance_key(&token, &owner); + let key = match &args.sub_prefix { + Some(sub_prefix) => { + let sub_prefix = Key::parse(sub_prefix).unwrap(); + let prefix = + token::multitoken_balance_prefix(&token, &sub_prefix); + token::multitoken_balance_key(&prefix, &owner) + } + None => token::balance_key(&token, &owner), + }; let currency_code = tokens .get(&token) .map(|c| Cow::Borrowed(*c)) .unwrap_or_else(|| Cow::Owned(token.to_string())); match query_storage_value::(&client, &key).await { - Some(balance) => { - println!("{}: {}", currency_code, balance); - } + Some(balance) => match &args.sub_prefix { + Some(sub_prefix) => { + println!( + "{} with {}: {}", + currency_code, sub_prefix, balance + ); + } + None => println!("{}: {}", currency_code, balance), + }, None => { println!("No {} balance found for {}", currency_code, owner) } @@ -136,12 +150,44 @@ pub async fn query_balance(ctx: Context, args: args::QueryBalance) { let owner = ctx.get(&owner); let mut found_any = false; for (token, currency_code) in tokens { - let key = token::balance_key(&token, &owner); - if let Some(balance) = - query_storage_value::(&client, &key).await - { - println!("{}: {}", currency_code, balance); - found_any = true; + let prefix = token.to_db_key().into(); + let balances = query_storage_prefix::( + client.clone(), + prefix, + ) + .await; + if let Some(balances) = balances { + let stdout = io::stdout(); + let mut w = stdout.lock(); + for (key, balance) in balances { + match token::is_any_multitoken_balance_key(&key) { + Some((sub_prefix, o)) if *o == owner => { + writeln!( + w, + "{} with {}: {}", + currency_code, sub_prefix, balance + ) + .unwrap(); + found_any = true; + } + Some(_) => {} + None => { + if let Some(o) = + token::is_any_token_balance_key(&key) + { + if *o == owner { + writeln!( + w, + "{}: {}", + currency_code, balance + ) + .unwrap(); + found_any = true; + } + } + } + } + } } } if !found_any { @@ -150,9 +196,9 @@ pub async fn query_balance(ctx: Context, args: args::QueryBalance) { } (Some(token), None) => { let token = ctx.get(&token); - let key = token::balance_prefix(&token); + let prefix = token.to_db_key().into(); let balances = - query_storage_prefix::(client, key).await; + query_storage_prefix::(client, prefix).await; match balances { Some(balances) => { let currency_code = tokens @@ -161,12 +207,30 @@ pub async fn query_balance(ctx: Context, args: args::QueryBalance) { .unwrap_or_else(|| Cow::Owned(token.to_string())); let stdout = io::stdout(); let mut w = stdout.lock(); - writeln!(w, "Token {}:", currency_code).unwrap(); + writeln!(w, "Token {}", currency_code).unwrap(); for (key, balance) in balances { - let owner = - token::is_any_token_balance_key(&key).unwrap(); - writeln!(w, " {}, owned by {}", balance, owner) - .unwrap(); + match token::is_any_multitoken_balance_key(&key) { + Some((sub_prefix, owner)) => { + writeln!( + w, + " with {}: {}, owned by {}", + sub_prefix, balance, owner + ) + .unwrap(); + } + None => { + if let Some(owner) = + token::is_any_token_balance_key(&key) + { + writeln!( + w, + ": {}, owned by {}", + balance, owner + ) + .unwrap(); + } + } + } } } None => { @@ -184,12 +248,30 @@ pub async fn query_balance(ctx: Context, args: args::QueryBalance) { .await; match balances { Some(balances) => { - writeln!(w, "Token {}:", currency_code).unwrap(); + writeln!(w, "Token {}", currency_code).unwrap(); for (key, balance) in balances { - let owner = - token::is_any_token_balance_key(&key).unwrap(); - writeln!(w, " {}, owned by {}", balance, owner) - .unwrap(); + match token::is_any_multitoken_balance_key(&key) { + Some((sub_prefix, owner)) => { + writeln!( + w, + " with {}: {}, owned by {}", + sub_prefix, balance, owner + ) + .unwrap(); + } + None => { + if let Some(owner) = + token::is_any_token_balance_key(&key) + { + writeln!( + w, + ": {}, owned by {}", + balance, owner + ) + .unwrap() + } + } + } } } None => { diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index 0bc8b72954..354c505ccd 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -11,7 +11,7 @@ use anoma::types::governance::{ }; use anoma::types::key::*; use anoma::types::nft::{self, Nft, NftToken}; -use anoma::types::storage::Epoch; +use anoma::types::storage::{Epoch, Key}; use anoma::types::token::Amount; use anoma::types::transaction::governance::{ InitProposalData, VoteProposalData, @@ -403,7 +403,17 @@ pub async fn submit_transfer(ctx: Context, args: args::TxTransfer) { } } // Check source balance - let balance_key = token::balance_key(&token, &source); + let (sub_prefix, balance_key) = match args.sub_prefix { + Some(sub_prefix) => { + let sub_prefix = Key::parse(sub_prefix).unwrap(); + let prefix = token::multitoken_balance_prefix(&token, &sub_prefix); + ( + Some(sub_prefix), + token::multitoken_balance_key(&prefix, &source), + ) + } + None => (None, token::balance_key(&token, &source)), + }; let client = HttpClient::new(args.tx.ledger_address.clone()).unwrap(); match rpc::query_storage_value::(&client, &balance_key).await { @@ -435,6 +445,7 @@ pub async fn submit_transfer(ctx: Context, args: args::TxTransfer) { source, target, token, + sub_prefix, amount: args.amount, }; tracing::debug!("Transfer data {:?}", transfer); diff --git a/apps/src/lib/node/ledger/protocol/mod.rs b/apps/src/lib/node/ledger/protocol/mod.rs index 28e27a454c..7c71c19190 100644 --- a/apps/src/lib/node/ledger/protocol/mod.rs +++ b/apps/src/lib/node/ledger/protocol/mod.rs @@ -333,7 +333,8 @@ where gas_meter = treasury.ctx.gas_meter.into_inner(); result } - InternalAddress::IbcEscrow(_) + InternalAddress::IbcToken(_) + | InternalAddress::IbcEscrow | InternalAddress::IbcBurn | InternalAddress::IbcMint => { // validate the transfer diff --git a/apps/src/lib/wallet/keys.rs b/apps/src/lib/wallet/keys.rs index 5041d88382..1bb207a00a 100644 --- a/apps/src/lib/wallet/keys.rs +++ b/apps/src/lib/wallet/keys.rs @@ -235,6 +235,6 @@ fn encryption_salt() -> kdf::Salt { /// Make encryption secret key from a password. fn encryption_key(salt: &kdf::Salt, password: String) -> kdf::SecretKey { kdf::Password::from_slice(password.as_bytes()) - .and_then(|password| kdf::derive_key(&password, salt, 3, 1 << 16, 32)) + .and_then(|password| kdf::derive_key(&password, salt, 3, 1 << 17, 32)) .expect("Generation of encryption secret key shouldn't fail") } diff --git a/matchmaker/mm_token_exch/src/lib.rs b/matchmaker/mm_token_exch/src/lib.rs index d7005a7d5b..183311f2a3 100644 --- a/matchmaker/mm_token_exch/src/lib.rs +++ b/matchmaker/mm_token_exch/src/lib.rs @@ -361,6 +361,7 @@ fn create_transfer( source: from_node.exchange.data.addr.clone(), target: to_node.exchange.data.addr.clone(), token: to_node.exchange.data.token_buy.clone(), + sub_prefix: None, amount, } } diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 797a73061b..2065d9bcba 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -79,11 +79,11 @@ ferveo-common = {git = "https://github.com/anoma/ferveo"} hex = "0.4.3" tpke = {package = "group-threshold-cryptography", optional = true, git = "https://github.com/anoma/ferveo"} # TODO using the same version of tendermint-rs as we do here. -ibc = {git = "https://github.com/heliaxdev/ibc-rs", rev = "30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc", default-features = false, optional = true} -ibc-abci = {package = "ibc", git = "https://github.com/heliaxdev/ibc-rs", branch = "yuji/v0.12.0_tm_v0.23.5", default-features = false, optional = true} -ibc-proto = {git = "https://github.com/heliaxdev/ibc-rs", rev = "30b3495ac56c6c37c99bc69ef9f2e84c3309c6cc", default-features = false, optional = true} -ibc-proto-abci = {package = "ibc-proto", git = "https://github.com/heliaxdev/ibc-rs", branch = "yuji/v0.12.0_tm_v0.23.5", default-features = false, optional = true} -ics23 = "0.6.7" +ibc = {git = "https://github.com/heliaxdev/ibc-rs", branch = "yuji/v0.14.0_abcipp_rebase_master", default-features = false, optional = true} +ibc-abci = {package = "ibc", git = "https://github.com/heliaxdev/ibc-rs", branch = "yuji/v0.14.0_tm_v0.23.5", default-features = false, optional = true} +ibc-proto = {git = "https://github.com/heliaxdev/ibc-rs", branch = "yuji/v0.14.0_abcipp_rebase_master", default-features = false, optional = true} +ibc-proto-abci = {package = "ibc-proto", git = "https://github.com/heliaxdev/ibc-rs", branch = "yuji/v0.14.0_tm_v0.23.5", default-features = false, optional = true} +ics23 = "0.7.0" itertools = "0.10.0" loupe = {version = "0.1.3", optional = true} parity-wasm = {version = "0.42.2", optional = true} @@ -100,7 +100,7 @@ serde = {version = "1.0.125", features = ["derive"]} serde_json = "1.0.62" sha2 = "0.9.3" # We switch off "blake2b" because it cannot be compiled to wasm -sparse-merkle-tree = {git = "https://github.com/heliaxdev/sparse-merkle-tree", branch = "yuji/prost-0.9", default-features = false, features = ["std", "borsh"]} +sparse-merkle-tree = {git = "https://github.com/heliaxdev/sparse-merkle-tree", branch = "yuji/ics23_0.7", default-features = false, features = ["std", "borsh"]} tempfile = {version = "3.2.0", optional = true} # temporarily using fork work-around for https://github.com/informalsystems/tendermint-rs/issues/971 tendermint = {git = "https://github.com/heliaxdev/tendermint-rs", rev = "95c52476bc37927218374f94ac8e2a19bd35bec9", optional = true} diff --git a/shared/src/ledger/ibc/handler.rs b/shared/src/ledger/ibc/handler.rs index bf45759535..6ba544eed6 100644 --- a/shared/src/ledger/ibc/handler.rs +++ b/shared/src/ledger/ibc/handler.rs @@ -2,7 +2,6 @@ use std::str::FromStr; -use prost::Message; use sha2::Digest; use thiserror::Error; @@ -37,15 +36,16 @@ use crate::ibc::core::ics03_connection::msgs::conn_open_confirm::MsgConnectionOp use crate::ibc::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; use crate::ibc::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; use crate::ibc::core::ics03_connection::msgs::ConnectionMsg; +use crate::ibc::core::ics03_connection::version::Version as ConnVersion; use crate::ibc::core::ics04_channel::channel::{ ChannelEnd, Counterparty as ChanCounterparty, Order, State as ChanState, }; +use crate::ibc::core::ics04_channel::commitment::PacketCommitment; use crate::ibc::core::ics04_channel::events::{ - AcknowledgePacket, Attributes as ChannelAttributes, - CloseConfirm as ChanCloseConfirm, CloseInit as ChanCloseInit, - OpenAck as ChanOpenAck, OpenConfirm as ChanOpenConfirm, - OpenInit as ChanOpenInit, OpenTry as ChanOpenTry, SendPacket, - TimeoutPacket, WriteAcknowledgement, + AcknowledgePacket, CloseConfirm as ChanCloseConfirm, + CloseInit as ChanCloseInit, OpenAck as ChanOpenAck, + OpenConfirm as ChanOpenConfirm, OpenInit as ChanOpenInit, + OpenTry as ChanOpenTry, SendPacket, TimeoutPacket, WriteAcknowledgement, }; use crate::ibc::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; use crate::ibc::core::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm; @@ -135,13 +135,7 @@ pub trait IbcActions { fn emit_ibc_event(&self, event: AnomaIbcEvent); /// Transfer token - fn transfer_token( - &self, - src: &Address, - dest: &Address, - token: &Address, - amount: Amount, - ); + fn transfer_token(&self, src: &Key, dest: &Key, amount: Amount); /// Get the current height of this chain fn get_height(&self) -> BlockHeight; @@ -406,8 +400,7 @@ pub trait IbcActions { let counter_key = storage::channel_counter_key(); let counter = self.get_and_inc_counter(&counter_key)?; let channel_id = channel_id(counter); - let port_channel_id = - port_channel_id(msg.port_id.clone(), channel_id.clone()); + let port_channel_id = port_channel_id(msg.port_id.clone(), channel_id); let channel_key = storage::channel_key(&port_channel_id); self.write_ibc_data( &channel_key, @@ -428,8 +421,7 @@ pub trait IbcActions { let counter_key = storage::channel_counter_key(); let counter = self.get_and_inc_counter(&counter_key)?; let channel_id = channel_id(counter); - let port_channel_id = - port_channel_id(msg.port_id.clone(), channel_id.clone()); + let port_channel_id = port_channel_id(msg.port_id.clone(), channel_id); let channel_key = storage::channel_key(&port_channel_id); self.write_ibc_data( &channel_key, @@ -447,7 +439,7 @@ pub trait IbcActions { /// Open the channel for ChannelOpenAck fn ack_channel(&self, msg: &MsgChannelOpenAck) -> Result<()> { let port_channel_id = - port_channel_id(msg.port_id.clone(), msg.channel_id.clone()); + port_channel_id(msg.port_id.clone(), msg.channel_id); let channel_key = storage::channel_key(&port_channel_id); let value = self.read_ibc_data(&channel_key).ok_or_else(|| { Error::Channel(format!( @@ -457,15 +449,23 @@ pub trait IbcActions { })?; let mut channel = ChannelEnd::decode_vec(&value).map_err(Error::Decoding)?; - channel - .set_counterparty_channel_id(msg.counterparty_channel_id.clone()); + channel.set_counterparty_channel_id(msg.counterparty_channel_id); open_channel(&mut channel); self.write_ibc_data( &channel_key, channel.encode_vec().expect("encoding shouldn't fail"), ); - let event = make_open_ack_channel_event(msg).try_into().unwrap(); + let conn_id = channel.connection_hops().get(0).ok_or_else(|| { + Error::Channel(format!( + "No connection for the channel: Port/Channel {}", + port_channel_id, + )) + })?; + let counterparty = channel.counterparty(); + let event = make_open_ack_channel_event(msg, conn_id, counterparty) + .try_into() + .unwrap(); self.emit_ibc_event(event); Ok(()) @@ -474,7 +474,7 @@ pub trait IbcActions { /// Open the channel for ChannelOpenConfirm fn confirm_channel(&self, msg: &MsgChannelOpenConfirm) -> Result<()> { let port_channel_id = - port_channel_id(msg.port_id.clone(), msg.channel_id.clone()); + port_channel_id(msg.port_id.clone(), msg.channel_id); let channel_key = storage::channel_key(&port_channel_id); let value = self.read_ibc_data(&channel_key).ok_or_else(|| { Error::Channel(format!( @@ -490,7 +490,16 @@ pub trait IbcActions { channel.encode_vec().expect("encoding shouldn't fail"), ); - let event = make_open_confirm_channel_event(msg).try_into().unwrap(); + let conn_id = channel.connection_hops().get(0).ok_or_else(|| { + Error::Channel(format!( + "No connection for the channel: Port/Channel {}", + port_channel_id, + )) + })?; + let counterparty = channel.counterparty(); + let event = make_open_confirm_channel_event(msg, conn_id, counterparty) + .try_into() + .unwrap(); self.emit_ibc_event(event); Ok(()) @@ -499,7 +508,7 @@ pub trait IbcActions { /// Close the channel for ChannelCloseInit fn close_init_channel(&self, msg: &MsgChannelCloseInit) -> Result<()> { let port_channel_id = - port_channel_id(msg.port_id.clone(), msg.channel_id.clone()); + port_channel_id(msg.port_id.clone(), msg.channel_id); let channel_key = storage::channel_key(&port_channel_id); let value = self.read_ibc_data(&channel_key).ok_or_else(|| { Error::Channel(format!( @@ -515,7 +524,16 @@ pub trait IbcActions { channel.encode_vec().expect("encoding shouldn't fail"), ); - let event = make_close_init_channel_event(msg).try_into().unwrap(); + let conn_id = channel.connection_hops().get(0).ok_or_else(|| { + Error::Channel(format!( + "No connection for the channel: Port/Channel {}", + port_channel_id, + )) + })?; + let counterparty = channel.counterparty(); + let event = make_close_init_channel_event(msg, conn_id, counterparty) + .try_into() + .unwrap(); self.emit_ibc_event(event); Ok(()) @@ -527,7 +545,7 @@ pub trait IbcActions { msg: &MsgChannelCloseConfirm, ) -> Result<()> { let port_channel_id = - port_channel_id(msg.port_id.clone(), msg.channel_id.clone()); + port_channel_id(msg.port_id.clone(), msg.channel_id); let channel_key = storage::channel_key(&port_channel_id); let value = self.read_ibc_data(&channel_key).ok_or_else(|| { Error::Channel(format!( @@ -543,7 +561,17 @@ pub trait IbcActions { channel.encode_vec().expect("encoding shouldn't fail"), ); - let event = make_close_confirm_channel_event(msg).try_into().unwrap(); + let conn_id = channel.connection_hops().get(0).ok_or_else(|| { + Error::Channel(format!( + "No connection for the channel: Port/Channel {}", + port_channel_id, + )) + })?; + let counterparty = channel.counterparty(); + let event = + make_close_confirm_channel_event(msg, conn_id, counterparty) + .try_into() + .unwrap(); self.emit_ibc_event(event); Ok(()) @@ -574,12 +602,11 @@ pub trait IbcActions { let packet = Packet { sequence, source_port: port_channel_id.port_id.clone(), - source_channel: port_channel_id.channel_id.clone(), + source_channel: port_channel_id.channel_id, destination_port: counterparty.port_id.clone(), - destination_channel: counterparty + destination_channel: *counterparty .channel_id() - .expect("the counterparty channel should exist") - .clone(), + .expect("the counterparty channel should exist"), data, timeout_height, timeout_timestamp, @@ -591,11 +618,7 @@ pub trait IbcActions { packet.sequence, ); let commitment = commitment(&packet); - let mut commitment_bytes = vec![]; - commitment - .encode(&mut commitment_bytes) - .expect("encoding shouldn't fail"); - self.write_ibc_data(&commitment_key, commitment_bytes); + self.write_ibc_data(&commitment_key, commitment.into_vec()); let event = make_send_packet_event(packet).try_into().unwrap(); self.emit_ibc_event(event); @@ -605,10 +628,17 @@ pub trait IbcActions { /// Receive a packet fn receive_packet(&self, msg: &MsgRecvPacket) -> Result<()> { + // TODO for other applications // check the packet data - if let Ok(data) = serde_json::from_slice(&msg.packet.data) { - self.receive_token(&msg.packet, &data)?; - } + let packet_ack = + if let Ok(data) = serde_json::from_slice(&msg.packet.data) { + match self.receive_token(&msg.packet, &data) { + Ok(_) => PacketAck::result_success(), + Err(e) => PacketAck::result_error(e.to_string()), + } + } else { + PacketAck::result_error("unknown packet data".to_string()) + }; // store the receipt let receipt_key = storage::receipt_key( @@ -624,13 +654,14 @@ pub trait IbcActions { &msg.packet.destination_channel, msg.packet.sequence, ); - let ack = PacketAck::default().encode_to_vec(); - self.write_ibc_data(&ack_key, ack.clone()); + let ack = packet_ack.encode_to_vec(); + let ack_commitment = sha2::Sha256::digest(&ack).to_vec(); + self.write_ibc_data(&ack_key, ack_commitment); // increment the next sequence receive let port_channel_id = port_channel_id( msg.packet.destination_port.clone(), - msg.packet.destination_channel.clone(), + msg.packet.destination_channel, ); let seq_key = storage::next_sequence_recv_key(&port_channel_id); self.get_and_inc_sequence(&seq_key)?; @@ -645,6 +676,15 @@ pub trait IbcActions { /// Receive a acknowledgement fn acknowledge_packet(&self, msg: &MsgAcknowledgement) -> Result<()> { + let ack = PacketAck::try_from(msg.acknowledgement.clone()) + .map_err(Error::IbcData)?; + if !ack.is_success() { + // TODO for other applications + if let Ok(data) = serde_json::from_slice(&msg.packet.data) { + self.refund_token(&msg.packet, &data)?; + } + } + let commitment_key = storage::commitment_key( &msg.packet.source_port, &msg.packet.source_channel, @@ -652,6 +692,14 @@ pub trait IbcActions { ); self.delete_ibc_data(&commitment_key); + // get and increment the next sequence ack + let port_channel_id = port_channel_id( + msg.packet.source_port.clone(), + msg.packet.source_channel, + ); + let seq_key = storage::next_sequence_ack_key(&port_channel_id); + self.get_and_inc_sequence(&seq_key)?; + let event = make_ack_event(msg.packet.clone()).try_into().unwrap(); self.emit_ibc_event(event); @@ -660,6 +708,7 @@ pub trait IbcActions { /// Receive a timeout fn timeout_packet(&self, msg: &MsgTimeout) -> Result<()> { + // TODO for other applications // check the packet data if let Ok(data) = serde_json::from_slice(&msg.packet.data) { self.refund_token(&msg.packet, &data)?; @@ -676,7 +725,7 @@ pub trait IbcActions { // close the channel let port_channel_id = port_channel_id( msg.packet.source_port.clone(), - msg.packet.source_channel.clone(), + msg.packet.source_channel, ); let channel_key = storage::channel_key(&port_channel_id); let value = self.read_ibc_data(&channel_key).ok_or_else(|| { @@ -703,6 +752,7 @@ pub trait IbcActions { /// Receive a timeout for TimeoutOnClose fn timeout_on_close_packet(&self, msg: &MsgTimeoutOnClose) -> Result<()> { + // TODO for other applications // check the packet data if let Ok(data) = serde_json::from_slice(&msg.packet.data) { self.refund_token(&msg.packet, &data)?; @@ -719,7 +769,7 @@ pub trait IbcActions { // close the channel let port_channel_id = port_channel_id( msg.packet.source_port.clone(), - msg.packet.source_channel.clone(), + msg.packet.source_channel, ); let channel_key = storage::channel_key(&port_channel_id); let value = self.read_ibc_data(&channel_key).ok_or_else(|| { @@ -817,19 +867,12 @@ pub trait IbcActions { /// Send the specified token by escrowing or burning fn send_token(&self, msg: &MsgTransfer) -> Result<()> { let data = FungibleTokenPacketData::from(msg.clone()); - let source = Address::decode(data.sender.clone()).map_err(|e| { + let token_str = data.denom.split('/').last().ok_or_else(|| { Error::SendingToken(format!( - "Invalid sender address: sender {}, error {}", - data.sender, e + "No token was specified: {}", + data.denom )) })?; - let token_str = - data.denomination.split('/').last().ok_or_else(|| { - Error::SendingToken(format!( - "No token was specified: {}", - data.denomination - )) - })?; let token = Address::decode(token_str).map_err(|e| { Error::SendingToken(format!( "Invalid token address: token {}, error {}", @@ -843,31 +886,53 @@ pub trait IbcActions { )) })?; - // check the denomination field + let source = if data.sender.contains('/') { + Key::parse(&data.sender).map_err(|e| { + Error::SendingToken(format!( + "Invalid sender account key: sender {}, error {}", + data.sender, e + )) + })? + } else { + let addr = Address::decode(data.sender.clone()).map_err(|e| { + Error::SendingToken(format!( + "Invalid sender address: sender {}, error {}", + data.sender, e + )) + })?; + token::balance_key(&token, &addr) + }; + + // check the denom field let prefix = format!( "{}/{}/", msg.source_port.clone(), msg.source_channel.clone() ); - if data.denomination.starts_with(&prefix) { + let key_prefix = storage::ibc_token_prefix( + &msg.source_port, + &msg.source_channel, + &token, + ); + if data.denom.starts_with(&prefix) { // sink zone - let burn = Address::Internal(InternalAddress::IbcBurn); - self.transfer_token(&source, &burn, &token, amount); + let burn = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcBurn), + ); + self.transfer_token(&source, &burn, amount); } else { // source zone - let escrow = - Address::Internal(InternalAddress::ibc_escrow_address( - msg.source_port.to_string(), - msg.source_channel.to_string(), - )); - self.transfer_token(&source, &escrow, &token, amount); + let escrow = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcEscrow), + ); + self.transfer_token(&source, &escrow, amount); } // send a packet - let port_channel_id = port_channel_id( - msg.source_port.clone(), - msg.source_channel.clone(), - ); + let port_channel_id = + port_channel_id(msg.source_port.clone(), msg.source_channel); let packet_data = serde_json::to_vec(&data) .expect("encoding the packet data shouldn't fail"); self.send_packet( @@ -884,19 +949,12 @@ pub trait IbcActions { packet: &Packet, data: &FungibleTokenPacketData, ) -> Result<()> { - let dest = Address::decode(data.receiver.clone()).map_err(|e| { + let token_str = data.denom.split('/').last().ok_or_else(|| { Error::ReceivingToken(format!( - "Invalid receiver address: receiver {}, error {}", - data.receiver, e + "No token was specified: {}", + data.denom )) })?; - let token_str = - data.denomination.split('/').last().ok_or_else(|| { - Error::ReceivingToken(format!( - "No token was specified: {}", - data.denomination - )) - })?; let token = Address::decode(token_str).map_err(|e| { Error::ReceivingToken(format!( "Invalid token address: token {}, error {}", @@ -910,23 +968,41 @@ pub trait IbcActions { )) })?; + // The receiver should be an address because the origin-specific account + // key should be assigned internally + let dest_addr = + Address::decode(data.receiver.clone()).map_err(|e| { + Error::ReceivingToken(format!( + "Invalid receiver address: receiver {}, error {}", + data.receiver, e + )) + })?; + let key_prefix = storage::ibc_token_prefix( + &packet.source_port, + &packet.source_channel, + &token, + ); + let dest = token::multitoken_balance_key(&key_prefix, &dest_addr); + let prefix = format!( "{}/{}/", packet.source_port.clone(), packet.source_channel.clone() ); - if data.denomination.starts_with(&prefix) { + if data.denom.starts_with(&prefix) { // unescrow the token because this chain is the source - let escrow = - Address::Internal(InternalAddress::ibc_escrow_address( - packet.destination_port.to_string(), - packet.destination_channel.to_string(), - )); - self.transfer_token(&escrow, &dest, &token, amount); + let escrow = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcEscrow), + ); + self.transfer_token(&escrow, &dest, amount); } else { // mint the token because the sender chain is the source - let mint = Address::Internal(InternalAddress::IbcMint); - self.transfer_token(&mint, &dest, &token, amount); + let mint = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcMint), + ); + self.transfer_token(&mint, &dest, amount); } Ok(()) } @@ -937,19 +1013,12 @@ pub trait IbcActions { packet: &Packet, data: &FungibleTokenPacketData, ) -> Result<()> { - let dest = Address::decode(data.sender.clone()).map_err(|e| { + let token_str = data.denom.split('/').last().ok_or_else(|| { Error::ReceivingToken(format!( - "Invalid sender address: sender {}, error {}", - data.sender, e + "No token was specified: {}", + data.denom )) })?; - let token_str = - data.denomination.split('/').last().ok_or_else(|| { - Error::ReceivingToken(format!( - "No token was specified: {}", - data.denomination - )) - })?; let token = Address::decode(token_str).map_err(|e| { Error::ReceivingToken(format!( "Invalid token address: token {}, error {}", @@ -963,23 +1032,47 @@ pub trait IbcActions { )) })?; + let dest = if data.sender.contains('/') { + Key::parse(&data.sender).map_err(|e| { + Error::SendingToken(format!( + "Invalid sender account key: sender {}, error {}", + data.sender, e + )) + })? + } else { + let addr = Address::decode(data.sender.clone()).map_err(|e| { + Error::SendingToken(format!( + "Invalid sender address: sender {}, error {}", + data.sender, e + )) + })?; + token::balance_key(&token, &addr) + }; + let prefix = format!( "{}/{}/", packet.source_port.clone(), packet.source_channel.clone() ); - if data.denomination.starts_with(&prefix) { + let key_prefix = storage::ibc_token_prefix( + &packet.source_port, + &packet.source_channel, + &token, + ); + if data.denom.starts_with(&prefix) { // mint the token because the sender chain is the sink zone - let mint = Address::Internal(InternalAddress::IbcMint); - self.transfer_token(&mint, &dest, &token, amount); + let mint = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcMint), + ); + self.transfer_token(&mint, &dest, amount); } else { // unescrow the token because the sender chain is the source zone - let escrow = - Address::Internal(InternalAddress::ibc_escrow_address( - packet.source_port.to_string(), - packet.source_channel.to_string(), - )); - self.transfer_token(&escrow, &dest, &token, amount); + let escrow = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcEscrow), + ); + self.transfer_token(&escrow, &dest, amount); } Ok(()) } @@ -1031,7 +1124,9 @@ pub fn init_connection(msg: &MsgConnectionOpenInit) -> ConnectionEnd { ConnState::Init, msg.client_id.clone(), msg.counterparty.clone(), - vec![msg.version.clone()], + msg.version + .clone() + .map_or_else(|| vec![ConnVersion::default()], |v| vec![v]), msg.delay_period, ) } @@ -1097,12 +1192,11 @@ pub fn packet_from_message( Packet { sequence, source_port: msg.source_port.clone(), - source_channel: msg.source_channel.clone(), + source_channel: msg.source_channel, destination_port: counterparty.port_id.clone(), - destination_channel: counterparty + destination_channel: *counterparty .channel_id() - .expect("the counterparty channel should exist") - .clone(), + .expect("the counterparty channel should exist"), data: serde_json::to_vec(&FungibleTokenPacketData::from(msg.clone())) .expect("encoding the packet data shouldn't fail"), timeout_height: msg.timeout_height, @@ -1111,13 +1205,19 @@ pub fn packet_from_message( } /// Returns a commitment from the given packet -pub fn commitment(packet: &Packet) -> String { - let input = format!( - "{:?},{:?},{:?}", - packet.timeout_timestamp, packet.timeout_height, packet.data, - ); - let r = sha2::Sha256::digest(input.as_bytes()); - format!("{:x}", r) +pub fn commitment(packet: &Packet) -> PacketCommitment { + let mut input = packet + .timeout_timestamp + .nanoseconds() + .to_be_bytes() + .to_vec(); + let revision_number = packet.timeout_height.revision_number.to_be_bytes(); + input.append(&mut revision_number.to_vec()); + let revision_height = packet.timeout_height.revision_height.to_be_bytes(); + input.append(&mut revision_height.to_vec()); + let data = sha2::Sha256::digest(&packet.data); + input.append(&mut data.to_vec()); + sha2::Sha256::digest(&input).to_vec().into() } /// Returns a counterparty of a connection @@ -1196,7 +1296,7 @@ pub fn make_open_init_connection_event( counterparty_client_id: msg.counterparty.client_id().clone(), ..Default::default() }; - IbcEvent::OpenInitConnection(ConnOpenInit::from(attributes)) + ConnOpenInit::from(attributes).into() } /// Makes OpenTryConnection event @@ -1211,7 +1311,7 @@ pub fn make_open_try_connection_event( counterparty_client_id: msg.counterparty.client_id().clone(), ..Default::default() }; - IbcEvent::OpenTryConnection(ConnOpenTry::from(attributes)) + ConnOpenTry::from(attributes).into() } /// Makes OpenAckConnection event @@ -1223,7 +1323,7 @@ pub fn make_open_ack_connection_event(msg: &MsgConnectionOpenAck) -> IbcEvent { ), ..Default::default() }; - IbcEvent::OpenAckConnection(ConnOpenAck::from(attributes)) + ConnOpenAck::from(attributes).into() } /// Makes OpenConfirmConnection event @@ -1234,7 +1334,7 @@ pub fn make_open_confirm_connection_event( connection_id: Some(msg.connection_id.clone()), ..Default::default() }; - IbcEvent::OpenConfirmConnection(ConnOpenConfirm::from(attributes)) + ConnOpenConfirm::from(attributes).into() } /// Makes OpenInitChannel event @@ -1246,9 +1346,10 @@ pub fn make_open_init_channel_event( Some(c) => c.clone(), None => ConnectionId::default(), }; - let attributes = ChannelAttributes { + let attributes = ChanOpenInit { + height: Height::default(), port_id: msg.port_id.clone(), - channel_id: Some(channel_id.clone()), + channel_id: Some(*channel_id), connection_id, counterparty_port_id: msg.channel.counterparty().port_id().clone(), counterparty_channel_id: msg @@ -1256,9 +1357,8 @@ pub fn make_open_init_channel_event( .counterparty() .channel_id() .cloned(), - ..Default::default() }; - IbcEvent::OpenInitChannel(ChanOpenInit::from(attributes)) + attributes.into() } /// Makes OpenTryChannel event @@ -1270,9 +1370,10 @@ pub fn make_open_try_channel_event( Some(c) => c.clone(), None => ConnectionId::default(), }; - let attributes = ChannelAttributes { + let attributes = ChanOpenTry { + height: Height::default(), port_id: msg.port_id.clone(), - channel_id: Some(channel_id.clone()), + channel_id: Some(*channel_id), connection_id, counterparty_port_id: msg.channel.counterparty().port_id().clone(), counterparty_channel_id: msg @@ -1280,54 +1381,76 @@ pub fn make_open_try_channel_event( .counterparty() .channel_id() .cloned(), - ..Default::default() }; - IbcEvent::OpenTryChannel(ChanOpenTry::from(attributes)) + attributes.into() } /// Makes OpenAckChannel event -pub fn make_open_ack_channel_event(msg: &MsgChannelOpenAck) -> IbcEvent { - let attributes = ChannelAttributes { +pub fn make_open_ack_channel_event( + msg: &MsgChannelOpenAck, + conn_id: &ConnectionId, + counterparty: &ChanCounterparty, +) -> IbcEvent { + let attributes = ChanOpenAck { + height: Height::default(), port_id: msg.port_id.clone(), - channel_id: Some(msg.channel_id.clone()), - counterparty_channel_id: Some(msg.counterparty_channel_id.clone()), - ..Default::default() + channel_id: Some(msg.channel_id), + counterparty_channel_id: Some(msg.counterparty_channel_id), + connection_id: conn_id.clone(), + counterparty_port_id: counterparty.port_id().clone(), }; - IbcEvent::OpenAckChannel(ChanOpenAck::from(attributes)) + attributes.into() } /// Makes OpenConfirmChannel event pub fn make_open_confirm_channel_event( msg: &MsgChannelOpenConfirm, + conn_id: &ConnectionId, + counterparty: &ChanCounterparty, ) -> IbcEvent { - let attributes = ChannelAttributes { + let attributes = ChanOpenConfirm { + height: Height::default(), port_id: msg.port_id.clone(), - channel_id: Some(msg.channel_id.clone()), - ..Default::default() + channel_id: Some(msg.channel_id), + connection_id: conn_id.clone(), + counterparty_port_id: counterparty.port_id().clone(), + counterparty_channel_id: counterparty.channel_id().cloned(), }; - IbcEvent::OpenConfirmChannel(ChanOpenConfirm::from(attributes)) + attributes.into() } /// Makes CloseInitChannel event -pub fn make_close_init_channel_event(msg: &MsgChannelCloseInit) -> IbcEvent { - let attributes = ChannelAttributes { +pub fn make_close_init_channel_event( + msg: &MsgChannelCloseInit, + conn_id: &ConnectionId, + counterparty: &ChanCounterparty, +) -> IbcEvent { + let attributes = ChanCloseInit { + height: Height::default(), port_id: msg.port_id.clone(), - channel_id: Some(msg.channel_id.clone()), - ..Default::default() + channel_id: msg.channel_id, + connection_id: conn_id.clone(), + counterparty_port_id: counterparty.port_id().clone(), + counterparty_channel_id: counterparty.channel_id().cloned(), }; - IbcEvent::CloseInitChannel(ChanCloseInit::from(attributes)) + attributes.into() } /// Makes CloseConfirmChannel event pub fn make_close_confirm_channel_event( msg: &MsgChannelCloseConfirm, + conn_id: &ConnectionId, + counterparty: &ChanCounterparty, ) -> IbcEvent { - let attributes = ChannelAttributes { + let attributes = ChanCloseConfirm { + height: Height::default(), port_id: msg.port_id.clone(), - channel_id: Some(msg.channel_id.clone()), - ..Default::default() + channel_id: Some(msg.channel_id), + connection_id: conn_id.clone(), + counterparty_port_id: counterparty.port_id.clone(), + counterparty_channel_id: counterparty.channel_id().cloned(), }; - IbcEvent::CloseConfirmChannel(ChanCloseConfirm::from(attributes)) + attributes.into() } /// Makes SendPacket event diff --git a/shared/src/ledger/ibc/storage.rs b/shared/src/ledger/ibc/storage.rs index 85e4011c5b..c8b9c02310 100644 --- a/shared/src/ledger/ibc/storage.rs +++ b/shared/src/ledger/ibc/storage.rs @@ -2,6 +2,7 @@ use std::str::FromStr; +use sha2::{Digest, Sha256}; use thiserror::Error; use crate::ibc::core::ics02_client::height::Height; @@ -16,7 +17,7 @@ use crate::ibc::core::ics24_host::path::{ SeqAcksPath, SeqRecvsPath, SeqSendsPath, }; use crate::ibc::core::ics24_host::Path; -use crate::types::address::{Address, InternalAddress}; +use crate::types::address::{Address, InternalAddress, HASH_LEN}; use crate::types::storage::{self, DbKeySeg, Key, KeySeg}; const CLIENTS_COUNTER: &str = "clients/counter"; @@ -24,6 +25,8 @@ const CONNECTIONS_COUNTER: &str = "connections/counter"; const CHANNELS_COUNTER: &str = "channelEnds/counter"; const CAPABILITIES_INDEX: &str = "capabilities/index"; const CAPABILITIES: &str = "capabilities"; +/// Key segment for a multitoken related to IBC +const MULTITOKEN_STORAGE_KEY: &str = "ibc"; #[allow(missing_docs)] #[derive(Error, Debug)] @@ -188,7 +191,7 @@ pub fn connection_key(conn_id: &ConnectionId) -> Key { pub fn channel_key(port_channel_id: &PortChannelId) -> Key { let path = Path::ChannelEnds(ChannelEndsPath( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )); ibc_key(path.to_string()) .expect("Creating a key for the channel shouldn't fail") @@ -211,7 +214,7 @@ pub fn capability_key(index: u64) -> Key { pub fn next_sequence_send_key(port_channel_id: &PortChannelId) -> Key { let path = Path::SeqSends(SeqSendsPath( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )); ibc_key(path.to_string()) .expect("Creating a key for nextSequenceSend shouldn't fail") @@ -221,7 +224,7 @@ pub fn next_sequence_send_key(port_channel_id: &PortChannelId) -> Key { pub fn next_sequence_recv_key(port_channel_id: &PortChannelId) -> Key { let path = Path::SeqRecvs(SeqRecvsPath( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )); ibc_key(path.to_string()) .expect("Creating a key for nextSequenceRecv shouldn't fail") @@ -231,7 +234,7 @@ pub fn next_sequence_recv_key(port_channel_id: &PortChannelId) -> Key { pub fn next_sequence_ack_key(port_channel_id: &PortChannelId) -> Key { let path = Path::SeqAcks(SeqAcksPath( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )); ibc_key(path.to_string()) .expect("Creating a key for nextSequenceAck shouldn't fail") @@ -245,7 +248,7 @@ pub fn commitment_key( ) -> Key { let path = Path::Commitments(CommitmentsPath { port_id: port_id.clone(), - channel_id: channel_id.clone(), + channel_id: *channel_id, sequence, }); ibc_key(path.to_string()) @@ -260,7 +263,7 @@ pub fn receipt_key( ) -> Key { let path = Path::Receipts(ReceiptsPath { port_id: port_id.clone(), - channel_id: channel_id.clone(), + channel_id: *channel_id, sequence, }); ibc_key(path.to_string()) @@ -275,7 +278,7 @@ pub fn ack_key( ) -> Key { let path = Path::Acks(AcksPath { port_id: port_id.clone(), - channel_id: channel_id.clone(), + channel_id: *channel_id, sequence, }); ibc_key(path.to_string()) @@ -482,3 +485,22 @@ pub fn capability(key: &Key) -> Result { ))), } } + +/// Returns the account key of the received token over IBC +pub fn ibc_token_prefix( + port_id: &PortId, + channel_id: &ChannelId, + token: &Address, +) -> Key { + let mut hasher = Sha256::new(); + let s = format!("{}/{}/{}", port_id, channel_id, token); + hasher.update(&s); + let hash = format!("{:.width$x}", hasher.finalize(), width = HASH_LEN); + + let ibc_token = Address::Internal(InternalAddress::IbcToken(hash)); + Key::from(token.to_db_key()) + .push(&MULTITOKEN_STORAGE_KEY.to_owned()) + .expect("Cannot obtain a storage key") + .push(&ibc_token.to_db_key()) + .expect("Cannot obtain a storage key") +} diff --git a/shared/src/ledger/ibc/vp/channel.rs b/shared/src/ledger/ibc/vp/channel.rs index 354899f31d..81544ae6e3 100644 --- a/shared/src/ledger/ibc/vp/channel.rs +++ b/shared/src/ledger/ibc/vp/channel.rs @@ -2,7 +2,6 @@ use core::time::Duration; -use prost::Message; use sha2::Digest; use thiserror::Error; @@ -28,6 +27,9 @@ use crate::ibc::core::ics03_connection::error::Error as Ics03Error; use crate::ibc::core::ics04_channel::channel::{ ChannelEnd, Counterparty, State, }; +use crate::ibc::core::ics04_channel::commitment::{ + AcknowledgementCommitment, PacketCommitment, +}; use crate::ibc::core::ics04_channel::context::ChannelReader; use crate::ibc::core::ics04_channel::error::Error as Ics04Error; use crate::ibc::core::ics04_channel::handler::verify::verify_channel_proofs; @@ -37,11 +39,14 @@ use crate::ibc::core::ics04_channel::msgs::chan_open_confirm::MsgChannelOpenConf use crate::ibc::core::ics04_channel::msgs::chan_open_try::MsgChannelOpenTry; use crate::ibc::core::ics04_channel::msgs::{ChannelMsg, PacketMsg}; use crate::ibc::core::ics04_channel::packet::{Receipt, Sequence}; -use crate::ibc::core::ics05_port::capabilities::Capability; +use crate::ibc::core::ics05_port::capabilities::{ + Capability, ChannelCapability, +}; use crate::ibc::core::ics05_port::context::PortReader; use crate::ibc::core::ics24_host::identifier::{ ChannelId, ClientId, ConnectionId, PortChannelId, PortId, }; +use crate::ibc::core::ics26_routing::context::ModuleId; use crate::ibc::core::ics26_routing::msgs::Ics26Envelope; use crate::ibc::proofs::Proofs; use crate::ibc::timestamp::Timestamp; @@ -51,7 +56,7 @@ use crate::ledger::storage::{self as ledger_storage, StorageHasher}; use crate::tendermint::Time; use crate::tendermint_proto::Protobuf; use crate::types::ibc::data::{ - Error as IbcDataError, IbcMessage, PacketAck, PacketReceipt, + Error as IbcDataError, IbcMessage, PacketReceipt, }; use crate::types::storage::Key; use crate::vm::WasmCacheAccess; @@ -134,7 +139,7 @@ where let channel = self .channel_end(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidChannel(format!( @@ -236,6 +241,13 @@ where tx_data: &[u8], ) -> Result<()> { let prev_channel = self.channel_end_pre(port_channel_id)?; + let conn_id = channel.connection_hops().get(0).ok_or_else(|| { + Error::InvalidChannel(format!( + "No connection for the channel: Port/Channel {}", + port_channel_id, + )) + })?; + let counterparty = channel.counterparty(); match channel.state() { State::Open => match prev_channel.state() { State::Init => { @@ -246,7 +258,11 @@ where channel, &msg, )?; - let event = make_open_ack_channel_event(&msg); + let event = make_open_ack_channel_event( + &msg, + conn_id, + counterparty, + ); self.check_emitted_event(event) .map_err(|e| Error::IbcEvent(e.to_string())) } @@ -258,7 +274,11 @@ where channel, &msg, )?; - let event = make_open_confirm_channel_event(&msg); + let event = make_open_confirm_channel_event( + &msg, + conn_id, + counterparty, + ); self.check_emitted_event(event) .map_err(|e| Error::IbcEvent(e.to_string())) } @@ -301,7 +321,11 @@ where Ics26Envelope::Ics4ChannelMsg( ChannelMsg::ChannelCloseInit(msg), ) => { - let event = make_close_init_channel_event(&msg); + let event = make_close_init_channel_event( + &msg, + conn_id, + counterparty, + ); self.check_emitted_event(event) .map_err(|e| Error::IbcEvent(e.to_string())) } @@ -313,7 +337,11 @@ where channel, &msg, )?; - let event = make_close_confirm_channel_event(&msg); + let event = make_close_confirm_channel_event( + &msg, + conn_id, + counterparty, + ); self.check_emitted_event(event) .map_err(|e| Error::IbcEvent(e.to_string())) } @@ -399,7 +427,7 @@ where } let expected_my_side = Counterparty::new( port_channel_id.port_id.clone(), - Some(port_channel_id.channel_id.clone()), + Some(port_channel_id.channel_id), ); self.verify_proofs( msg.proofs.height(), @@ -418,7 +446,7 @@ where ) -> Result<()> { let expected_my_side = Counterparty::new( port_channel_id.port_id.clone(), - Some(port_channel_id.channel_id.clone()), + Some(port_channel_id.channel_id), ); self.verify_proofs( msg.proofs.height(), @@ -437,7 +465,7 @@ where ) -> Result<()> { let expected_my_side = Counterparty::new( port_channel_id.port_id.clone(), - Some(port_channel_id.channel_id.clone()), + Some(port_channel_id.channel_id), ); self.verify_proofs( msg.proofs.height(), @@ -592,15 +620,10 @@ where pub(super) fn get_packet_commitment_pre( &self, key: &(PortId, ChannelId, Sequence), - ) -> Result { + ) -> Result { let key = commitment_key(&key.0, &key.1, key.2); match self.ctx.read_pre(&key)? { - Some(value) => String::decode(&value[..]).map_err(|e| { - Error::InvalidPacketInfo(format!( - "Decoding the prior commitment failed: {}", - e - )) - }), + Some(value) => Ok(value.into()), None => Err(Error::InvalidPacketInfo(format!( "The prior commitment doesn't exist: Key {}", key @@ -668,7 +691,7 @@ where ) -> Ics04Result { let port_channel_id = PortChannelId { port_id: port_channel_id.0.clone(), - channel_id: port_channel_id.1.clone(), + channel_id: port_channel_id.1, }; let key = channel_key(&port_channel_id); match self.ctx.read_post(&key) { @@ -751,12 +774,13 @@ where fn authenticated_capability( &self, port_id: &PortId, - ) -> Ics04Result { - let (_, cap) = self + ) -> Ics04Result { + let (_, port_cap) = self .lookup_module_by_port(port_id) .map_err(|_| Ics04Error::no_port_capability(port_id.clone()))?; - if self.authenticate(port_id.clone(), &cap) { - Ok(cap) + if self.authenticate(port_id.clone(), &port_cap) { + let cap: Capability = port_cap.into(); + Ok(cap.into()) } else { Err(Ics04Error::invalid_port_capability()) } @@ -768,7 +792,7 @@ where ) -> Ics04Result { let port_channel_id = PortChannelId { port_id: port_channel_id.0.clone(), - channel_id: port_channel_id.1.clone(), + channel_id: port_channel_id.1, }; let key = next_sequence_send_key(&port_channel_id); self.get_sequence(&key).map_err(|_| { @@ -785,7 +809,7 @@ where ) -> Ics04Result { let port_channel_id = PortChannelId { port_id: port_channel_id.0.clone(), - channel_id: port_channel_id.1.clone(), + channel_id: port_channel_id.1, }; let key = next_sequence_recv_key(&port_channel_id); self.get_sequence(&key).map_err(|_| { @@ -802,7 +826,7 @@ where ) -> Ics04Result { let port_channel_id = PortChannelId { port_id: port_channel_id.0.clone(), - channel_id: port_channel_id.1.clone(), + channel_id: port_channel_id.1, }; let key = next_sequence_ack_key(&port_channel_id); self.get_sequence(&key).map_err(|_| { @@ -816,11 +840,10 @@ where fn get_packet_commitment( &self, key: &(PortId, ChannelId, Sequence), - ) -> Ics04Result { + ) -> Ics04Result { let commitment_key = commitment_key(&key.0, &key.1, key.2); match self.ctx.read_post(&commitment_key) { - Ok(Some(value)) => String::decode(&value[..]) - .map_err(|_| Ics04Error::implementation_specific()), + Ok(Some(value)) => Ok(value.into()), Ok(None) => Err(Ics04Error::packet_commitment_not_found(key.2)), Err(_) => Err(Ics04Error::implementation_specific()), } @@ -838,22 +861,20 @@ where } } - // TODO should return Vec or Acknowledgment. fix in ibc-rs? fn get_packet_acknowledgement( &self, key: &(PortId, ChannelId, Sequence), - ) -> Ics04Result { + ) -> Ics04Result { let ack_key = ack_key(&key.0, &key.1, key.2); match self.ctx.read_post(&ack_key) { - Ok(Some(_)) => Ok(PacketAck::default().to_string()), + Ok(Some(value)) => Ok(value.into()), Ok(None) => Err(Ics04Error::packet_commitment_not_found(key.2)), Err(_) => Err(Ics04Error::implementation_specific()), } } - fn hash(&self, value: String) -> String { - let r = sha2::Sha256::digest(value.as_bytes()); - format!("{:x}", r) + fn hash(&self, value: Vec) -> Vec { + sha2::Sha256::digest(&value).to_vec() } fn host_height(&self) -> Height { @@ -929,6 +950,18 @@ where Err(_) => Duration::default(), } } + + fn lookup_module_by_channel( + &self, + _channel_id: &ChannelId, + port_id: &PortId, + ) -> Ics04Result<(ModuleId, ChannelCapability)> { + let (module_id, port_cap) = self + .lookup_module_by_port(port_id) + .map_err(Ics04Error::ics05_port)?; + let cap: Capability = port_cap.into(); + Ok((module_id, cap.into())) + } } impl From for Error { diff --git a/shared/src/ledger/ibc/vp/mod.rs b/shared/src/ledger/ibc/vp/mod.rs index b6bd15e43b..a8a46cfe33 100644 --- a/shared/src/ledger/ibc/vp/mod.rs +++ b/shared/src/ledger/ibc/vp/mod.rs @@ -344,13 +344,12 @@ mod tests { use crate::ibc::Height; use crate::ibc_proto::cosmos::base::v1beta1::Coin; use prost::Message; - use sha2::Digest; - use crate::tendermint_proto::Protobuf; use crate::tendermint::time::Time as TmTime; + use crate::tendermint_proto::Protobuf; use super::get_dummy_header; use super::super::handler::{ - commitment_prefix, init_connection, make_create_client_event, + self, commitment_prefix, init_connection, make_create_client_event, make_open_ack_channel_event, make_open_ack_connection_event, make_open_confirm_channel_event, make_open_confirm_connection_event, make_open_init_channel_event, make_open_init_connection_event, @@ -454,7 +453,7 @@ mod tests { } fn get_channel_id() -> ChannelId { - ChannelId::from_str("test_channel").unwrap() + ChannelId::from_str("channel-42").unwrap() } fn get_connection(conn_state: ConnState) -> ConnectionEnd { @@ -494,9 +493,8 @@ mod tests { fn get_channel_counterparty() -> ChanCounterparty { let counterpart_port_id = PortId::from_str("counterpart_test_port") .expect("Creating a port ID failed"); - let counterpart_channel_id = - ChannelId::from_str("counterpart_test_channel") - .expect("Creating a channel ID failed"); + let counterpart_channel_id = ChannelId::from_str("channel-0") + .expect("Creating a channel ID failed"); ChanCounterparty::new(counterpart_port_id, Some(counterpart_channel_id)) } @@ -533,15 +531,6 @@ mod tests { .expect("write failed"); } - fn hash(packet: &Packet) -> String { - let input = format!( - "{:?},{:?},{:?}", - packet.timeout_timestamp, packet.timeout_height, packet.data, - ); - let r = sha2::Sha256::digest(input.as_bytes()); - format!("{:x}", r) - } - #[test] fn test_create_client() { let (storage, mut write_log) = insert_init_states(); @@ -696,7 +685,7 @@ mod tests { let msg = MsgConnectionOpenInit { client_id: get_client_id(), counterparty: get_conn_counterparty(), - version: ConnVersion::default(), + version: None, delay_period: Duration::new(100, 0), signer: Signer::new("account0"), }; @@ -745,7 +734,7 @@ mod tests { let msg = MsgConnectionOpenInit { client_id: get_client_id(), counterparty: get_conn_counterparty(), - version: ConnVersion::default(), + version: None, delay_period: Duration::new(100, 0), signer: Signer::new("account0"), }; @@ -1154,10 +1143,9 @@ mod tests { let msg = MsgChannelOpenAck { port_id: get_port_id(), channel_id: get_channel_id(), - counterparty_channel_id: get_channel_counterparty() + counterparty_channel_id: *get_channel_counterparty() .channel_id() - .unwrap() - .clone(), + .unwrap(), counterparty_version: ChanVersion::ics20(), proofs, signer: Signer::new("account0"), @@ -1166,8 +1154,13 @@ mod tests { // update the channel to Open let channel = get_channel(ChanState::Open, Order::Ordered); let bytes = channel.encode_vec().expect("encoding failed"); + let conn_id = channel + .connection_hops() + .get(0) + .expect("connection should exist"); + let counterparty = channel.counterparty(); write_log.write(&channel_key, bytes).expect("write failed"); - let event = make_open_ack_channel_event(&msg); + let event = make_open_ack_channel_event(&msg, conn_id, counterparty); write_log.set_ibc_event(event.try_into().unwrap()); let tx_code = vec![]; @@ -1240,7 +1233,14 @@ mod tests { let channel = get_channel(ChanState::Open, Order::Ordered); let bytes = channel.encode_vec().expect("encoding failed"); write_log.write(&channel_key, bytes).expect("write failed"); - let event = make_open_confirm_channel_event(&msg); + + let conn_id = channel + .connection_hops() + .get(0) + .expect("connection should exist"); + let counterparty = channel.counterparty(); + let event = + make_open_confirm_channel_event(&msg, conn_id, counterparty); write_log.set_ibc_event(event.try_into().unwrap()); let tx_code = vec![]; @@ -1373,14 +1373,10 @@ mod tests { let counterparty = get_channel_counterparty(); let packet = packet_from_message(&msg, sequence, &counterparty); // insert a commitment - let commitment = hash(&packet); - let mut commitment_bytes = vec![]; - commitment - .encode(&mut commitment_bytes) - .expect("encoding shouldn't fail"); + let commitment = handler::commitment(&packet); let key = commitment_key(&get_port_id(), &get_channel_id(), sequence); write_log - .write(&key, commitment_bytes) + .write(&key, commitment.into_vec()) .expect("write failed"); let tx_code = vec![]; @@ -1436,7 +1432,7 @@ mod tests { let packet = Packet { sequence, source_port: counterparty.port_id().clone(), - source_channel: counterparty.channel_id().unwrap().clone(), + source_channel: *counterparty.channel_id().unwrap(), destination_port: get_port_id(), destination_channel: get_channel_id(), data: vec![0], @@ -1459,7 +1455,7 @@ mod tests { .write(&key, PacketReceipt::default().as_bytes().to_vec()) .expect("write failed"); let key = ack_key(&get_port_id(), &get_channel_id(), sequence); - let ack = PacketAck::default().encode_to_vec(); + let ack = PacketAck::result_success().encode_to_vec(); write_log.write(&key, ack).expect("write failed"); let tx_code = vec![]; @@ -1502,7 +1498,7 @@ mod tests { source_port: get_port_id(), source_channel: get_channel_id(), destination_port: counterparty.port_id().clone(), - destination_channel: counterparty.channel_id().unwrap().clone(), + destination_channel: *counterparty.channel_id().unwrap(), data: vec![0], timeout_height: Height::new(0, 100), timeout_timestamp, @@ -1519,24 +1515,24 @@ mod tests { let bytes = channel.encode_vec().expect("encoding failed"); write_log.write(&channel_key, bytes).expect("write failed"); // insert a commitment - let commitment = hash(&packet); + let commitment = handler::commitment(&packet); let commitment_key = commitment_key(&get_port_id(), &get_channel_id(), sequence); write_log - .write(&commitment_key, commitment.as_bytes().to_vec()) + .write(&commitment_key, commitment.into_vec()) .expect("write failed"); write_log.commit_tx(); write_log.commit_block(&mut storage).expect("commit failed"); // prepare data - let ack = PacketAck::default().encode_to_vec(); + let ack = PacketAck::result_success().encode_to_vec(); let proof_packet = CommitmentProofBytes::try_from(vec![0]).unwrap(); let proofs = Proofs::new(proof_packet, None, None, None, Height::new(0, 1)) .unwrap(); let msg = MsgAcknowledgement { packet, - acknowledgement: ack, + acknowledgement: ack.into(), proofs, signer: Signer::new("account0"), }; @@ -1610,18 +1606,14 @@ mod tests { let counterparty = get_channel_counterparty(); let packet = packet_from_message(&msg, sequence, &counterparty); // insert a commitment - let commitment = hash(&packet); + let commitment = handler::commitment(&packet); let commitment_key = commitment_key( &packet.source_port, &packet.source_channel, sequence, ); - let mut commitment_bytes = vec![]; - commitment - .encode(&mut commitment_bytes) - .expect("encoding shouldn't fail"); write_log - .write(&commitment_key, commitment_bytes) + .write(&commitment_key, commitment.into_vec()) .expect("write failed"); let event = make_send_packet_event(packet); write_log.set_ibc_event(event.try_into().unwrap()); @@ -1675,7 +1667,7 @@ mod tests { let packet = Packet { sequence: Sequence::from(1), source_port: counterparty.port_id().clone(), - source_channel: counterparty.channel_id().unwrap().clone(), + source_channel: *counterparty.channel_id().unwrap(), destination_port: get_port_id(), destination_channel: get_channel_id(), data: vec![0], @@ -1706,7 +1698,7 @@ mod tests { &msg.packet.destination_channel, msg.packet.sequence, ); - let ack = PacketAck::default().encode_to_vec(); + let ack = PacketAck::result_success().encode_to_vec(); write_log.write(&ack_key, ack).expect("write failed"); write_log.commit_tx(); @@ -1747,7 +1739,7 @@ mod tests { .expect("write failed"); let ack_key = ack_key(&get_port_id(), &get_channel_id(), Sequence::from(1)); - let ack = PacketAck::default().encode_to_vec(); + let ack = PacketAck::result_success().encode_to_vec(); write_log.write(&ack_key, ack).expect("write failed"); write_log.commit_tx(); diff --git a/shared/src/ledger/ibc/vp/packet.rs b/shared/src/ledger/ibc/vp/packet.rs index 9d1b344e98..7c0e6d3992 100644 --- a/shared/src/ledger/ibc/vp/packet.rs +++ b/shared/src/ledger/ibc/vp/packet.rs @@ -3,7 +3,7 @@ use thiserror::Error; use super::super::handler::{ - make_send_packet_event, make_timeout_event, packet_from_message, + self, make_send_packet_event, make_timeout_event, packet_from_message, }; use super::super::storage::{ port_channel_sequence_id, Error as IbcStorageError, @@ -13,6 +13,7 @@ use crate::ibc::core::ics02_client::height::Height; use crate::ibc::core::ics04_channel::channel::{ ChannelEnd, Counterparty, Order, State, }; +use crate::ibc::core::ics04_channel::commitment::PacketCommitment; use crate::ibc::core::ics04_channel::context::ChannelReader; use crate::ibc::core::ics04_channel::error::Error as Ics04Error; use crate::ibc::core::ics04_channel::handler::verify::{ @@ -20,7 +21,9 @@ use crate::ibc::core::ics04_channel::handler::verify::{ verify_packet_acknowledgement_proofs, verify_packet_receipt_absence, verify_packet_recv_proofs, }; -use crate::ibc::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; +use crate::ibc::core::ics04_channel::msgs::acknowledgement::{ + Acknowledgement, MsgAcknowledgement, +}; use crate::ibc::core::ics04_channel::msgs::recv_packet::MsgRecvPacket; use crate::ibc::core::ics04_channel::msgs::PacketMsg; use crate::ibc::core::ics04_channel::packet::{Packet, Sequence}; @@ -92,10 +95,7 @@ where let msg = ibc_msg.msg_transfer()?; // make a packet let channel = self - .channel_end(&( - commitment_key.0.clone(), - commitment_key.1.clone(), - )) + .channel_end(&(commitment_key.0.clone(), commitment_key.1)) .map_err(|e| Error::InvalidChannel(e.to_string()))?; let packet = packet_from_message( &msg, @@ -125,10 +125,7 @@ where StateChange::Deleted => { // check the channel state let channel = self - .channel_end(&( - commitment_key.0.clone(), - commitment_key.1.clone(), - )) + .channel_end(&(commitment_key.0.clone(), commitment_key.1)) .map_err(|_| { Error::InvalidChannel(format!( "The channel doesn't exist: Port {}, Channel {}", @@ -206,7 +203,7 @@ where // The receipt should have been stored self.get_packet_receipt(&( ack_key.0.clone(), - ack_key.1.clone(), + ack_key.1, ack_key.2, )) .map_err(|_| { @@ -273,7 +270,7 @@ where })?; let port_channel_id = PortChannelId { port_id: port_channel_seq_id.0.clone(), - channel_id: port_channel_seq_id.1.clone(), + channel_id: port_channel_seq_id.1, }; self.verify_recv_proof( &port_channel_id, @@ -303,7 +300,7 @@ where let port_channel_id = PortChannelId { port_id: port_channel_seq_id.0.clone(), - channel_id: port_channel_seq_id.1.clone(), + channel_id: port_channel_seq_id.1, }; self.verify_ack_proof( &port_channel_id, @@ -333,7 +330,7 @@ where } PortChannelId { port_id: packet.source_port.clone(), - channel_id: packet.source_channel.clone(), + channel_id: packet.source_channel, } } Phase::Recv => { @@ -347,7 +344,7 @@ where } PortChannelId { port_id: packet.destination_port.clone(), - channel_id: packet.destination_channel.clone(), + channel_id: packet.destination_channel, } } }; @@ -364,7 +361,7 @@ where let channel = self .channel_end(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidChannel(format!( @@ -392,11 +389,11 @@ where let counterparty = match phase { Phase::Send | Phase::Ack => Counterparty::new( packet.destination_port.clone(), - Some(packet.destination_channel.clone()), + Some(packet.destination_channel), ), Phase::Recv => Counterparty::new( packet.source_port.clone(), - Some(packet.source_channel.clone()), + Some(packet.source_channel), ), }; if !channel.counterparty_matches(&counterparty) { @@ -438,13 +435,9 @@ where fn validate_packet_commitment( &self, packet: &Packet, - commitment: String, + commitment: PacketCommitment, ) -> Result<()> { - let input = format!( - "{:?},{:?},{:?}", - packet.timeout_timestamp, packet.timeout_height, packet.data, - ); - if commitment == self.hash(input) { + if commitment == handler::commitment(packet) { Ok(()) } else { Err(Error::InvalidPacket( @@ -463,7 +456,7 @@ where let channel = self .channel_end(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidChannel(format!( @@ -484,13 +477,13 @@ where port_channel_id: &PortChannelId, height: Height, packet: &Packet, - ack: Vec, + ack: Acknowledgement, proofs: &Proofs, ) -> Result<()> { let channel = self .channel_end(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidChannel(format!( @@ -552,12 +545,12 @@ where // the counterparty should be equal to that of the channel let port_channel_id = PortChannelId { port_id: packet.source_port.clone(), - channel_id: packet.source_channel.clone(), + channel_id: packet.source_channel, }; let channel = self .channel_end(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidChannel(format!( @@ -567,7 +560,7 @@ where })?; let counterparty = Counterparty::new( packet.destination_port.clone(), - Some(packet.destination_channel.clone()), + Some(packet.destination_channel), ); if !channel.counterparty_matches(&counterparty) { return Err(Error::InvalidPacket(format!( @@ -589,7 +582,7 @@ where // check that the counterpart channel has been closed let expected_my_side = Counterparty::new( packet.source_port.clone(), - Some(packet.source_channel.clone()), + Some(packet.source_channel), ); let counterparty = connection.counterparty(); let conn_id = diff --git a/shared/src/ledger/ibc/vp/port.rs b/shared/src/ledger/ibc/vp/port.rs index 2819cdeab5..da5ef4e25f 100644 --- a/shared/src/ledger/ibc/vp/port.rs +++ b/shared/src/ledger/ibc/vp/port.rs @@ -9,10 +9,13 @@ use super::super::storage::{ }; use super::{Ibc, StateChange}; use crate::ibc::core::ics04_channel::context::ChannelReader; -use crate::ibc::core::ics05_port::capabilities::{Capability, CapabilityName}; +use crate::ibc::core::ics05_port::capabilities::{ + Capability, CapabilityName, PortCapability, +}; use crate::ibc::core::ics05_port::context::{CapabilityReader, PortReader}; use crate::ibc::core::ics05_port::error::Error as Ics05Error; use crate::ibc::core::ics24_host::identifier::PortId; +use crate::ibc::core::ics26_routing::context::ModuleId; use crate::ledger::storage::{self as ledger_storage, StorageHasher}; use crate::types::storage::Key; use crate::vm::WasmCacheAccess; @@ -35,6 +38,8 @@ pub type Result = std::result::Result; /// ConnectionReader result type Ics05Result = core::result::Result; +const MODULE_ID: &str = "ledger"; + impl<'a, DB, H, CA> Ibc<'a, DB, H, CA> where DB: 'static + ledger_storage::DB + for<'iter> ledger_storage::DBIter<'iter>, @@ -84,14 +89,13 @@ where let cap = capability(key)?; let port_id = self.get_port_by_capability(&cap)?; match self.lookup_module_by_port(&port_id) { - Ok((_, c)) if c == cap => Ok(()), + Ok((_, c)) if c == cap.into() => Ok(()), Ok(_) => Err(Error::InvalidPort(format!( "The port is invalid: ID {}", port_id ))), Err(_) => Err(Error::NoCapability(format!( - "The capability is not mapped: Index {}, Port {}", - cap.index(), + "The capability is not mapped: Port {}", port_id ))), } @@ -154,12 +158,10 @@ where H: 'static + StorageHasher, CA: 'static + WasmCacheAccess, { - type ModuleId = (); - fn lookup_module_by_port( &self, port_id: &PortId, - ) -> Ics05Result<(Self::ModuleId, Capability)> { + ) -> Ics05Result<(ModuleId, PortCapability)> { let key = port_key(port_id); match self.ctx.read_post(&key) { Ok(Some(value)) => { @@ -167,7 +169,9 @@ where .try_into() .map_err(|_| Ics05Error::implementation_specific())?; let index = u64::from_be_bytes(index); - Ok(((), Capability::from(index))) + let module_id = ModuleId::new(MODULE_ID.into()) + .expect("Creating the module ID shouldn't fail"); + Ok((module_id, Capability::from(index).into())) } Ok(None) => Err(Ics05Error::unknown_port(port_id.clone())), Err(_) => Err(Ics05Error::implementation_specific()), @@ -184,7 +188,7 @@ where fn get_capability(&self, name: &CapabilityName) -> Ics05Result { let port_id = get_port_id(name)?; let (_, capability) = self.lookup_module_by_port(&port_id)?; - Ok(capability) + Ok(capability.into()) } fn authenticate_capability( diff --git a/shared/src/ledger/ibc/vp/sequence.rs b/shared/src/ledger/ibc/vp/sequence.rs index 166de408c6..0e751ea0de 100644 --- a/shared/src/ledger/ibc/vp/sequence.rs +++ b/shared/src/ledger/ibc/vp/sequence.rs @@ -53,7 +53,7 @@ where let channel = self .channel_end(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|e| Error::InvalidChannel(e.to_string()))?; let next_seq_pre = self @@ -64,7 +64,7 @@ where let next_seq = self .get_next_sequence_send(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidSequence( @@ -116,7 +116,7 @@ where let next_seq = self .get_next_sequence_recv(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidSequence( @@ -174,7 +174,7 @@ where let next_seq = self .get_next_sequence_ack(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidSequence( @@ -218,7 +218,7 @@ where let channel = self .channel_end(&( port_channel_id.port_id.clone(), - port_channel_id.channel_id.clone(), + port_channel_id.channel_id, )) .map_err(|_| { Error::InvalidChannel(format!( diff --git a/shared/src/ledger/ibc/vp/token.rs b/shared/src/ledger/ibc/vp/token.rs index f56382b360..4de506784f 100644 --- a/shared/src/ledger/ibc/vp/token.rs +++ b/shared/src/ledger/ibc/vp/token.rs @@ -10,6 +10,7 @@ use crate::ibc::applications::ics20_fungible_token_transfer::msgs::transfer::Msg use crate::ibc::core::ics04_channel::msgs::PacketMsg; use crate::ibc::core::ics04_channel::packet::Packet; use crate::ibc::core::ics26_routing::msgs::Ics26Envelope; +use crate::ledger::ibc::storage as ibc_storage; use crate::ledger::native_vp::{self, Ctx, NativeVp}; use crate::ledger::storage::{self as ledger_storage, StorageHasher}; use crate::proto::SignedTxData; @@ -18,9 +19,7 @@ use crate::types::ibc::data::{ Error as IbcDataError, FungibleTokenPacketData, IbcMessage, }; use crate::types::storage::Key; -use crate::types::token::{ - self, is_non_owner_balance_key, Amount, AmountParseError, -}; +use crate::types::token::{self, Amount, AmountParseError}; use crate::vm::WasmCacheAccess; #[allow(missing_docs)] @@ -70,7 +69,7 @@ where { type Error = Error; - const ADDR: InternalAddress = InternalAddress::IbcBurn; + const ADDR: InternalAddress = InternalAddress::IbcEscrow; fn validate_tx( &self, @@ -82,14 +81,30 @@ where SignedTxData::try_from_slice(tx_data).map_err(Error::Decoding)?; let tx_data = &signed.data.ok_or(Error::NoTxData)?; - // Check the non-onwer balance updates + // Check the special IBC account updates let keys_changed: HashSet = keys_changed .iter() - .filter(|k| is_non_owner_balance_key(k).is_some()) + .filter(|k| { + matches!( + token::is_any_multitoken_balance_key(k), + Some((_, Address::Internal(InternalAddress::IbcEscrow))) + | Some(( + _, + Address::Internal(InternalAddress::IbcBurn) + )) + | Some(( + _, + Address::Internal(InternalAddress::IbcMint) + )) + ) + }) .cloned() .collect(); - if keys_changed.len() != 1 { - // a transaction can update at most 1 non-owner balance for now + if keys_changed.is_empty() { + // no account is checked by this VP + return Ok(true); + } else if keys_changed.len() > 1 { + // a transaction can update at most 1 special IBC account for now return Err(Error::TokenTransfer( "Invalid transfer for multiple non-owner balances".to_owned(), )); @@ -102,6 +117,9 @@ where Ics26Envelope::Ics4PacketMsg(PacketMsg::RecvPacket(msg)) => { self.validate_receiving_token(&msg.packet) } + Ics26Envelope::Ics4PacketMsg(PacketMsg::AckPacket(msg)) => { + self.validate_refunding_token(&msg.packet) + } Ics26Envelope::Ics4PacketMsg(PacketMsg::ToPacket(msg)) => { self.validate_refunding_token(&msg.packet) } @@ -121,21 +139,27 @@ where { fn validate_sending_token(&self, msg: &MsgTransfer) -> Result { let data = FungibleTokenPacketData::from(msg.clone()); - let token_str = - data.denomination.split('/').last().ok_or(Error::NoToken)?; + let token_str = data.denom.split('/').last().ok_or(Error::NoToken)?; let token = Address::decode(token_str).map_err(Error::Address)?; let amount = Amount::from_str(&data.amount).map_err(Error::Amount)?; - // check the denomination field + // check the denom field let prefix = format!( "{}/{}/", msg.source_port.clone(), msg.source_channel.clone() ); - let change = if data.denomination.starts_with(&prefix) { + let key_prefix = ibc_storage::ibc_token_prefix( + &msg.source_port, + &msg.source_channel, + &token, + ); + let change = if data.denom.starts_with(&prefix) { // sink zone - let target = Address::Internal(InternalAddress::IbcBurn); - let target_key = token::balance_key(&token, &target); + let target_key = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcBurn), + ); let post = try_decode_token_amount(self.ctx.read_temp(&target_key)?)? .unwrap_or_default(); @@ -143,12 +167,10 @@ where post.change() } else { // source zone - let target = - Address::Internal(InternalAddress::ibc_escrow_address( - msg.source_port.to_string(), - msg.source_channel.to_string(), - )); - let target_key = token::balance_key(&token, &target); + let target_key = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcEscrow), + ); let pre = try_decode_token_amount(self.ctx.read_pre(&target_key)?)? .unwrap_or_default(); let post = @@ -171,8 +193,7 @@ where let data: FungibleTokenPacketData = serde_json::from_slice(&packet.data) .map_err(Error::DecodingPacketData)?; - let token_str = - data.denomination.split('/').last().ok_or(Error::NoToken)?; + let token_str = data.denom.split('/').last().ok_or(Error::NoToken)?; let token = Address::decode(token_str).map_err(Error::Address)?; let amount = Amount::from_str(&data.amount).map_err(Error::Amount)?; @@ -181,14 +202,17 @@ where packet.source_port.clone(), packet.source_channel.clone() ); - let change = if data.denomination.starts_with(&prefix) { + let key_prefix = ibc_storage::ibc_token_prefix( + &packet.source_port, + &packet.source_channel, + &token, + ); + let change = if data.denom.starts_with(&prefix) { // this chain is the source - let source = - Address::Internal(InternalAddress::ibc_escrow_address( - packet.destination_port.to_string(), - packet.destination_channel.to_string(), - )); - let source_key = token::balance_key(&token, &source); + let source_key = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcEscrow), + ); let pre = try_decode_token_amount(self.ctx.read_pre(&source_key)?)? .unwrap_or_default(); let post = @@ -197,8 +221,10 @@ where pre.change() - post.change() } else { // the sender is the source - let source = Address::Internal(InternalAddress::IbcMint); - let source_key = token::balance_key(&token, &source); + let source_key = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcMint), + ); let post = try_decode_token_amount(self.ctx.read_temp(&source_key)?)? .unwrap_or_default(); @@ -220,21 +246,27 @@ where let data: FungibleTokenPacketData = serde_json::from_slice(&packet.data) .map_err(Error::DecodingPacketData)?; - let token_str = - data.denomination.split('/').last().ok_or(Error::NoToken)?; + let token_str = data.denom.split('/').last().ok_or(Error::NoToken)?; let token = Address::decode(token_str).map_err(Error::Address)?; let amount = Amount::from_str(&data.amount).map_err(Error::Amount)?; - // check the denomination field + // check the denom field let prefix = format!( "{}/{}/", packet.source_port.clone(), packet.source_channel.clone() ); - let change = if data.denomination.starts_with(&prefix) { + let key_prefix = ibc_storage::ibc_token_prefix( + &packet.source_port, + &packet.source_channel, + &token, + ); + let change = if data.denom.starts_with(&prefix) { // sink zone: mint the token for the refund - let source = Address::Internal(InternalAddress::IbcMint); - let source_key = token::balance_key(&token, &source); + let source_key = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcMint), + ); let post = try_decode_token_amount(self.ctx.read_temp(&source_key)?)? .unwrap_or_default(); @@ -242,12 +274,10 @@ where Amount::max().change() - post.change() } else { // source zone: unescrow the token for the refund - let source = - Address::Internal(InternalAddress::ibc_escrow_address( - packet.source_port.to_string(), - packet.source_channel.to_string(), - )); - let source_key = token::balance_key(&token, &source); + let source_key = token::multitoken_balance_key( + &key_prefix, + &Address::Internal(InternalAddress::IbcEscrow), + ); let pre = try_decode_token_amount(self.ctx.read_pre(&source_key)?)? .unwrap_or_default(); let post = diff --git a/shared/src/types/address.rs b/shared/src/types/address.rs index 704dcdbdb2..6839ccc4c7 100644 --- a/shared/src/types/address.rs +++ b/shared/src/types/address.rs @@ -53,20 +53,22 @@ mod internal { "ano::Proof of Stake "; pub const POS_SLASH_POOL: &str = "ano::Proof of Stake Slash Pool "; - pub const IBC: &str = - "ano::Inter-Blockchain Communication "; pub const PARAMETERS: &str = "ano::Protocol Parameters "; pub const GOVERNANCE: &str = "ano::Governance "; pub const TREASURY: &str = "ano::Treasury "; - pub const IBC_BURN: &str = - "ano::IBC Burn Address "; - pub const IBC_MINT: &str = - "ano::IBC Mint Address "; pub const ETH_BRIDGE: &str = "ano::ETH Bridge Address "; + pub const IBC: &str = + "ibc::Inter-Blockchain Communication "; + pub const IBC_ESCROW: &str = + "ibc::IBC Escrow Address "; + pub const IBC_BURN: &str = + "ibc::IBC Burn Address "; + pub const IBC_MINT: &str = + "ibc::IBC Mint Address "; } /// Fixed-length address strings prefix for established addresses. @@ -75,6 +77,8 @@ const PREFIX_ESTABLISHED: &str = "est"; const PREFIX_IMPLICIT: &str = "imp"; /// Fixed-length address strings prefix for internal addresses. const PREFIX_INTERNAL: &str = "ano"; +/// Fixed-length address strings prefix for IBC addresses. +const PREFIX_IBC: &str = "ibc"; #[allow(missing_docs)] #[derive(Error, Debug)] @@ -178,7 +182,6 @@ impl Address { InternalAddress::PosSlashPool => { internal::POS_SLASH_POOL.to_string() } - InternalAddress::Ibc => internal::IBC.to_string(), InternalAddress::Parameters => { internal::PARAMETERS.to_string() } @@ -186,8 +189,12 @@ impl Address { internal::GOVERNANCE.to_string() } InternalAddress::Treasury => internal::TREASURY.to_string(), - InternalAddress::IbcEscrow(hash) => { - format!("{}::{}", PREFIX_INTERNAL, hash) + InternalAddress::Ibc => internal::IBC.to_string(), + InternalAddress::IbcToken(hash) => { + format!("{}::{}", PREFIX_IBC, hash) + } + InternalAddress::IbcEscrow => { + internal::IBC_ESCROW.to_string() } InternalAddress::IbcBurn => internal::IBC_BURN.to_string(), InternalAddress::IbcMint => internal::IBC_MINT.to_string(), @@ -230,36 +237,45 @@ impl Address { .map_err(|err| Error::new(ErrorKind::InvalidData, err))?; Ok(Address::Implicit(ImplicitAddress(pkh))) } - Some((PREFIX_INTERNAL, raw)) => match string { + Some((PREFIX_INTERNAL, _)) => match string { internal::POS => Ok(Address::Internal(InternalAddress::PoS)), internal::POS_SLASH_POOL => { Ok(Address::Internal(InternalAddress::PosSlashPool)) } - internal::IBC => Ok(Address::Internal(InternalAddress::Ibc)), internal::PARAMETERS => { Ok(Address::Internal(InternalAddress::Parameters)) } - internal::IBC_BURN => { - Ok(Address::Internal(InternalAddress::IbcBurn)) - } internal::GOVERNANCE => { Ok(Address::Internal(InternalAddress::Governance)) } internal::TREASURY => { Ok(Address::Internal(InternalAddress::Treasury)) } - internal::IBC_MINT => { - Ok(Address::Internal(InternalAddress::IbcMint)) - } internal::ETH_BRIDGE => { Ok(Address::Internal(InternalAddress::EthBridge)) } + _ => Err(Error::new( + ErrorKind::InvalidData, + "Invalid internal address", + )), + }, + Some((PREFIX_IBC, raw)) => match string { + internal::IBC => Ok(Address::Internal(InternalAddress::Ibc)), + internal::IBC_ESCROW => { + Ok(Address::Internal(InternalAddress::IbcEscrow)) + } + internal::IBC_BURN => { + Ok(Address::Internal(InternalAddress::IbcBurn)) + } + internal::IBC_MINT => { + Ok(Address::Internal(InternalAddress::IbcMint)) + } _ if raw.len() == HASH_LEN => Ok(Address::Internal( - InternalAddress::IbcEscrow(raw.to_string()), + InternalAddress::IbcToken(raw.to_string()), )), _ => Err(Error::new( ErrorKind::InvalidData, - "Invalid internal address", + "Invalid IBC internal address", )), }, _ => Err(Error::new( @@ -435,12 +451,14 @@ pub enum InternalAddress { PoS, /// Proof-of-stake slash pool contains slashed tokens PosSlashPool, - /// Inter-blockchain communication - Ibc, /// Protocol parameters Parameters, + /// Inter-blockchain communication + Ibc, + /// IBC-related token + IbcToken(String), /// Escrow for IBC token transfer - IbcEscrow(String), + IbcEscrow, /// Burn tokens with IBC token transfer IbcBurn, /// Mint tokens from this address with IBC token transfer @@ -455,12 +473,16 @@ pub enum InternalAddress { impl InternalAddress { /// Get an escrow address from the port ID and channel ID - pub fn ibc_escrow_address(port_id: String, channel_id: String) -> Self { + pub fn ibc_token_address( + port_id: String, + channel_id: String, + token: &Address, + ) -> Self { let mut hasher = Sha256::new(); - let s = format!("{}/{}", port_id, channel_id); + let s = format!("{}/{}/{}", port_id, channel_id, token); hasher.update(&s); - let hash = format!("{:.width$X}", hasher.finalize(), width = HASH_LEN); - InternalAddress::IbcEscrow(hash) + let hash = format!("{:.width$x}", hasher.finalize(), width = HASH_LEN); + InternalAddress::IbcToken(hash) } } @@ -472,11 +494,12 @@ impl Display for InternalAddress { match self { Self::PoS => "PoS".to_string(), Self::PosSlashPool => "PosSlashPool".to_string(), - Self::Ibc => "IBC".to_string(), Self::Parameters => "Parameters".to_string(), Self::Governance => "Governance".to_string(), Self::Treasury => "Treasury".to_string(), - Self::IbcEscrow(hash) => format!("IbcEscrow: {}", hash), + Self::Ibc => "IBC".to_string(), + Self::IbcToken(hash) => format!("IbcToken: {}", hash), + Self::IbcEscrow => "IbcEscrow".to_string(), Self::IbcBurn => "IbcBurn".to_string(), Self::IbcMint => "IbcMint".to_string(), Self::EthBridge => "EthBridge".to_string(), @@ -710,11 +733,12 @@ pub mod testing { match InternalAddress::PoS { InternalAddress::PoS => {} InternalAddress::PosSlashPool => {} - InternalAddress::Ibc => {} InternalAddress::Governance => {} InternalAddress::Treasury => {} InternalAddress::Parameters => {} - InternalAddress::IbcEscrow(_) => {} + InternalAddress::Ibc => {} + InternalAddress::IbcToken(_) => {} + InternalAddress::IbcEscrow => {} InternalAddress::IbcBurn => {} InternalAddress::IbcMint => {} InternalAddress::EthBridge => {} /* Add new addresses in the @@ -723,10 +747,12 @@ pub mod testing { prop_oneof![ Just(InternalAddress::PoS), Just(InternalAddress::PosSlashPool), - Just(InternalAddress::Ibc), Just(InternalAddress::Parameters), - arb_port_channel_id() - .prop_map(|(p, c)| InternalAddress::ibc_escrow_address(p, c)), + Just(InternalAddress::Ibc), + arb_port_channel_id().prop_map(|(p, c)| { + InternalAddress::ibc_token_address(p, c, &xan()) + }), + Just(InternalAddress::IbcEscrow), Just(InternalAddress::IbcBurn), Just(InternalAddress::IbcMint), Just(InternalAddress::Governance), diff --git a/shared/src/types/ibc/data.rs b/shared/src/types/ibc/data.rs index 4a9cdd41c6..947142ab97 100644 --- a/shared/src/types/ibc/data.rs +++ b/shared/src/types/ibc/data.rs @@ -3,7 +3,6 @@ use std::convert::TryFrom; use std::fmt::{self, Display, Formatter}; use prost::Message; -use prost_types::Any; use thiserror::Error; use crate::ibc::applications::ics20_fungible_token_transfer::msgs::transfer::MsgTransfer; @@ -17,7 +16,9 @@ use crate::ibc::core::ics03_connection::msgs::conn_open_confirm::MsgConnectionOp use crate::ibc::core::ics03_connection::msgs::conn_open_init::MsgConnectionOpenInit; use crate::ibc::core::ics03_connection::msgs::conn_open_try::MsgConnectionOpenTry; use crate::ibc::core::ics03_connection::msgs::ConnectionMsg; -use crate::ibc::core::ics04_channel::msgs::acknowledgement::MsgAcknowledgement; +use crate::ibc::core::ics04_channel::msgs::acknowledgement::{ + Acknowledgement, MsgAcknowledgement, +}; use crate::ibc::core::ics04_channel::msgs::chan_close_confirm::MsgChannelCloseConfirm; use crate::ibc::core::ics04_channel::msgs::chan_close_init::MsgChannelCloseInit; use crate::ibc::core::ics04_channel::msgs::chan_open_ack::MsgChannelOpenAck; @@ -32,14 +33,15 @@ use crate::ibc::core::ics04_channel::packet::Receipt; use crate::ibc::core::ics26_routing::error::Error as Ics26Error; use crate::ibc::core::ics26_routing::msgs::Ics26Envelope; use crate::ibc::downcast; -use crate::ibc_proto::ibc::core::channel::v1::acknowledgement::Response; -use crate::ibc_proto::ibc::core::channel::v1::Acknowledgement; +use crate::ibc_proto::google::protobuf::Any; #[allow(missing_docs)] #[derive(Error, Debug)] pub enum Error { #[error("Decoding IBC data error: {0}")] DecodingData(prost::DecodeError), + #[error("Decoding Json data error: {0}")] + DecodingJsonData(serde_json::Error), #[error("Decoding message error: {0}")] DecodingMessage(Ics26Error), #[error("Downcast error: {0}")] @@ -326,39 +328,70 @@ impl Default for PacketReceipt { } /// Acknowledgement for a packet -#[derive(Clone, Debug)] -pub struct PacketAck(pub Acknowledgement); +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum PacketAck { + /// Success Acknowledgement + Result(String), + /// Error Acknowledgement + Error(String), +} + +/// Success acknowledgement +const ACK_SUCCESS_B64: &str = "AQ=="; +/// Error acknowledgement +const ACK_ERR_STR: &str = + "error handling packet on destination chain: see events for details"; // TODO temporary type. add a new type for ack to ibc-rs impl PacketAck { + /// Success acknowledgement + pub fn result_success() -> Self { + Self::Result(ACK_SUCCESS_B64.to_string()) + } + + /// Acknowledgement with an error + pub fn result_error(err: String) -> Self { + Self::Error(format!("{}: {}", ACK_ERR_STR, err)) + } + + /// Check if the ack is for success + pub fn is_success(&self) -> bool { + match self { + Self::Result(_) => true, + Self::Error(_) => false, + } + } + /// Encode the ack pub fn encode_to_vec(&self) -> Vec { - // TODO encode as ibc-go - self.to_string().as_bytes().to_vec() + serde_json::to_vec(&self) + .expect("Encoding acknowledgement shouldn't fail") } } -impl Default for PacketAck { - fn default() -> Self { - Self(Acknowledgement { - response: Some(Response::Result(vec![1_u8])), - }) +impl TryFrom for PacketAck { + type Error = Error; + + fn try_from(ack: Acknowledgement) -> Result { + serde_json::from_slice(&ack.into_bytes()) + .map_err(Error::DecodingJsonData) } } // for the string to be used by the current reader impl Display for PacketAck { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "ack") + write!(f, "{}", serde_json::to_string(&self).unwrap()) } } -// TODO temporary type. add a new type for ack to ibc-rs +// TODO temporary type. add a new type for packet data to ibc-rs /// Data to transfer a token #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct FungibleTokenPacketData { /// the token denomination to be transferred - pub denomination: String, + pub denom: String, /// the token amount to be transferred pub amount: String, /// the sender address @@ -372,7 +405,7 @@ impl From for FungibleTokenPacketData { // TODO validation let token = msg.token.unwrap(); Self { - denomination: token.denom, + denom: token.denom, amount: token.amount, sender: msg.sender.to_string(), receiver: msg.receiver.to_string(), diff --git a/shared/src/types/intent.rs b/shared/src/types/intent.rs index c3effbb4fc..3acb43f0c0 100644 --- a/shared/src/types/intent.rs +++ b/shared/src/types/intent.rs @@ -316,12 +316,14 @@ mod tests { source: bertha_addr.clone(), target: albert_addr.clone(), token: Address::from_str(BTC).unwrap(), + sub_prefix: None, amount: token::Amount::from(100), }, token::Transfer { source: albert_addr, target: bertha_addr, token: Address::from_str(XAN).unwrap(), + sub_prefix: None, amount: token::Amount::from(1), }, ] @@ -424,12 +426,14 @@ mod tests { source: bertha_addr.clone(), target: albert_addr.clone(), token: Address::from_str(BTC).unwrap(), + sub_prefix: None, amount: token::Amount::from(100), }, token::Transfer { source: albert_addr, target: bertha_addr, token: Address::from_str(XAN).unwrap(), + sub_prefix: None, amount: token::Amount::from(1), }, ] diff --git a/shared/src/types/token.rs b/shared/src/types/token.rs index f3e4cd4ed2..733de49edf 100644 --- a/shared/src/types/token.rs +++ b/shared/src/types/token.rs @@ -1,6 +1,5 @@ //! A basic fungible token -use std::convert::TryFrom; use std::fmt::Display; use std::ops::{Add, AddAssign, Mul, Sub, SubAssign}; use std::str::FromStr; @@ -9,8 +8,7 @@ use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::types::address::{Address, Error as AddressError, InternalAddress}; -use crate::types::ibc::data::FungibleTokenPacketData; +use crate::types::address::{Address, Error as AddressError}; use crate::types::storage::{DbKeySeg, Key, KeySeg}; /// Amount in micro units. For different granularity another representation @@ -250,6 +248,23 @@ pub fn balance_prefix(token_addr: &Address) -> Key { .expect("Cannot obtain a storage key") } +/// Obtain a storage key prefix for multitoken balances. +pub fn multitoken_balance_prefix( + token_addr: &Address, + sub_prefix: &Key, +) -> Key { + Key::from(token_addr.to_db_key()).join(sub_prefix) +} + +/// Obtain a storage key for user's multitoken balance. +pub fn multitoken_balance_key(prefix: &Key, owner: &Address) -> Key { + prefix + .push(&BALANCE_STORAGE_KEY.to_owned()) + .expect("Cannot obtain a storage key") + .push(&owner.to_db_key()) + .expect("Cannot obtain a storage key") +} + /// Check if the given storage key is balance key for the given token. If it is, /// returns the owner. pub fn is_balance_key<'a>( @@ -279,20 +294,50 @@ pub fn is_any_token_balance_key(key: &Key) -> Option<&Address> { } } -/// Check if the given storage key is non-owner's balance key. If it is, returns -/// the address. -pub fn is_non_owner_balance_key(key: &Key) -> Option<&Address> { - match &key.segments[..] { - [ - DbKeySeg::AddressSeg(_), - DbKeySeg::StringSeg(key), - DbKeySeg::AddressSeg(owner), - ] if key == BALANCE_STORAGE_KEY => match owner { - Address::Internal(InternalAddress::IbcEscrow(_)) - | Address::Internal(InternalAddress::IbcBurn) - | Address::Internal(InternalAddress::IbcMint) => Some(owner), - _ => None, - }, +/// Check if the given storage key is multitoken balance key for the given +/// token. If it is, returns the sub prefix and the owner. +pub fn is_multitoken_balance_key<'a>( + token_addr: &Address, + key: &'a Key, +) -> Option<(Key, &'a Address)> { + match key.segments.first() { + Some(DbKeySeg::AddressSeg(addr)) if addr == token_addr => { + multitoken_balance_owner(key) + } + _ => None, + } +} + +/// Check if the given storage key is multitoken balance key for unspecified +/// token. If it is, returns the sub prefix and the owner. +pub fn is_any_multitoken_balance_key(key: &Key) -> Option<(Key, &Address)> { + match key.segments.first() { + Some(DbKeySeg::AddressSeg(_)) => multitoken_balance_owner(key), + _ => None, + } +} + +fn multitoken_balance_owner(key: &Key) -> Option<(Key, &Address)> { + let len = key.segments.len(); + if len < 4 { + // the key of a multitoken should have 1 or more segments other than + // token, balance, owner + return None; + } + match key.get_at(len - 2) { + Some(DbKeySeg::StringSeg(balance)) + if balance == BALANCE_STORAGE_KEY => + { + match key.segments.last() { + Some(DbKeySeg::AddressSeg(owner)) => { + let sub_prefix = Key { + segments: key.segments[1..(len - 2)].to_vec(), + }; + Some((sub_prefix, owner)) + } + _ => None, + } + } _ => None, } } @@ -318,6 +363,8 @@ pub struct Transfer { pub target: Address, /// Token's address pub token: Address, + /// Source token's sub prefix + pub sub_prefix: Option, /// The amount of tokens pub amount: Amount, } @@ -333,32 +380,6 @@ pub enum TransferError { NoToken, } -impl TryFrom for Transfer { - type Error = TransferError; - - fn try_from(data: FungibleTokenPacketData) -> Result { - let source = - Address::decode(&data.sender).map_err(TransferError::Address)?; - let target = - Address::decode(&data.receiver).map_err(TransferError::Address)?; - let token_str = data - .denomination - .split('/') - .last() - .ok_or(TransferError::NoToken)?; - let token = - Address::decode(token_str).map_err(TransferError::Address)?; - let amount = - Amount::from_str(&data.amount).map_err(TransferError::Amount)?; - Ok(Self { - source, - target, - token, - amount, - }) - } -} - #[cfg(test)] mod tests { use proptest::prelude::*; diff --git a/tests/src/e2e/ledger_tests.rs b/tests/src/e2e/ledger_tests.rs index 33643bf0f0..e94117fb4c 100644 --- a/tests/src/e2e/ledger_tests.rs +++ b/tests/src/e2e/ledger_tests.rs @@ -440,6 +440,7 @@ fn invalid_transactions() -> Result<()> { source: find_address(&test, DAEWON)?, target: find_address(&test, ALBERT)?, token: find_address(&test, XAN)?, + sub_prefix: None, amount: token::Amount::whole(1), }; let data = transfer diff --git a/tests/src/vm_host_env/ibc.rs b/tests/src/vm_host_env/ibc.rs index 8ac4fe16f9..1c2411ddf2 100644 --- a/tests/src/vm_host_env/ibc.rs +++ b/tests/src/vm_host_env/ibc.rs @@ -63,7 +63,7 @@ use anoma::ledger::storage::Sha256Hasher; use anoma::proto::Tx; use anoma::tendermint_proto::Protobuf; use anoma::types::address::{self, Address, InternalAddress}; -use anoma::types::ibc::data::FungibleTokenPacketData; +use anoma::types::ibc::data::{FungibleTokenPacketData, PacketAck}; use anoma::types::ibc::IbcEvent; use anoma::types::storage::{BlockHash, BlockHeight, Key}; use anoma::types::time::Rfc3339String; @@ -128,37 +128,51 @@ impl IbcActions for TestIbcActions { tx_host_env::emit_ibc_event(&event) } - fn transfer_token( - &self, - src: &Address, - dest: &Address, - token: &Address, - amount: Amount, - ) { - let src_key = token::balance_key(token, src); - let dest_key = token::balance_key(token, dest); - let src_bal: Option = tx_host_env::read(&src_key.to_string()); - let mut src_bal = src_bal.unwrap_or_else(|| match src { - Address::Internal(InternalAddress::IbcMint) => Amount::max(), - _ => unreachable!(), - }); + fn transfer_token(&self, src: &Key, dest: &Key, amount: Amount) { + let src_owner = + token::is_any_multitoken_balance_key(src).map(|(_, o)| o); + let src_bal: Option = match src_owner { + Some(Address::Internal(InternalAddress::IbcMint)) => { + Some(Amount::max()) + } + Some(Address::Internal(InternalAddress::IbcBurn)) => { + unreachable!() + } + Some(_) => tx_host_env::read(&src.to_string()), + None => { + // the key is not multitoken key + match token::is_any_token_balance_key(src) { + Some(_) => tx_host_env::read(src.to_string()), + None => unreachable!(), + } + } + }; + let mut src_bal = src_bal.unwrap(); src_bal.spend(&amount); - let mut dest_bal: Amount = - tx_host_env::read(&dest_key.to_string()).unwrap_or_default(); + let dest_owner = + token::is_any_multitoken_balance_key(dest).map(|(_, o)| o); + let mut dest_bal: Amount = match dest_owner { + Some(Address::Internal(InternalAddress::IbcMint)) => unreachable!(), + Some(_) => tx_host_env::read(dest.to_string()).unwrap_or_default(), + None => match token::is_any_token_balance_key(dest) { + Some(_) => { + tx_host_env::read(dest.to_string()).unwrap_or_default() + } + None => unreachable!(), + }, + }; dest_bal.receive(&amount); - match src { - Address::Internal(InternalAddress::IbcMint) => { - tx_host_env::write_temp(&src_key.to_string(), src_bal) + match src_owner { + Some(Address::Internal(InternalAddress::IbcMint)) => { + tx_host_env::write_temp(&src.to_string(), src_bal) } - Address::Internal(InternalAddress::IbcBurn) => unreachable!(), - _ => tx_host_env::write(&src_key.to_string(), src_bal), + _ => tx_host_env::write(&src.to_string(), src_bal), } - match dest { - Address::Internal(InternalAddress::IbcMint) => unreachable!(), - Address::Internal(InternalAddress::IbcBurn) => { - tx_host_env::write_temp(&dest_key.to_string(), dest_bal) + match dest_owner { + Some(Address::Internal(InternalAddress::IbcBurn)) => { + tx_host_env::write_temp(&dest.to_string(), dest_bal) } - _ => tx_host_env::write(&dest_key.to_string(), dest_bal), + _ => tx_host_env::write(&dest.to_string(), dest_bal), } } @@ -205,16 +219,16 @@ pub fn init_ibc_vp_from_tx<'a>( pub fn init_token_vp_from_tx<'a>( tx_env: &'a TestTxEnv, tx: &'a Tx, - addr: &Address, + target: &Key, ) -> (TestIbcTokenVp<'a>, TempDir) { - let (verifiers, keys_changed) = tx_env + let (_, keys_changed) = tx_env .write_log .verifiers_and_changed_keys(&tx_env.verifiers); - if !verifiers.contains(addr) { + if !keys_changed.contains(target) { panic!( - "The given token address {} isn't part of the tx verifiers set: \ + "The given target address {} isn't part of the tx verifiers set: \ {:#?}", - addr, verifiers + target, keys_changed, ); } let (vp_wasm_cache, vp_cache_dir) = @@ -326,7 +340,7 @@ pub fn prepare_opened_channel( writes.insert(key, bytes); // channel let channel_id = channel_id(0); - let port_channel_id = port_channel_id(port_id.clone(), channel_id.clone()); + let port_channel_id = port_channel_id(port_id.clone(), channel_id); let key = channel_key(&port_channel_id); let msg = msg_channel_open_init(port_id.clone(), conn_id.clone()); let mut channel = msg.channel; @@ -397,7 +411,7 @@ pub fn msg_connection_open_init(client_id: ClientId) -> MsgConnectionOpenInit { MsgConnectionOpenInit { client_id, counterparty: dummy_connection_counterparty(), - version: ConnVersion::default(), + version: None, delay_period: Duration::new(100, 0), signer: Signer::new("test"), } @@ -501,10 +515,9 @@ pub fn msg_channel_open_ack( MsgChannelOpenAck { port_id, channel_id, - counterparty_channel_id: dummy_channel_counterparty() + counterparty_channel_id: *dummy_channel_counterparty() .channel_id() - .unwrap() - .clone(), + .unwrap(), counterparty_version: ChanVersion::ics20(), proofs: dummy_proofs(), signer: Signer::new("test"), @@ -563,9 +576,8 @@ fn dummy_channel( pub fn dummy_channel_counterparty() -> ChanCounterparty { let counterpart_port_id = PortId::from_str("counterpart_test_port") .expect("Creating a port ID failed"); - let counterpart_channel_id = - ChannelId::from_str("counterpart_test_channel") - .expect("Creating a channel ID failed"); + let counterpart_channel_id = ChannelId::from_str("channel-42") + .expect("Creating a channel ID failed"); channel_counterparty(counterpart_port_id, counterpart_channel_id) } @@ -612,7 +624,7 @@ pub fn msg_packet_recv(packet: Packet) -> MsgRecvPacket { pub fn msg_packet_ack(packet: Packet) -> MsgAcknowledgement { MsgAcknowledgement { packet, - acknowledgement: vec![0], + acknowledgement: PacketAck::result_success().encode_to_vec().into(), proofs: dummy_proofs(), signer: Signer::new("test"), } @@ -629,7 +641,7 @@ pub fn received_packet( let timeout_timestamp = (Timestamp::now() + Duration::from_secs(100)).unwrap(); let data = FungibleTokenPacketData { - denomination: token, + denom: token, amount: 100u64.to_string(), sender: address::testing::gen_established_address().to_string(), receiver: receiver.to_string(), @@ -637,7 +649,7 @@ pub fn received_packet( Packet { sequence, source_port: counterparty.port_id().clone(), - source_channel: counterparty.channel_id().unwrap().clone(), + source_channel: *counterparty.channel_id().unwrap(), destination_port: port_id, destination_channel: channel_id, data: serde_json::to_vec(&data).unwrap(), diff --git a/tests/src/vm_host_env/mod.rs b/tests/src/vm_host_env/mod.rs index 70bc1efc0d..ec90278d8d 100644 --- a/tests/src/vm_host_env/mod.rs +++ b/tests/src/vm_host_env/mod.rs @@ -22,6 +22,7 @@ mod tests { use anoma::ibc::tx_msg::Msg; use anoma::ledger::ibc::handler::IbcActions; + use anoma::ledger::ibc::storage as ibc_storage; use anoma::ledger::ibc::vp::{ get_dummy_header as tm_dummy_header, Error as IbcError, }; @@ -885,7 +886,7 @@ mod tests { .expect("getting the counter failed"); // channel let channel_id = ibc::channel_id(counter); - let port_channel_id = ibc::port_channel_id(port_id, channel_id.clone()); + let port_channel_id = ibc::port_channel_id(port_id, channel_id); let channel_key = ibc::channel_key(&port_channel_id).to_string(); tx_host_env::write_bytes( &channel_key, @@ -932,7 +933,7 @@ mod tests { .expect("getting the counter failed"); // insert a opened channel let channel_id = ibc::channel_id(counter); - let port_channel_id = ibc::port_channel_id(port_id, channel_id.clone()); + let port_channel_id = ibc::port_channel_id(port_id, channel_id); let channel_key = ibc::channel_key(&port_channel_id).to_string(); let mut channel = msg.channel.clone(); ibc::open_channel(&mut channel); @@ -1215,11 +1216,14 @@ mod tests { .expect("validation failed unexpectedly") ); // Check if the token was escrowed - let escrow = address::Address::Internal( - address::InternalAddress::ibc_escrow_address( - msg.source_port.to_string(), - msg.source_channel.to_string(), - ), + let key_prefix = ibc_storage::ibc_token_prefix( + &msg.source_port, + &msg.source_channel, + &token, + ); + let escrow = token::multitoken_balance_key( + &key_prefix, + &address::Address::Internal(address::InternalAddress::IbcEscrow), ); let (token_vp, _) = ibc::init_token_vp_from_tx(&env, &tx, &escrow); assert!( @@ -1281,8 +1285,13 @@ mod tests { // Start a transaction to send a packet // Set this chain is the sink zone - let token = format!("{}/{}/{}", port_id, channel_id, token); - let msg = ibc::msg_transfer(port_id, channel_id, token, &sender); + let prefixed_token = format!("{}/{}/{}", port_id, channel_id, token); + let msg = ibc::msg_transfer( + port_id.clone(), + channel_id, + prefixed_token, + &sender, + ); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); let tx = Tx { @@ -1305,8 +1314,12 @@ mod tests { .expect("validation failed unexpectedly") ); // Check if the token was burned - let burn = - address::Address::Internal(address::InternalAddress::IbcBurn); + let key_prefix = + ibc_storage::ibc_token_prefix(&port_id, &channel_id, &token); + let burn = token::multitoken_balance_key( + &key_prefix, + &address::Address::Internal(address::InternalAddress::IbcBurn), + ); let (token_vp, _) = ibc::init_token_vp_from_tx(&env, &tx, &burn); assert!( token_vp @@ -1367,8 +1380,16 @@ mod tests { .expect("validation failed unexpectedly") ); // Check if the token was minted - let mint = - address::Address::Internal(address::InternalAddress::IbcMint); + let counterparty = ibc::dummy_channel_counterparty(); + let key_prefix = ibc_storage::ibc_token_prefix( + counterparty.port_id(), + counterparty.channel_id().unwrap(), + &token, + ); + let mint = token::multitoken_balance_key( + &key_prefix, + &address::Address::Internal(address::InternalAddress::IbcMint), + ); let (token_vp, _) = ibc::init_token_vp_from_tx(&env, &tx, &mint); assert!( token_vp @@ -1397,16 +1418,18 @@ mod tests { }); // escrow in advance let counterparty = ibc::dummy_channel_counterparty(); - let escrow = address::Address::Internal( - address::InternalAddress::ibc_escrow_address( - port_id.to_string(), - channel_id.to_string(), - ), + let key_prefix = ibc_storage::ibc_token_prefix( + counterparty.port_id(), + counterparty.channel_id().unwrap(), + &token, + ); + let escrow = token::multitoken_balance_key( + &key_prefix, + &address::Address::Internal(address::InternalAddress::IbcEscrow), ); - let key = token::balance_key(&token, &escrow); let val = Amount::from(1_000_000_000u64).try_to_vec().unwrap(); tx_host_env::with(|env| { - env.storage.write(&key, &val).expect("write error"); + env.storage.write(&escrow, &val).expect("write error"); }); // Set this chain as the source zone @@ -1659,11 +1682,14 @@ mod tests { .expect("validation failed unexpectedly") ); // Check if the token was refunded - let escrow = address::Address::Internal( - address::InternalAddress::ibc_escrow_address( - packet.source_port.to_string(), - packet.source_channel.to_string(), - ), + let key_prefix = ibc_storage::ibc_token_prefix( + &packet.source_port, + &packet.source_channel, + &token, + ); + let escrow = token::multitoken_balance_key( + &key_prefix, + &address::Address::Internal(address::InternalAddress::IbcEscrow), ); let (token_vp, _) = ibc::init_token_vp_from_tx(&env, &tx, &escrow); assert!( @@ -1736,11 +1762,14 @@ mod tests { .expect("validation failed unexpectedly") ); // Check if the token was refunded - let escrow = address::Address::Internal( - address::InternalAddress::ibc_escrow_address( - packet.source_port.to_string(), - packet.source_channel.to_string(), - ), + let key_prefix = ibc_storage::ibc_token_prefix( + &packet.source_port, + &packet.source_channel, + &token, + ); + let escrow = token::multitoken_balance_key( + &key_prefix, + &address::Address::Internal(address::InternalAddress::IbcEscrow), ); let (token_vp, _) = ibc::init_token_vp_from_tx(&env, &tx, &escrow); assert!( diff --git a/vm_env/src/governance.rs b/vm_env/src/governance.rs index 77e0ceda69..764fdb46b3 100644 --- a/vm_env/src/governance.rs +++ b/vm_env/src/governance.rs @@ -63,6 +63,7 @@ pub mod tx { &data.author, &governance_address, &m1t(), + None, min_proposal_funds, ); } diff --git a/vm_env/src/ibc.rs b/vm_env/src/ibc.rs index 9d11c34cd6..a10124b708 100644 --- a/vm_env/src/ibc.rs +++ b/vm_env/src/ibc.rs @@ -1,14 +1,13 @@ //! IBC functions for transactions. pub use anoma::ledger::ibc::handler::IbcActions; -use anoma::types::address::Address; use anoma::types::ibc::IbcEvent; use anoma::types::storage::{BlockHeight, Key}; use anoma::types::time::Rfc3339String; use anoma::types::token::Amount; use crate::imports::tx; -use crate::token::tx::transfer; +use crate::token::tx::multitoken_transfer; /// This struct integrates and gives access to lower-level IBC functions. pub struct Ibc; @@ -30,14 +29,8 @@ impl IbcActions for Ibc { tx::emit_ibc_event(&event) } - fn transfer_token( - &self, - src: &Address, - dest: &Address, - token: &Address, - amount: Amount, - ) { - transfer(src, dest, token, amount) + fn transfer_token(&self, src: &Key, dest: &Key, amount: Amount) { + multitoken_transfer(src, dest, amount) } fn get_height(&self) -> BlockHeight { diff --git a/vm_env/src/proof_of_stake.rs b/vm_env/src/proof_of_stake.rs index 2dbc31ef43..c1bb2e2e3c 100644 --- a/vm_env/src/proof_of_stake.rs +++ b/vm_env/src/proof_of_stake.rs @@ -256,6 +256,6 @@ impl anoma_proof_of_stake::PosActions for PoS { src: &Self::Address, dest: &Self::Address, ) { - crate::token::tx::transfer(src, dest, token, amount) + crate::token::tx::transfer(src, dest, token, None, amount) } } diff --git a/vm_env/src/token.rs b/vm_env/src/token.rs index c3af13d094..8b8e849075 100644 --- a/vm_env/src/token.rs +++ b/vm_env/src/token.rs @@ -20,7 +20,12 @@ pub mod vp { ) -> bool { let mut change: Change = 0; let all_checked = keys_changed.iter().all(|key| { - match token::is_balance_key(token, key) { + let owner: Option<&Address> = + match token::is_multitoken_balance_key(token, key) { + Some((_, o)) => Some(o), + None => token::is_balance_key(token, key), + }; + match owner { None => { // Unknown changes to this address space are disallowed, but // unknown changes anywhere else are permitted @@ -73,38 +78,101 @@ pub mod tx { src: &Address, dest: &Address, token: &Address, + sub_prefix: Option, amount: Amount, ) { - let src_key = token::balance_key(token, src); - let dest_key = token::balance_key(token, dest); + let src_key = match &sub_prefix { + Some(sub_prefix) => { + let prefix = + token::multitoken_balance_prefix(token, sub_prefix); + token::multitoken_balance_key(&prefix, src) + } + None => token::balance_key(token, src), + }; + let dest_key = match &sub_prefix { + Some(sub_prefix) => { + let prefix = + token::multitoken_balance_prefix(token, sub_prefix); + token::multitoken_balance_key(&prefix, dest) + } + None => token::balance_key(token, dest), + }; let src_bal: Option = tx::read(&src_key.to_string()); - let mut src_bal = src_bal.unwrap_or_else(|| match src { - Address::Internal(InternalAddress::IbcMint) => Amount::max(), - _ => { + match src_bal { + None => { tx::log_string(format!("src {} has no balance", src)); unreachable!() } - }); - src_bal.spend(&amount); - let mut dest_bal: Amount = - tx::read(&dest_key.to_string()).unwrap_or_default(); - dest_bal.receive(&amount); - match src { - Address::Internal(InternalAddress::IbcMint) => { - tx::write_temp(&src_key.to_string(), src_bal) + Some(mut src_bal) => { + src_bal.spend(&amount); + let mut dest_bal: Amount = + tx::read(&dest_key.to_string()).unwrap_or_default(); + dest_bal.receive(&amount); + tx::write(&src_key.to_string(), src_bal); + tx::write(&dest_key.to_string(), dest_bal); } - Address::Internal(InternalAddress::IbcBurn) => { + } + } + + /// A token transfer with storage keys that can be used in a transaction. + pub fn multitoken_transfer(src_key: &Key, dest_key: &Key, amount: Amount) { + let src_owner = is_any_multitoken_balance_key(src_key).map(|(_, o)| o); + let src_bal: Option = match src_owner { + Some(Address::Internal(InternalAddress::IbcMint)) => { + Some(Amount::max()) + } + Some(Address::Internal(InternalAddress::IbcBurn)) => { tx::log_string("invalid transfer from the burn address"); unreachable!() } - _ => tx::write(&src_key.to_string(), src_bal), - } - match dest { - Address::Internal(InternalAddress::IbcMint) => { + Some(_) => tx::read(&src_key.to_string()), + None => { + // the key is not multitoken key + match is_any_token_balance_key(src_key) { + Some(_) => tx::read(src_key.to_string()), + None => { + tx::log_string(format!( + "invalid balance key: {}", + src_key + )); + unreachable!() + } + } + } + }; + let mut src_bal = src_bal.unwrap_or_else(|| { + tx::log_string(format!("src {} has no balance", src_key)); + unreachable!() + }); + src_bal.spend(&amount); + let dest_owner = + is_any_multitoken_balance_key(dest_key).map(|(_, o)| o); + let mut dest_bal: Amount = match dest_owner { + Some(Address::Internal(InternalAddress::IbcMint)) => { tx::log_string("invalid transfer to the mint address"); unreachable!() } - Address::Internal(InternalAddress::IbcBurn) => { + Some(_) => tx::read(dest_key.to_string()).unwrap_or_default(), + None => match is_any_token_balance_key(dest_key) { + Some(_) => tx::read(dest_key.to_string()).unwrap_or_default(), + None => { + tx::log_string(format!( + "invalid balance key: {}", + dest_key + )); + unreachable!() + } + }, + }; + dest_bal.receive(&amount); + match src_owner { + Some(Address::Internal(InternalAddress::IbcMint)) => { + tx::write_temp(&src_key.to_string(), src_bal) + } + _ => tx::write(&src_key.to_string(), src_bal), + } + match dest_owner { + Some(Address::Internal(InternalAddress::IbcBurn)) => { tx::write_temp(&dest_key.to_string(), dest_bal) } _ => tx::write(&dest_key.to_string(), dest_bal), diff --git a/wasm/checksums.json b/wasm/checksums.json index 42eb0294e3..b13c981d6d 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,19 +1,21 @@ { - "tx_bond.wasm": "tx_bond.753f415cfc1ab36b23afc113e6b988fd84e24e493b651906bda007471c6d767d.wasm", - "tx_from_intent.wasm": "tx_from_intent.9309a7f0ac8f7b57d897cd69e913cb7ce183e2172e255e2d808c471217a7486b.wasm", - "tx_ibc.wasm": "tx_ibc.5f526fcc143bc57988a3015e5c93250406a4a9ea5467f44d940eece3e0af781d.wasm", - "tx_init_account.wasm": "tx_init_account.7523feaefe42396b98728b6b8993648041b99c2c4b97faa85e1016fe0ef35ce0.wasm", - "tx_init_nft.wasm": "tx_init_nft.92c350bd1640aec55618155573f2d520a85676959fbcec548f5c6378419124f0.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.7ac4859d1ebd536d119c8936336ddd7ea5cb491b079261b2f83f03bf89255d3f.wasm", - "tx_init_validator.wasm": "tx_init_validator.83a93ba9a1c40c03ddb92012ee354743f8dff8c5796ebdc557654c2bd95a497c.wasm", - "tx_mint_nft.wasm": "tx_mint_nft.9c582bc9d4ee0f185a66c2c468290ee0668064987050779529b1a4db39a3989b.wasm", - "tx_transfer.wasm": "tx_transfer.f2773e82cd6519662f7d9dbdeb10a2aff9a5fc8ca54d144e6cff571b1fca97cd.wasm", - "tx_unbond.wasm": "tx_unbond.b4ae4df26a3501af40ab409d95b72bff27f953d2e2ebf20c3f7395a2454dad68.wasm", - "tx_update_vp.wasm": "tx_update_vp.23a6a4f18e826c67708b32b98be67c7c241fd1478424196ae47f972c7a1334e0.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.466a6be90f5a5a79965a2106b8a5a385accc1cdb6f66345c9f39e6488e4e2a05.wasm", - "tx_withdraw.wasm": "tx_withdraw.aabfff97bf82723436bdddbd584e8199a18355decc2f1c10818ad84c57e92182.wasm", - "vp_nft.wasm": "vp_nft.d85a9628f4702f31f54888b704745f8e868b7945208d40d24ead134b338557d1.wasm", - "vp_testnet_faucet.wasm": "vp_testnet_faucet.07226b30af3f6c091b5acfd0e6f7794f31e363cbbdb5db9acb8a0086fff82005.wasm", - "vp_token.wasm": "vp_token.bad2c74e2788089ec2692b1fce0549466f57769336df774c8582076cd3fad136.wasm", - "vp_user.wasm": "vp_user.9299851563f7fdb4e8bc9b0f23ae948655b0a049e402b090ddb453df37eb98ff.wasm" + "mm_filter_token_exch.wasm": "mm_filter_token_exch.246328e51718dd00783fae8aa92dbf546d1305a8249c23879215a7dbae50dffb.wasm", + "mm_token_exch.wasm": "mm_token_exch.64b9a9af60165d999c4af2b9e425c152d606e517250dd76cbfb3251b37661450.wasm", + "tx_bond.wasm": "tx_bond.7cb1d8e0c31d378142cf0a467904904561508d24625c32534bf51396be660a85.wasm", + "tx_from_intent.wasm": "tx_from_intent.26e1a1a7d6298baf8e091d5d0efe6a5b8959b3e097c5f537986382b094a49215.wasm", + "tx_ibc.wasm": "tx_ibc.9503ffccbe9b83c68b014e436fdce9eb241982a004fc25003001352c886a3f3a.wasm", + "tx_init_account.wasm": "tx_init_account.8bb7520ec08aa245faa1b83f9603a718513fcbccd3ed0cd5866b6697ad53ed85.wasm", + "tx_init_nft.wasm": "tx_init_nft.cb4c75f30b8f847f646c588b9135e8b0d623cf0f87260045e012eb599577a3c4.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.d3ac3e9edb90a99cc7c20b4b05ac2fea8153e1b2eff0d2965291715f13c15f0d.wasm", + "tx_init_validator.wasm": "tx_init_validator.8813da5f9137f8a0b25c7c66e2ad79a03e7591501d856f1407c60c594e9ad8af.wasm", + "tx_mint_nft.wasm": "tx_mint_nft.e6e5c22d7c6a32113fae2c8699cd8622dd8ba76306ad13edc9453d4e2f4f20bd.wasm", + "tx_transfer.wasm": "tx_transfer.877c16c63f471d99155b19556bcdd3cfcd829ac39db07abe639e07d11fef30b7.wasm", + "tx_unbond.wasm": "tx_unbond.837bd2da79729f0e240bbdb33c91430e6a075e2bbbe34480286be83af846c3e6.wasm", + "tx_update_vp.wasm": "tx_update_vp.e8d707cc334aaec254701ff512ade565da313546137be57f47d3f694fc1f331d.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.6f11cd48cffdf8e5519d2b06dbb2dae337fe1c42167a8e978f9e40edd86494a4.wasm", + "tx_withdraw.wasm": "tx_withdraw.1b4c9a75597e0ffc65f4883fd3f1c0df92ce29a05fd47eb855e17aa96957774f.wasm", + "vp_nft.wasm": "vp_nft.0f3d2f1b32d7f2fac8dd5f26fa3a5ce9e130f06a9e28d4506a878cf5d2aeb621.wasm", + "vp_testnet_faucet.wasm": "vp_testnet_faucet.d8c711883c86e727414feaf3015e6da962db22666ea10c8e07e0bef006ab2dce.wasm", + "vp_token.wasm": "vp_token.7f3e90a988b8b7060532b500e6e1e62a9e61573ecf933514075a40660a480913.wasm", + "vp_user.wasm": "vp_user.b98e61b8c671d05b45e95f815403c9d69b202969741f817b6c2ce3f2ab4c5b3f.wasm" } \ No newline at end of file diff --git a/wasm/tx_template/Cargo.lock b/wasm/tx_template/Cargo.lock index 4e0ac1ccee..956e491ce9 100644 --- a/wasm/tx_template/Cargo.lock +++ b/wasm/tx_template/Cargo.lock @@ -252,27 +252,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "async-stream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-trait" version = "0.1.52" @@ -1044,25 +1023,6 @@ dependencies = [ "syn", ] -[[package]] -name = "h2" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9f1f717ddc7b2ba36df7e871fd88db79326551d3d6f1fc406fbfd28b582ff8e" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util 0.6.9", - "tracing", -] - [[package]] name = "hashbrown" version = "0.11.2" @@ -1096,80 +1056,10 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "http" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "ibc" -version = "0.12.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.14.0" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ "bytes", "derive_more", @@ -1195,22 +1085,22 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.16.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.17.1" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ + "base64", "bytes", "prost", "prost-types", "serde", "tendermint-proto", - "tonic", ] [[package]] name = "ics23" -version = "0.6.7" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce15e4758c46a0453bdf4b3b1dfcce70c43f79d1943c2ee0635b77eb2e7aa233" +checksum = "9d454cc0a22bd556cc3d3c69f9d75a392a36244634840697a4b9eb81bc5c8ae0" dependencies = [ "anyhow", "bytes", @@ -1417,28 +1307,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - [[package]] name = "more-asserts" version = "0.2.2" @@ -1451,15 +1319,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - [[package]] name = "num-bigint" version = "0.4.3" @@ -2253,28 +2112,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc47a29ce97772ca5c927f75bac34866b16d64e07f330c3248e2d7226623901b" -[[package]] -name = "slab" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" - [[package]] name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" -[[package]] -name = "socket2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "sp-std" version = "3.0.0" @@ -2284,7 +2127,7 @@ checksum = "35391ea974fa5ee869cb094d5b437688fbf3d8127d64d1b9fed5822a1ed39b12" [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/prost-0.9#be4b2293558361df2f452c60a3e90c6b5e52e225" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/ics23_0.7#b0ca0dc2fbb46b0e38da4b1eaf70b5ef27538554" dependencies = [ "borsh", "cfg-if 1.0.0", @@ -2561,82 +2404,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" -dependencies = [ - "bytes", - "libc", - "memchr", - "mio", - "pin-project-lite", - "socket2", - "tokio-macros", - "winapi", -] - -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-macros" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-stream" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64910e1b9c1901aaf5375561e35b9c057d95ff41a44ede043a03e09279eabaf1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml" version = "0.5.8" @@ -2646,37 +2413,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tonic" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff08f4649d10a70ffa3522ca559031285d8e421d727ac85c60825761818f5d0a" -dependencies = [ - "async-stream", - "async-trait", - "base64", - "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "prost-derive", - "tokio", - "tokio-stream", - "tokio-util 0.6.9", - "tower", - "tower-layer", - "tower-service", - "tracing", - "tracing-futures", -] - [[package]] name = "tonic-build" version = "0.6.2" @@ -2689,43 +2425,11 @@ dependencies = [ "syn", ] -[[package]] -name = "tower" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a89fd63ad6adf737582df5db40d286574513c69a11dac5214dc3b5603d6713e" -dependencies = [ - "futures-core", - "futures-util", - "indexmap", - "pin-project", - "pin-project-lite", - "rand", - "slab", - "tokio", - "tokio-util 0.7.0", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - [[package]] name = "tracing" -version = "0.1.31" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", @@ -2736,9 +2440,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" dependencies = [ "proc-macro2", "quote", @@ -2755,16 +2459,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-subscriber" version = "0.3.9" @@ -2780,12 +2474,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - [[package]] name = "tx_template" version = "0.6.1" @@ -2892,16 +2580,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" diff --git a/wasm/vp_template/Cargo.lock b/wasm/vp_template/Cargo.lock index 032f4ec18f..93c6286362 100644 --- a/wasm/vp_template/Cargo.lock +++ b/wasm/vp_template/Cargo.lock @@ -252,27 +252,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "async-stream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-trait" version = "0.1.52" @@ -1044,25 +1023,6 @@ dependencies = [ "syn", ] -[[package]] -name = "h2" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9f1f717ddc7b2ba36df7e871fd88db79326551d3d6f1fc406fbfd28b582ff8e" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util 0.6.9", - "tracing", -] - [[package]] name = "hashbrown" version = "0.11.2" @@ -1096,80 +1056,10 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "http" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "ibc" -version = "0.12.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.14.0" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ "bytes", "derive_more", @@ -1195,22 +1085,22 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.16.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.17.1" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ + "base64", "bytes", "prost", "prost-types", "serde", "tendermint-proto", - "tonic", ] [[package]] name = "ics23" -version = "0.6.7" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce15e4758c46a0453bdf4b3b1dfcce70c43f79d1943c2ee0635b77eb2e7aa233" +checksum = "9d454cc0a22bd556cc3d3c69f9d75a392a36244634840697a4b9eb81bc5c8ae0" dependencies = [ "anyhow", "bytes", @@ -1417,28 +1307,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - [[package]] name = "more-asserts" version = "0.2.2" @@ -1451,15 +1319,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - [[package]] name = "num-bigint" version = "0.4.3" @@ -2253,28 +2112,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc47a29ce97772ca5c927f75bac34866b16d64e07f330c3248e2d7226623901b" -[[package]] -name = "slab" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" - [[package]] name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" -[[package]] -name = "socket2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "sp-std" version = "3.0.0" @@ -2284,7 +2127,7 @@ checksum = "35391ea974fa5ee869cb094d5b437688fbf3d8127d64d1b9fed5822a1ed39b12" [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/prost-0.9#be4b2293558361df2f452c60a3e90c6b5e52e225" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/ics23_0.7#b0ca0dc2fbb46b0e38da4b1eaf70b5ef27538554" dependencies = [ "borsh", "cfg-if 1.0.0", @@ -2561,82 +2404,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" -dependencies = [ - "bytes", - "libc", - "memchr", - "mio", - "pin-project-lite", - "socket2", - "tokio-macros", - "winapi", -] - -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-macros" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-stream" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64910e1b9c1901aaf5375561e35b9c057d95ff41a44ede043a03e09279eabaf1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml" version = "0.5.8" @@ -2646,37 +2413,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tonic" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff08f4649d10a70ffa3522ca559031285d8e421d727ac85c60825761818f5d0a" -dependencies = [ - "async-stream", - "async-trait", - "base64", - "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "prost-derive", - "tokio", - "tokio-stream", - "tokio-util 0.6.9", - "tower", - "tower-layer", - "tower-service", - "tracing", - "tracing-futures", -] - [[package]] name = "tonic-build" version = "0.6.2" @@ -2689,43 +2425,11 @@ dependencies = [ "syn", ] -[[package]] -name = "tower" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a89fd63ad6adf737582df5db40d286574513c69a11dac5214dc3b5603d6713e" -dependencies = [ - "futures-core", - "futures-util", - "indexmap", - "pin-project", - "pin-project-lite", - "rand", - "slab", - "tokio", - "tokio-util 0.7.0", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - [[package]] name = "tracing" -version = "0.1.31" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", @@ -2736,9 +2440,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" dependencies = [ "proc-macro2", "quote", @@ -2755,16 +2459,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-subscriber" version = "0.3.9" @@ -2780,12 +2474,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - [[package]] name = "typenum" version = "1.15.0" @@ -2892,16 +2580,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" diff --git a/wasm/wasm_source/Cargo.lock b/wasm/wasm_source/Cargo.lock index 619817c90f..a192de6a5e 100644 --- a/wasm/wasm_source/Cargo.lock +++ b/wasm/wasm_source/Cargo.lock @@ -278,27 +278,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "async-stream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-trait" version = "0.1.52" @@ -1070,25 +1049,6 @@ dependencies = [ "syn", ] -[[package]] -name = "h2" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9f1f717ddc7b2ba36df7e871fd88db79326551d3d6f1fc406fbfd28b582ff8e" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util 0.6.9", - "tracing", -] - [[package]] name = "hashbrown" version = "0.11.2" @@ -1122,80 +1082,10 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "http" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "ibc" -version = "0.12.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.14.0" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ "bytes", "derive_more", @@ -1221,22 +1111,22 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.16.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.17.1" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ + "base64", "bytes", "prost", "prost-types", "serde", "tendermint-proto", - "tonic", ] [[package]] name = "ics23" -version = "0.6.7" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce15e4758c46a0453bdf4b3b1dfcce70c43f79d1943c2ee0635b77eb2e7aa233" +checksum = "9d454cc0a22bd556cc3d3c69f9d75a392a36244634840697a4b9eb81bc5c8ae0" dependencies = [ "anyhow", "bytes", @@ -1443,28 +1333,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - [[package]] name = "more-asserts" version = "0.2.2" @@ -1477,15 +1345,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - [[package]] name = "num-bigint" version = "0.4.3" @@ -2279,28 +2138,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc47a29ce97772ca5c927f75bac34866b16d64e07f330c3248e2d7226623901b" -[[package]] -name = "slab" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" - [[package]] name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" -[[package]] -name = "socket2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "sp-std" version = "3.0.0" @@ -2310,7 +2153,7 @@ checksum = "35391ea974fa5ee869cb094d5b437688fbf3d8127d64d1b9fed5822a1ed39b12" [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/prost-0.9#be4b2293558361df2f452c60a3e90c6b5e52e225" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/ics23_0.7#b0ca0dc2fbb46b0e38da4b1eaf70b5ef27538554" dependencies = [ "borsh", "cfg-if 1.0.0", @@ -2587,82 +2430,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" -dependencies = [ - "bytes", - "libc", - "memchr", - "mio", - "pin-project-lite", - "socket2", - "tokio-macros", - "winapi", -] - -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-macros" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-stream" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64910e1b9c1901aaf5375561e35b9c057d95ff41a44ede043a03e09279eabaf1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml" version = "0.5.8" @@ -2672,37 +2439,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tonic" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff08f4649d10a70ffa3522ca559031285d8e421d727ac85c60825761818f5d0a" -dependencies = [ - "async-stream", - "async-trait", - "base64", - "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "prost-derive", - "tokio", - "tokio-stream", - "tokio-util 0.6.9", - "tower", - "tower-layer", - "tower-service", - "tracing", - "tracing-futures", -] - [[package]] name = "tonic-build" version = "0.6.2" @@ -2715,43 +2451,11 @@ dependencies = [ "syn", ] -[[package]] -name = "tower" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a89fd63ad6adf737582df5db40d286574513c69a11dac5214dc3b5603d6713e" -dependencies = [ - "futures-core", - "futures-util", - "indexmap", - "pin-project", - "pin-project-lite", - "rand", - "slab", - "tokio", - "tokio-util 0.7.0", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - [[package]] name = "tracing" -version = "0.1.31" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", @@ -2762,9 +2466,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" dependencies = [ "proc-macro2", "quote", @@ -2781,16 +2485,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-subscriber" version = "0.3.9" @@ -2806,12 +2500,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - [[package]] name = "typenum" version = "1.15.0" @@ -2907,16 +2595,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" diff --git a/wasm/wasm_source/src/tx_from_intent.rs b/wasm/wasm_source/src/tx_from_intent.rs index 936d03b50b..120206d1ee 100644 --- a/wasm/wasm_source/src/tx_from_intent.rs +++ b/wasm/wasm_source/src/tx_from_intent.rs @@ -20,10 +20,11 @@ fn apply_tx(tx_data: Vec) { source, target, token, + sub_prefix, amount, } in tx_data.matches.transfers { - token::transfer(&source, &target, &token, amount); + token::transfer(&source, &target, &token, sub_prefix, amount); } tx_data diff --git a/wasm/wasm_source/src/tx_transfer.rs b/wasm/wasm_source/src/tx_transfer.rs index 187898d86a..f48ff52d45 100644 --- a/wasm/wasm_source/src/tx_transfer.rs +++ b/wasm/wasm_source/src/tx_transfer.rs @@ -14,7 +14,8 @@ fn apply_tx(tx_data: Vec) { source, target, token, + sub_prefix, amount, } = transfer; - token::transfer(&source, &target, &token, amount) + token::transfer(&source, &target, &token, sub_prefix, amount) } diff --git a/wasm/wasm_source/src/vp_testnet_faucet.rs b/wasm/wasm_source/src/vp_testnet_faucet.rs index afc1ca6ea6..f86d14935b 100644 --- a/wasm/wasm_source/src/vp_testnet_faucet.rs +++ b/wasm/wasm_source/src/vp_testnet_faucet.rs @@ -136,7 +136,9 @@ mod tests { // Initialize VP environment from a transaction vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Apply transfer in a transaction - tx_host_env::token::transfer(&source, address, &token, amount); + tx_host_env::token::transfer( + &source, address, &token, None, amount, + ); }); let vp_env = vp_host_env::take(); @@ -251,7 +253,7 @@ mod tests { // Initialize VP environment from a transaction vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Apply transfer in a transaction - tx_host_env::token::transfer(address, &target, &token, amount); + tx_host_env::token::transfer(address, &target, &token, None, amount); }); let vp_env = vp_host_env::take(); @@ -284,7 +286,7 @@ mod tests { // Initialize VP environment from a transaction vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Apply transfer in a transaction - tx_host_env::token::transfer(address, &target, &token, amount); + tx_host_env::token::transfer(address, &target, &token, None, amount); }); let vp_env = vp_host_env::take(); diff --git a/wasm/wasm_source/src/vp_user.rs b/wasm/wasm_source/src/vp_user.rs index d24e63f8ab..973b0fe328 100644 --- a/wasm/wasm_source/src/vp_user.rs +++ b/wasm/wasm_source/src/vp_user.rs @@ -34,6 +34,10 @@ impl<'a> From<&'a storage::Key> for KeyType<'a> { fn from(key: &'a storage::Key) -> KeyType<'a> { if let Some(address) = token::is_any_token_balance_key(key) { Self::Token(address) + } else if let Some((_, address)) = + token::is_any_multitoken_balance_key(key) + { + Self::Token(address) } else if proof_of_stake::is_pos_key(key) { Self::PoS } else if let Some(address) = intent::is_invalid_intent_key(key) { @@ -412,7 +416,9 @@ mod tests { // Initialize VP environment from a transaction vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Apply transfer in a transaction - tx_host_env::token::transfer(&source, address, &token, amount); + tx_host_env::token::transfer( + &source, address, &token, None, amount, + ); }); let vp_env = vp_host_env::take(); @@ -445,7 +451,9 @@ mod tests { // Initialize VP environment from a transaction vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Apply transfer in a transaction - tx_host_env::token::transfer(address, &target, &token, amount); + tx_host_env::token::transfer( + address, &target, &token, None, amount, + ); }); let vp_env = vp_host_env::take(); @@ -482,7 +490,9 @@ mod tests { // Initialize VP environment from a transaction vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { // Apply transfer in a transaction - tx_host_env::token::transfer(address, &target, &token, amount); + tx_host_env::token::transfer( + address, &target, &token, None, amount, + ); }); let mut vp_env = vp_host_env::take(); @@ -520,7 +530,9 @@ mod tests { vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |address| { tx_host_env::insert_verifier(address); // Apply transfer in a transaction - tx_host_env::token::transfer(&source, &target, &token, amount); + tx_host_env::token::transfer( + &source, &target, &token, None, amount, + ); }); let vp_env = vp_host_env::take(); diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index ec5527525c..ebceef4c1b 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -273,27 +273,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "async-stream" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "async-trait" version = "0.1.53" @@ -1025,7 +1004,7 @@ dependencies = [ "cfg-if 1.0.0", "js-sys", "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] @@ -1066,25 +1045,6 @@ dependencies = [ "syn", ] -[[package]] -name = "h2" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util 0.7.1", - "tracing", -] - [[package]] name = "hashbrown" version = "0.11.2" @@ -1127,80 +1087,10 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "http" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "ibc" -version = "0.12.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.14.0" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ "bytes", "derive_more", @@ -1226,22 +1116,22 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.16.0" -source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.12.0_tm_v0.23.5#e14560ecfc3f275a63b5702e038cbabd2797b2b6" +version = "0.17.1" +source = "git+https://github.com/heliaxdev/ibc-rs?branch=yuji/v0.14.0_tm_v0.23.5#e22ff9f372ceb2f2e7fc4efc949cfafa853febf1" dependencies = [ + "base64", "bytes", "prost", "prost-types", "serde", "tendermint-proto", - "tonic", ] [[package]] name = "ics23" -version = "0.6.7" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce15e4758c46a0453bdf4b3b1dfcce70c43f79d1943c2ee0635b77eb2e7aa233" +checksum = "9d454cc0a22bd556cc3d3c69f9d75a392a36244634840697a4b9eb81bc5c8ae0" dependencies = [ "anyhow", "bytes", @@ -1448,29 +1338,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "mio" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "wasi 0.11.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - [[package]] name = "more-asserts" version = "0.2.2" @@ -1483,15 +1350,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - [[package]] name = "num-bigint" version = "0.4.3" @@ -2285,28 +2143,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc47a29ce97772ca5c927f75bac34866b16d64e07f330c3248e2d7226623901b" -[[package]] -name = "slab" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" - [[package]] name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" -[[package]] -name = "socket2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "sp-std" version = "3.0.0" @@ -2316,7 +2158,7 @@ checksum = "35391ea974fa5ee869cb094d5b437688fbf3d8127d64d1b9fed5822a1ed39b12" [[package]] name = "sparse-merkle-tree" version = "0.3.1-pre" -source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/prost-0.9#be4b2293558361df2f452c60a3e90c6b5e52e225" +source = "git+https://github.com/heliaxdev/sparse-merkle-tree?branch=yuji/ics23_0.7#b0ca0dc2fbb46b0e38da4b1eaf70b5ef27538554" dependencies = [ "borsh", "cfg-if 1.0.0", @@ -2557,7 +2399,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi", "winapi", ] @@ -2593,82 +2435,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" -dependencies = [ - "bytes", - "libc", - "memchr", - "mio", - "pin-project-lite", - "socket2", - "tokio-macros", - "winapi", -] - -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-macros" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-stream" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - [[package]] name = "toml" version = "0.5.8" @@ -2678,37 +2444,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tonic" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff08f4649d10a70ffa3522ca559031285d8e421d727ac85c60825761818f5d0a" -dependencies = [ - "async-stream", - "async-trait", - "base64", - "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "prost-derive", - "tokio", - "tokio-stream", - "tokio-util 0.6.9", - "tower", - "tower-layer", - "tower-service", - "tracing", - "tracing-futures", -] - [[package]] name = "tonic-build" version = "0.6.2" @@ -2721,43 +2456,11 @@ dependencies = [ "syn", ] -[[package]] -name = "tower" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a89fd63ad6adf737582df5db40d286574513c69a11dac5214dc3b5603d6713e" -dependencies = [ - "futures-core", - "futures-util", - "indexmap", - "pin-project", - "pin-project-lite", - "rand", - "slab", - "tokio", - "tokio-util 0.7.1", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - [[package]] name = "tracing" -version = "0.1.32" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", @@ -2787,16 +2490,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "tracing-subscriber" version = "0.3.9" @@ -2812,12 +2505,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - [[package]] name = "typenum" version = "1.15.0" @@ -2913,28 +2600,12 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasm-bindgen" version = "0.2.79" diff --git a/wasm_for_tests/wasm_source/src/lib.rs b/wasm_for_tests/wasm_source/src/lib.rs index be175f47f4..4308034f89 100644 --- a/wasm_for_tests/wasm_source/src/lib.rs +++ b/wasm_for_tests/wasm_source/src/lib.rs @@ -140,6 +140,7 @@ pub mod main { source: _, target, token, + sub_prefix: _, amount, } = transfer; let target_key = token::balance_key(&token, &target);