From 7bd142348a269c6ca93318b12953116d09fcddf7 Mon Sep 17 00:00:00 2001 From: satan Date: Fri, 22 Nov 2024 14:50:20 +0100 Subject: [PATCH 01/14] First draft implementation of a pfm module --- Cargo.lock | 106 ++++-- Cargo.toml | 10 +- crates/ibc/Cargo.toml | 2 + crates/ibc/src/context/mod.rs | 1 + crates/ibc/src/context/nft_transfer_mod.rs | 6 +- crates/ibc/src/context/pfm_mod.rs | 408 +++++++++++++++++++++ crates/ibc/src/context/token_transfer.rs | 6 +- crates/ibc/src/context/transfer_mod.rs | 6 +- crates/ibc/src/lib.rs | 2 + wasm/Cargo.lock | 122 ++++-- wasm_for_tests/Cargo.lock | 246 +++++++++++-- 11 files changed, 802 insertions(+), 113 deletions(-) create mode 100644 crates/ibc/src/context/pfm_mod.rs diff --git a/Cargo.lock b/Cargo.lock index 7861b507ae..a8664ee1cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1892,6 +1892,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" +[[package]] +name = "dur" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce5b6c91b5e394b75cd96c36393fc938496c030220207a0ccf34d6cd313d3b49" +dependencies = [ + "nom", + "rust_decimal", +] + [[package]] name = "duration-str" version = "0.10.0" @@ -3336,7 +3346,7 @@ dependencies = [ [[package]] name = "ibc" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-apps", "ibc-clients", @@ -3349,7 +3359,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-nft-transfer-types", "ibc-core", @@ -3359,7 +3369,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "base64 0.22.1", @@ -3381,7 +3391,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-transfer-types", "ibc-core", @@ -3391,7 +3401,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3410,7 +3420,7 @@ dependencies = [ [[package]] name = "ibc-apps" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-nft-transfer", "ibc-app-transfer", @@ -3419,7 +3429,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "ibc-client-tendermint-types", @@ -3436,7 +3446,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "displaydoc", "ibc-core-client-types", @@ -3453,7 +3463,7 @@ dependencies = [ [[package]] name = "ibc-client-wasm-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "base64 0.22.1", "displaydoc", @@ -3467,7 +3477,7 @@ dependencies = [ [[package]] name = "ibc-clients" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-client-tendermint", "ibc-client-wasm-types", @@ -3476,7 +3486,7 @@ dependencies = [ [[package]] name = "ibc-core" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -3492,7 +3502,7 @@ dependencies = [ [[package]] name = "ibc-core-channel" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel-types", "ibc-core-client", @@ -3507,7 +3517,7 @@ dependencies = [ [[package]] name = "ibc-core-channel-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3531,7 +3541,7 @@ dependencies = [ [[package]] name = "ibc-core-client" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-client-context", "ibc-core-client-types", @@ -3544,7 +3554,7 @@ dependencies = [ [[package]] name = "ibc-core-client-context" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -3560,7 +3570,7 @@ dependencies = [ [[package]] name = "ibc-core-client-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3581,7 +3591,7 @@ dependencies = [ [[package]] name = "ibc-core-commitment-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3601,7 +3611,7 @@ dependencies = [ [[package]] name = "ibc-core-connection" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-client-wasm-types", "ibc-core-client", @@ -3615,7 +3625,7 @@ dependencies = [ [[package]] name = "ibc-core-connection-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3637,7 +3647,7 @@ dependencies = [ [[package]] name = "ibc-core-handler" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -3652,7 +3662,7 @@ dependencies = [ [[package]] name = "ibc-core-handler-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3677,7 +3687,7 @@ dependencies = [ [[package]] name = "ibc-core-host" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -3695,7 +3705,7 @@ dependencies = [ [[package]] name = "ibc-core-host-cosmos" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -3718,7 +3728,7 @@ dependencies = [ [[package]] name = "ibc-core-host-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3734,7 +3744,7 @@ dependencies = [ [[package]] name = "ibc-core-router" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -3748,7 +3758,7 @@ dependencies = [ [[package]] name = "ibc-core-router-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -3767,17 +3777,36 @@ dependencies = [ [[package]] name = "ibc-derive" version = "0.8.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "proc-macro2", "quote", "syn 2.0.52", ] +[[package]] +name = "ibc-middleware-packet-forward" +version = "0.2.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.2.0#6edafe7335c7287191488a3f7c7466ceebd7961f" +dependencies = [ + "borsh", + "dur", + "either", + "ibc-app-transfer-types", + "ibc-core-channel", + "ibc-core-channel-types", + "ibc-core-host-types", + "ibc-core-router", + "ibc-core-router-types", + "ibc-primitives", + "serde", + "serde_json", +] + [[package]] name = "ibc-primitives" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "arbitrary", "borsh", @@ -3818,7 +3847,7 @@ dependencies = [ [[package]] name = "ibc-query" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "displaydoc", "ibc", @@ -3829,7 +3858,7 @@ dependencies = [ [[package]] name = "ibc-testkit" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "basecoin-store", "derive_more", @@ -5060,8 +5089,10 @@ dependencies = [ "assert_matches", "borsh", "data-encoding", + "dur", "ibc", "ibc-derive", + "ibc-middleware-packet-forward", "ibc-testkit", "ics23", "konst", @@ -7283,12 +7314,18 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.35.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" dependencies = [ "arrayvec", + "borsh", + "bytes", "num-traits 0.2.17", + "rand 0.8.5", + "rkyv", + "serde", + "serde_json", ] [[package]] @@ -7678,11 +7715,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] diff --git a/Cargo.toml b/Cargo.toml index c6699f1ce5..5ffae8cef3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,6 +99,7 @@ derivation-path = "0.2.0" derivative = "2.2.0" directories = "4.0.1" drain_filter_polyfill = "0.1.3" +dur = "0.5.3" duration-str = "0.10.0" ed25519-consensus = "2.1.0" either = "1.12.0" @@ -118,9 +119,10 @@ fs_extra = "1.2.0" futures = "0.3" git2 = { version = "0.18.1", default-features = false } # branch yuji/derive-arbitrary -ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd", features = ["serde"] } -ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" } -ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd", default-features = false } +ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", features = ["serde"] } +ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583" } +ibc-middleware-packet-forward = {git = "https://github.com/heliaxdev/ibc-middleware", tag = "v0.2.0", features = ["borsh"]} +ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", default-features = false } ics23 = "0.12.0" index-set = { git = "https://github.com/heliaxdev/index-set", tag = "v0.8.1", features = ["serialize-borsh", "serialize-serde"] } indexmap = { git = "https://github.com/heliaxdev/indexmap", tag = "2.2.4-heliax-1", features = ["borsh-schema", "serde"] } @@ -173,7 +175,7 @@ rpassword = "5.0.1" rustversion = "1.0" serde = {version = "1.0.125", features = ["derive"]} serde_bytes = "0.11.5" -serde_json = "1.0.62" +serde_json = "1.0.133" serde_tuple = "0.5.0" sha2 = "0.9.3" sha2-const = "0.1.2" diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index 39f0c77965..f520e810c3 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -40,10 +40,12 @@ namada_vp = { path = "../vp" } arbitrary = { workspace = true, optional = true } borsh.workspace = true data-encoding.workspace = true +dur.workspace = true konst.workspace = true linkme = {workspace = true, optional = true} ibc.workspace = true ibc-derive.workspace = true +ibc-middleware-packet-forward.workspace = true ibc-testkit = {workspace = true, optional = true} ics23.workspace = true masp_primitives.workspace = true diff --git a/crates/ibc/src/context/mod.rs b/crates/ibc/src/context/mod.rs index d6e238c6c9..89a82b13e7 100644 --- a/crates/ibc/src/context/mod.rs +++ b/crates/ibc/src/context/mod.rs @@ -5,6 +5,7 @@ pub mod common; pub mod execution; pub mod nft_transfer; pub mod nft_transfer_mod; +pub mod pfm_mod; pub mod router; pub mod storage; pub mod token_transfer; diff --git a/crates/ibc/src/context/nft_transfer_mod.rs b/crates/ibc/src/context/nft_transfer_mod.rs index 420d80362e..b8450468ce 100644 --- a/crates/ibc/src/context/nft_transfer_mod.rs +++ b/crates/ibc/src/context/nft_transfer_mod.rs @@ -261,7 +261,7 @@ where &mut self, packet: &Packet, _relayer: &Signer, - ) -> (ModuleExtras, Acknowledgement) { + ) -> (ModuleExtras, Option) { on_recv_packet_execute(&mut self.ctx, packet) } @@ -482,10 +482,10 @@ pub mod testing { &mut self, _packet: &Packet, _relayer: &Signer, - ) -> (ModuleExtras, Acknowledgement) { + ) -> (ModuleExtras, Option) { ( ModuleExtras::empty(), - AcknowledgementStatus::success(ack_success_b64()).into(), + Some(AcknowledgementStatus::success(ack_success_b64()).into()), ) } diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs new file mode 100644 index 0000000000..58a4472e2e --- /dev/null +++ b/crates/ibc/src/context/pfm_mod.rs @@ -0,0 +1,408 @@ +//! Implementation of Packet Forward Middleware for our IBC modules. + +use std::fmt::{Debug, Formatter}; +use std::marker::PhantomData; + +use ibc::apps::transfer::context::TokenTransferExecutionContext; +use ibc::apps::transfer::handler::send_transfer_execute; +use ibc::apps::transfer::types::msgs::transfer::MsgTransfer; +use ibc::apps::transfer::types::packet::PacketData; +use ibc::apps::transfer::types::{PrefixedDenom, TracePrefix}; +use ibc::core::channel::handler::{ + commit_packet_acknowledgment, emit_packet_acknowledgement_event, +}; +use ibc::core::channel::types::acknowledgement::Acknowledgement; +use ibc::core::channel::types::channel::{Counterparty, Order}; +use ibc::core::channel::types::error::{ChannelError, PacketError}; +use ibc::core::channel::types::packet::Packet; +use ibc::core::channel::types::timeout::TimeoutTimestamp; +use ibc::core::channel::types::Version; +use ibc::core::host::types::identifiers::{ + ChannelId, ConnectionId, PortId, Sequence, +}; +use ibc::core::router::module::Module; +use ibc::core::router::types::module::{ModuleExtras, ModuleId}; +use ibc::primitives::Signer; +use ibc_middleware_packet_forward::{ + InFlightPacket, InFlightPacketKey, PacketForwardMiddleware, PfmContext, +}; +use namada_core::address::{Address, InternalAddress, MULTITOKEN}; +use namada_core::borsh::BorshSerializeExt; +use namada_core::storage::{self, KeySeg}; +use namada_state::{StorageRead, StorageWrite}; + +use crate::context::transfer_mod::TransferModule; +use crate::context::IbcContext; +use crate::trace::is_sender_chain_source; +use crate::{ + Error, IbcCommonContext, IbcStorageContext, ModuleWrapper, + TokenTransferContext, +}; + +const MIDDLEWARES_SUBKEY: &str = "middlewarez"; +const PFM_SUBKEY: &str = "pfm"; + +/// Get the Namada storage key associated to the provided `InFlightPacketKey`. +pub fn get_inflight_packet_key( + inflight_packet_key: &InFlightPacketKey, +) -> storage::Key { + let key: storage::Key = + Address::Internal(InternalAddress::Ibc).to_db_key().into(); + key.with_segment(MIDDLEWARES_SUBKEY.to_string()) + .with_segment(PFM_SUBKEY.to_string()) + .with_segment(inflight_packet_key.port.to_string()) + .with_segment(inflight_packet_key.channel.to_string()) + .with_segment(inflight_packet_key.sequence.to_string()) +} + +/// A wrapper around an IBC transfer module necessary to +/// build execution contexts. This allows us to implement +/// packet forward middleware on this struct. +pub struct PfmTransferModule +where + C: IbcCommonContext + Debug, +{ + /// The main module + pub transfer_module: TransferModule, + #[allow(missing_docs)] + pub _phantom: PhantomData, +} + +impl Debug + for PfmTransferModule +{ + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("PfmTransferModule") + .field("transfer_module", &self.transfer_module) + .finish() + } +} + +impl Module for PfmTransferModule +where + C: IbcCommonContext + Debug, +{ + fn on_chan_open_init_validate( + &self, + order: Order, + connection_hops: &[ConnectionId], + port_id: &PortId, + channel_id: &ChannelId, + counterparty: &Counterparty, + version: &Version, + ) -> Result { + self.transfer_module.on_chan_open_init_validate( + order, + connection_hops, + port_id, + channel_id, + counterparty, + version, + ) + } + + fn on_chan_open_init_execute( + &mut self, + order: Order, + connection_hops: &[ConnectionId], + port_id: &PortId, + channel_id: &ChannelId, + counterparty: &Counterparty, + version: &Version, + ) -> Result<(ModuleExtras, Version), ChannelError> { + self.transfer_module.on_chan_open_init_execute( + order, + connection_hops, + port_id, + channel_id, + counterparty, + version, + ) + } + + fn on_chan_open_try_validate( + &self, + order: Order, + connection_hops: &[ConnectionId], + port_id: &PortId, + channel_id: &ChannelId, + counterparty: &Counterparty, + counterparty_version: &Version, + ) -> Result { + self.transfer_module.on_chan_open_try_validate( + order, + connection_hops, + port_id, + channel_id, + counterparty, + counterparty_version, + ) + } + + fn on_chan_open_try_execute( + &mut self, + order: Order, + connection_hops: &[ConnectionId], + port_id: &PortId, + channel_id: &ChannelId, + counterparty: &Counterparty, + counterparty_version: &Version, + ) -> Result<(ModuleExtras, Version), ChannelError> { + self.transfer_module.on_chan_open_try_execute( + order, + connection_hops, + port_id, + channel_id, + counterparty, + counterparty_version, + ) + } + + fn on_recv_packet_execute( + &mut self, + packet: &Packet, + relayer: &Signer, + ) -> (ModuleExtras, Option) { + self.transfer_module.on_recv_packet_execute(packet, relayer) + } + + fn on_acknowledgement_packet_validate( + &self, + _packet: &Packet, + _acknowledgement: &Acknowledgement, + _relayer: &Signer, + ) -> Result<(), PacketError> { + self.transfer_module.on_acknowledgement_packet_validate( + _packet, + _acknowledgement, + _relayer, + ) + } + + fn on_acknowledgement_packet_execute( + &mut self, + _packet: &Packet, + _acknowledgement: &Acknowledgement, + _relayer: &Signer, + ) -> (ModuleExtras, Result<(), PacketError>) { + self.transfer_module.on_acknowledgement_packet_execute( + _packet, + _acknowledgement, + _relayer, + ) + } + + fn on_timeout_packet_validate( + &self, + packet: &Packet, + relayer: &Signer, + ) -> Result<(), PacketError> { + self.transfer_module + .on_timeout_packet_validate(packet, relayer) + } + + fn on_timeout_packet_execute( + &mut self, + packet: &Packet, + relayer: &Signer, + ) -> (ModuleExtras, Result<(), PacketError>) { + self.transfer_module + .on_timeout_packet_execute(packet, relayer) + } +} + +impl PfmContext for PfmTransferModule +where + C: IbcCommonContext + Debug, + Params: namada_systems::parameters::Read<::Storage>, +{ + type Error = crate::Error; + + fn send_transfer_execute( + &mut self, + msg: MsgTransfer, + ) -> Result { + let seq = self + .transfer_module + .ctx + .inner + .borrow() + .get_next_sequence_send(&msg.port_id_on_a, &msg.chan_id_on_a) + .map_err(|e| Error::Context(Box::new(e)))?; + + let mut ctx = IbcContext::::new( + self.transfer_module.ctx.inner.clone(), + ); + let mut token_transfer_ctx = TokenTransferContext::new( + self.transfer_module.ctx.inner.clone(), + Default::default(), + ); + + send_transfer_execute(&mut ctx, &mut token_transfer_ctx, msg) + .map_err(Error::TokenTransfer)?; + Ok(seq) + } + + fn receive_refund_execute( + &mut self, + _: &Packet, + _: PacketData, + ) -> Result<(), Self::Error> { + Ok(()) + } + + fn send_refund_execute( + &mut self, + msg: &InFlightPacket, + ) -> Result<(), Self::Error> { + // the token is not Namada native + if is_sender_chain_source( + msg.packet_data.token.to_string(), + &msg.packet_src_port_id, + &msg.packet_src_channel_id, + ) { + let escrow_address = Address::Internal(InternalAddress::Ibc); + self.transfer_module.ctx.insert_verifier(&MULTITOKEN); + let mut token_transfer_ctx = TokenTransferContext::new( + self.transfer_module.ctx.inner.clone(), + self.transfer_module.ctx.verifiers.clone(), + ); + + token_transfer_ctx + .burn_coins_execute( + &escrow_address, + &msg.packet_data.token, + &msg.packet_data.memo, + ) + .map_err(Error::TokenTransfer) + } else { + Ok(()) + } + } + + fn write_ack_and_events( + &mut self, + packet: &Packet, + acknowledgement: &Acknowledgement, + ) -> Result<(), Self::Error> { + let mut ctx = IbcContext::::new( + self.transfer_module.ctx.inner.clone(), + ); + commit_packet_acknowledgment(&mut ctx, packet, acknowledgement) + .map_err(|e| Error::Context(Box::new(e)))?; + emit_packet_acknowledgement_event( + &mut ctx, + packet.clone(), + acknowledgement.clone(), + ) + .map_err(|e| Error::Context(Box::new(e))) + } + + fn override_receiver( + &self, + _: &ChannelId, + _: &Signer, + ) -> Result { + Ok(Address::Internal(InternalAddress::Ibc).to_string().into()) + } + + #[allow(clippy::arithmetic_side_effects)] + fn timeout_timestamp( + &self, + timeout_duration: dur::Duration, + ) -> Result { + let timestamp = self + .transfer_module + .ctx + .inner + .borrow() + .host_timestamp() + .map_err(|e| Error::Other(e.to_string()))? + + timeout_duration.try_to_std().ok_or_else(|| { + Error::Other(format!( + "Packet timeout duration is too large: {timeout_duration}" + )) + })?; + timestamp + .map(TimeoutTimestamp::At) + .map_err(|e| Error::Other(e.to_string())) + } + + fn store_inflight_packet( + &mut self, + key: InFlightPacketKey, + inflight_packet: InFlightPacket, + ) -> Result<(), Self::Error> { + let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); + let key = get_inflight_packet_key(&key); + ctx.storage_mut() + .write(&key, inflight_packet.serialize_to_vec()) + .map_err(Error::Storage) + } + + fn retrieve_inflight_packet( + &self, + key: &InFlightPacketKey, + ) -> Result, Self::Error> { + let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); + let key = get_inflight_packet_key(key); + ctx.storage_mut().read(&key).map_err(Error::Storage) + } + + fn delete_inflight_packet( + &mut self, + key: &InFlightPacketKey, + ) -> Result<(), Self::Error> { + let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); + let key = get_inflight_packet_key(key); + ctx.storage_mut().delete(&key).map_err(Error::Storage) + } + + fn get_denom_for_this_chain( + &self, + this_chain_port: &PortId, + this_chain_chan: &ChannelId, + source_port: &PortId, + source_chan: &ChannelId, + source_denom: &PrefixedDenom, + ) -> Result { + let mut new_denom = source_denom.clone(); + // We will see this prefix on the asset if it is Namada native + let native_prefix = + TracePrefix::new(source_port.clone(), source_chan.clone()); + if source_denom.trace_path.starts_with(&native_prefix) { + // this asset originated from this chain; unwind + new_denom.trace_path.remove_prefix(&native_prefix); + } else { + // this asset originated from a foreign chain; add a new hop + new_denom.trace_path.add_prefix(TracePrefix::new( + this_chain_port.clone(), + this_chain_chan.clone(), + )); + } + Ok(new_denom) + } +} + +impl ModuleWrapper + for PacketForwardMiddleware> +where + C: IbcCommonContext + Debug, + Params: namada_systems::parameters::Read<::Storage>, +{ + fn as_module(&self) -> &dyn Module { + self + } + + fn as_module_mut(&mut self) -> &mut dyn Module { + self + } + + fn module_id(&self) -> ModuleId { + ModuleId::new(ibc::apps::transfer::types::MODULE_ID_STR.to_string()) + } + + fn port_id(&self) -> PortId { + PortId::transfer() + } +} diff --git a/crates/ibc/src/context/token_transfer.rs b/crates/ibc/src/context/token_transfer.rs index da3bedc41c..fecc8d4d2d 100644 --- a/crates/ibc/src/context/token_transfer.rs +++ b/crates/ibc/src/context/token_transfer.rs @@ -25,8 +25,8 @@ pub struct TokenTransferContext where C: IbcCommonContext, { - inner: Rc>, - verifiers: Rc>>, + pub(crate) inner: Rc>, + pub(crate) verifiers: Rc>>, is_shielded: bool, } @@ -47,7 +47,7 @@ where } /// Insert a verifier address whose VP will verify the tx. - fn insert_verifier(&mut self, addr: &Address) { + pub(crate) fn insert_verifier(&mut self, addr: &Address) { self.verifiers.borrow_mut().insert(addr.clone()); } diff --git a/crates/ibc/src/context/transfer_mod.rs b/crates/ibc/src/context/transfer_mod.rs index 9a1075e280..a30826514d 100644 --- a/crates/ibc/src/context/transfer_mod.rs +++ b/crates/ibc/src/context/transfer_mod.rs @@ -276,7 +276,7 @@ where &mut self, packet: &Packet, _relayer: &Signer, - ) -> (ModuleExtras, Acknowledgement) { + ) -> (ModuleExtras, Option) { on_recv_packet_execute(&mut self.ctx, packet) } @@ -497,10 +497,10 @@ pub mod testing { &mut self, _packet: &Packet, _relayer: &Signer, - ) -> (ModuleExtras, Acknowledgement) { + ) -> (ModuleExtras, Option) { ( ModuleExtras::empty(), - AcknowledgementStatus::success(ack_success_b64()).into(), + Some(AcknowledgementStatus::success(ack_success_b64()).into()), ) } diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index 74830fda51..c4e84151cf 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -143,6 +143,8 @@ pub enum Error { ChainId(IdentifierError), #[error("Verifier insertion error: {0}")] Verifier(StorageError), + #[error("Storage read/write error: {0}")] + Storage(StorageError), #[error("IBC error: {0}")] Other(String), } diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index a31ac28ac3..1f9185ca3d 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -1369,6 +1369,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" +[[package]] +name = "dur" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce5b6c91b5e394b75cd96c36393fc938496c030220207a0ccf34d6cd313d3b49" +dependencies = [ + "nom", + "rust_decimal", +] + [[package]] name = "duration-str" version = "0.10.0" @@ -2554,7 +2564,7 @@ dependencies = [ [[package]] name = "ibc" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-apps", "ibc-clients", @@ -2567,7 +2577,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-nft-transfer-types", "ibc-core", @@ -2577,7 +2587,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "base64 0.22.1", "borsh", @@ -2598,7 +2608,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-transfer-types", "ibc-core", @@ -2608,7 +2618,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2626,7 +2636,7 @@ dependencies = [ [[package]] name = "ibc-apps" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-nft-transfer", "ibc-app-transfer", @@ -2635,7 +2645,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "ibc-client-tendermint-types", @@ -2652,7 +2662,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "displaydoc", "ibc-core-client-types", @@ -2669,7 +2679,7 @@ dependencies = [ [[package]] name = "ibc-client-wasm-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "base64 0.22.1", "displaydoc", @@ -2683,7 +2693,7 @@ dependencies = [ [[package]] name = "ibc-clients" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-client-tendermint", "ibc-client-wasm-types", @@ -2692,7 +2702,7 @@ dependencies = [ [[package]] name = "ibc-core" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -2708,7 +2718,7 @@ dependencies = [ [[package]] name = "ibc-core-channel" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel-types", "ibc-core-client", @@ -2723,7 +2733,7 @@ dependencies = [ [[package]] name = "ibc-core-channel-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2746,7 +2756,7 @@ dependencies = [ [[package]] name = "ibc-core-client" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-client-context", "ibc-core-client-types", @@ -2759,7 +2769,7 @@ dependencies = [ [[package]] name = "ibc-core-client-context" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -2775,7 +2785,7 @@ dependencies = [ [[package]] name = "ibc-core-client-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2795,7 +2805,7 @@ dependencies = [ [[package]] name = "ibc-core-commitment-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2814,7 +2824,7 @@ dependencies = [ [[package]] name = "ibc-core-connection" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-client-wasm-types", "ibc-core-client", @@ -2828,7 +2838,7 @@ dependencies = [ [[package]] name = "ibc-core-connection-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2849,7 +2859,7 @@ dependencies = [ [[package]] name = "ibc-core-handler" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -2864,7 +2874,7 @@ dependencies = [ [[package]] name = "ibc-core-handler-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2888,7 +2898,7 @@ dependencies = [ [[package]] name = "ibc-core-host" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -2906,7 +2916,7 @@ dependencies = [ [[package]] name = "ibc-core-host-cosmos" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -2929,7 +2939,7 @@ dependencies = [ [[package]] name = "ibc-core-host-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2944,7 +2954,7 @@ dependencies = [ [[package]] name = "ibc-core-router" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -2958,7 +2968,7 @@ dependencies = [ [[package]] name = "ibc-core-router-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -2977,17 +2987,36 @@ dependencies = [ [[package]] name = "ibc-derive" version = "0.8.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "proc-macro2", "quote", "syn 2.0.52", ] +[[package]] +name = "ibc-middleware-packet-forward" +version = "0.2.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.2.0#6edafe7335c7287191488a3f7c7466ceebd7961f" +dependencies = [ + "borsh", + "dur", + "either", + "ibc-app-transfer-types", + "ibc-core-channel", + "ibc-core-channel-types", + "ibc-core-host-types", + "ibc-core-router", + "ibc-core-router-types", + "ibc-primitives", + "serde", + "serde_json", +] + [[package]] name = "ibc-primitives" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -3027,7 +3056,7 @@ dependencies = [ [[package]] name = "ibc-query" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "displaydoc", "ibc", @@ -3038,7 +3067,7 @@ dependencies = [ [[package]] name = "ibc-testkit" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "basecoin-store", "derive_more", @@ -3578,6 +3607,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -3778,8 +3813,10 @@ version = "0.46.0" dependencies = [ "borsh", "data-encoding", + "dur", "ibc", "ibc-derive", + "ibc-middleware-packet-forward", "ibc-testkit", "ics23", "konst", @@ -4335,6 +4372,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nonempty" version = "0.7.0" @@ -5482,12 +5529,18 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.35.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" dependencies = [ "arrayvec", + "borsh", + "bytes", "num-traits 0.2.17", + "rand 0.8.5", + "rkyv", + "serde", + "serde_json", ] [[package]] @@ -5850,11 +5903,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] diff --git a/wasm_for_tests/Cargo.lock b/wasm_for_tests/Cargo.lock index f9acde8215..a8b863ffc1 100644 --- a/wasm_for_tests/Cargo.lock +++ b/wasm_for_tests/Cargo.lock @@ -23,6 +23,17 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "1.1.2" @@ -389,6 +400,28 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -690,6 +723,16 @@ dependencies = [ "syn 2.0.65", ] +[[package]] +name = "dur" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce5b6c91b5e394b75cd96c36393fc938496c030220207a0ccf34d6cd313d3b49" +dependencies = [ + "nom", + "rust_decimal", +] + [[package]] name = "dyn-clone" version = "1.0.16" @@ -1033,6 +1076,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + [[package]] name = "hashbrown" version = "0.14.3" @@ -1106,7 +1158,7 @@ dependencies = [ [[package]] name = "ibc" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-apps", "ibc-clients", @@ -1119,7 +1171,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-nft-transfer-types", "ibc-core", @@ -1129,7 +1181,7 @@ dependencies = [ [[package]] name = "ibc-app-nft-transfer-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "base64 0.22.1", "borsh", @@ -1150,7 +1202,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-transfer-types", "ibc-core", @@ -1160,7 +1212,7 @@ dependencies = [ [[package]] name = "ibc-app-transfer-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1178,7 +1230,7 @@ dependencies = [ [[package]] name = "ibc-apps" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-app-nft-transfer", "ibc-app-transfer", @@ -1187,7 +1239,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "ibc-client-tendermint-types", @@ -1204,7 +1256,7 @@ dependencies = [ [[package]] name = "ibc-client-tendermint-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "displaydoc", "ibc-core-client-types", @@ -1221,7 +1273,7 @@ dependencies = [ [[package]] name = "ibc-client-wasm-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "base64 0.22.1", "displaydoc", @@ -1235,7 +1287,7 @@ dependencies = [ [[package]] name = "ibc-clients" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-client-tendermint", "ibc-client-wasm-types", @@ -1244,7 +1296,7 @@ dependencies = [ [[package]] name = "ibc-core" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -1260,7 +1312,7 @@ dependencies = [ [[package]] name = "ibc-core-channel" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel-types", "ibc-core-client", @@ -1275,7 +1327,7 @@ dependencies = [ [[package]] name = "ibc-core-channel-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1298,7 +1350,7 @@ dependencies = [ [[package]] name = "ibc-core-client" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-client-context", "ibc-core-client-types", @@ -1311,7 +1363,7 @@ dependencies = [ [[package]] name = "ibc-core-client-context" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -1327,7 +1379,7 @@ dependencies = [ [[package]] name = "ibc-core-client-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1347,7 +1399,7 @@ dependencies = [ [[package]] name = "ibc-core-commitment-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1366,7 +1418,7 @@ dependencies = [ [[package]] name = "ibc-core-connection" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-client-wasm-types", "ibc-core-client", @@ -1380,7 +1432,7 @@ dependencies = [ [[package]] name = "ibc-core-connection-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1401,7 +1453,7 @@ dependencies = [ [[package]] name = "ibc-core-handler" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "ibc-core-channel", "ibc-core-client", @@ -1416,7 +1468,7 @@ dependencies = [ [[package]] name = "ibc-core-handler-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1440,7 +1492,7 @@ dependencies = [ [[package]] name = "ibc-core-host" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -1458,7 +1510,7 @@ dependencies = [ [[package]] name = "ibc-core-host-cosmos" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -1481,7 +1533,7 @@ dependencies = [ [[package]] name = "ibc-core-host-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1496,7 +1548,7 @@ dependencies = [ [[package]] name = "ibc-core-router" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "derive_more", "displaydoc", @@ -1510,7 +1562,7 @@ dependencies = [ [[package]] name = "ibc-core-router-types" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1529,17 +1581,36 @@ dependencies = [ [[package]] name = "ibc-derive" version = "0.8.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "proc-macro2", "quote", "syn 2.0.65", ] +[[package]] +name = "ibc-middleware-packet-forward" +version = "0.2.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.2.0#6edafe7335c7287191488a3f7c7466ceebd7961f" +dependencies = [ + "borsh", + "dur", + "either", + "ibc-app-transfer-types", + "ibc-core-channel", + "ibc-core-channel-types", + "ibc-core-host-types", + "ibc-core-router", + "ibc-core-router-types", + "ibc-primitives", + "serde", + "serde_json", +] + [[package]] name = "ibc-primitives" version = "0.54.0" -source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=38bd2a32f35117d4d9165a3c68c64ccd87ad56dd#38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" +source = "git+https://github.com/heliaxdev/cosmos-ibc-rs?rev=aa229566e6bb688cc2626dab276c3849abc0c583#aa229566e6bb688cc2626dab276c3849abc0c583" dependencies = [ "borsh", "derive_more", @@ -1674,7 +1745,7 @@ source = "git+https://github.com/heliaxdev/indexmap?tag=2.2.4-heliax-1#b5b5b547b dependencies = [ "borsh", "equivalent", - "hashbrown", + "hashbrown 0.14.3", "serde", ] @@ -1685,7 +1756,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.3", ] [[package]] @@ -1942,6 +2013,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "multimap" version = "0.8.3" @@ -2065,8 +2142,10 @@ version = "0.46.0" dependencies = [ "borsh", "data-encoding", + "dur", "ibc", "ibc-derive", + "ibc-middleware-packet-forward", "ics23", "konst", "masp_primitives", @@ -2402,6 +2481,16 @@ dependencies = [ "sha2 0.9.9", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nonempty" version = "0.7.0" @@ -2876,6 +2965,26 @@ dependencies = [ "prost 0.13.2", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quote" version = "1.0.36" @@ -3021,6 +3130,15 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + [[package]] name = "rfc6979" version = "0.4.0" @@ -3040,6 +3158,35 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "rkyv" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "rlp" version = "0.5.2" @@ -3062,6 +3209,22 @@ dependencies = [ "svgbobdoc", ] +[[package]] +name = "rust_decimal" +version = "1.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" +dependencies = [ + "arrayvec", + "borsh", + "bytes", + "num-traits 0.2.17", + "rand", + "rkyv", + "serde", + "serde_json", +] + [[package]] name = "rustc-hex" version = "2.1.0" @@ -3150,6 +3313,12 @@ dependencies = [ "syn 2.0.65", ] +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "sec1" version = "0.7.3" @@ -3234,11 +3403,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -3314,6 +3484,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + [[package]] name = "slab" version = "0.4.9" @@ -3902,6 +4078,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "uuid" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" + [[package]] name = "version_check" version = "0.9.4" From 8ace5244d06b2035117d7a5c6dd96d2cccdb287a Mon Sep 17 00:00:00 2001 From: satan Date: Fri, 22 Nov 2024 15:19:04 +0100 Subject: [PATCH 02/14] Replaced ibc transfer modules with pfm transfer modules --- crates/benches/native_vps.rs | 15 ++++++++++----- crates/ibc/src/context/pfm_mod.rs | 19 +++++++++++++++++++ crates/ibc/src/vp/mod.rs | 11 +++++++---- crates/tx_prelude/src/ibc.rs | 8 ++++++-- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/crates/benches/native_vps.rs b/crates/benches/native_vps.rs index f2350ca722..13553332f3 100644 --- a/crates/benches/native_vps.rs +++ b/crates/benches/native_vps.rs @@ -23,6 +23,7 @@ use namada_apps_lib::governance::pgf::storage::steward::StewardDetail; use namada_apps_lib::governance::storage::proposal::ProposalType; use namada_apps_lib::governance::storage::vote::ProposalVote; use namada_apps_lib::governance::{InitProposalData, VoteProposalData}; +use namada_apps_lib::ibc::context::pfm_mod::PfmTransferModule; use namada_apps_lib::ibc::core::channel::types::channel::Order; use namada_apps_lib::ibc::core::channel::types::msgs::MsgChannelOpenInit; use namada_apps_lib::ibc::core::channel::types::Version as ChannelVersion; @@ -34,9 +35,7 @@ use namada_apps_lib::ibc::core::host::types::identifiers::{ ClientId, ConnectionId, PortId, }; use namada_apps_lib::ibc::primitives::ToProto; -use namada_apps_lib::ibc::{ - IbcActions, NftTransferModule, TransferModule, COMMITMENT_PREFIX, -}; +use namada_apps_lib::ibc::{IbcActions, NftTransferModule, COMMITMENT_PREFIX}; use namada_apps_lib::masp_primitives::merkle_tree::CommitmentTree; use namada_apps_lib::masp_primitives::transaction::Transaction; use namada_apps_lib::masp_proofs::sapling::SaplingVerificationContextInner; @@ -1718,7 +1717,10 @@ fn ibc_vp_validate_action(c: &mut Criterion) { ); actions.set_validation_params(ibc.validation_params().unwrap()); - let module = TransferModule::new(ctx.clone(), verifiers); + let module = PfmTransferModule::<_, parameters::Store<_>>::wrap( + ctx.clone(), + verifiers, + ); actions.add_transfer_module(module); let module = NftTransferModule::<_, token::Store<()>>::new(ctx); actions.add_transfer_module(module); @@ -1779,7 +1781,10 @@ fn ibc_vp_execute_action(c: &mut Criterion) { ); actions.set_validation_params(ibc.validation_params().unwrap()); - let module = TransferModule::new(ctx.clone(), verifiers); + let module = PfmTransferModule::<_, parameters::Store<_>>::wrap( + ctx.clone(), + verifiers, + ); actions.add_transfer_module(module); let module = NftTransferModule::<_, token::Store<()>>::new(ctx); actions.add_transfer_module(module); diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index 58a4472e2e..391a67eea1 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -1,7 +1,10 @@ //! Implementation of Packet Forward Middleware for our IBC modules. +use std::cell::RefCell; +use std::collections::BTreeSet; use std::fmt::{Debug, Formatter}; use std::marker::PhantomData; +use std::rc::Rc; use ibc::apps::transfer::context::TokenTransferExecutionContext; use ibc::apps::transfer::handler::send_transfer_execute; @@ -68,6 +71,22 @@ where pub _phantom: PhantomData, } +impl PfmTransferModule +where + C: IbcCommonContext + Debug, +{ + /// Create a new [`PfmTransferModule`] + pub fn wrap( + ctx: Rc>, + verifiers: Rc>>, + ) -> PacketForwardMiddleware { + PacketForwardMiddleware::next(Self { + transfer_module: TransferModule::new(ctx, verifiers), + _phantom: Default::default(), + }) + } +} + impl Debug for PfmTransferModule { diff --git a/crates/ibc/src/vp/mod.rs b/crates/ibc/src/vp/mod.rs index 6df0eba624..4ecd134963 100644 --- a/crates/ibc/src/vp/mod.rs +++ b/crates/ibc/src/vp/mod.rs @@ -27,6 +27,7 @@ use namada_vp::native_vp::{Ctx, CtxPreStorageRead, NativeVp, VpEvaluator}; use namada_vp::VpEnv; use thiserror::Error; +use crate::context::pfm_mod::PfmTransferModule; use crate::core::host::types::identifiers::ChainId as IbcChainId; use crate::core::host::types::path::UPGRADED_IBC_STATE; use crate::event::IbcEvent; @@ -36,8 +37,8 @@ use crate::storage::{ }; use crate::trace::calc_hash; use crate::{ - Error as ActionError, IbcActions, NftTransferModule, TransferModule, - ValidationParams, COMMITMENT_PREFIX, + Error as ActionError, IbcActions, NftTransferModule, ValidationParams, + COMMITMENT_PREFIX, }; #[allow(missing_docs)] @@ -246,7 +247,8 @@ where ctx.clone(), verifiers.clone(), ); - let module = TransferModule::new(ctx.clone(), verifiers); + let module = + PfmTransferModule::<_, ParamsPseudo>::wrap(ctx.clone(), verifiers); actions.add_transfer_module(module); let module = NftTransferModule::<_, Token>::new(ctx.clone()); actions.add_transfer_module(module); @@ -301,7 +303,8 @@ where IbcActions::<_, Params, Token>::new(ctx.clone(), verifiers.clone()); actions.set_validation_params(self.validation_params()?); - let module = TransferModule::new(ctx.clone(), verifiers); + let module = + PfmTransferModule::<_, Params>::wrap(ctx.clone(), verifiers); actions.add_transfer_module(module); let module = NftTransferModule::<_, Token>::new(ctx); actions.add_transfer_module(module); diff --git a/crates/tx_prelude/src/ibc.rs b/crates/tx_prelude/src/ibc.rs index 283dc0f723..436a6befc2 100644 --- a/crates/tx_prelude/src/ibc.rs +++ b/crates/tx_prelude/src/ibc.rs @@ -6,6 +6,7 @@ use std::rc::Rc; use namada_core::address::Address; use namada_core::token::Amount; +use namada_ibc::context::pfm_mod::PfmTransferModule; pub use namada_ibc::event::{IbcEvent, IbcEventType}; pub use namada_ibc::storage::{ burn_tokens, client_state_key, is_ibc_key, mint_limit_key, mint_tokens, @@ -19,7 +20,7 @@ pub use namada_ibc::{ }; use namada_tx_env::TxEnv; -use crate::{token, Ctx, Result}; +use crate::{parameters, token, Ctx, Result}; /// IBC actions to handle an IBC message. The `verifiers` inserted into the set /// must be inserted into the tx context with `Ctx::insert_verifier` after tx @@ -30,7 +31,10 @@ pub fn ibc_actions( let ctx = Rc::new(RefCell::new(ctx.clone())); let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); let mut actions = IbcActions::new(ctx.clone(), verifiers.clone()); - let module = TransferModule::new(ctx.clone(), verifiers); + let module = PfmTransferModule::<_, parameters::Store>::wrap( + ctx.clone(), + verifiers, + ); actions.add_transfer_module(module); let module = NftTransferModule::>::new(ctx); actions.add_transfer_module(module); From f4989848fc3f47a7a344a29eb7e1a78bca94e6b7 Mon Sep 17 00:00:00 2001 From: satan Date: Fri, 22 Nov 2024 15:48:58 +0100 Subject: [PATCH 03/14] Made module wrapper impl of pfms more generic --- crates/ibc/src/context/pfm_mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index 391a67eea1..3656d897df 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -403,11 +403,9 @@ where } } -impl ModuleWrapper - for PacketForwardMiddleware> +impl ModuleWrapper for PacketForwardMiddleware where - C: IbcCommonContext + Debug, - Params: namada_systems::parameters::Read<::Storage>, + T: Module + PfmContext, { fn as_module(&self) -> &dyn Module { self From 0ce12107294ca46d9990019cab37b5daf67a30d5 Mon Sep 17 00:00:00 2001 From: satan Date: Fri, 22 Nov 2024 16:14:35 +0100 Subject: [PATCH 04/14] Fixed bug in pfm module impl --- crates/ibc/src/context/pfm_mod.rs | 104 ++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 12 deletions(-) diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index 3656d897df..ab7adde370 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -177,6 +177,86 @@ where ) } + fn on_chan_open_ack_validate( + &self, + port_id: &PortId, + channel_id: &ChannelId, + counterparty_version: &Version, + ) -> Result<(), ChannelError> { + self.transfer_module.on_chan_open_ack_validate( + port_id, + channel_id, + counterparty_version, + ) + } + + fn on_chan_open_ack_execute( + &mut self, + port_id: &PortId, + channel_id: &ChannelId, + counterparty_version: &Version, + ) -> Result { + self.transfer_module.on_chan_open_ack_execute( + port_id, + channel_id, + counterparty_version, + ) + } + + fn on_chan_open_confirm_validate( + &self, + port_id: &PortId, + channel_id: &ChannelId, + ) -> Result<(), ChannelError> { + self.transfer_module + .on_chan_open_confirm_validate(port_id, channel_id) + } + + fn on_chan_open_confirm_execute( + &mut self, + port_id: &PortId, + channel_id: &ChannelId, + ) -> Result { + self.transfer_module + .on_chan_open_confirm_execute(port_id, channel_id) + } + + fn on_chan_close_init_validate( + &self, + port_id: &PortId, + channel_id: &ChannelId, + ) -> Result<(), ChannelError> { + self.transfer_module + .on_chan_close_init_validate(port_id, channel_id) + } + + fn on_chan_close_init_execute( + &mut self, + port_id: &PortId, + channel_id: &ChannelId, + ) -> Result { + self.transfer_module + .on_chan_close_init_execute(port_id, channel_id) + } + + fn on_chan_close_confirm_validate( + &self, + port_id: &PortId, + channel_id: &ChannelId, + ) -> Result<(), ChannelError> { + self.transfer_module + .on_chan_close_confirm_validate(port_id, channel_id) + } + + fn on_chan_close_confirm_execute( + &mut self, + port_id: &PortId, + channel_id: &ChannelId, + ) -> Result { + self.transfer_module + .on_chan_close_confirm_execute(port_id, channel_id) + } + fn on_recv_packet_execute( &mut self, packet: &Packet, @@ -187,27 +267,27 @@ where fn on_acknowledgement_packet_validate( &self, - _packet: &Packet, - _acknowledgement: &Acknowledgement, - _relayer: &Signer, + packet: &Packet, + acknowledgement: &Acknowledgement, + relayer: &Signer, ) -> Result<(), PacketError> { self.transfer_module.on_acknowledgement_packet_validate( - _packet, - _acknowledgement, - _relayer, + packet, + acknowledgement, + relayer, ) } fn on_acknowledgement_packet_execute( &mut self, - _packet: &Packet, - _acknowledgement: &Acknowledgement, - _relayer: &Signer, + packet: &Packet, + acknowledgement: &Acknowledgement, + relayer: &Signer, ) -> (ModuleExtras, Result<(), PacketError>) { self.transfer_module.on_acknowledgement_packet_execute( - _packet, - _acknowledgement, - _relayer, + packet, + acknowledgement, + relayer, ) } From 631555249e771088d0e34bda64a4cb5185e178c2 Mon Sep 17 00:00:00 2001 From: satan Date: Tue, 26 Nov 2024 11:25:59 +0100 Subject: [PATCH 05/14] WIP ibc pfm e2e test --- Cargo.lock | 5 +- Cargo.toml | 2 +- crates/tests/Cargo.toml | 1 + crates/tests/src/e2e/helpers.rs | 32 +++++- crates/tests/src/e2e/ibc_tests.rs | 164 ++++++++++++++++++++++++------ crates/tests/src/e2e/setup.rs | 64 ++++++++---- wasm/Cargo.lock | 5 +- wasm_for_tests/Cargo.lock | 4 +- 8 files changed, 216 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a8664ee1cb..ef201866a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3786,8 +3786,8 @@ dependencies = [ [[package]] name = "ibc-middleware-packet-forward" -version = "0.2.0" -source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.2.0#6edafe7335c7287191488a3f7c7466ceebd7961f" +version = "0.3.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.3.0#128ffa23f785d0a681038aca28a1d96cacb80452" dependencies = [ "borsh", "dur", @@ -5532,6 +5532,7 @@ dependencies = [ "flate2", "fs_extra", "hyper 0.14.27", + "ibc-middleware-packet-forward", "ibc-testkit", "ics23", "itertools 0.12.1", diff --git a/Cargo.toml b/Cargo.toml index 5ffae8cef3..e61db93cb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,7 +121,7 @@ git2 = { version = "0.18.1", default-features = false } # branch yuji/derive-arbitrary ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", features = ["serde"] } ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583" } -ibc-middleware-packet-forward = {git = "https://github.com/heliaxdev/ibc-middleware", tag = "v0.2.0", features = ["borsh"]} +ibc-middleware-packet-forward = {git = "https://github.com/heliaxdev/ibc-middleware", tag = "v0.3.0", features = ["borsh"]} ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", default-features = false } ics23 = "0.12.0" index-set = { git = "https://github.com/heliaxdev/index-set", tag = "v0.8.1", features = ["serialize-borsh", "serialize-serde"] } diff --git a/crates/tests/Cargo.toml b/crates/tests/Cargo.toml index 14e422cce2..de8a32e36c 100644 --- a/crates/tests/Cargo.toml +++ b/crates/tests/Cargo.toml @@ -39,6 +39,7 @@ namada_vm = {path = "../vm", features = ["testing"]} concat-idents.workspace = true derivative.workspace = true hyper = {version = "0.14.20", features = ["full"]} +ibc-middleware-packet-forward.workspace = true ibc-testkit.workspace = true ics23.workspace = true itertools.workspace = true diff --git a/crates/tests/src/e2e/helpers.rs b/crates/tests/src/e2e/helpers.rs index ab3579a1a2..70662eb6ba 100644 --- a/crates/tests/src/e2e/helpers.rs +++ b/crates/tests/src/e2e/helpers.rs @@ -585,7 +585,8 @@ fn make_hermes_chain_config_for_cosmos( ) -> Value { let mut table = toml::map::Map::new(); table.insert("mode".to_owned(), Value::String("push".to_owned())); - let url = format!("ws://{}/websocket", setup::constants::COSMOS_RPC); + let offset = chain_type.get_offset(); + let url = format!("ws://127.0.0.1:6416{}/websocket", offset); table.insert("url".to_owned(), Value::String(url)); table.insert("batch_delay".to_owned(), Value::String("500ms".to_owned())); let event_source = Value::Table(table); @@ -596,14 +597,16 @@ fn make_hermes_chain_config_for_cosmos( Value::String(test.net.chain_id.to_string()), ); chain.insert("type".to_owned(), Value::String("CosmosSdk".to_owned())); + chain.insert( "rpc_addr".to_owned(), - Value::String(format!("http://{}", setup::constants::COSMOS_RPC)), + Value::String(format!("http://127.0.0.1:6416{}", offset)), ); chain.insert( "grpc_addr".to_owned(), - Value::String("http://127.0.0.1:9090".to_owned()), + Value::String(format!("http://127.0.0.1:{}", offset + 9090)), ); + chain.insert("event_source".to_owned(), event_source); chain.insert( "account_prefix".to_owned(), @@ -629,7 +632,10 @@ fn make_hermes_chain_config_for_cosmos( Value::Table(chain) } -pub fn update_cosmos_config(test: &Test) -> Result<()> { +pub fn update_cosmos_config(test: &Test, mut update_config: F) -> Result<()> +where + F: FnMut(&mut Value), +{ let cosmos_dir = test.test_dir.as_ref().join(test.net.chain_id.as_str()); let config_path = cosmos_dir.join("config/config.toml"); let s = std::fs::read_to_string(&config_path) @@ -645,6 +651,24 @@ pub fn update_cosmos_config(test: &Test) -> Result<()> { *timeout_propose = "1s".into(); } } + let offset = CosmosChainType::chain_type(test.net.chain_id.as_str()).unwrap().get_offset(); + let p2p = values.get_mut("p2p") + .expect("Test failed") + .as_table_mut() + .expect("Test failed"); + let Some(laddr) = p2p.get_mut("laddr") else { + panic!("Test failed") + }; + *laddr = format!("tcp://0.0.0.0:266{}{}", offset, offset).into(); + let rpc = values.get_mut("rpc") + .expect("Test failed") + .as_table_mut() + .expect("Test failed"); + let Some(laddr) = rpc.get_mut("laddr") else { + panic!("Test failed") + }; + *laddr = format!("tcp://0.0.0.0:6416{offset}").into(); + update_config(&mut values); let mut file = OpenOptions::new() .write(true) .truncate(true) diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index bde2ca2fa3..97e041da49 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -15,6 +15,8 @@ use std::path::{Path, PathBuf}; use color_eyre::eyre::Result; use eyre::eyre; +use ibc_middleware_packet_forward::ForwardMetadata; +use itertools::Either; use namada_apps_lib::client::rpc::query_storage_value_bytes; use namada_apps_lib::config::ethereum_bridge; use namada_apps_lib::config::genesis::templates; @@ -52,13 +54,10 @@ use crate::e2e::helpers::{ use crate::e2e::ledger_tests::{ start_namada_ledger_node_wait_wasm, write_json_file, }; -use crate::e2e::setup::{ - self, apply_use_device, run_cosmos_cmd, run_hermes_cmd, - set_ethereum_bridge_mode, setup_cosmos, setup_hermes, sleep, working_dir, - Bin, CosmosChainType, NamadaCmd, Test, Who, ENV_VAR_COSMWASM_CONTRACT_DIR, -}; +use crate::e2e::setup::{self, apply_use_device, run_cosmos_cmd, run_hermes_cmd, set_ethereum_bridge_mode, setup_cosmos, setup_hermes, sleep, working_dir, Bin, CosmosChainType, NamadaCmd, Test, Who, ENV_VAR_COSMWASM_CONTRACT_DIR}; use crate::strings::TX_APPLIED_SUCCESS; use crate::{run, run_as}; +use crate::ibc::primitives::Signer; const IBC_REFUND_TARGET_ALIAS: &str = "ibc-refund-target"; const IBC_CLINET_ID: &str = "07-tendermint-0"; @@ -100,11 +99,11 @@ fn ibc_transfers() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) }; let (ledger, gaia, test, test_gaia) = - run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?; + run_namada_cosmos(CosmosChainType::Gaia(None), update_genesis)?; let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia)?; + setup_hermes(&test, &test_gaia, false)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( @@ -239,7 +238,7 @@ fn ibc_transfers() -> Result<()> { 100, &port_id_gaia, &channel_id_gaia, - Some(shielding_data_path), + Some(Either::Left(shielding_data_path)), None, )?; wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test_gaia)?; @@ -297,7 +296,7 @@ fn ibc_transfers() -> Result<()> { 1_000_000, &port_id_gaia, &channel_id_gaia, - Some(memo_path), + Some(Either::Left(memo_path)), None, )?; wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; @@ -446,7 +445,7 @@ fn ibc_transfers() -> Result<()> { 101, &port_id_gaia, &channel_id_gaia, - Some(shielding_data_path), + Some(Either::Left(shielding_data_path)), // MASP VP shall reject it, make it timeout Some(Duration::new(10, 0)), )?; @@ -477,7 +476,7 @@ fn ibc_nft_transfers() -> Result<()> { let _bg_ledger = ledger.background(); let _bg_wasmd = cosmwasm.background(); - setup_hermes(&test, &test_cosmwasm)?; + setup_hermes(&test, &test_cosmwasm, false)?; let port_id_namada: PortId = NFT_PORT_ID.parse().unwrap(); let (cw721_contract, ics721_contract) = @@ -607,11 +606,11 @@ fn pgf_over_ibc() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) }; let (ledger, gaia, test, test_gaia) = - run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?; + run_namada_cosmos(CosmosChainType::Gaia(None), update_genesis)?; let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia)?; + setup_hermes(&test, &test_gaia, false)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia: PortId = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( @@ -704,7 +703,7 @@ fn fee_payment_with_ibc_token() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) }; let (ledger, gaia, test, test_gaia) = - run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?; + run_namada_cosmos(CosmosChainType::Gaia(None), update_genesis)?; let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); @@ -727,7 +726,7 @@ fn fee_payment_with_ibc_token() -> Result<()> { submit_votes(&test)?; // Create an IBC channel while waiting the grace epoch - setup_hermes(&test, &test_gaia)?; + setup_hermes(&test, &test_gaia, false)?; let port_id_gaia = FT_PORT_ID.parse().unwrap(); let port_id_namada = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( @@ -810,7 +809,7 @@ fn ibc_token_inflation() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) }; let (ledger, gaia, test, test_gaia) = - run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?; + run_namada_cosmos(CosmosChainType::Gaia(None), update_genesis)?; let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); @@ -833,7 +832,7 @@ fn ibc_token_inflation() -> Result<()> { submit_votes(&test)?; // Create an IBC channel while waiting the grace epoch - setup_hermes(&test, &test_gaia)?; + setup_hermes(&test, &test_gaia, false)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( @@ -871,7 +870,7 @@ fn ibc_token_inflation() -> Result<()> { 1, &port_id_gaia, &channel_id_gaia, - Some(shielding_data_path), + Some(Either::Left(shielding_data_path)), None, )?; wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; @@ -900,11 +899,11 @@ fn ibc_upgrade_client() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) }; let (ledger, gaia, test, test_gaia) = - run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?; + run_namada_cosmos(CosmosChainType::Gaia(None), update_genesis)?; let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia)?; + setup_hermes(&test, &test_gaia, false)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia: PortId = FT_PORT_ID.parse().unwrap(); create_channel_with_hermes( @@ -971,11 +970,11 @@ fn ibc_rate_limit() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) }; let (ledger, gaia, test, test_gaia) = - run_namada_cosmos(CosmosChainType::Gaia, update_genesis)?; + run_namada_cosmos(CosmosChainType::Gaia(None), update_genesis)?; let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia)?; + setup_hermes(&test, &test_gaia, false)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia: PortId = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( @@ -1088,6 +1087,89 @@ fn ibc_rate_limit() -> Result<()> { Ok(()) } +/// de wanna wanga +#[test] +fn ibc_pfm() -> Result<()> { + let update_genesis = + |mut genesis: templates::All, base_dir: &_| { + genesis.parameters.parameters.epochs_per_year = + epochs_per_year_from_min_duration(1800); + genesis.parameters.ibc_params.default_mint_limit = + Amount::max_signed(); + genesis + .parameters + .ibc_params + .default_per_epoch_throughput_limit = Amount::max_signed(); + setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) + }; + let (ledger, gaia_1, test, test_gaia_1) = + run_namada_cosmos(CosmosChainType::Gaia(Some(1)), update_genesis)?; + + // set up a second cosmos network + let test_gaia_2 = setup_cosmos( + CosmosChainType::Gaia(Some(2)) + )?; + let gaia_2 = run_cosmos(&test_gaia_2)?; + sleep(5); + + let _bg_ledger = ledger.background(); + let _bg_gaia_1 = gaia_1.background(); + let _bg_gaia_2 = gaia_2.background(); + setup_hermes(&test, &test_gaia_1, false)?; + setup_hermes(&test, &test_gaia_2, true)?; + sleep(5); + // create hermes relayers for connections between both cosmos networks and namada + let port_id_namada = FT_PORT_ID.parse().unwrap(); + let port_id_gaia_1 = FT_PORT_ID.parse().unwrap(); + let port_id_gaia_2 = FT_PORT_ID.parse().unwrap(); + + let (channel_id_gaia_1, channel_id_namada_1) = create_channel_with_hermes( + &test_gaia_1, + &test, + &port_id_namada, + &port_id_gaia_1, + )?; + let (channel_id_gaia_2, channel_id_namada_2) = create_channel_with_hermes( + &test_gaia_2, + &test, + &port_id_namada, + &port_id_gaia_2, + )?; + + // Start relaying + let hermes_1 = run_hermes(&test_gaia_1)?; + let hermes_2 = run_hermes(&test_gaia_2)?; + let _bg_hermes_1 = hermes_1.background(); + let _bg_hermes_2 = hermes_2.background(); + + // we will send a packt to bertha on namada + let namada_receiver = find_address(&test, BERTHA)?.to_string(); + // this will cause the ibc packet to be forwarded to the second + // cosmos network. + let pfm_memo = packet_forward_memo( + find_cosmos_address(&test_gaia_2, COSMOS_USER)?.into(), + port_id_namada.clone(), + channel_id_namada_2 + ); + transfer_from_cosmos( + &test_gaia_1, + COSMOS_USER, + &namada_receiver, + "samoleans", + 10, + &port_id_gaia_1, + &channel_id_gaia_1, + Some(Either::Right(pfm_memo)), + None, + )?; + wait_for_packet_relay(&port_id_namada, &channel_id_namada_1, &test)?; + wait_for_packet_relay(&port_id_gaia_2, &channel_id_gaia_2, &test)?; + // Check the samoleans have been received on the target cosmos network + check_cosmos_balance(&test_gaia_2, COSMOS_USER, format!("transfer/{channel_id_namada_1}/transfer/{channel_id_gaia_2}/samoleans"), 10)?; + + Ok(()) +} + fn run_namada_cosmos( chain_type: CosmosChainType, mut update_genesis: impl FnMut( @@ -1183,13 +1265,13 @@ fn run_cosmos(test: &Test) -> Result { .args(["-9", cmd_path]) .output() .unwrap(); - + let port_arg = format!("0.0.0.0:{}", 9090 + chain_type.get_offset()); let args = [ "start", "--pruning", "nothing", "--grpc.address", - "0.0.0.0:9090", + &port_arg, ]; let cosmos = run_cosmos_cmd(test, args, Some(40))?; Ok(cosmos) @@ -1805,7 +1887,7 @@ fn transfer_from_cosmos( amount: u64, port_id: &PortId, channel_id: &ChannelId, - memo_path: Option, + memo: Option>, timeout_sec: Option, ) -> Result<()> { let port_id = port_id.to_string(); @@ -1839,13 +1921,16 @@ fn transfer_from_cosmos( "--yes", ]; - let memo = memo_path - .as_ref() - .map(|path| { - std::fs::read_to_string(path).expect("Reading memo file failed") + let is_memo = memo.is_some(); + let memo = memo + .map(|m| { + match m { + Either::Left(path) => std::fs::read_to_string(path).expect("Reading memo file failed"), + Either::Right(memo) => memo, + } }) .unwrap_or_default(); - if memo_path.is_some() { + if is_memo { args.push("--memo"); args.push(&memo); } @@ -2331,3 +2416,22 @@ fn nft_transfer_from_cosmos( Ok(()) } + + +/// Create a packet forward memo and serialize it +fn packet_forward_memo( + receiver: Signer, + port_id: PortId, + channel_id: ChannelId, +) -> String { + serde_json::to_string(&ibc_middleware_packet_forward::PacketMetadata { + forward: ForwardMetadata { + receiver, + port: port_id, + channel: channel_id, + timeout: None, + retries: None, + next: None, + }, + }).expect("Test failed") +} diff --git a/crates/tests/src/e2e/setup.rs b/crates/tests/src/e2e/setup.rs index ebd2329aaa..ec815e4aa1 100644 --- a/crates/tests/src/e2e/setup.rs +++ b/crates/tests/src/e2e/setup.rs @@ -41,10 +41,7 @@ use rand::rngs::OsRng; use rand::Rng; use tempfile::{tempdir, tempdir_in, TempDir}; -use crate::e2e::helpers::{ - find_cosmos_address, generate_bin_command, make_hermes_config, - update_cosmos_config, -}; +use crate::e2e::helpers::{find_cosmos_address, generate_bin_command, make_hermes_config, update_cosmos_config}; /// For `color_eyre::install`, which fails if called more than once in the same /// process @@ -1251,12 +1248,12 @@ pub fn sleep(seconds: u64) { thread::sleep(time::Duration::from_secs(seconds)); } -pub fn setup_hermes(test_a: &Test, test_b: &Test) -> Result<()> { +pub fn setup_hermes(test_a: &Test, test_b: &Test, skip_keys: bool) -> Result<()> { println!("\n{}", "Setting up Hermes".underline().green(),); make_hermes_config(test_a, test_b)?; - for test in [test_a, test_b] { + for test in [test_b, test_a] { let chain_id = test.net.chain_id.as_str(); let chain_dir = test.test_dir.as_ref().join(chain_id); let key_file_path = match CosmosChainType::chain_type(chain_id) { @@ -1274,6 +1271,9 @@ pub fn setup_hermes(test_a: &Test, test_b: &Test) -> Result<()> { ]; let mut hermes = run_hermes_cmd(test, args, Some(20))?; hermes.assert_success(); + if skip_keys { + break; + } } Ok(()) @@ -1344,46 +1344,70 @@ where #[derive(Clone, Copy, Debug)] pub enum CosmosChainType { - Gaia, + Gaia(Option), CosmWasm, } impl CosmosChainType { - pub fn chain_id(&self) -> &str { + pub fn chain_id(&self) -> String { match self { - Self::Gaia => constants::GAIA_CHAIN_ID, - Self::CosmWasm => constants::COSMWASM_CHAIN_ID, + Self::Gaia(Some(suffix)) => { + format!("{}{}", constants::GAIA_CHAIN_ID, suffix) + } + Self::Gaia(_) => constants::GAIA_CHAIN_ID.to_string(), + Self::CosmWasm => constants::COSMWASM_CHAIN_ID.to_string(), } } pub fn command_path(&self) -> &str { match self { - Self::Gaia => "gaiad", + Self::Gaia(_) => "gaiad", Self::CosmWasm => "wasmd", } } pub fn chain_type(chain_id: &str) -> Result { - match chain_id { - constants::GAIA_CHAIN_ID => Ok(Self::Gaia), - constants::COSMWASM_CHAIN_ID => Ok(Self::CosmWasm), - _ => Err(eyre!(format!("Unexpected Cosmos chain ID: {chain_id}"))), + if chain_id == constants::COSMWASM_CHAIN_ID { + return Ok(Self::CosmWasm); + } + match chain_id.strip_prefix(constants::GAIA_CHAIN_ID) { + Some("") => Ok(Self::Gaia(None)), + Some(suffix) => { + Ok(Self::Gaia(Some(suffix.parse().map_err(|_| { + eyre!("Unexpected Cosmos chain ID: {chain_id}") + })?))) + } + _ => Err(eyre!("Unexpected Cosmos chain ID: {chain_id}")), } } pub fn account_prefix(&self) -> &str { match self { - Self::Gaia => "cosmos", + Self::Gaia(_) => "cosmos", Self::CosmWasm => "wasm", } } + + pub fn get_offset(&self) -> u64 { + match self { + Self::Gaia(Some(off)) => *off, + _ => 0 + } + } } pub fn setup_cosmos(chain_type: CosmosChainType) -> Result { + setup_cosmos_aux(chain_type, |_| {}) +} + +pub fn setup_cosmos_aux( + chain_type: CosmosChainType, + update_gaia: impl FnMut(&mut toml::Value), +) -> Result { let working_dir = working_dir(); let test_dir = TestDir::new(); let chain_id = chain_type.chain_id(); - let cosmos_dir = test_dir.as_ref().join(chain_id); + let cosmos_dir = test_dir.as_ref().join(&chain_id); let net = Network { chain_id: ChainId(chain_id.to_string()), }; @@ -1395,7 +1419,7 @@ pub fn setup_cosmos(chain_type: CosmosChainType) -> Result { }; // initialize - let args = ["--chain-id", chain_id, "init", chain_id]; + let args = ["--chain-id", &chain_id, "init", &chain_id]; let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); @@ -1460,7 +1484,7 @@ pub fn setup_cosmos(chain_type: CosmosChainType) -> Result { "--keyring-backend", "test", "--chain-id", - chain_id, + &chain_id, ]; let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); @@ -1469,7 +1493,7 @@ pub fn setup_cosmos(chain_type: CosmosChainType) -> Result { let mut cosmos = run_cosmos_cmd(&test, args, Some(10))?; cosmos.assert_success(); - update_cosmos_config(&test)?; + update_cosmos_config(&test, update_gaia)?; Ok(test) } diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 1f9185ca3d..ab2e941761 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -2996,8 +2996,8 @@ dependencies = [ [[package]] name = "ibc-middleware-packet-forward" -version = "0.2.0" -source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.2.0#6edafe7335c7287191488a3f7c7466ceebd7961f" +version = "0.3.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.3.0#128ffa23f785d0a681038aca28a1d96cacb80452" dependencies = [ "borsh", "dur", @@ -4102,6 +4102,7 @@ dependencies = [ "concat-idents", "derivative", "hyper 0.14.27", + "ibc-middleware-packet-forward", "ibc-testkit", "ics23", "itertools 0.12.1", diff --git a/wasm_for_tests/Cargo.lock b/wasm_for_tests/Cargo.lock index a8b863ffc1..02b53e4dda 100644 --- a/wasm_for_tests/Cargo.lock +++ b/wasm_for_tests/Cargo.lock @@ -1590,8 +1590,8 @@ dependencies = [ [[package]] name = "ibc-middleware-packet-forward" -version = "0.2.0" -source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.2.0#6edafe7335c7287191488a3f7c7466ceebd7961f" +version = "0.3.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.3.0#128ffa23f785d0a681038aca28a1d96cacb80452" dependencies = [ "borsh", "dur", From ffdd5296b653b50b454c15dc97618df410eb609d Mon Sep 17 00:00:00 2001 From: satan Date: Tue, 26 Nov 2024 12:09:34 +0100 Subject: [PATCH 06/14] wip --- crates/tests/src/e2e/ibc_tests.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 97e041da49..9553c0aac7 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -1109,7 +1109,7 @@ fn ibc_pfm() -> Result<()> { let test_gaia_2 = setup_cosmos( CosmosChainType::Gaia(Some(2)) )?; - let gaia_2 = run_cosmos(&test_gaia_2)?; + let gaia_2 = run_cosmos(&test_gaia_2, false)?; sleep(5); let _bg_ledger = ledger.background(); @@ -1165,7 +1165,7 @@ fn ibc_pfm() -> Result<()> { wait_for_packet_relay(&port_id_namada, &channel_id_namada_1, &test)?; wait_for_packet_relay(&port_id_gaia_2, &channel_id_gaia_2, &test)?; // Check the samoleans have been received on the target cosmos network - check_cosmos_balance(&test_gaia_2, COSMOS_USER, format!("transfer/{channel_id_namada_1}/transfer/{channel_id_gaia_2}/samoleans"), 10)?; + check_cosmos_balance(&test_gaia_2, COSMOS_USER, format!("transfer/{channel_id_gaia_2}/transfer/{channel_id_namada_1}/samoleans"), 10)?; Ok(()) } @@ -1191,7 +1191,7 @@ fn run_namada_cosmos( // Cosmos let test_cosmos = setup_cosmos(chain_type)?; - let cosmos = run_cosmos(&test_cosmos)?; + let cosmos = run_cosmos(&test_cosmos, true)?; sleep(5); Ok((ledger, cosmos, test, test_cosmos)) @@ -1256,15 +1256,17 @@ fn run_hermes(test: &Test) -> Result { Ok(hermes) } -fn run_cosmos(test: &Test) -> Result { +fn run_cosmos(test: &Test, kill: bool) -> Result { let chain_type = CosmosChainType::chain_type(test.net.chain_id.as_str())?; let cmd_path = chain_type.command_path(); // cosmos process is sometimes left lingering causing subsequent runs to // fail - std::process::Command::new("pkill") - .args(["-9", cmd_path]) - .output() - .unwrap(); + if kill { + std::process::Command::new("pkill") + .args(["-9", cmd_path]) + .output() + .unwrap(); + } let port_arg = format!("0.0.0.0:{}", 9090 + chain_type.get_offset()); let args = [ "start", @@ -1295,7 +1297,7 @@ fn wait_for_packet_relay( channel_id.as_str(), ]; for _ in 0..10 { - sleep(10); + sleep(30); let mut hermes = run_hermes_cmd(test, args, Some(40))?; // Check no pending packet if hermes @@ -1893,7 +1895,8 @@ fn transfer_from_cosmos( let port_id = port_id.to_string(); let channel_id = channel_id.to_string(); let amount = format!("{}{}", amount, token.as_ref()); - let rpc = format!("tcp://{COSMOS_RPC}"); + let offset = CosmosChainType::chain_type(test.net.chain_id.as_str()).unwrap().get_offset(); + let rpc = format!("tcp://127.0.0.1:6416{offset}"); // If the receiver is a pyament address we want to mask it to the more // general MASP internal address to improve on privacy let receiver = match PaymentAddress::from_str(receiver.as_ref()) { From b3012db98599e6f23b5d5355a9c3cd5973d0bb5a Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 26 Nov 2024 16:03:58 +0000 Subject: [PATCH 07/14] wip --- crates/ibc/src/context/common.rs | 9 +- crates/ibc/src/context/pfm_mod.rs | 37 ++++- crates/ibc/src/context/validation.rs | 12 +- crates/ibc/src/lib.rs | 15 +- crates/tests/src/e2e/helpers.rs | 45 ++--- crates/tests/src/e2e/ibc_tests.rs | 237 +++++++++++++++++++-------- crates/tests/src/e2e/setup.rs | 30 ++-- 7 files changed, 258 insertions(+), 127 deletions(-) diff --git a/crates/ibc/src/context/common.rs b/crates/ibc/src/context/common.rs index 7f920d8cb3..35233fd70e 100644 --- a/crates/ibc/src/context/common.rs +++ b/crates/ibc/src/context/common.rs @@ -576,14 +576,11 @@ pub trait IbcCommonContext: IbcStorageContext { port_id: &PortId, channel_id: &ChannelId, sequence: Sequence, - ) -> Result { + ) -> Result> { let key = storage::ack_key(port_id, channel_id, sequence); match self.storage().read_bytes(&key)? { - Some(value) => Ok(value.into()), - None => { - Err(PacketError::PacketAcknowledgementNotFound { sequence } - .into()) - } + Some(value) => Ok(Some(value.into())), + None => Ok(None), } } diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index ab7adde370..7493af4cef 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -30,7 +30,6 @@ use ibc_middleware_packet_forward::{ InFlightPacket, InFlightPacketKey, PacketForwardMiddleware, PfmContext, }; use namada_core::address::{Address, InternalAddress, MULTITOKEN}; -use namada_core::borsh::BorshSerializeExt; use namada_core::storage::{self, KeySeg}; use namada_state::{StorageRead, StorageWrite}; @@ -328,6 +327,7 @@ where .borrow() .get_next_sequence_send(&msg.port_id_on_a, &msg.chan_id_on_a) .map_err(|e| Error::Context(Box::new(e)))?; + tracing::warn!(?seq, ?msg, "PFM send_refund_execute"); let mut ctx = IbcContext::::new( self.transfer_module.ctx.inner.clone(), @@ -344,9 +344,10 @@ where fn receive_refund_execute( &mut self, - _: &Packet, - _: PacketData, + packet: &Packet, + data: PacketData, ) -> Result<(), Self::Error> { + tracing::warn!(?packet, ?data, "PFM receive_refund_execute"); Ok(()) } @@ -354,12 +355,15 @@ where &mut self, msg: &InFlightPacket, ) -> Result<(), Self::Error> { + tracing::warn!(?msg, "PFM send_transfer_execute"); // the token is not Namada native if is_sender_chain_source( msg.packet_data.token.to_string(), &msg.packet_src_port_id, &msg.packet_src_channel_id, ) { + tracing::warn!("PFM burn"); + let escrow_address = Address::Internal(InternalAddress::Ibc); self.transfer_module.ctx.insert_verifier(&MULTITOKEN); let mut token_transfer_ctx = TokenTransferContext::new( @@ -375,6 +379,7 @@ where ) .map_err(Error::TokenTransfer) } else { + tracing::warn!("PFM no burn"); Ok(()) } } @@ -384,6 +389,7 @@ where packet: &Packet, acknowledgement: &Acknowledgement, ) -> Result<(), Self::Error> { + tracing::warn!(?packet, ?acknowledgement, "PFM write_ack_and_events"); let mut ctx = IbcContext::::new( self.transfer_module.ctx.inner.clone(), ); @@ -399,9 +405,10 @@ where fn override_receiver( &self, - _: &ChannelId, - _: &Signer, + channel: &ChannelId, + original_sender: &Signer, ) -> Result { + tracing::warn!(?channel, ?original_sender, "PFM override_receiver"); Ok(Address::Internal(InternalAddress::Ibc).to_string().into()) } @@ -422,9 +429,11 @@ where "Packet timeout duration is too large: {timeout_duration}" )) })?; - timestamp + let ts = timestamp .map(TimeoutTimestamp::At) - .map_err(|e| Error::Other(e.to_string())) + .map_err(|e| Error::Other(e.to_string()))?; + tracing::warn!(timeout_timestamp = ?ts, "PFM timeout_timestamp"); + Ok(ts) } fn store_inflight_packet( @@ -432,10 +441,11 @@ where key: InFlightPacketKey, inflight_packet: InFlightPacket, ) -> Result<(), Self::Error> { + tracing::warn!(?key, ?inflight_packet, "PFM store_inflight_packet"); let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); let key = get_inflight_packet_key(&key); ctx.storage_mut() - .write(&key, inflight_packet.serialize_to_vec()) + .write(&key, inflight_packet) .map_err(Error::Storage) } @@ -443,6 +453,7 @@ where &self, key: &InFlightPacketKey, ) -> Result, Self::Error> { + tracing::warn!(?key, "PFM retrieve_inflight_packet"); let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); let key = get_inflight_packet_key(key); ctx.storage_mut().read(&key).map_err(Error::Storage) @@ -452,6 +463,7 @@ where &mut self, key: &InFlightPacketKey, ) -> Result<(), Self::Error> { + tracing::warn!(?key, "PFM delete_inflight_packet"); let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); let key = get_inflight_packet_key(key); ctx.storage_mut().delete(&key).map_err(Error::Storage) @@ -479,6 +491,15 @@ where this_chain_chan.clone(), )); } + tracing::warn!( + ?new_denom, + ?this_chain_port, + ?this_chain_chan, + ?source_port, + ?source_chan, + ?source_denom, + "PFM get_denom_for_this_chain" + ); Ok(new_denom) } } diff --git a/crates/ibc/src/context/validation.rs b/crates/ibc/src/context/validation.rs index 0f00feefcf..ecf81a7520 100644 --- a/crates/ibc/src/context/validation.rs +++ b/crates/ibc/src/context/validation.rs @@ -5,6 +5,7 @@ use ibc::core::channel::types::channel::ChannelEnd; use ibc::core::channel::types::commitment::{ AcknowledgementCommitment, PacketCommitment, }; +use ibc::core::channel::types::error::PacketError; use ibc::core::channel::types::packet::Receipt; use ibc::core::client::context::{ ClientValidationContext, ExtClientValidationContext, @@ -253,11 +254,18 @@ where &self, path: &AckPath, ) -> Result { - self.inner.borrow().packet_ack( + let maybe_ack = self.inner.borrow().packet_ack( &path.port_id, &path.channel_id, path.sequence, - ) + )?; + + maybe_ack.ok_or_else(|| { + PacketError::PacketAcknowledgementNotFound { + sequence: 9999999u64.into(), + } + .into() + }) } fn channel_counter(&self) -> Result { diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index c4e84151cf..d40ee18d61 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -692,7 +692,9 @@ where // Extract MASP tx from the memo in the packet if needed let masp_tx = match &*envelope { MsgEnvelope::Packet(PacketMsg::Recv(msg)) - if self.is_receiving_success(msg)? => + if self + .is_receiving_success(msg)? + .is_some_and(|ack_succ| ack_succ) => { extract_masp_tx_from_packet(&msg.packet) } @@ -715,8 +717,8 @@ where pub fn is_receiving_success( &self, msg: &IbcMsgRecvPacket, - ) -> Result { - let packet_ack = self + ) -> Result, Error> { + let Some(packet_ack) = self .ctx .inner .borrow() @@ -725,11 +727,14 @@ where &msg.packet.chan_id_on_b, msg.packet.seq_on_a, ) - .map_err(|e| Error::Context(Box::new(e)))?; + .map_err(|e| Error::Context(Box::new(e)))? + else { + return Ok(None); + }; let success_ack_commitment = compute_ack_commitment( &AcknowledgementStatus::success(ack_success_b64()).into(), ); - Ok(packet_ack == success_ack_commitment) + Ok(Some(packet_ack == success_ack_commitment)) } /// Validate according to the message in IBC VP diff --git a/crates/tests/src/e2e/helpers.rs b/crates/tests/src/e2e/helpers.rs index 70662eb6ba..d116bb868c 100644 --- a/crates/tests/src/e2e/helpers.rs +++ b/crates/tests/src/e2e/helpers.rs @@ -31,7 +31,7 @@ use toml::Value; use super::setup::{ self, ensure_hot_key, run_cosmos_cmd, sleep, NamadaBgCmd, NamadaCmd, Test, - ENV_VAR_DEBUG, ENV_VAR_USE_PREBUILT_BINARIES, + TestDir, ENV_VAR_DEBUG, ENV_VAR_USE_PREBUILT_BINARIES, }; use crate::e2e::setup::{Bin, CosmosChainType, Who, APPS_PACKAGE}; use crate::strings::{LEDGER_STARTED, TX_APPLIED_SUCCESS}; @@ -464,7 +464,11 @@ pub fn epochs_per_year_from_min_duration(min_duration: u64) -> u64 { } /// Make a Hermes config -pub fn make_hermes_config(test_a: &Test, test_b: &Test) -> Result<()> { +pub fn make_hermes_config( + hermes_dir: &TestDir, + test_a: &Test, + test_b: &Test, +) -> Result<()> { let mut config = toml::map::Map::new(); let mut global = toml::map::Map::new(); @@ -502,28 +506,19 @@ pub fn make_hermes_config(test_a: &Test, test_b: &Test) -> Result<()> { config.insert("telemetry".to_owned(), Value::Table(telemetry)); let chains = vec![ - make_hermes_chain_config(test_a), + make_hermes_chain_config(hermes_dir, test_a), match CosmosChainType::chain_type(test_b.net.chain_id.as_str()) { - Ok(chain_type) => { - make_hermes_chain_config_for_cosmos(chain_type, test_b) - } - Err(_) => make_hermes_chain_config(test_b), + Ok(chain_type) => make_hermes_chain_config_for_cosmos( + hermes_dir, chain_type, test_b, + ), + Err(_) => make_hermes_chain_config(hermes_dir, test_b), }, ]; config.insert("chains".to_owned(), Value::Array(chains)); let toml_string = toml::to_string(&Value::Table(config)).unwrap(); - let hermes_dir = test_a.test_dir.as_ref().join("hermes"); - std::fs::create_dir_all(&hermes_dir).unwrap(); - let config_path = hermes_dir.join("config.toml"); - let mut file = File::create(config_path).unwrap(); - file.write_all(toml_string.as_bytes()).map_err(|e| { - eyre!(format!("Writing a Hermes config failed: {}", e,)) - })?; - // One Hermes config.toml is OK, but add one more config.toml to execute - // Hermes from test_b - let hermes_dir = test_b.test_dir.as_ref().join("hermes"); + let hermes_dir = hermes_dir.as_ref().join("hermes"); std::fs::create_dir_all(&hermes_dir).unwrap(); let config_path = hermes_dir.join("config.toml"); let mut file = File::create(config_path).unwrap(); @@ -534,7 +529,7 @@ pub fn make_hermes_config(test_a: &Test, test_b: &Test) -> Result<()> { Ok(()) } -fn make_hermes_chain_config(test: &Test) -> Value { +fn make_hermes_chain_config(_hermes_dir: &TestDir, test: &Test) -> Value { let chain_id = test.net.chain_id.as_str(); let rpc_addr = get_actor_rpc(test, Who::Validator(0)); let rpc_addr = rpc_addr.strip_prefix("http://").unwrap(); @@ -580,6 +575,7 @@ fn make_hermes_chain_config(test: &Test) -> Value { } fn make_hermes_chain_config_for_cosmos( + hermes_dir: &TestDir, chain_type: CosmosChainType, test: &Test, ) -> Value { @@ -616,7 +612,8 @@ fn make_hermes_chain_config_for_cosmos( "key_name".to_owned(), Value::String(setup::constants::COSMOS_RELAYER.to_string()), ); - let key_dir = test.test_dir.as_ref().join("hermes/keys"); + let hermes_dir: &Path = hermes_dir.as_ref(); + let key_dir = hermes_dir.join("hermes/keys"); chain.insert( "key_store_folder".to_owned(), Value::String(key_dir.to_string_lossy().to_string()), @@ -651,8 +648,11 @@ where *timeout_propose = "1s".into(); } } - let offset = CosmosChainType::chain_type(test.net.chain_id.as_str()).unwrap().get_offset(); - let p2p = values.get_mut("p2p") + let offset = CosmosChainType::chain_type(test.net.chain_id.as_str()) + .unwrap() + .get_offset(); + let p2p = values + .get_mut("p2p") .expect("Test failed") .as_table_mut() .expect("Test failed"); @@ -660,7 +660,8 @@ where panic!("Test failed") }; *laddr = format!("tcp://0.0.0.0:266{}{}", offset, offset).into(); - let rpc = values.get_mut("rpc") + let rpc = values + .get_mut("rpc") .expect("Test failed") .as_table_mut() .expect("Test failed"); diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 9553c0aac7..3104456cb8 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -54,10 +54,15 @@ use crate::e2e::helpers::{ use crate::e2e::ledger_tests::{ start_namada_ledger_node_wait_wasm, write_json_file, }; -use crate::e2e::setup::{self, apply_use_device, run_cosmos_cmd, run_hermes_cmd, set_ethereum_bridge_mode, setup_cosmos, setup_hermes, sleep, working_dir, Bin, CosmosChainType, NamadaCmd, Test, Who, ENV_VAR_COSMWASM_CONTRACT_DIR}; +use crate::e2e::setup::{ + self, apply_use_device, run_cosmos_cmd, run_hermes_cmd, + set_ethereum_bridge_mode, setup_cosmos, setup_hermes, sleep, working_dir, + Bin, CosmosChainType, NamadaCmd, Test, TestDir, Who, + ENV_VAR_COSMWASM_CONTRACT_DIR, +}; +use crate::ibc::primitives::Signer; use crate::strings::TX_APPLIED_SUCCESS; use crate::{run, run_as}; -use crate::ibc::primitives::Signer; const IBC_REFUND_TARGET_ALIAS: &str = "ibc-refund-target"; const IBC_CLINET_ID: &str = "07-tendermint-0"; @@ -103,10 +108,11 @@ fn ibc_transfers() -> Result<()> { let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia, false)?; + let hermes_dir = setup_hermes(&test, &test_gaia)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( + &hermes_dir, &test, &test_gaia, &port_id_namada, @@ -114,7 +120,7 @@ fn ibc_transfers() -> Result<()> { )?; // Start relaying - let hermes = run_hermes(&test)?; + let hermes = run_hermes(&hermes_dir)?; let bg_hermes = hermes.background(); // 1. Transparent transfers @@ -134,7 +140,12 @@ fn ibc_transfers() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; check_balance(&test, ALBERT, APFEL, 999_998)?; let token_addr = find_address(&test, APFEL)?; @@ -160,7 +171,7 @@ fn ibc_transfers() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; + wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?; // Check the balances check_balance(&test, ALBERT, APFEL, 999_999)?; @@ -183,7 +194,7 @@ fn ibc_transfers() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; + wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?; // Check the token on Namada let ibc_denom_on_namada = @@ -205,7 +216,12 @@ fn ibc_transfers() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; // Check the balances check_balance(&test, ALBERT, &ibc_denom_on_namada, 100)?; @@ -241,7 +257,12 @@ fn ibc_transfers() -> Result<()> { Some(Either::Left(shielding_data_path)), None, )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test_gaia)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_gaia, + &channel_id_gaia, + &test_gaia, + )?; // Check the token on Namada check_balance(&test, AA_VIEWING_KEY, &ibc_denom_on_namada, 100)?; check_cosmos_balance(&test_gaia, COSMOS_USER, COSMOS_COIN, 800)?; @@ -274,7 +295,12 @@ fn ibc_transfers() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; check_balance(&test, AB_VIEWING_KEY, &ibc_denom_on_namada, 40)?; check_cosmos_balance(&test_gaia, COSMOS_USER, COSMOS_COIN, 810)?; @@ -299,7 +325,7 @@ fn ibc_transfers() -> Result<()> { Some(Either::Left(memo_path)), None, )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; + wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?; // Check the token on Namada check_balance(&test, AA_VIEWING_KEY, APFEL, 1)?; @@ -320,7 +346,12 @@ fn ibc_transfers() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; // The balance should not be changed check_balance(&test, ALBERT, APFEL, 999_999)?; @@ -346,10 +377,15 @@ fn ibc_transfers() -> Result<()> { sleep(10); // Restart relaying - let hermes = run_hermes(&test)?; + let hermes = run_hermes(&hermes_dir)?; let bg_hermes = hermes.background(); - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; // The balance should not be changed check_balance(&test, ALBERT, &ibc_denom_on_namada, 100)?; @@ -368,7 +404,12 @@ fn ibc_transfers() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; // Check the token has been refunded to the refund target check_balance(&test, AA_VIEWING_KEY, &ibc_denom_on_namada, 40)?; check_balance(&test, IBC_REFUND_TARGET_ALIAS, &ibc_denom_on_namada, 10)?; @@ -396,10 +437,15 @@ fn ibc_transfers() -> Result<()> { sleep(10); // Restart relaying - let hermes = run_hermes(&test)?; + let hermes = run_hermes(&hermes_dir)?; let _bg_hermes = hermes.background(); - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; // Check the token has been refunded to the refund target check_balance(&test, AA_VIEWING_KEY, APFEL, 0)?; check_balance(&test, IBC_REFUND_TARGET_ALIAS, APFEL, 1)?; @@ -423,7 +469,12 @@ fn ibc_transfers() -> Result<()> { // MASP VP shall reject it, make it timeout Some(Duration::new(10, 0)), )?; - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; // Check the balance didn't change check_balance(&test, AA_VIEWING_KEY, &ibc_denom_on_namada, 40)?; check_cosmos_balance(&test_gaia, COSMOS_USER, COSMOS_COIN, 810)?; @@ -449,7 +500,12 @@ fn ibc_transfers() -> Result<()> { // MASP VP shall reject it, make it timeout Some(Duration::new(10, 0)), )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test_gaia)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_gaia, + &channel_id_gaia, + &test_gaia, + )?; // Check the balances didn't change check_balance(&test, AA_VIEWING_KEY, &ibc_denom_on_namada, 40)?; check_cosmos_balance(&test_gaia, COSMOS_USER, COSMOS_COIN, 810)?; @@ -476,7 +532,7 @@ fn ibc_nft_transfers() -> Result<()> { let _bg_ledger = ledger.background(); let _bg_wasmd = cosmwasm.background(); - setup_hermes(&test, &test_cosmwasm, false)?; + let hermes_dir = setup_hermes(&test, &test_cosmwasm)?; let port_id_namada: PortId = NFT_PORT_ID.parse().unwrap(); let (cw721_contract, ics721_contract) = @@ -487,6 +543,7 @@ fn ibc_nft_transfers() -> Result<()> { let port_id_cosmwasm = get_cosmwasm_port_id(&test_cosmwasm, &ics721_contract)?; let (channel_id_namada, channel_id_cosmwasm) = create_channel_with_hermes( + &hermes_dir, &test, &test_cosmwasm, &port_id_namada, @@ -511,7 +568,12 @@ fn ibc_nft_transfers() -> Result<()> { None, None, )?; - clear_packet(&port_id_cosmwasm, &channel_id_cosmwasm, &test_cosmwasm)?; + clear_packet( + &hermes_dir, + &port_id_cosmwasm, + &channel_id_cosmwasm, + &test_cosmwasm, + )?; check_balance(&test, &namada_receiver, &ibc_trace_on_namada, 1)?; // Namada to CosmWasm @@ -528,7 +590,7 @@ fn ibc_nft_transfers() -> Result<()> { None, None, )?; - clear_packet(&port_id_namada, &channel_id_namada, &test)?; + clear_packet(&hermes_dir, &port_id_namada, &channel_id_namada, &test)?; check_balance(&test, &namada_receiver, &ibc_trace_on_namada, 0)?; // 2. Shielding/Unshielding transfers @@ -552,7 +614,12 @@ fn ibc_nft_transfers() -> Result<()> { Some(shielding_data_path), None, )?; - clear_packet(&port_id_cosmwasm, &channel_id_cosmwasm, &test_cosmwasm)?; + clear_packet( + &hermes_dir, + &port_id_cosmwasm, + &channel_id_cosmwasm, + &test_cosmwasm, + )?; check_balance(&test, AA_VIEWING_KEY, &ibc_trace_on_namada, 1)?; // Shielded transfer on Namada @@ -583,7 +650,7 @@ fn ibc_nft_transfers() -> Result<()> { None, None, )?; - clear_packet(&port_id_namada, &channel_id_namada, &test)?; + clear_packet(&hermes_dir, &port_id_namada, &channel_id_namada, &test)?; check_balance(&test, AB_VIEWING_KEY, &ibc_trace_on_namada, 0)?; Ok(()) @@ -610,10 +677,11 @@ fn pgf_over_ibc() -> Result<()> { let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia, false)?; + let hermes_dir = setup_hermes(&test, &test_gaia)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia: PortId = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( + &hermes_dir, &test, &test_gaia, &port_id_namada, @@ -621,7 +689,7 @@ fn pgf_over_ibc() -> Result<()> { )?; // Start relaying - let hermes = run_hermes(&test)?; + let hermes = run_hermes(&hermes_dir)?; let _bg_hermes = hermes.background(); // Transfer to PGF account @@ -667,7 +735,12 @@ fn pgf_over_ibc() -> Result<()> { while epoch < grace_epoch { epoch = epoch_sleep(&test, &rpc, 120)?; } - wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?; + wait_for_packet_relay( + &hermes_dir, + &port_id_namada, + &channel_id_namada, + &test, + )?; // Check balances after funding over IBC let token_addr = find_address(&test, NAM)?; @@ -726,10 +799,11 @@ fn fee_payment_with_ibc_token() -> Result<()> { submit_votes(&test)?; // Create an IBC channel while waiting the grace epoch - setup_hermes(&test, &test_gaia, false)?; + let hermes_dir = setup_hermes(&test, &test_gaia)?; let port_id_gaia = FT_PORT_ID.parse().unwrap(); let port_id_namada = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( + &hermes_dir, &test, &test_gaia, &port_id_namada, @@ -738,7 +812,7 @@ fn fee_payment_with_ibc_token() -> Result<()> { let ibc_token_on_namada = format!("{port_id_namada}/{channel_id_namada}/{COSMOS_COIN}"); // Start relaying - let hermes = run_hermes(&test)?; + let hermes = run_hermes(&hermes_dir)?; let _bg_hermes = hermes.background(); // wait for the grace @@ -760,7 +834,7 @@ fn fee_payment_with_ibc_token() -> Result<()> { None, None, )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; + wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?; // Check the token on Namada check_balance(&test, ALBERT_KEY, &ibc_token_on_namada, 250)?; @@ -832,17 +906,18 @@ fn ibc_token_inflation() -> Result<()> { submit_votes(&test)?; // Create an IBC channel while waiting the grace epoch - setup_hermes(&test, &test_gaia, false)?; + let hermes_dir = setup_hermes(&test, &test_gaia)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( + &hermes_dir, &test, &test_gaia, &port_id_namada, &port_id_gaia, )?; // Start relaying - let hermes = run_hermes(&test)?; + let hermes = run_hermes(&hermes_dir)?; let _bg_hermes = hermes.background(); // wait for the grace @@ -873,7 +948,7 @@ fn ibc_token_inflation() -> Result<()> { Some(Either::Left(shielding_data_path)), None, )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; + wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?; // wait the next masp epoch to dispense the reward let mut epoch = get_epoch(&test, &rpc).unwrap(); @@ -903,10 +978,11 @@ fn ibc_upgrade_client() -> Result<()> { let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia, false)?; + let hermes_dir = setup_hermes(&test, &test_gaia)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia: PortId = FT_PORT_ID.parse().unwrap(); create_channel_with_hermes( + &hermes_dir, &test, &test_gaia, &port_id_namada, @@ -931,7 +1007,7 @@ fn ibc_upgrade_client() -> Result<()> { } // Upgrade the IBC client of Gaia on Namada with Hermes - upgrade_client(&test, test.net.chain_id.to_string(), upgrade_height)?; + upgrade_client(&hermes_dir, test.net.chain_id.to_string(), upgrade_height)?; // Check the upgraded client let upgraded_client_state = @@ -974,10 +1050,11 @@ fn ibc_rate_limit() -> Result<()> { let _bg_ledger = ledger.background(); let _bg_gaia = gaia.background(); - setup_hermes(&test, &test_gaia, false)?; + let hermes_dir = setup_hermes(&test, &test_gaia)?; let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia: PortId = FT_PORT_ID.parse().unwrap(); let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes( + &hermes_dir, &test, &test_gaia, &port_id_namada, @@ -985,7 +1062,7 @@ fn ibc_rate_limit() -> Result<()> { )?; // Start relaying - let hermes = run_hermes(&test)?; + let hermes = run_hermes(&hermes_dir)?; let _bg_hermes = hermes.background(); // wait for the next epoch @@ -1074,7 +1151,7 @@ fn ibc_rate_limit() -> Result<()> { None, Some(Duration::new(10, 0)), )?; - wait_for_packet_relay(&port_id_gaia, &channel_id_gaia, &test)?; + wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?; // Check if Namada hasn't receive it let ibc_denom = @@ -1106,30 +1183,31 @@ fn ibc_pfm() -> Result<()> { run_namada_cosmos(CosmosChainType::Gaia(Some(1)), update_genesis)?; // set up a second cosmos network - let test_gaia_2 = setup_cosmos( - CosmosChainType::Gaia(Some(2)) - )?; + let test_gaia_2 = setup_cosmos(CosmosChainType::Gaia(Some(2)))?; let gaia_2 = run_cosmos(&test_gaia_2, false)?; sleep(5); let _bg_ledger = ledger.background(); let _bg_gaia_1 = gaia_1.background(); let _bg_gaia_2 = gaia_2.background(); - setup_hermes(&test, &test_gaia_1, false)?; - setup_hermes(&test, &test_gaia_2, true)?; + let hermes_gaia1_namada = setup_hermes(&test, &test_gaia_1)?; + let hermes_namada_gaia2 = setup_hermes(&test, &test_gaia_2)?; sleep(5); - // create hermes relayers for connections between both cosmos networks and namada + // create hermes relayers for connections between both cosmos networks and + // namada let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia_1 = FT_PORT_ID.parse().unwrap(); let port_id_gaia_2 = FT_PORT_ID.parse().unwrap(); let (channel_id_gaia_1, channel_id_namada_1) = create_channel_with_hermes( + &hermes_gaia1_namada, &test_gaia_1, &test, &port_id_namada, &port_id_gaia_1, )?; let (channel_id_gaia_2, channel_id_namada_2) = create_channel_with_hermes( + &hermes_namada_gaia2, &test_gaia_2, &test, &port_id_namada, @@ -1137,8 +1215,8 @@ fn ibc_pfm() -> Result<()> { )?; // Start relaying - let hermes_1 = run_hermes(&test_gaia_1)?; - let hermes_2 = run_hermes(&test_gaia_2)?; + let hermes_1 = run_hermes(&hermes_gaia1_namada)?; + let hermes_2 = run_hermes(&hermes_namada_gaia2)?; let _bg_hermes_1 = hermes_1.background(); let _bg_hermes_2 = hermes_2.background(); @@ -1149,7 +1227,7 @@ fn ibc_pfm() -> Result<()> { let pfm_memo = packet_forward_memo( find_cosmos_address(&test_gaia_2, COSMOS_USER)?.into(), port_id_namada.clone(), - channel_id_namada_2 + channel_id_namada_2, ); transfer_from_cosmos( &test_gaia_1, @@ -1162,10 +1240,28 @@ fn ibc_pfm() -> Result<()> { Some(Either::Right(pfm_memo)), None, )?; - wait_for_packet_relay(&port_id_namada, &channel_id_namada_1, &test)?; - wait_for_packet_relay(&port_id_gaia_2, &channel_id_gaia_2, &test)?; + wait_for_packet_relay( + &hermes_gaia1_namada, + &port_id_namada, + &channel_id_namada_1, + &test, + )?; + wait_for_packet_relay( + &hermes_namada_gaia2, + &port_id_gaia_2, + &channel_id_gaia_2, + &test, + )?; // Check the samoleans have been received on the target cosmos network - check_cosmos_balance(&test_gaia_2, COSMOS_USER, format!("transfer/{channel_id_gaia_2}/transfer/{channel_id_namada_1}/samoleans"), 10)?; + check_cosmos_balance( + &test_gaia_2, + COSMOS_USER, + format!( + "transfer/{channel_id_gaia_2}/transfer/{channel_id_namada_1}/\ + samoleans" + ), + 10, + )?; Ok(()) } @@ -1198,6 +1294,7 @@ fn run_namada_cosmos( } fn create_channel_with_hermes( + hermes_dir: &TestDir, test_a: &Test, test_b: &Test, port_id_a: &PortId, @@ -1227,7 +1324,7 @@ fn create_channel_with_hermes( "--yes", ]; - let mut hermes = run_hermes_cmd(test_a, args, Some(240))?; + let mut hermes = run_hermes_cmd(hermes_dir, args, Some(240))?; let (channel_id_a, channel_id_b) = get_channel_ids_from_hermes_output(&mut hermes)?; hermes.assert_success(); @@ -1249,9 +1346,9 @@ fn get_channel_ids_from_hermes_output( Ok((channel_id_a, channel_id_b)) } -fn run_hermes(test: &Test) -> Result { +fn run_hermes(hermes_dir: &TestDir) -> Result { let args = ["start"]; - let mut hermes = run_hermes_cmd(test, args, Some(40))?; + let mut hermes = run_hermes_cmd(hermes_dir, args, Some(40))?; hermes.exp_string("Hermes has started")?; Ok(hermes) } @@ -1268,18 +1365,13 @@ fn run_cosmos(test: &Test, kill: bool) -> Result { .unwrap(); } let port_arg = format!("0.0.0.0:{}", 9090 + chain_type.get_offset()); - let args = [ - "start", - "--pruning", - "nothing", - "--grpc.address", - &port_arg, - ]; + let args = ["start", "--pruning", "nothing", "--grpc.address", &port_arg]; let cosmos = run_cosmos_cmd(test, args, Some(40))?; Ok(cosmos) } fn wait_for_packet_relay( + hermes_dir: &TestDir, port_id: &PortId, channel_id: &ChannelId, test: &Test, @@ -1298,7 +1390,7 @@ fn wait_for_packet_relay( ]; for _ in 0..10 { sleep(30); - let mut hermes = run_hermes_cmd(test, args, Some(40))?; + let mut hermes = run_hermes_cmd(hermes_dir, args, Some(40))?; // Check no pending packet if hermes .exp_string( @@ -1319,6 +1411,7 @@ fn wait_for_packet_relay( } fn clear_packet( + hermes_dir: &TestDir, port_id: &PortId, channel_id: &ChannelId, test: &Test, @@ -1333,14 +1426,14 @@ fn clear_packet( "--channel", channel_id.as_str(), ]; - let mut hermes = run_hermes_cmd(test, args, Some(40))?; + let mut hermes = run_hermes_cmd(hermes_dir, args, Some(40))?; hermes.assert_success(); Ok(()) } fn upgrade_client( - test: &Test, + hermes_dir: &TestDir, host_chain_id: impl AsRef, upgrade_height: u64, ) -> Result<()> { @@ -1354,7 +1447,7 @@ fn upgrade_client( "--upgrade-height", &upgrade_height.to_string(), ]; - let mut hermes = run_hermes_cmd(test, args, Some(120))?; + let mut hermes = run_hermes_cmd(hermes_dir, args, Some(120))?; hermes.exp_string("upgraded-chain")?; hermes.assert_success(); @@ -1895,7 +1988,9 @@ fn transfer_from_cosmos( let port_id = port_id.to_string(); let channel_id = channel_id.to_string(); let amount = format!("{}{}", amount, token.as_ref()); - let offset = CosmosChainType::chain_type(test.net.chain_id.as_str()).unwrap().get_offset(); + let offset = CosmosChainType::chain_type(test.net.chain_id.as_str()) + .unwrap() + .get_offset(); let rpc = format!("tcp://127.0.0.1:6416{offset}"); // If the receiver is a pyament address we want to mask it to the more // general MASP internal address to improve on privacy @@ -1926,11 +2021,11 @@ fn transfer_from_cosmos( let is_memo = memo.is_some(); let memo = memo - .map(|m| { - match m { - Either::Left(path) => std::fs::read_to_string(path).expect("Reading memo file failed"), - Either::Right(memo) => memo, + .map(|m| match m { + Either::Left(path) => { + std::fs::read_to_string(path).expect("Reading memo file failed") } + Either::Right(memo) => memo, }) .unwrap_or_default(); if is_memo { @@ -2420,7 +2515,6 @@ fn nft_transfer_from_cosmos( Ok(()) } - /// Create a packet forward memo and serialize it fn packet_forward_memo( receiver: Signer, @@ -2436,5 +2530,6 @@ fn packet_forward_memo( retries: None, next: None, }, - }).expect("Test failed") + }) + .expect("Test failed") } diff --git a/crates/tests/src/e2e/setup.rs b/crates/tests/src/e2e/setup.rs index ec815e4aa1..df2121fd34 100644 --- a/crates/tests/src/e2e/setup.rs +++ b/crates/tests/src/e2e/setup.rs @@ -41,7 +41,10 @@ use rand::rngs::OsRng; use rand::Rng; use tempfile::{tempdir, tempdir_in, TempDir}; -use crate::e2e::helpers::{find_cosmos_address, generate_bin_command, make_hermes_config, update_cosmos_config}; +use crate::e2e::helpers::{ + find_cosmos_address, generate_bin_command, make_hermes_config, + update_cosmos_config, +}; /// For `color_eyre::install`, which fails if called more than once in the same /// process @@ -1248,12 +1251,14 @@ pub fn sleep(seconds: u64) { thread::sleep(time::Duration::from_secs(seconds)); } -pub fn setup_hermes(test_a: &Test, test_b: &Test, skip_keys: bool) -> Result<()> { +pub fn setup_hermes(test_a: &Test, test_b: &Test) -> Result { + let hermes_dir = TestDir::new(); + println!("\n{}", "Setting up Hermes".underline().green(),); - make_hermes_config(test_a, test_b)?; + make_hermes_config(&hermes_dir, test_a, test_b)?; - for test in [test_b, test_a] { + for test in [test_a, test_b] { let chain_id = test.net.chain_id.as_str(); let chain_dir = test.test_dir.as_ref().join(chain_id); let key_file_path = match CosmosChainType::chain_type(chain_id) { @@ -1264,23 +1269,21 @@ pub fn setup_hermes(test_a: &Test, test_b: &Test, skip_keys: bool) -> Result<()> let args = [ "keys", "add", + "--overwrite", "--chain", chain_id, "--key-file", &key_file_path.to_string_lossy(), ]; - let mut hermes = run_hermes_cmd(test, args, Some(20))?; + let mut hermes = run_hermes_cmd(&hermes_dir, args, Some(20))?; hermes.assert_success(); - if skip_keys { - break; - } } - Ok(()) + Ok(hermes_dir) } pub fn run_hermes_cmd( - test: &Test, + hermes_dir: &TestDir, args: I, timeout_sec: Option, ) -> Result @@ -1289,7 +1292,8 @@ where S: AsRef, { let mut run_cmd = Command::new("hermes"); - let hermes_dir = test.test_dir.as_ref().join("hermes"); + let hermes_dir: &Path = hermes_dir.as_ref(); + let hermes_dir = hermes_dir.join("hermes"); run_cmd.current_dir(hermes_dir.clone()); let config_path = hermes_dir.join("config.toml"); run_cmd.args(["--config", &config_path.to_string_lossy()]); @@ -1312,7 +1316,7 @@ where let log_path = { let mut rng = rand::thread_rng(); - let log_dir = test.get_base_dir(Who::NonValidator).join("logs"); + let log_dir = hermes_dir.join("logs"); std::fs::create_dir_all(&log_dir)?; log_dir.join(format!( "{}-hermes-{}.log", @@ -1391,7 +1395,7 @@ impl CosmosChainType { pub fn get_offset(&self) -> u64 { match self { Self::Gaia(Some(off)) => *off, - _ => 0 + _ => 0, } } } From 9440aef44cb8e7ae9e36d1843347b56fccd6d6bc Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 27 Nov 2024 09:09:49 +0000 Subject: [PATCH 08/14] Update PFM --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- wasm/Cargo.lock | 4 ++-- wasm_for_tests/Cargo.lock | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef201866a3..bf056d4621 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3786,8 +3786,8 @@ dependencies = [ [[package]] name = "ibc-middleware-packet-forward" -version = "0.3.0" -source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.3.0#128ffa23f785d0a681038aca28a1d96cacb80452" +version = "0.4.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=pfm/v0.4.0#193185ca21a94ed5ed31576b2e8e8cb80f097c71" dependencies = [ "borsh", "dur", diff --git a/Cargo.toml b/Cargo.toml index e61db93cb7..6aef585b91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,7 +121,7 @@ git2 = { version = "0.18.1", default-features = false } # branch yuji/derive-arbitrary ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", features = ["serde"] } ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583" } -ibc-middleware-packet-forward = {git = "https://github.com/heliaxdev/ibc-middleware", tag = "v0.3.0", features = ["borsh"]} +ibc-middleware-packet-forward = {git = "https://github.com/heliaxdev/ibc-middleware", tag = "pfm/v0.4.0", features = ["borsh"]} ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "aa229566e6bb688cc2626dab276c3849abc0c583", default-features = false } ics23 = "0.12.0" index-set = { git = "https://github.com/heliaxdev/index-set", tag = "v0.8.1", features = ["serialize-borsh", "serialize-serde"] } diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index ab2e941761..268882c809 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -2996,8 +2996,8 @@ dependencies = [ [[package]] name = "ibc-middleware-packet-forward" -version = "0.3.0" -source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.3.0#128ffa23f785d0a681038aca28a1d96cacb80452" +version = "0.4.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=pfm/v0.4.0#193185ca21a94ed5ed31576b2e8e8cb80f097c71" dependencies = [ "borsh", "dur", diff --git a/wasm_for_tests/Cargo.lock b/wasm_for_tests/Cargo.lock index 02b53e4dda..7d1cd858ef 100644 --- a/wasm_for_tests/Cargo.lock +++ b/wasm_for_tests/Cargo.lock @@ -1590,8 +1590,8 @@ dependencies = [ [[package]] name = "ibc-middleware-packet-forward" -version = "0.3.0" -source = "git+https://github.com/heliaxdev/ibc-middleware?tag=v0.3.0#128ffa23f785d0a681038aca28a1d96cacb80452" +version = "0.4.0" +source = "git+https://github.com/heliaxdev/ibc-middleware?tag=pfm/v0.4.0#193185ca21a94ed5ed31576b2e8e8cb80f097c71" dependencies = [ "borsh", "dur", From 46afc2f7fac9ff69c24f4d8bcb1244009807f35a Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 27 Nov 2024 09:10:23 +0000 Subject: [PATCH 09/14] Fix PFM happy flow test --- crates/ibc/src/context/pfm_mod.rs | 8 +++++--- crates/tests/src/e2e/ibc_tests.rs | 17 +++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index 7493af4cef..ffc86617fc 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -356,9 +356,11 @@ where msg: &InFlightPacket, ) -> Result<(), Self::Error> { tracing::warn!(?msg, "PFM send_transfer_execute"); + let packet_data: PacketData = + serde_json::from_slice(&msg.packet_data).unwrap(); // the token is not Namada native if is_sender_chain_source( - msg.packet_data.token.to_string(), + packet_data.token.to_string(), &msg.packet_src_port_id, &msg.packet_src_channel_id, ) { @@ -374,8 +376,8 @@ where token_transfer_ctx .burn_coins_execute( &escrow_address, - &msg.packet_data.token, - &msg.packet_data.memo, + &packet_data.token, + &packet_data.memo, ) .map_err(Error::TokenTransfer) } else { diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 3104456cb8..07c93f83aa 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -1250,7 +1250,7 @@ fn ibc_pfm() -> Result<()> { &hermes_namada_gaia2, &port_id_gaia_2, &channel_id_gaia_2, - &test, + &test_gaia_2, )?; // Check the samoleans have been received on the target cosmos network check_cosmos_balance( @@ -1389,7 +1389,7 @@ fn wait_for_packet_relay( channel_id.as_str(), ]; for _ in 0..10 { - sleep(30); + sleep(10); let mut hermes = run_hermes_cmd(hermes_dir, args, Some(40))?; // Check no pending packet if hermes @@ -2124,14 +2124,11 @@ fn check_cosmos_balance( expected_amount: u64, ) -> Result<()> { let addr = find_cosmos_address(test, owner)?; - let args = [ - "query", - "bank", - "balances", - &addr, - "--node", - &format!("tcp://{COSMOS_RPC}"), - ]; + let offset = CosmosChainType::chain_type(test.net.chain_id.as_str()) + .unwrap() + .get_offset(); + let rpc = format!("tcp://127.0.0.1:6416{offset}"); + let args = ["query", "bank", "balances", &addr, "--node", &rpc]; let mut cosmos = run_cosmos_cmd(test, args, Some(40))?; cosmos.exp_string(&format!("amount: \"{expected_amount}\""))?; let expected_denom = if denom.as_ref().contains('/') { From ed9aee7579ea6f52e607bb1a0a95471400fba0c7 Mon Sep 17 00:00:00 2001 From: satan Date: Wed, 27 Nov 2024 11:57:06 +0100 Subject: [PATCH 10/14] Finished ibc pfm happy flow test --- crates/ibc/src/context/pfm_mod.rs | 32 ++--- crates/tests/src/e2e/ibc_tests.rs | 200 ++++++++++++++++++++++++++++-- 2 files changed, 205 insertions(+), 27 deletions(-) diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index ffc86617fc..50ab9cd562 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -327,7 +327,7 @@ where .borrow() .get_next_sequence_send(&msg.port_id_on_a, &msg.chan_id_on_a) .map_err(|e| Error::Context(Box::new(e)))?; - tracing::warn!(?seq, ?msg, "PFM send_refund_execute"); + tracing::debug!(?seq, ?msg, "PFM send_refund_execute"); let mut ctx = IbcContext::::new( self.transfer_module.ctx.inner.clone(), @@ -347,7 +347,7 @@ where packet: &Packet, data: PacketData, ) -> Result<(), Self::Error> { - tracing::warn!(?packet, ?data, "PFM receive_refund_execute"); + tracing::debug!(?packet, ?data, "PFM receive_refund_execute"); Ok(()) } @@ -355,7 +355,7 @@ where &mut self, msg: &InFlightPacket, ) -> Result<(), Self::Error> { - tracing::warn!(?msg, "PFM send_transfer_execute"); + tracing::debug!(?msg, "PFM send_transfer_execute"); let packet_data: PacketData = serde_json::from_slice(&msg.packet_data).unwrap(); // the token is not Namada native @@ -364,7 +364,7 @@ where &msg.packet_src_port_id, &msg.packet_src_channel_id, ) { - tracing::warn!("PFM burn"); + tracing::debug!("PFM burn"); let escrow_address = Address::Internal(InternalAddress::Ibc); self.transfer_module.ctx.insert_verifier(&MULTITOKEN); @@ -381,7 +381,7 @@ where ) .map_err(Error::TokenTransfer) } else { - tracing::warn!("PFM no burn"); + tracing::debug!("PFM refund escrow"); Ok(()) } } @@ -391,7 +391,7 @@ where packet: &Packet, acknowledgement: &Acknowledgement, ) -> Result<(), Self::Error> { - tracing::warn!(?packet, ?acknowledgement, "PFM write_ack_and_events"); + tracing::debug!(?packet, ?acknowledgement, "PFM write_ack_and_events"); let mut ctx = IbcContext::::new( self.transfer_module.ctx.inner.clone(), ); @@ -407,10 +407,9 @@ where fn override_receiver( &self, - channel: &ChannelId, - original_sender: &Signer, + _channel: &ChannelId, + _original_sender: &Signer, ) -> Result { - tracing::warn!(?channel, ?original_sender, "PFM override_receiver"); Ok(Address::Internal(InternalAddress::Ibc).to_string().into()) } @@ -434,7 +433,7 @@ where let ts = timestamp .map(TimeoutTimestamp::At) .map_err(|e| Error::Other(e.to_string()))?; - tracing::warn!(timeout_timestamp = ?ts, "PFM timeout_timestamp"); + tracing::debug!(timeout_timestamp = ?ts, "PFM timeout_timestamp"); Ok(ts) } @@ -443,7 +442,7 @@ where key: InFlightPacketKey, inflight_packet: InFlightPacket, ) -> Result<(), Self::Error> { - tracing::warn!(?key, ?inflight_packet, "PFM store_inflight_packet"); + tracing::debug!(?key, ?inflight_packet, "PFM store_inflight_packet"); let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); let key = get_inflight_packet_key(&key); ctx.storage_mut() @@ -455,17 +454,20 @@ where &self, key: &InFlightPacketKey, ) -> Result, Self::Error> { - tracing::warn!(?key, "PFM retrieve_inflight_packet"); let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); let key = get_inflight_packet_key(key); - ctx.storage_mut().read(&key).map_err(Error::Storage) + let packet = ctx.storage_mut().read(&key).map_err(Error::Storage); + + tracing::debug!(?key, ?packet, "PFM retrieve_inflight_packet"); + + packet } fn delete_inflight_packet( &mut self, key: &InFlightPacketKey, ) -> Result<(), Self::Error> { - tracing::warn!(?key, "PFM delete_inflight_packet"); + tracing::debug!(?key, "PFM delete_inflight_packet"); let mut ctx = self.transfer_module.ctx.inner.borrow_mut(); let key = get_inflight_packet_key(key); ctx.storage_mut().delete(&key).map_err(Error::Storage) @@ -493,7 +495,7 @@ where this_chain_chan.clone(), )); } - tracing::warn!( + tracing::debug!( ?new_denom, ?this_chain_port, ?this_chain_chan, diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 07c93f83aa..446a766cbd 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -1164,9 +1164,18 @@ fn ibc_rate_limit() -> Result<()> { Ok(()) } -/// de wanna wanga +/// Test the happy flows of ibc pfm +/// +/// Setup: Two instances of Gaia and one +/// Namada instance. +/// +/// 1. Test sending a transfer from first cosmos chain to the second via the PFM +/// module on Namada (henceforth denoted "via PFM") +/// 2. Test sending the above transfer back to first cosmos chain via PFM +/// 3. Send wrapped NAM from first cosmos chain to the second via PFM +/// 4. Reverse the transaction in the step above #[test] -fn ibc_pfm() -> Result<()> { +fn ibc_pfm_happy_flows() -> Result<()> { let update_genesis = |mut genesis: templates::All, base_dir: &_| { genesis.parameters.parameters.epochs_per_year = @@ -1193,7 +1202,7 @@ fn ibc_pfm() -> Result<()> { let hermes_gaia1_namada = setup_hermes(&test, &test_gaia_1)?; let hermes_namada_gaia2 = setup_hermes(&test, &test_gaia_2)?; sleep(5); - // create hermes relayers for connections between both cosmos networks and + // create hermes relayers for connections between both cosmos chains and // namada let port_id_namada = FT_PORT_ID.parse().unwrap(); let port_id_gaia_1 = FT_PORT_ID.parse().unwrap(); @@ -1220,14 +1229,16 @@ fn ibc_pfm() -> Result<()> { let _bg_hermes_1 = hermes_1.background(); let _bg_hermes_2 = hermes_2.background(); - // we will send a packt to bertha on namada + // ------------------- Step 1. ------------------- + + // Bertha is our most trusted intermediary in all things let namada_receiver = find_address(&test, BERTHA)?.to_string(); // this will cause the ibc packet to be forwarded to the second - // cosmos network. + // cosmos chain. let pfm_memo = packet_forward_memo( find_cosmos_address(&test_gaia_2, COSMOS_USER)?.into(), - port_id_namada.clone(), - channel_id_namada_2, + &port_id_namada, + &channel_id_namada_2, ); transfer_from_cosmos( &test_gaia_1, @@ -1252,7 +1263,7 @@ fn ibc_pfm() -> Result<()> { &channel_id_gaia_2, &test_gaia_2, )?; - // Check the samoleans have been received on the target cosmos network + // Check the samoleans have been received on the second cosmos chain check_cosmos_balance( &test_gaia_2, COSMOS_USER, @@ -1263,6 +1274,171 @@ fn ibc_pfm() -> Result<()> { 10, )?; + // Check the samoleans have been sent from the first cosmos chain + check_cosmos_balance(&test_gaia_1, COSMOS_USER, "samoleans", 1000 - 10)?; + + // ------------------- Step 2. ------------------- + + // this will cause the ibc packet to be forwarded to the first + // cosmos chain. + let pfm_memo = packet_forward_memo( + find_cosmos_address(&test_gaia_1, COSMOS_USER)?.into(), + &port_id_namada, + &channel_id_namada_1, + ); + transfer_from_cosmos( + &test_gaia_2, + COSMOS_USER, + &namada_receiver, + format!( + "transfer/{channel_id_gaia_2}/transfer/{channel_id_namada_1}/\ + samoleans" + ), + 10, + &port_id_gaia_1, + &channel_id_gaia_1, + Some(Either::Right(pfm_memo)), + None, + )?; + + wait_for_packet_relay( + &hermes_namada_gaia2, + &port_id_namada, + &channel_id_namada_2, + &test, + )?; + wait_for_packet_relay( + &hermes_gaia1_namada, + &port_id_gaia_1, + &channel_id_gaia_1, + &test_gaia_1, + )?; + + // Check the samoleans have been received on the fist cosmos chain + check_cosmos_balance(&test_gaia_1, COSMOS_USER, "samoleans", 1000)?; + + // ------------------- Step 3. ------------------- + let nam_addr = find_address(&test, NAM)?; + // we first send some NAM to the first cosmos chain. + let gaia_receiver = find_cosmos_address(&test_gaia_1, COSMOS_USER)?; + transfer( + &test, + BERTHA, + gaia_receiver, + NAM, + 20, + Some(BERTHA_KEY), + &port_id_namada, + &channel_id_namada_1, + None, + None, + None, + )?; + + wait_for_packet_relay( + &hermes_gaia1_namada, + &port_id_gaia_1, + &channel_id_gaia_1, + &test_gaia_1, + )?; + + // Check the NAM have been sent to the first cosmos chain + check_cosmos_balance( + &test_gaia_1, + COSMOS_USER, + format!("transfer/{channel_id_gaia_1}/{nam_addr}"), + 20_000_000, + )?; + + // this will cause the ibc packet to be forwarded to the second + // cosmos chain. + let pfm_memo = packet_forward_memo( + find_cosmos_address(&test_gaia_2, COSMOS_USER)?.into(), + &port_id_namada, + &channel_id_namada_2, + ); + + transfer_from_cosmos( + &test_gaia_1, + COSMOS_USER, + &namada_receiver, + format!("transfer/{channel_id_gaia_1}/{nam_addr}"), + 10_000_000, + &port_id_gaia_1, + &channel_id_gaia_1, + Some(Either::Right(pfm_memo)), + None, + )?; + wait_for_packet_relay( + &hermes_gaia1_namada, + &port_id_namada, + &channel_id_namada_1, + &test, + )?; + wait_for_packet_relay( + &hermes_namada_gaia2, + &port_id_gaia_2, + &channel_id_gaia_2, + &test_gaia_2, + )?; + // Check the NAM have been received on the second cosmos chain + check_cosmos_balance( + &test_gaia_2, + COSMOS_USER, + format!("transfer/{channel_id_gaia_2}/{nam_addr}"), + 10_000_000, + )?; + + // Check the NAM have been sent from the first cosmos chain + check_cosmos_balance( + &test_gaia_1, + COSMOS_USER, + format!("transfer/{channel_id_gaia_1}/{nam_addr}"), + 20_000_000 - 10_000_000, + )?; + + // ------------------- Step 4. ------------------- + + // this will cause the ibc packet to be forwarded to the first + // cosmos chain. + let pfm_memo = packet_forward_memo( + find_cosmos_address(&test_gaia_1, COSMOS_USER)?.into(), + &port_id_namada, + &channel_id_namada_1, + ); + transfer_from_cosmos( + &test_gaia_2, + COSMOS_USER, + &namada_receiver, + format!("transfer/{channel_id_gaia_2}/{nam_addr}"), + 10_000_000, + &port_id_gaia_1, + &channel_id_gaia_1, + Some(Either::Right(pfm_memo)), + None, + )?; + + wait_for_packet_relay( + &hermes_namada_gaia2, + &port_id_namada, + &channel_id_namada_2, + &test, + )?; + wait_for_packet_relay( + &hermes_gaia1_namada, + &port_id_gaia_1, + &channel_id_gaia_1, + &test_gaia_1, + )?; + + // Check the NAM have been received on the first cosmos chain + check_cosmos_balance( + &test_gaia_1, + COSMOS_USER, + format!("transfer/{channel_id_gaia_1}/{nam_addr}"), + 20_000_000, + )?; + Ok(()) } @@ -2515,14 +2691,14 @@ fn nft_transfer_from_cosmos( /// Create a packet forward memo and serialize it fn packet_forward_memo( receiver: Signer, - port_id: PortId, - channel_id: ChannelId, + port_id: &PortId, + channel_id: &ChannelId, ) -> String { serde_json::to_string(&ibc_middleware_packet_forward::PacketMetadata { forward: ForwardMetadata { receiver, - port: port_id, - channel: channel_id, + port: port_id.clone(), + channel: channel_id.clone(), timeout: None, retries: None, next: None, From d80b837cb6d0a156d066aff3bfaee305e8a062f4 Mon Sep 17 00:00:00 2001 From: satan Date: Wed, 27 Nov 2024 16:43:26 +0100 Subject: [PATCH 11/14] dogface --- crates/ibc/src/context/pfm_mod.rs | 32 +++-- crates/ibc/src/context/token_transfer.rs | 7 +- crates/tests/src/e2e/ibc_tests.rs | 170 +++++++++++++++++++++++ 3 files changed, 195 insertions(+), 14 deletions(-) diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index 50ab9cd562..ada950ad0e 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -7,7 +7,7 @@ use std::marker::PhantomData; use std::rc::Rc; use ibc::apps::transfer::context::TokenTransferExecutionContext; -use ibc::apps::transfer::handler::send_transfer_execute; +use ibc::apps::transfer::handler::{refund_packet_token_execute, send_transfer_execute}; use ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use ibc::apps::transfer::types::packet::PacketData; use ibc::apps::transfer::types::{PrefixedDenom, TracePrefix}; @@ -327,7 +327,7 @@ where .borrow() .get_next_sequence_send(&msg.port_id_on_a, &msg.chan_id_on_a) .map_err(|e| Error::Context(Box::new(e)))?; - tracing::debug!(?seq, ?msg, "PFM send_refund_execute"); + tracing::debug!(?seq, ?msg, "PFM send_transfer_execute"); let mut ctx = IbcContext::::new( self.transfer_module.ctx.inner.clone(), @@ -348,16 +348,27 @@ where data: PacketData, ) -> Result<(), Self::Error> { tracing::debug!(?packet, ?data, "PFM receive_refund_execute"); - Ok(()) + let mut token_transfer_ctx = TokenTransferContext::new( + self.transfer_module.ctx.inner.clone(), + self.transfer_module.ctx.verifiers.clone(), + ); + refund_packet_token_execute(&mut token_transfer_ctx, packet, &data) + .map_err(Error::TokenTransfer) } fn send_refund_execute( &mut self, msg: &InFlightPacket, ) -> Result<(), Self::Error> { - tracing::debug!(?msg, "PFM send_transfer_execute"); + tracing::debug!(?msg, "PFM send_refund_execute"); let packet_data: PacketData = serde_json::from_slice(&msg.packet_data).unwrap(); + let mut token_transfer_ctx = TokenTransferContext::new( + self.transfer_module.ctx.inner.clone(), + self.transfer_module.ctx.verifiers.clone(), + ); + + let escrow_address = Address::Internal(InternalAddress::Ibc); // the token is not Namada native if is_sender_chain_source( packet_data.token.to_string(), @@ -366,12 +377,7 @@ where ) { tracing::debug!("PFM burn"); - let escrow_address = Address::Internal(InternalAddress::Ibc); self.transfer_module.ctx.insert_verifier(&MULTITOKEN); - let mut token_transfer_ctx = TokenTransferContext::new( - self.transfer_module.ctx.inner.clone(), - self.transfer_module.ctx.verifiers.clone(), - ); token_transfer_ctx .burn_coins_execute( @@ -382,7 +388,13 @@ where .map_err(Error::TokenTransfer) } else { tracing::debug!("PFM refund escrow"); - Ok(()) + token_transfer_ctx.escrow_coins_execute( + &escrow_address, + &msg.refund_port_id, + &msg.refund_channel_id, + &packet_data.token, + &packet_data.memo, + ).map_err(Error::TokenTransfer) } } diff --git a/crates/ibc/src/context/token_transfer.rs b/crates/ibc/src/context/token_transfer.rs index fecc8d4d2d..f0ecffb8e1 100644 --- a/crates/ibc/src/context/token_transfer.rs +++ b/crates/ibc/src/context/token_transfer.rs @@ -100,7 +100,7 @@ where } else { mint.checked_sub(amount).ok_or_else(|| { TokenTransferError::Other( - "The mint amount underflowed".to_string(), + format!("The mint amount underflowed: {mint} - {amount}"), ) })? }; @@ -316,7 +316,7 @@ where // Store the IBC denom with the token hash to be able to retrieve it // later self.maybe_store_ibc_denom(account, coin)?; - + tracing::info!("\n\n\n\nMinting {} {} to {}\n\n\n", amount, ibc_token, account); self.inner .borrow_mut() .mint_token(account, &ibc_token, amount) @@ -330,7 +330,7 @@ where _memo: &Memo, ) -> Result<(), TokenTransferError> { let (ibc_token, amount) = self.get_token_amount(coin)?; - + tracing::info!("\n\n\n ATTEMPTING TO BURN {amount} {ibc_token} ({coin}) from {account} \n\n\n"); self.update_mint_amount(&ibc_token, amount, false)?; self.add_withdraw(&ibc_token, amount)?; @@ -342,7 +342,6 @@ where } let account = if self.is_shielded { &MASP } else { account }; - // The burn is "unminting" from the minted balance self.inner .borrow_mut() diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 446a766cbd..5f09cbbaa8 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -1439,6 +1439,176 @@ fn ibc_pfm_happy_flows() -> Result<()> { 20_000_000, )?; + Ok(()) +} +/// Test the flows of ibc pfm where the packet cannot be +/// completed and refunds must be issued. +/// +/// Setup: Two instances of Gaia and one +/// Namada instance. +/// +/// 1. Test sending a transfer from first cosmos chain to the second via the PFM +/// module on Namada (henceforth denoted "via PFM"), failing on the second +/// cosmos chain due to an error. +/// 2. Same as above except that the failure occurs due to a time-out on the +/// second cosmos chain. +/// 3. Same as the first except that wrapped NAM is sent from the first cosmos chain +/// 4. Same as above except that the failure occurs due to a time-out on the +/// second cosmos chain. +#[test] +fn ibc_pfm_unhappy_flows() -> Result<()> { + let update_genesis = + |mut genesis: templates::All, base_dir: &_| { + genesis.parameters.parameters.epochs_per_year = + epochs_per_year_from_min_duration(1800); + genesis.parameters.ibc_params.default_mint_limit = + Amount::max_signed(); + genesis + .parameters + .ibc_params + .default_per_epoch_throughput_limit = Amount::max_signed(); + setup::set_validators(1, genesis, base_dir, |_| 0, vec![]) + }; + let (ledger, gaia_1, test, test_gaia_1) = + run_namada_cosmos(CosmosChainType::Gaia(Some(1)), update_genesis)?; + + // set up a second cosmos network + let test_gaia_2 = setup_cosmos(CosmosChainType::Gaia(Some(2)))?; + let gaia_2 = run_cosmos(&test_gaia_2, false)?; + sleep(5); + + let _bg_ledger = ledger.background(); + let _bg_gaia_1 = gaia_1.background(); + let _bg_gaia_2 = gaia_2.background(); + let hermes_gaia1_namada = setup_hermes(&test, &test_gaia_1)?; + let hermes_namada_gaia2 = setup_hermes(&test, &test_gaia_2)?; + sleep(5); + // create hermes relayers for connections between both cosmos chains and + // namada + let port_id_namada = FT_PORT_ID.parse().unwrap(); + let port_id_gaia_1 = FT_PORT_ID.parse().unwrap(); + let port_id_gaia_2 = FT_PORT_ID.parse().unwrap(); + + let (channel_id_gaia_1, channel_id_namada_1) = create_channel_with_hermes( + &hermes_gaia1_namada, + &test_gaia_1, + &test, + &port_id_namada, + &port_id_gaia_1, + )?; + let (channel_id_gaia_2, channel_id_namada_2) = create_channel_with_hermes( + &hermes_namada_gaia2, + &test_gaia_2, + &test, + &port_id_namada, + &port_id_gaia_2, + )?; + + // Start relaying + let hermes_1 = run_hermes(&hermes_gaia1_namada)?; + let hermes_2 = run_hermes(&hermes_namada_gaia2)?; + let _bg_hermes_1 = hermes_1.background(); + let _bg_hermes_2 = hermes_2.background(); + + // ------------------- Step 1. ------------------- + + // Bertha is our most trusted intermediary in all things + let namada_receiver = find_address(&test, BERTHA)?.to_string(); + // this will cause the ibc packet to be forwarded to the second + // cosmos chain. + let pfm_memo = packet_forward_memo( + "Hodor".to_string().into(), + &port_id_namada, + &channel_id_namada_2, + ); + transfer_from_cosmos( + &test_gaia_1, + COSMOS_USER, + &namada_receiver, + "samoleans", + 10, + &port_id_gaia_1, + &channel_id_gaia_1, + Some(Either::Right(pfm_memo)), + None, + )?; + wait_for_packet_relay( + &hermes_gaia1_namada, + &port_id_namada, + &channel_id_namada_1, + &test, + )?; + wait_for_packet_relay( + &hermes_namada_gaia2, + &port_id_gaia_2, + &channel_id_gaia_2, + &test_gaia_2, + )?; + + // Check the samoleans have been sent from the first cosmos chain + check_cosmos_balance(&test_gaia_1, COSMOS_USER, "samoleans", 1000)?; + + // ------------------- Step 2. ------------------- + /* let pfm_memo = packet_forward_memo( + find_cosmos_address(&test_gaia_1, COSMOS_USER)?.into(), + &port_id_namada, + &channel_id_namada_2, + ); + transfer_from_cosmos( + &test_gaia_1, + COSMOS_USER, + namada_receiver, + "samoleans", + 10, + &port_id_gaia_1, + &channel_id_gaia_1, + Some(Either::Right(pfm_memo)), + None, + )?; + wait_for_packet_relay( + &hermes_gaia1_namada, + &port_id_namada, + &channel_id_namada_1, + &test, + )?; + wait_for_packet_relay( + &hermes_namada_gaia2, + &port_id_gaia_2, + &channel_id_gaia_2, + &test_gaia_2, + )?; + + // Check the samoleans have been sent from the first cosmos chain + check_cosmos_balance(&test_gaia_1, COSMOS_USER, "samoleans", 1000)?; + + // Stop Hermes for timeout test + let mut hermes = bg_hermes.foreground(); + hermes.interrupt()?; + + // Transfer will be timed out to check the refund for the burned IBC token + transfer( + &test, + ALBERT, + &gaia_receiver, + &ibc_denom_on_namada, + 10, + Some(ALBERT_KEY), + &port_id_namada, + &channel_id_namada, + Some(Duration::new(10, 0)), + None, + None, + )?; + // wait for the timeout + sleep(10); + + // Restart relaying + let hermes = run_hermes(&hermes_dir)?; + let bg_hermes = hermes.background(); +*/ + + + Ok(()) } From 7789a9055a07f5c0087fdc2809aac13c2fe182ce Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 27 Nov 2024 17:14:07 +0000 Subject: [PATCH 12/14] Fix PFM refund logic --- crates/ibc/src/context/pfm_mod.rs | 79 +++++++++++++++++++------------ 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/crates/ibc/src/context/pfm_mod.rs b/crates/ibc/src/context/pfm_mod.rs index ada950ad0e..2e67bd2d0b 100644 --- a/crates/ibc/src/context/pfm_mod.rs +++ b/crates/ibc/src/context/pfm_mod.rs @@ -7,10 +7,14 @@ use std::marker::PhantomData; use std::rc::Rc; use ibc::apps::transfer::context::TokenTransferExecutionContext; -use ibc::apps::transfer::handler::{refund_packet_token_execute, send_transfer_execute}; +use ibc::apps::transfer::handler::{ + refund_packet_token_execute, send_transfer_execute, +}; use ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use ibc::apps::transfer::types::packet::PacketData; -use ibc::apps::transfer::types::{PrefixedDenom, TracePrefix}; +use ibc::apps::transfer::types::{ + is_receiver_chain_source, PrefixedDenom, TracePrefix, +}; use ibc::core::channel::handler::{ commit_packet_acknowledgment, emit_packet_acknowledgement_event, }; @@ -29,13 +33,12 @@ use ibc::primitives::Signer; use ibc_middleware_packet_forward::{ InFlightPacket, InFlightPacketKey, PacketForwardMiddleware, PfmContext, }; -use namada_core::address::{Address, InternalAddress, MULTITOKEN}; +use namada_core::address::{Address, IBC as IBC_ADDRESS, MULTITOKEN}; use namada_core::storage::{self, KeySeg}; use namada_state::{StorageRead, StorageWrite}; use crate::context::transfer_mod::TransferModule; use crate::context::IbcContext; -use crate::trace::is_sender_chain_source; use crate::{ Error, IbcCommonContext, IbcStorageContext, ModuleWrapper, TokenTransferContext, @@ -48,8 +51,7 @@ const PFM_SUBKEY: &str = "pfm"; pub fn get_inflight_packet_key( inflight_packet_key: &InFlightPacketKey, ) -> storage::Key { - let key: storage::Key = - Address::Internal(InternalAddress::Ibc).to_db_key().into(); + let key: storage::Key = IBC_ADDRESS.to_db_key().into(); key.with_segment(MIDDLEWARES_SUBKEY.to_string()) .with_segment(PFM_SUBKEY.to_string()) .with_segment(inflight_packet_key.port.to_string()) @@ -352,6 +354,7 @@ where self.transfer_module.ctx.inner.clone(), self.transfer_module.ctx.verifiers.clone(), ); + self.transfer_module.ctx.insert_verifier(&MULTITOKEN); refund_packet_token_execute(&mut token_transfer_ctx, packet, &data) .map_err(Error::TokenTransfer) } @@ -361,40 +364,56 @@ where msg: &InFlightPacket, ) -> Result<(), Self::Error> { tracing::debug!(?msg, "PFM send_refund_execute"); - let packet_data: PacketData = - serde_json::from_slice(&msg.packet_data).unwrap(); + + let packet_data: PacketData = serde_json::from_slice(&msg.packet_data) + .expect( + "The in-flight packet data should have belonged to an ICS-20 \ + packet", + ); + let mut token_transfer_ctx = TokenTransferContext::new( self.transfer_module.ctx.inner.clone(), self.transfer_module.ctx.verifiers.clone(), ); - let escrow_address = Address::Internal(InternalAddress::Ibc); - // the token is not Namada native - if is_sender_chain_source( - packet_data.token.to_string(), - &msg.packet_src_port_id, - &msg.packet_src_channel_id, - ) { - tracing::debug!("PFM burn"); + self.transfer_module.ctx.insert_verifier(&MULTITOKEN); - self.transfer_module.ctx.insert_verifier(&MULTITOKEN); + if is_receiver_chain_source( + msg.packet_src_port_id.clone(), + msg.packet_src_channel_id.clone(), + &packet_data.token.denom, + ) { + let coin = { + let mut c = packet_data.token; + c.denom.remove_trace_prefix(&TracePrefix::new( + msg.packet_src_port_id.clone(), + msg.packet_src_channel_id.clone(), + )); + c + }; token_transfer_ctx - .burn_coins_execute( - &escrow_address, - &packet_data.token, - &packet_data.memo, + .escrow_coins_execute( + &IBC_ADDRESS, + &msg.refund_port_id, + &msg.refund_channel_id, + &coin, + &String::new().into(), ) .map_err(Error::TokenTransfer) } else { - tracing::debug!("PFM refund escrow"); - token_transfer_ctx.escrow_coins_execute( - &escrow_address, - &msg.refund_port_id, - &msg.refund_channel_id, - &packet_data.token, - &packet_data.memo, - ).map_err(Error::TokenTransfer) + let coin = { + let mut c = packet_data.token; + c.denom.add_trace_prefix(TracePrefix::new( + msg.refund_port_id.clone(), + msg.refund_channel_id.clone(), + )); + c + }; + + token_transfer_ctx + .burn_coins_execute(&IBC_ADDRESS, &coin, &String::new().into()) + .map_err(Error::TokenTransfer) } } @@ -422,7 +441,7 @@ where _channel: &ChannelId, _original_sender: &Signer, ) -> Result { - Ok(Address::Internal(InternalAddress::Ibc).to_string().into()) + Ok(IBC_ADDRESS.to_string().into()) } #[allow(clippy::arithmetic_side_effects)] From 2cfbb9fa76fae013e12426a94fd88108470ff174 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 27 Nov 2024 17:14:42 +0000 Subject: [PATCH 13/14] Change test comment to smth more accurate --- crates/tests/src/e2e/ibc_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 5f09cbbaa8..c209a1418d 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -1545,7 +1545,7 @@ fn ibc_pfm_unhappy_flows() -> Result<()> { &test_gaia_2, )?; - // Check the samoleans have been sent from the first cosmos chain + // Check the samoleans have been refunded on the first chain check_cosmos_balance(&test_gaia_1, COSMOS_USER, "samoleans", 1000)?; // ------------------- Step 2. ------------------- From 087102df3bc6a075ab7e780f5dbd020ed0724ce4 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 27 Nov 2024 17:15:49 +0000 Subject: [PATCH 14/14] Undo dogface --- crates/ibc/src/context/token_transfer.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ibc/src/context/token_transfer.rs b/crates/ibc/src/context/token_transfer.rs index f0ecffb8e1..fecc8d4d2d 100644 --- a/crates/ibc/src/context/token_transfer.rs +++ b/crates/ibc/src/context/token_transfer.rs @@ -100,7 +100,7 @@ where } else { mint.checked_sub(amount).ok_or_else(|| { TokenTransferError::Other( - format!("The mint amount underflowed: {mint} - {amount}"), + "The mint amount underflowed".to_string(), ) })? }; @@ -316,7 +316,7 @@ where // Store the IBC denom with the token hash to be able to retrieve it // later self.maybe_store_ibc_denom(account, coin)?; - tracing::info!("\n\n\n\nMinting {} {} to {}\n\n\n", amount, ibc_token, account); + self.inner .borrow_mut() .mint_token(account, &ibc_token, amount) @@ -330,7 +330,7 @@ where _memo: &Memo, ) -> Result<(), TokenTransferError> { let (ibc_token, amount) = self.get_token_amount(coin)?; - tracing::info!("\n\n\n ATTEMPTING TO BURN {amount} {ibc_token} ({coin}) from {account} \n\n\n"); + self.update_mint_amount(&ibc_token, amount, false)?; self.add_withdraw(&ibc_token, amount)?; @@ -342,6 +342,7 @@ where } let account = if self.is_shielded { &MASP } else { account }; + // The burn is "unminting" from the minted balance self.inner .borrow_mut()