From d361e020e7e3c70f40b82cf8fdaa357e0882dd15 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Fri, 25 Aug 2023 16:37:10 -0700 Subject: [PATCH 01/25] feat: implement mock cosmos chain --- Cargo.lock | 1116 +++++++++++++---- Cargo.toml | 1 + crates/relayer-cosmos-mock/Cargo.toml | 37 + .../src/contexts/birelay.rs | 32 + .../src/contexts/builder.rs | 86 ++ .../relayer-cosmos-mock/src/contexts/chain.rs | 174 +++ .../relayer-cosmos-mock/src/contexts/mod.rs | 5 + .../relayer-cosmos-mock/src/contexts/relay.rs | 62 + .../src/contexts/runtime.rs | 59 + .../relayer-cosmos-mock/src/impls/birelay.rs | 27 + crates/relayer-cosmos-mock/src/impls/chain.rs | 479 +++++++ .../src/impls/components.rs | 66 + .../relayer-cosmos-mock/src/impls/endpoint.rs | 30 + .../relayer-cosmos-mock/src/impls/handler.rs | 189 +++ crates/relayer-cosmos-mock/src/impls/mod.rs | 7 + crates/relayer-cosmos-mock/src/impls/relay.rs | 397 ++++++ .../relayer-cosmos-mock/src/impls/runtime.rs | 34 + crates/relayer-cosmos-mock/src/lib.rs | 11 + .../src/tests/ics02_client.rs | 53 + crates/relayer-cosmos-mock/src/tests/init.rs | 18 + crates/relayer-cosmos-mock/src/tests/mod.rs | 2 + .../src/traits/endpoint.rs | 9 + .../relayer-cosmos-mock/src/traits/handler.rs | 26 + crates/relayer-cosmos-mock/src/traits/mod.rs | 2 + crates/relayer-cosmos-mock/src/types/error.rs | 180 +++ crates/relayer-cosmos-mock/src/types/mod.rs | 2 + .../relayer-cosmos-mock/src/types/status.rs | 23 + .../src/util/conversion.rs | 20 + crates/relayer-cosmos-mock/src/util/dummy.rs | 53 + crates/relayer-cosmos-mock/src/util/mod.rs | 4 + crates/relayer-cosmos-mock/src/util/msgs.rs | 52 + crates/relayer-cosmos-mock/src/util/mutex.rs | 21 + 32 files changed, 3052 insertions(+), 225 deletions(-) create mode 100644 crates/relayer-cosmos-mock/Cargo.toml create mode 100644 crates/relayer-cosmos-mock/src/contexts/birelay.rs create mode 100644 crates/relayer-cosmos-mock/src/contexts/builder.rs create mode 100644 crates/relayer-cosmos-mock/src/contexts/chain.rs create mode 100644 crates/relayer-cosmos-mock/src/contexts/mod.rs create mode 100644 crates/relayer-cosmos-mock/src/contexts/relay.rs create mode 100644 crates/relayer-cosmos-mock/src/contexts/runtime.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/birelay.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/chain.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/components.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/endpoint.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/handler.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/mod.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/relay.rs create mode 100644 crates/relayer-cosmos-mock/src/impls/runtime.rs create mode 100644 crates/relayer-cosmos-mock/src/lib.rs create mode 100644 crates/relayer-cosmos-mock/src/tests/ics02_client.rs create mode 100644 crates/relayer-cosmos-mock/src/tests/init.rs create mode 100644 crates/relayer-cosmos-mock/src/tests/mod.rs create mode 100644 crates/relayer-cosmos-mock/src/traits/endpoint.rs create mode 100644 crates/relayer-cosmos-mock/src/traits/handler.rs create mode 100644 crates/relayer-cosmos-mock/src/traits/mod.rs create mode 100644 crates/relayer-cosmos-mock/src/types/error.rs create mode 100644 crates/relayer-cosmos-mock/src/types/mod.rs create mode 100644 crates/relayer-cosmos-mock/src/types/status.rs create mode 100644 crates/relayer-cosmos-mock/src/util/conversion.rs create mode 100644 crates/relayer-cosmos-mock/src/util/dummy.rs create mode 100644 crates/relayer-cosmos-mock/src/util/mod.rs create mode 100644 crates/relayer-cosmos-mock/src/util/msgs.rs create mode 100644 crates/relayer-cosmos-mock/src/util/mutex.rs diff --git a/Cargo.lock b/Cargo.lock index efb873b300..fdb420417a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,7 +12,7 @@ dependencies = [ "arc-swap", "backtrace", "canonical-path", - "clap", + "clap 3.2.25", "color-eyre", "fs-err", "once_cell", @@ -43,9 +43,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -58,9 +58,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" dependencies = [ "memchr", ] @@ -80,11 +80,60 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + [[package]] name = "anyhow" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "arc-swap" @@ -92,6 +141,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-io" version = "1.13.0" @@ -108,15 +163,15 @@ dependencies = [ "polling", "rustix 0.37.23", "slab", - "socket2", + "socket2 0.4.9", "waker-fn", ] [[package]] name = "async-lock" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ "event-listener", ] @@ -140,18 +195,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] name = "async-trait" -version = "0.1.72" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -189,9 +244,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a1de45611fdb535bfde7b7de4fd54f4fd2b17b1737c0a59b69bf9b92074b8c" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", "axum-core", @@ -238,9 +293,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -275,12 +330,82 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "basecoin-app" +version = "0.1.0" +source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=e7f23d3#e7f23d381226ed5c395dd6124d0f9c50ae2adc48" +dependencies = [ + "base64 0.21.2", + "basecoin-store", + "clap 4.3.23", + "cosmrs", + "derive_more", + "displaydoc", + "ibc", + "ibc-proto 0.34.0", + "ics23", + "primitive-types", + "prost", + "serde", + "serde_derive", + "serde_json", + "sha2 0.10.7", + "tendermint 0.33.0", + "tendermint-proto 0.33.0", + "tendermint-rpc 0.33.0", + "tokio", + "toml 0.7.6", + "tonic", + "tonic-reflection", + "tower", + "tower-abci", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "basecoin-store" +version = "0.1.0" +source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=e7f23d3#e7f23d381226ed5c395dd6124d0f9c50ae2adc48" +dependencies = [ + "base64 0.21.2", + "derive_more", + "displaydoc", + "ed25519", + "ibc", + "ics23", + "prost", + "serde", + "serde_json", + "sha2 0.10.7", + "tendermint 0.33.0", + "tracing", +] + [[package]] name = "bech32" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bip32" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e141fb0f8be1c7b45887af94c88b182472b57c96b56773250ae00cd6a14a164" +dependencies = [ + "bs58", + "hmac", + "k256", + "once_cell", + "pbkdf2 0.12.2", + "rand_core", + "ripemd", + "sha2 0.10.7", + "subtle", + "zeroize", +] + [[package]] name = "bitcoin" version = "0.30.1" @@ -319,9 +444,21 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] [[package]] name = "block-buffer" @@ -347,6 +484,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" dependencies = [ + "sha2 0.10.7", "tinyvec", ] @@ -356,6 +494,12 @@ version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + [[package]] name = "byte-unit" version = "4.0.19" @@ -426,9 +570,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -465,8 +612,8 @@ checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags 1.3.2", - "clap_derive", - "clap_lex", + "clap_derive 3.2.25", + "clap_lex 0.2.4", "indexmap 1.9.3", "once_cell", "strsim", @@ -474,13 +621,37 @@ dependencies = [ "textwrap", ] +[[package]] +name = "clap" +version = "4.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03aef18ddf7d879c15ce20f04826ef8418101c7e528014c3eeea13321047dca3" +dependencies = [ + "clap_builder", + "clap_derive 4.3.12", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ce6fffb678c9b80a70b6b6de0aad31df727623a70fd9a842c30cd573e2fa98" +dependencies = [ + "anstream", + "anstyle", + "clap_lex 0.5.0", + "strsim", + "terminal_size", +] + [[package]] name = "clap_complete" version = "3.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8" dependencies = [ - "clap", + "clap 3.2.25", ] [[package]] @@ -496,6 +667,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "clap_derive" +version = "4.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.29", +] + [[package]] name = "clap_lex" version = "0.2.4" @@ -505,6 +688,12 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + [[package]] name = "color-eyre" version = "0.6.2" @@ -532,6 +721,12 @@ dependencies = [ "tracing-error", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "concurrent-queue" version = "2.2.0" @@ -556,9 +751,9 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "contracts" @@ -587,6 +782,37 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "cosmos-sdk-proto" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73c9d2043a9e617b0d602fbc0a0ecd621568edbf3a9774890a6d562389bd8e1c" +dependencies = [ + "prost", + "prost-types", + "tendermint-proto 0.32.2", +] + +[[package]] +name = "cosmrs" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af13955d6f356272e6def9ff5e2450a7650df536d8934f47052a20c76513d2f6" +dependencies = [ + "bip32", + "cosmos-sdk-proto", + "ecdsa", + "eyre", + "getrandom", + "k256", + "rand_core", + "serde", + "serde_json", + "subtle-encoding", + "tendermint 0.32.0", + "thiserror", +] + [[package]] name = "cpufeatures" version = "0.2.9" @@ -711,7 +937,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -727,6 +953,41 @@ dependencies = [ "zeroize", ] +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.29", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.29", +] + [[package]] name = "dashmap" version = "4.0.2" @@ -739,9 +1000,9 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.5.0" +version = "5.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" +checksum = "edd72493923899c6f10c641bdbdeddc7183d6396641d99c1a0d1597f37f92e28" dependencies = [ "cfg-if 1.0.0", "hashbrown 0.14.0", @@ -752,9 +1013,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ed52955ce76b1554f509074bb357d3fb8ac9b51288a65a3fd480d1dfba946" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", "zeroize", @@ -762,9 +1023,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8810e7e2cf385b1e9b50d68264908ec367ba642c96d02edfe61c39e88e2a3c01" +checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" [[package]] name = "derivation-path" @@ -837,11 +1098,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "displaydoc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.29", +] + [[package]] name = "dyn-clone" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "304e6508efa593091e97a9abbc10f90aa7ca635b6d2784feff3c89d41dd12272" +checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" [[package]] name = "ecdsa" @@ -968,9 +1240,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "erased-serde" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da96524cc884f6558f1769b6c46686af2fe8e8b4cd253bd5a3cdba8181b8e070" +checksum = "fc978899517288e3ebbd1a3bfc1d9537dbb87eeab149e53ea490e63bcdff561a" dependencies = [ "serde", ] @@ -1058,6 +1330,9 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ + "byteorder", + "rand", + "rustc-hex", "static_assertions", ] @@ -1093,6 +1368,12 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541" +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.3.28" @@ -1164,7 +1445,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -1223,9 +1504,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "glob" @@ -1266,9 +1547,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -1279,7 +1560,7 @@ dependencies = [ "indexmap 1.9.3", "slab", "tokio", - "tokio-util", + "tokio-util 0.7.8", "tracing", ] @@ -1310,6 +1591,16 @@ dependencies = [ "byteorder", ] +[[package]] +name = "hdrhistogram" +version = "7.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f19b9f54f7c7f55e31401bb647626ce0cf0f67b0004982ce815b3ee72a02aa8" +dependencies = [ + "byteorder", + "num-traits", +] + [[package]] name = "headers" version = "0.3.8" @@ -1407,9 +1698,9 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "humantime" @@ -1444,7 +1735,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -1497,7 +1788,7 @@ dependencies = [ "futures-util", "http", "hyper", - "rustls 0.21.5", + "rustls 0.21.6", "tokio", "tokio-rustls 0.24.1", ] @@ -1537,6 +1828,36 @@ dependencies = [ "cc", ] +[[package]] +name = "ibc" +version = "0.44.1" +source = "git+https://github.com/cosmos/ibc-rs.git?rev=6ffe8ce#6ffe8ce26f40b029e176d8fe92dde13467fb3735" +dependencies = [ + "bytes", + "derive_more", + "displaydoc", + "ibc-derive", + "ibc-proto 0.34.0", + "ics23", + "num-traits", + "parking_lot", + "primitive-types", + "prost", + "safe-regex", + "serde", + "serde_derive", + "serde_json", + "sha2 0.10.7", + "subtle-encoding", + "tendermint 0.33.0", + "tendermint-light-client-verifier 0.33.0", + "tendermint-proto 0.33.0", + "tendermint-testgen 0.33.0", + "time 0.3.25", + "tracing", + "uint", +] + [[package]] name = "ibc-chain-registry" version = "0.25.0" @@ -1545,17 +1866,28 @@ dependencies = [ "flex-error", "futures", "http", - "ibc-proto", + "ibc-proto 0.32.1", "ibc-relayer-types", "itertools", "reqwest", "serde", "serde_json", - "tendermint-rpc", + "tendermint-rpc 0.32.0", "tokio", "tracing", ] +[[package]] +name = "ibc-derive" +version = "0.3.0" +source = "git+https://github.com/cosmos/ibc-rs.git?rev=6ffe8ce#6ffe8ce26f40b029e176d8fe92dde13467fb3735" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.29", +] + [[package]] name = "ibc-integration-test" version = "0.25.0" @@ -1573,7 +1905,7 @@ dependencies = [ "serde", "serde_json", "tempfile", - "time 0.3.24", + "time 0.3.25", "tokio", "toml 0.7.6", "tonic", @@ -1592,7 +1924,24 @@ dependencies = [ "prost", "serde", "subtle-encoding", - "tendermint-proto", + "tendermint-proto 0.32.2", + "tonic", +] + +[[package]] +name = "ibc-proto" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6e8625e1aa28e4da4a33505c6469747a9201f14ccd9012e2481313dfbbf9e2f" +dependencies = [ + "base64 0.21.2", + "bytes", + "flex-error", + "ics23", + "prost", + "serde", + "subtle-encoding", + "tendermint-proto 0.33.0", "tonic", ] @@ -1622,7 +1971,7 @@ dependencies = [ "http", "humantime", "humantime-serde", - "ibc-proto", + "ibc-proto 0.32.1", "ibc-relayer-types", "ibc-telemetry", "itertools", @@ -1644,11 +1993,11 @@ dependencies = [ "signature", "strum", "subtle-encoding", - "tendermint", + "tendermint 0.32.0", "tendermint-light-client", "tendermint-light-client-detector", - "tendermint-rpc", - "tendermint-testgen", + "tendermint-rpc 0.32.0", + "tendermint-testgen 0.32.0", "test-log", "thiserror", "tiny-bip39", @@ -1680,7 +2029,7 @@ dependencies = [ "abscissa_core", "async-trait", "chrono", - "clap", + "clap 3.2.25", "clap_complete", "color-eyre", "console", @@ -1712,10 +2061,10 @@ dependencies = [ "serial_test", "signal-hook", "subtle-encoding", - "tendermint", - "tendermint-light-client-verifier", - "tendermint-rpc", - "time 0.3.24", + "tendermint 0.32.0", + "tendermint-light-client-verifier 0.32.0", + "tendermint-rpc 0.32.0", + "time 0.3.25", "tokio", "tracing", "tracing-subscriber", @@ -1748,7 +2097,7 @@ dependencies = [ "eyre", "flex-error", "futures", - "ibc-proto", + "ibc-proto 0.32.1", "ibc-relayer", "ibc-relayer-all-in-one", "ibc-relayer-components", @@ -1757,18 +2106,44 @@ dependencies = [ "ibc-relayer-types", "ibc-telemetry", "itertools", - "moka 0.10.3", + "moka 0.10.4", "opentelemetry 0.17.0", "prost", "serde", "serde_derive", - "tendermint", - "tendermint-rpc", + "tendermint 0.32.0", + "tendermint-rpc 0.32.0", "tokio", "tonic", "tracing", ] +[[package]] +name = "ibc-relayer-cosmos-mock" +version = "0.1.0" +dependencies = [ + "async-trait", + "basecoin-app", + "basecoin-store", + "ibc", + "ibc-proto 0.34.0", + "ibc-relayer-components", + "ibc-relayer-runtime", + "ibc-relayer-types", + "primitive-types", + "prost", + "rand", + "serde_json", + "sha2 0.10.7", + "subtle-encoding", + "tendermint 0.33.0", + "tendermint-testgen 0.33.0", + "tokio", + "tower", + "tower-abci", + "tracing", +] + [[package]] name = "ibc-relayer-mock" version = "0.1.0" @@ -1822,7 +2197,7 @@ dependencies = [ "env_logger", "erased-serde", "flex-error", - "ibc-proto", + "ibc-proto 0.32.1", "ics23", "itertools", "num-rational", @@ -1833,13 +2208,13 @@ dependencies = [ "serde_derive", "serde_json", "subtle-encoding", - "tendermint", - "tendermint-light-client-verifier", - "tendermint-proto", - "tendermint-rpc", - "tendermint-testgen", + "tendermint 0.32.0", + "tendermint-light-client-verifier 0.32.0", + "tendermint-proto 0.32.2", + "tendermint-rpc 0.32.0", + "tendermint-testgen 0.32.0", "test-log", - "time 0.3.24", + "time 0.3.25", "tracing", "tracing-subscriber", "uint", @@ -1850,7 +2225,7 @@ name = "ibc-telemetry" version = "0.25.0" dependencies = [ "axum", - "dashmap 5.5.0", + "dashmap 5.5.1", "ibc-relayer-types", "moka 0.11.3", "once_cell", @@ -1859,7 +2234,7 @@ dependencies = [ "prometheus", "serde", "serde_json", - "tendermint", + "tendermint 0.32.0", "tokio", "tracing", ] @@ -1876,7 +2251,7 @@ dependencies = [ "hdpath", "hex", "http", - "ibc-proto", + "ibc-proto 0.32.1", "ibc-relayer", "ibc-relayer-all-in-one", "ibc-relayer-cli", @@ -1893,7 +2268,7 @@ dependencies = [ "serde_yaml", "sha2 0.10.7", "subtle-encoding", - "tendermint-rpc", + "tendermint-rpc 0.32.0", "tokio", "toml 0.7.6", "tonic", @@ -1903,14 +2278,14 @@ dependencies = [ [[package]] name = "ics23" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af9e8f569c5cc88e08b8d076dc207e0748aa1f52d4b84910ec919c8f2bed6ea7" +checksum = "442d4bab37956e76f739c864f246c825d87c0bb7f9afa65660c57833c91bf6d4" dependencies = [ "anyhow", "bytes", "hex", - "pbjson", + "informalsystems-pbjson", "prost", "ripemd", "serde", @@ -1934,6 +2309,15 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + [[package]] name = "impl-serde" version = "0.4.0" @@ -1943,6 +2327,17 @@ dependencies = [ "serde", ] +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "indenter" version = "0.3.3" @@ -1969,6 +2364,16 @@ dependencies = [ "hashbrown 0.14.0", ] +[[package]] +name = "informalsystems-pbjson" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4eecd90f87bea412eac91c6ef94f6b1e390128290898cbe14f2b926787ae1fb" +dependencies = [ + "base64 0.13.1", + "serde", +] + [[package]] name = "instant" version = "0.1.12" @@ -2002,7 +2407,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.2", - "rustix 0.38.4", + "rustix 0.38.8", "windows-sys 0.48.0", ] @@ -2039,7 +2444,9 @@ dependencies = [ "cfg-if 1.0.0", "ecdsa", "elliptic-curve", + "once_cell", "sha2 0.10.7", + "signature", ] [[package]] @@ -2071,9 +2478,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" @@ -2087,9 +2494,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "mach2" @@ -2111,9 +2518,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67827e6ea8ee8a7c4a72227ef4fc08957040acffdb5f122733b24fa12daff41b" +checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" [[package]] name = "maybe-uninit" @@ -2164,9 +2571,9 @@ dependencies = [ [[package]] name = "moka" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713518e40360e799c7a0b991b63fcd59814b00901ad3acbe8ecfb5daa23723be" +checksum = "0be0a3dd6fe7c99233c2b1476e703147fb7516c68dce585b19b51efc08fe93d8" dependencies = [ "async-io", "async-lock", @@ -2222,9 +2629,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" dependencies = [ "autocfg", "num-integer", @@ -2287,9 +2694,9 @@ dependencies = [ [[package]] name = "object" -version = "0.31.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe" dependencies = [ "memchr", ] @@ -2387,7 +2794,7 @@ checksum = "8b3a2a91fdbfdd4d212c0dcc2ab540de2c2bcbbd90be17de7a7daf8822d010c1" dependencies = [ "async-trait", "crossbeam-channel 0.5.8", - "dashmap 5.5.0", + "dashmap 5.5.1", "fnv", "futures-channel", "futures-executor", @@ -2417,6 +2824,32 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "parity-scale-codec" +version = "3.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8e946cc0cc711189c0b0249fb8b599cbeeab9784d83c415719368bb8d4ac64" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a296c3079b5fefbc499e1de58dc26c09b1b9a5952d26694ee89f04a43ebbb3e" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "parking" version = "2.1.0" @@ -2443,7 +2876,7 @@ dependencies = [ "libc", "redox_syscall 0.3.5", "smallvec", - "windows-targets 0.48.1", + "windows-targets 0.48.5", ] [[package]] @@ -2453,22 +2886,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] -name = "pbjson" -version = "0.5.1" +name = "pbkdf2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "048f9ac93c1eab514f9470c4bc8d97ca2a0a236b84f45cc19d69a59fc11467f6" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ - "base64 0.13.1", - "serde", + "digest 0.10.7", ] [[package]] name = "pbkdf2" -version = "0.11.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ "digest 0.10.7", + "hmac", ] [[package]] @@ -2506,29 +2939,29 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" [[package]] name = "pin-utils" @@ -2581,10 +3014,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" dependencies = [ "fixed-hash", + "impl-codec", "impl-serde", "uint", ] +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -2700,13 +3144,19 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -2777,13 +3227,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.4", + "regex-automata 0.3.6", "regex-syntax 0.7.4", ] @@ -2798,9 +3248,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.4" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" +checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" dependencies = [ "aho-corasick", "memchr", @@ -2821,9 +3271,9 @@ checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "20b9b67e2ca7dd9e9f9285b759de30ff538aab981abaaf7bc9bd90b84a0126c3" dependencies = [ "base64 0.21.2", "bytes", @@ -2842,7 +3292,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.5", + "rustls 0.21.6", "rustls-pemfile", "serde", "serde_json", @@ -2854,7 +3304,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.22.6", + "webpki-roots 0.25.2", "winreg", ] @@ -2910,6 +3360,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + [[package]] name = "rustc_version" version = "0.4.0" @@ -2935,14 +3391,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.3", + "linux-raw-sys 0.4.5", "windows-sys 0.48.0", ] @@ -2973,9 +3429,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36" +checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" dependencies = [ "log", "ring", @@ -3018,9 +3474,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.101.2" +version = "0.101.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513722fd73ad80a71f72b61009ea1b584bcfa1483ca93949c8f290298837fa59" +checksum = "7d93931baf2d282fff8d3a532bbfd7653f734643161b87e3e01e59a04439bf0d" dependencies = [ "ring", "untrusted", @@ -3217,9 +3673,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.179" +version = "1.0.185" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5bf42b8d227d4abf38a1ddb08602e229108a517cd4e5bb28f9c7eaafdce5c0" +checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" dependencies = [ "serde_derive", ] @@ -3245,20 +3701,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.179" +version = "1.0.185" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "741e124f5485c7e60c03b043f79f320bff3527f4bbf12cf3831750dc46a0ec2c" +checksum = "dc59dfdcbad1437773485e0367fea4b090a2e0a16d9ffc46af47764536a298ec" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] name = "serde_json" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" +checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" dependencies = [ "itoa", "ryu", @@ -3283,7 +3739,7 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -3326,7 +3782,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e56dd856803e253c8f298af3f4d7eb0ae5e23a737252cd90bb4f3b435033b2d" dependencies = [ - "dashmap 5.5.0", + "dashmap 5.5.1", "futures", "lazy_static", "log", @@ -3342,7 +3798,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -3457,9 +3913,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] @@ -3480,6 +3936,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "spin" version = "0.5.2" @@ -3519,15 +3985,15 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.25.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6069ca09d878a33f883cc06aaa9718ede171841d3832450354410b718b097232" +checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" dependencies = [ "heck", "proc-macro2", "quote", "rustversion", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -3564,9 +4030,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.28" +version = "2.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" dependencies = [ "proc-macro2", "quote", @@ -3597,16 +4063,22 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", "redox_syscall 0.3.5", - "rustix 0.38.4", + "rustix 0.38.8", "windows-sys 0.48.0", ] @@ -3636,8 +4108,37 @@ dependencies = [ "signature", "subtle", "subtle-encoding", - "tendermint-proto", - "time 0.3.24", + "tendermint-proto 0.32.2", + "time 0.3.25", + "zeroize", +] + +[[package]] +name = "tendermint" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6d550db02d6bec4ebcbbebc4301ec22181bc489c37fb3f167e64b14c1be8321" +dependencies = [ + "bytes", + "digest 0.10.7", + "ed25519", + "ed25519-consensus", + "flex-error", + "futures", + "num-traits", + "once_cell", + "prost", + "prost-types", + "serde", + "serde_bytes", + "serde_json", + "serde_repr", + "sha2 0.10.7", + "signature", + "subtle", + "subtle-encoding", + "tendermint-proto 0.33.0", + "time 0.3.25", "zeroize", ] @@ -3650,7 +4151,21 @@ dependencies = [ "flex-error", "serde", "serde_json", - "tendermint", + "tendermint 0.32.0", + "toml 0.5.11", + "url", +] + +[[package]] +name = "tendermint-config" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36a787b139f314c92756becbcae855bef6772227d97d8ecee948ad90327fe6e7" +dependencies = [ + "flex-error", + "serde", + "serde_json", + "tendermint 0.33.0", "toml 0.5.11", "url", ] @@ -3672,10 +4187,10 @@ dependencies = [ "serde_derive", "serde_json", "static_assertions", - "tendermint", - "tendermint-light-client-verifier", - "tendermint-rpc", - "time 0.3.24", + "tendermint 0.32.0", + "tendermint-light-client-verifier 0.32.0", + "tendermint-rpc 0.32.0", + "time 0.3.25", "tokio", "tracing", ] @@ -3696,11 +4211,11 @@ dependencies = [ "serde_derive", "serde_json", "static_assertions", - "tendermint", + "tendermint 0.32.0", "tendermint-light-client", - "tendermint-proto", - "tendermint-rpc", - "time 0.3.24", + "tendermint-proto 0.32.2", + "tendermint-rpc 0.32.0", + "time 0.3.25", "tracing", ] @@ -3713,15 +4228,46 @@ dependencies = [ "derive_more", "flex-error", "serde", - "tendermint", - "time 0.3.24", + "tendermint 0.32.0", + "time 0.3.25", +] + +[[package]] +name = "tendermint-light-client-verifier" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bc1e4e3dd6f65cfa7979cf721b5afa1d79d32c4a2fe5fddb6416a98638634a9" +dependencies = [ + "derive_more", + "flex-error", + "serde", + "tendermint 0.33.0", + "time 0.3.25", ] [[package]] name = "tendermint-proto" -version = "0.32.0" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0cec054567d16d85e8c3f6a3139963d1a66d9d3051ed545d31562550e9bcc3d" +dependencies = [ + "bytes", + "flex-error", + "num-derive", + "num-traits", + "prost", + "prost-types", + "serde", + "serde_bytes", + "subtle-encoding", + "time 0.3.25", +] + +[[package]] +name = "tendermint-proto" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23c8ff0e6634eb4c3c4aeed45076dc97dac91aac5501a905a67fa222e165b" +checksum = "1834fa2eb884ba69b9c0eea55f0178270bed421217596ca4e54c19ef75dcb660" dependencies = [ "bytes", "flex-error", @@ -3732,7 +4278,7 @@ dependencies = [ "serde", "serde_bytes", "subtle-encoding", - "time 0.3.24", + "time 0.3.25", ] [[package]] @@ -3759,11 +4305,46 @@ dependencies = [ "serde_json", "subtle", "subtle-encoding", - "tendermint", - "tendermint-config", - "tendermint-proto", + "tendermint 0.32.0", + "tendermint-config 0.32.0", + "tendermint-proto 0.32.2", + "thiserror", + "time 0.3.25", + "tokio", + "tracing", + "url", + "uuid 0.8.2", + "walkdir", +] + +[[package]] +name = "tendermint-rpc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03f8ff62948110e58d6df12c3bb73a00e74553384255d6413deed4c21d7480bf" +dependencies = [ + "async-trait", + "bytes", + "flex-error", + "futures", + "getrandom", + "http", + "hyper", + "hyper-proxy", + "hyper-rustls 0.22.1", + "peg", + "pin-project", + "semver", + "serde", + "serde_bytes", + "serde_json", + "subtle", + "subtle-encoding", + "tendermint 0.33.0", + "tendermint-config 0.33.0", + "tendermint-proto 0.33.0", "thiserror", - "time 0.3.24", + "time 0.3.25", "tokio", "tracing", "url", @@ -3783,8 +4364,24 @@ dependencies = [ "serde_json", "simple-error", "tempfile", - "tendermint", - "time 0.3.24", + "tendermint 0.32.0", + "time 0.3.25", +] + +[[package]] +name = "tendermint-testgen" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23a1e92079f943bdb0868795e9550c5185b8d0c6222be1475548314cf4f44c49" +dependencies = [ + "ed25519-consensus", + "gumdrop", + "serde", + "serde_json", + "simple-error", + "tempfile", + "tendermint 0.33.0", + "time 0.3.25", ] [[package]] @@ -3796,6 +4393,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237" +dependencies = [ + "rustix 0.37.23", + "windows-sys 0.48.0", +] + [[package]] name = "test-log" version = "0.2.12" @@ -3815,22 +4422,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -3856,9 +4463,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79eabcd964882a646b3584543ccabeae7869e9ac32a46f6f22b7a5bd405308b" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" dependencies = [ "deranged", "serde", @@ -3890,7 +4497,7 @@ dependencies = [ "anyhow", "hmac", "once_cell", - "pbkdf2", + "pbkdf2 0.11.0", "rand", "rustc-hash", "sha2 0.10.7", @@ -3926,11 +4533,10 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.1" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", @@ -3939,7 +4545,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.3", "tokio-macros", "windows-sys 0.48.0", ] @@ -3962,7 +4568,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -3993,7 +4599,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.5", + "rustls 0.21.6", "tokio", ] @@ -4008,6 +4614,20 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-util" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.8" @@ -4097,6 +4717,19 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic-reflection" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0543d7092032041fbeac1f2c84304537553421a11a623c2301b12ef0264862c7" +dependencies = [ + "prost", + "prost-types", + "tokio", + "tokio-stream", + "tonic", +] + [[package]] name = "tower" version = "0.4.13" @@ -4105,18 +4738,38 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", + "hdrhistogram", "indexmap 1.9.3", "pin-project", "pin-project-lite", "rand", "slab", "tokio", - "tokio-util", + "tokio-util 0.7.8", "tower-layer", "tower-service", "tracing", ] +[[package]] +name = "tower-abci" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42c629f4e6844d9c506d4b3b7894821015c72c818fc4e7e66275d34e5e0b43a2" +dependencies = [ + "bytes", + "futures", + "pin-project", + "prost", + "tendermint 0.33.0", + "tendermint-proto 0.33.0", + "tokio", + "tokio-stream", + "tokio-util 0.6.10", + "tower", + "tracing", +] + [[package]] name = "tower-layer" version = "0.3.2" @@ -4150,7 +4803,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] [[package]] @@ -4268,9 +4921,9 @@ dependencies = [ [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] @@ -4349,6 +5002,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "0.8.2" @@ -4443,7 +5102,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", "wasm-bindgen-shared", ] @@ -4477,7 +5136,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4529,12 +5188,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" -dependencies = [ - "webpki 0.22.0", -] +checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" [[package]] name = "winapi" @@ -4573,7 +5229,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets 0.48.1", + "windows-targets 0.48.5", ] [[package]] @@ -4591,7 +5247,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.48.1", + "windows-targets 0.48.5", ] [[package]] @@ -4611,17 +5267,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -4632,9 +5288,9 @@ checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" @@ -4644,9 +5300,9 @@ checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" @@ -4656,9 +5312,9 @@ checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" @@ -4668,9 +5324,9 @@ checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" @@ -4680,9 +5336,9 @@ checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" @@ -4692,9 +5348,9 @@ checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" @@ -4704,26 +5360,36 @@ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.2" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd122eb777186e60c3fdf765a58ac76e41c582f1f535fbf3314434c6b58f3f7" +checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97" dependencies = [ "memchr", ] [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if 1.0.0", + "windows-sys 0.48.0", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", ] [[package]] @@ -4743,5 +5409,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.29", ] diff --git a/Cargo.toml b/Cargo.toml index 06789b519e..3ad5cb7da3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "crates/relayer-mock", "crates/relayer-runtime", "crates/relayer-cosmos", + "crates/relayer-cosmos-mock", "crates/telemetry", "crates/chain-registry", "tools/integration-test", diff --git a/crates/relayer-cosmos-mock/Cargo.toml b/crates/relayer-cosmos-mock/Cargo.toml new file mode 100644 index 0000000000..e6e4762579 --- /dev/null +++ b/crates/relayer-cosmos-mock/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "ibc-relayer-cosmos-mock" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +readme = "README.md" +keywords = ["blockchain", "consensus", "cosmos", "ibc", "tendermint"] +repository = "https://github.com/informalsystems/ibc-rs" +authors = ["Informal Systems "] +rust-version = "1.68" +description = """ + TBD +""" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +async-trait = "0.1.56" +basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "e7f23d3" } +basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "e7f23d3" } +ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev= "6ffe8ce", features = ["mocks"] } +ibc-proto = "0.34.0" +ibc-relayer-components = { version = "0.1.0", path = "../relayer-components" } +ibc-relayer-runtime = { path = "../relayer-runtime" } +ibc-relayer-types = { path = "../relayer-types" } +primitive-types = { version = "0.12.0", default-features = false} +prost = "0.11.0" +serde_json = "1.0" +sha2 = { version = "0.10", default-features = false } +subtle-encoding = { version = "0.5", default-features = false } +rand = "0.8.5" +tendermint = { version = "0.33.0", features = ["rust-crypto"] } +tendermint-testgen = "0.33.0" +tracing = "0.1.36" +tokio = { version = "1.0", features = ["full"] } +tower-abci = "0.9" +tower = { version = "0.4", features = ["full"] } diff --git a/crates/relayer-cosmos-mock/src/contexts/birelay.rs b/crates/relayer-cosmos-mock/src/contexts/birelay.rs new file mode 100644 index 0000000000..a392834671 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/birelay.rs @@ -0,0 +1,32 @@ +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; +use std::sync::Arc; + +use super::relay::MockCosmosRelay; + +pub struct MockCosmosBiRelay { + pub runtime: TokioRuntimeContext, + pub relay_a_to_b: Arc, + pub relay_b_to_a: Arc, +} + +impl MockCosmosBiRelay { + pub fn new( + runtime: TokioRuntimeContext, + relay_a_to_b: Arc, + relay_b_to_a: Arc, + ) -> Self { + Self { + runtime, + relay_a_to_b, + relay_b_to_a, + } + } + + pub fn relay_a_to_b(&self) -> &Arc { + &self.relay_a_to_b + } + + pub fn relay_b_to_a(&self) -> &Arc { + &self.relay_b_to_a + } +} diff --git a/crates/relayer-cosmos-mock/src/contexts/builder.rs b/crates/relayer-cosmos-mock/src/contexts/builder.rs new file mode 100644 index 0000000000..4b9b5abf18 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/builder.rs @@ -0,0 +1,86 @@ +use alloc::sync::Arc; +use ibc::core::ics24_host::identifier::ChainId; +use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket; +use tokio::task::JoinHandle; + +use crate::traits::handler::ChainHandler; +use crate::util::msgs::build_transfer_packet; + +use super::chain::MockCosmosChain; +use super::relay::MockCosmosRelay; +use super::runtime::MockClock; +use super::runtime::MockRuntimeContext; + +pub struct MockCosmosBuilder { + pub chains: Vec>, + pub relayers: Vec>, + pub handlers: Vec>, + pub runtime: MockRuntimeContext, +} + +impl MockCosmosBuilder { + pub fn new(clock: Arc) -> Self { + Self { + chains: Vec::new(), + relayers: Vec::new(), + handlers: Vec::new(), + runtime: MockRuntimeContext { clock }, + } + } + + pub fn new_default() -> Self { + Self::new(Arc::new(MockClock::default())) + } + + pub fn build_chain(&mut self, chain_id: ChainId) -> Arc { + let chain = Arc::new(MockCosmosChain::new(chain_id, self.runtime.clock.clone())); + + self.chains.push(chain.clone()); + + chain + } + + pub fn build_relayer( + &mut self, + src_chain: Arc, + dst_chain: Arc, + ) -> MockCosmosRelay { + let relayer = MockCosmosRelay::new(src_chain, dst_chain, self.runtime.clone()); + + self.relayers.push(Arc::new(relayer.clone())); + + relayer + } + + pub fn spawn_chains(&mut self) { + for c in self.chains.clone() { + let c_clone = c.clone(); + + let handle = tokio::spawn(async move { + c_clone.run().await.unwrap(); + }); + + self.handlers.push(handle); + } + } + + pub async fn relay_packet(&mut self) { + for r in &self.relayers { + let packet = build_transfer_packet(1); + + let relayer_clone = r.clone(); + + let handle = tokio::spawn(async move { + relayer_clone.relay_packet(&packet).await.unwrap(); + }); + + self.handlers.push(handle); + } + } + + pub fn stop(&self) { + for h in &self.handlers { + h.abort(); + } + } +} diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs new file mode 100644 index 0000000000..f33ab30d07 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -0,0 +1,174 @@ +use basecoin_app::modules::auth::Auth; +use basecoin_app::modules::bank::Bank; +use basecoin_app::modules::context::prefix; +use basecoin_app::modules::context::Identifiable; +use basecoin_app::modules::ibc::Ibc; +use basecoin_app::modules::ibc::IbcContext; +use basecoin_app::{BaseCoinApp, Builder}; +use basecoin_store::impls::InMemoryStore; +use basecoin_store::impls::RevertibleStore; + +use ibc::clients::ics07_tendermint::client_state::AllowUpdate; +use ibc::clients::ics07_tendermint::client_state::ClientState; +use ibc::clients::ics07_tendermint::client_type; +use ibc::clients::ics07_tendermint::header::Header; +use ibc::core::ics02_client::msgs::create_client::MsgCreateClient; +use ibc::core::ics02_client::msgs::update_client::MsgUpdateClient; +use ibc::core::ics24_host::identifier::ChainId; +use ibc::core::ics24_host::identifier::ClientId; +use ibc::core::timestamp::Timestamp; +use ibc::core::Msg; +use ibc::core::ValidationContext; +use ibc::Any; +use ibc::Height; +use tendermint_testgen::Generator; + +use std::sync::Arc; +use std::sync::Mutex; +use std::time::Duration; + +use tendermint::chain::Id; +use tendermint_testgen::LightBlock; + +use super::runtime::MockClock; +use crate::contexts::runtime::MockRuntimeContext; +use crate::traits::endpoint::Endpoint; +use crate::types::error::Error; +use crate::types::status::ChainStatus; +use crate::util::dummy::dummy_signer; +use crate::util::mutex::MutexUtil; + +#[derive(Clone)] +pub struct MockCosmosChain { + /// Chain identifier + pub chain_id: ChainId, + /// Current chain status + pub current_state: Arc>, + /// Chain application + pub app: BaseCoinApp, + /// Chain blocks + pub blocks: Arc>>, + /// Chain runtime + pub runtime: MockRuntimeContext, +} + +impl MockCosmosChain { + /// Constructs a new mock cosmos chain instance. + pub fn new(chain_id: ChainId, clock: Arc) -> Self { + let app_builder = Builder::new(InMemoryStore::default()); + + let auth = Auth::new(app_builder.module_store(&prefix::Auth {}.identifier())); + let bank = Bank::new( + app_builder.module_store(&prefix::Bank {}.identifier()), + auth.account_reader().clone(), + auth.account_keeper().clone(), + ); + let ibc: Ibc> = Ibc::new( + app_builder.module_store(&prefix::Ibc {}.identifier()), + bank.bank_keeper().clone(), + ); + + // register modules with the app + let app = app_builder + .add_module(prefix::Auth {}.identifier(), auth.clone()) + .add_module(prefix::Bank {}.identifier(), bank.clone()) + .add_module(prefix::Ibc {}.identifier(), ibc) + .build(); + + let runtime = MockRuntimeContext::new(clock.clone()); + + let genesis_height = 1; + + let genesis_block = LightBlock::new_default(genesis_height); + + let current_state = Arc::new(Mutex::new(ChainStatus::new( + Height::new(chain_id.revision_number(), genesis_height).unwrap(), + clock.get_timestamp(), + ))); + + Self { + chain_id, + current_state, + app, + blocks: Arc::new(Mutex::new(vec![genesis_block])), + runtime, + } + } + + pub fn chain_id(&self) -> &ChainId { + &self.chain_id + } + + pub fn runtime(&self) -> &MockRuntimeContext { + &self.runtime + } + + pub fn get_current_timestamp(&self) -> Timestamp { + self.current_state.acquire_mutex().timestamp + } + + pub fn get_current_height(&self) -> Height { + self.current_state.acquire_mutex().height + } + + pub fn ibc_context(&self) -> IbcContext> { + self.app.ibc().ctx() + } + + pub async fn build_msg_create_client(&self) -> Result { + let tm_client_state = ClientState::new( + self.chain_id.clone(), + Default::default(), + Duration::from_secs(64000), + Duration::from_secs(128000), + Duration::from_millis(3000), + self.get_current_height(), + Default::default(), + Default::default(), + AllowUpdate { + after_expiry: false, + after_misbehaviour: false, + }, + )?; + + let current_height = self.get_current_height(); + + let tm_consensus_state = self.query_host_consensus_state(¤t_height)?; + + let msg_create_client = MsgCreateClient { + client_state: tm_client_state.into(), + consensus_state: tm_consensus_state.into(), + signer: dummy_signer(), + }; + + Ok(msg_create_client.to_any()) + } + + pub async fn build_msg_update_client(&self) -> Result { + let client_counter = self.ibc_context().client_counter()?; + + let client_id = ClientId::new(client_type(), client_counter)?; + + let last_block = self.blocks.acquire_mutex().last().unwrap().clone(); + + let mut tm_light_block = last_block.generate().map_err(Error::source)?; + + tm_light_block.signed_header.header.chain_id = + Id::try_from(self.chain_id.to_string()).unwrap(); + + let header = Header { + signed_header: tm_light_block.signed_header, + validator_set: tm_light_block.validators, + trusted_height: self.get_current_height(), + trusted_next_validator_set: tm_light_block.next_validators, + }; + + let msg_update_client = MsgUpdateClient { + client_id, + client_message: header.into(), + signer: dummy_signer(), + }; + + Ok(msg_update_client.to_any()) + } +} diff --git a/crates/relayer-cosmos-mock/src/contexts/mod.rs b/crates/relayer-cosmos-mock/src/contexts/mod.rs new file mode 100644 index 0000000000..cdcf68ace5 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/mod.rs @@ -0,0 +1,5 @@ +pub mod birelay; +pub mod builder; +pub mod chain; +pub mod relay; +pub mod runtime; diff --git a/crates/relayer-cosmos-mock/src/contexts/relay.rs b/crates/relayer-cosmos-mock/src/contexts/relay.rs new file mode 100644 index 0000000000..ecc27aeae8 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/relay.rs @@ -0,0 +1,62 @@ +use ibc::clients::ics07_tendermint::client_type; +use ibc::core::ics24_host::identifier::ClientId; +use ibc::core::ValidationContext; +use std::sync::Arc; + +use super::chain::MockCosmosChain; +use super::runtime::MockRuntimeContext; + +#[derive(Clone)] +pub struct MockCosmosRelay { + pub src_chain: Arc, + pub dst_chain: Arc, + pub src_client_id: ClientId, + pub dst_client_id: ClientId, + pub runtime: MockRuntimeContext, +} + +impl MockCosmosRelay { + pub fn new( + src_chain: Arc, + dst_chain: Arc, + runtime: MockRuntimeContext, + ) -> Self { + let src_client_counter = src_chain + .ibc_context() + .client_counter() + .expect("never fails"); + + let src_client_id = ClientId::new(client_type(), src_client_counter).expect("never fails"); + + let dst_client_counter = dst_chain + .ibc_context() + .client_counter() + .expect("never fails"); + + let dst_client_id = ClientId::new(client_type(), dst_client_counter).expect("never fails"); + + Self { + src_chain, + dst_chain, + src_client_id, + dst_client_id, + runtime, + } + } + + pub fn src_chain(&self) -> &Arc { + &self.src_chain + } + + pub fn dst_chain(&self) -> &Arc { + &self.dst_chain + } + + pub fn src_client_id(&self) -> &ClientId { + &self.src_client_id + } + + pub fn dst_client_id(&self) -> &ClientId { + &self.dst_client_id + } +} diff --git a/crates/relayer-cosmos-mock/src/contexts/runtime.rs b/crates/relayer-cosmos-mock/src/contexts/runtime.rs new file mode 100644 index 0000000000..3e583d0526 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/runtime.rs @@ -0,0 +1,59 @@ +use alloc::sync::Arc; +use core::time::Duration; +use ibc::core::timestamp::Timestamp; +use std::ops::Add; +use std::sync::Mutex; + +use crate::types::error::Error; +use crate::util::mutex::MutexUtil; + +pub struct MockRuntimeContext { + pub clock: Arc, +} + +impl MockRuntimeContext { + pub fn new(clock: Arc) -> Self { + Self { clock } + } + + pub fn get_time(&self) -> Timestamp { + self.clock.get_timestamp() + } +} + +impl Clone for MockRuntimeContext { + fn clone(&self) -> Self { + let clock = self.clock.clone(); + Self::new(clock) + } +} + +pub struct MockClock { + timestamp: Arc>, +} + +impl Default for MockClock { + fn default() -> Self { + Self { + timestamp: Arc::new(Mutex::new(Timestamp::now())), + } + } +} + +impl MockClock { + pub fn increment_timestamp(&self, duration: Duration) -> Result<(), Error> { + let mut locked_timestamp = self.timestamp.acquire_mutex(); + *locked_timestamp = locked_timestamp.add(duration).map_err(|_| { + Error::invalid(format!( + "overflow when adding {} to {:?}", + locked_timestamp, duration + )) + })?; + + Ok(()) + } + + pub fn get_timestamp(&self) -> Timestamp { + *self.timestamp.acquire_mutex() + } +} diff --git a/crates/relayer-cosmos-mock/src/impls/birelay.rs b/crates/relayer-cosmos-mock/src/impls/birelay.rs new file mode 100644 index 0000000000..43a7545e8e --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/birelay.rs @@ -0,0 +1,27 @@ +use ibc_relayer_components::core::traits::error::HasErrorType; +use ibc_relayer_components::relay::traits::two_way::HasTwoWayRelay; + +use crate::contexts::{birelay::MockCosmosBiRelay, relay::MockCosmosRelay}; +use crate::types::error::Error; + +impl HasErrorType for MockCosmosBiRelay { + type Error = Error; +} + +impl HasTwoWayRelay for MockCosmosBiRelay { + type RelayAToB = MockCosmosRelay; + + type RelayBToA = MockCosmosRelay; + + fn relay_a_to_b(&self) -> &Self::RelayAToB { + self.relay_a_to_b() + } + + fn relay_b_to_a(&self) -> &Self::RelayBToA { + self.relay_b_to_a() + } + + fn relay_error(e: ::Error) -> Self::Error { + Error::source(e) + } +} diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs new file mode 100644 index 0000000000..3cc4e16d29 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -0,0 +1,479 @@ +use async_trait::async_trait; + +use ibc::clients::ics07_tendermint::client_state::ClientState as TmClientState; +use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; +use ibc::core::events::IbcEvent; +use ibc::core::ics04_channel::events::{SendPacket, WriteAcknowledgement}; +use ibc::core::ics04_channel::msgs::{MsgAcknowledgement, MsgRecvPacket, MsgTimeout}; +use ibc::core::ics04_channel::packet::Packet; +use ibc::core::ics04_channel::packet::Sequence; +use ibc::core::ics04_channel::timeout::TimeoutHeight; +use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; +use ibc::core::ics24_host::path::{AckPath, ClientConsensusStatePath, ReceiptPath}; +use ibc::core::timestamp::Timestamp; +use ibc::core::{Msg, ValidationContext}; +use ibc::Any; +use ibc::Height; + +use ibc_relayer_components::chain::traits::logs::event::CanLogChainEvent; +use ibc_relayer_components::chain::traits::logs::packet::CanLogChainPacket; +use ibc_relayer_components::chain::traits::message_builders::ack_packet::CanBuildAckPacketMessage; +use ibc_relayer_components::chain::traits::message_builders::ack_packet::CanBuildAckPacketPayload; +use ibc_relayer_components::chain::traits::message_builders::receive_packet::CanBuildReceivePacketMessage; +use ibc_relayer_components::chain::traits::message_builders::receive_packet::CanBuildReceivePacketPayload; +use ibc_relayer_components::chain::traits::message_builders::timeout_unordered_packet::CanBuildTimeoutUnorderedPacketMessage; +use ibc_relayer_components::chain::traits::message_builders::timeout_unordered_packet::CanBuildTimeoutUnorderedPacketPayload; +use ibc_relayer_components::chain::traits::message_sender::CanSendMessages; +use ibc_relayer_components::chain::traits::queries::consensus_state::CanQueryConsensusState; +use ibc_relayer_components::chain::traits::queries::received_packet::CanQueryReceivedPacket; +use ibc_relayer_components::chain::traits::queries::status::CanQueryChainStatus; +use ibc_relayer_components::chain::traits::queries::write_ack::CanQueryWriteAcknowledgement; +use ibc_relayer_components::chain::traits::types::chain_id::HasChainId; +use ibc_relayer_components::chain::traits::types::chain_id::HasChainIdType; +use ibc_relayer_components::chain::traits::types::client_state::HasClientStateType; +use ibc_relayer_components::chain::traits::types::consensus_state::HasConsensusStateType; +use ibc_relayer_components::chain::traits::types::event::HasEventType; +use ibc_relayer_components::chain::traits::types::height::CanIncrementHeight; +use ibc_relayer_components::chain::traits::types::height::HasHeightType; +use ibc_relayer_components::chain::traits::types::ibc::HasCounterpartyMessageHeight; +use ibc_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use ibc_relayer_components::chain::traits::types::ibc_events::send_packet::HasSendPacketEvent; +use ibc_relayer_components::chain::traits::types::ibc_events::write_ack::HasWriteAcknowledgementEvent; +use ibc_relayer_components::chain::traits::types::message::CanEstimateMessageSize; +use ibc_relayer_components::chain::traits::types::message::HasMessageType; +use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketFields; +use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketTypes; +use ibc_relayer_components::chain::traits::types::packets::ack::HasAckPacketPayload; +use ibc_relayer_components::chain::traits::types::packets::receive::HasReceivePacketPayload; +use ibc_relayer_components::chain::traits::types::packets::timeout::HasTimeoutUnorderedPacketPayload; +use ibc_relayer_components::chain::traits::types::status::HasChainStatusType; +use ibc_relayer_components::chain::traits::types::timestamp::HasTimestampType; +use ibc_relayer_components::core::traits::error::HasErrorType; +use ibc_relayer_components::logger::traits::has_logger::HasLogger; +use ibc_relayer_components::logger::traits::has_logger::HasLoggerType; +use ibc_relayer_components::runtime::traits::runtime::HasRuntime; + +use ibc_relayer_runtime::types::error::Error as TokioError; +use ibc_relayer_runtime::types::log::logger::TracingLogger; +use ibc_relayer_runtime::types::log::value::LogValue; + +use crate::contexts::chain::MockCosmosChain; +use crate::contexts::runtime::MockRuntimeContext; +use crate::traits::handler::ChainHandler; +use crate::types::error::Error; +use crate::types::status::ChainStatus; +use crate::util::dummy::dummy_signer; + +impl HasErrorType for MockCosmosChain { + type Error = Error; +} + +impl HasRuntime for MockCosmosChain { + type Runtime = MockRuntimeContext; + + fn runtime(&self) -> &Self::Runtime { + &self.runtime + } + + fn runtime_error(e: TokioError) -> Error { + Error::source(e) + } +} + +impl HasLoggerType for MockCosmosChain { + type Logger = TracingLogger; +} + +impl HasHeightType for MockCosmosChain { + type Height = Height; +} + +impl HasEventType for MockCosmosChain { + type Event = IbcEvent; +} + +impl HasTimestampType for MockCosmosChain { + type Timestamp = Timestamp; +} + +impl HasMessageType for MockCosmosChain { + type Message = Any; +} + +impl HasChainIdType for MockCosmosChain { + type ChainId = ChainId; +} + +impl HasIbcChainTypes for MockCosmosChain { + type ClientId = ClientId; + + type ConnectionId = ConnectionId; + + type ChannelId = ChannelId; + + type PortId = PortId; + + type Sequence = Sequence; +} + +impl HasIbcPacketTypes for MockCosmosChain { + type IncomingPacket = Packet; + + type OutgoingPacket = Packet; +} + +impl HasIbcPacketFields for MockCosmosChain { + fn incoming_packet_src_channel_id(packet: &Self::IncomingPacket) -> &Self::ChannelId { + &packet.chan_id_on_a + } + + fn incoming_packet_src_port(packet: &Self::IncomingPacket) -> &Self::PortId { + &packet.port_id_on_a + } + + fn incoming_packet_dst_channel_id(packet: &Self::IncomingPacket) -> &Self::ChannelId { + &packet.chan_id_on_b + } + + fn incoming_packet_dst_port(packet: &Self::IncomingPacket) -> &Self::PortId { + &packet.port_id_on_b + } + + fn incoming_packet_sequence(packet: &Self::IncomingPacket) -> &Self::Sequence { + &packet.seq_on_a + } + + fn incoming_packet_timeout_height(packet: &Self::IncomingPacket) -> Option<&Self::Height> { + match &packet.timeout_height_on_b { + TimeoutHeight::Never => None, + TimeoutHeight::At(height) => Some(height), + } + } + + fn incoming_packet_timeout_timestamp(packet: &Self::IncomingPacket) -> &Self::Timestamp { + &packet.timeout_timestamp_on_b + } + + fn outgoing_packet_src_channel_id(packet: &Self::OutgoingPacket) -> &Self::ChannelId { + &packet.chan_id_on_a + } + + fn outgoing_packet_src_port(packet: &Self::OutgoingPacket) -> &Self::PortId { + &packet.port_id_on_a + } + + fn outgoing_packet_dst_port(packet: &Self::OutgoingPacket) -> &Self::PortId { + &packet.port_id_on_b + } + + fn outgoing_packet_dst_channel_id(packet: &Self::OutgoingPacket) -> &Self::ChannelId { + &packet.chan_id_on_b + } + + fn outgoing_packet_sequence(packet: &Self::OutgoingPacket) -> &Self::Sequence { + &packet.seq_on_a + } + + fn outgoing_packet_timeout_height(packet: &Self::OutgoingPacket) -> Option<&Self::Height> { + match &packet.timeout_height_on_b { + TimeoutHeight::Never => None, + TimeoutHeight::At(height) => Some(height), + } + } + + fn outgoing_packet_timeout_timestamp(packet: &Self::OutgoingPacket) -> &Self::Timestamp { + &packet.timeout_timestamp_on_b + } +} + +impl HasWriteAcknowledgementEvent for MockCosmosChain { + type WriteAcknowledgementEvent = WriteAcknowledgement; + + fn try_extract_write_acknowledgement_event( + event: &Self::Event, + ) -> Option { + match event { + IbcEvent::WriteAcknowledgement(e) => Some(e.clone()), + _ => None, + } + } +} + +impl HasConsensusStateType for MockCosmosChain { + type ConsensusState = TmConsensusState; +} + +impl HasClientStateType for MockCosmosChain { + type ClientState = TmClientState; +} + +impl HasChainStatusType for MockCosmosChain { + type ChainStatus = ChainStatus; + + fn chain_status_height(status: &Self::ChainStatus) -> &Self::Height { + &status.height + } + + fn chain_status_timestamp(status: &Self::ChainStatus) -> &Self::Timestamp { + &status.timestamp + } +} + +#[async_trait] +impl CanQueryChainStatus for MockCosmosChain { + async fn query_chain_status(&self) -> Result { + Ok(self.current_state.lock().unwrap().clone()) + } +} + +impl HasSendPacketEvent for MockCosmosChain { + type SendPacketEvent = SendPacket; + + fn try_extract_send_packet_event(event: &Self::Event) -> Option { + match event { + IbcEvent::SendPacket(e) => Some(e.clone()), + _ => None, + } + } + + fn extract_packet_from_send_packet_event( + event: &Self::SendPacketEvent, + ) -> Self::OutgoingPacket { + Packet { + seq_on_a: *event.seq_on_a(), + port_id_on_a: event.port_id_on_a().clone(), + chan_id_on_a: event.chan_id_on_a().clone(), + port_id_on_b: event.port_id_on_b().clone(), + chan_id_on_b: event.chan_id_on_b().clone(), + data: event.packet_data().to_vec(), + timeout_height_on_b: *event.timeout_height_on_b(), + timeout_timestamp_on_b: *event.timeout_timestamp_on_b(), + } + } +} + +impl HasLogger for MockCosmosChain { + fn logger(&self) -> &TracingLogger { + &TracingLogger + } +} + +impl CanLogChainEvent for MockCosmosChain { + fn log_event<'a>(event: &Self::Event) -> LogValue<'_> { + LogValue::Debug(event) + } +} + +impl CanIncrementHeight for MockCosmosChain { + fn increment_height(height: &Self::Height) -> Result { + Ok(height.increment()) + } +} + +impl CanEstimateMessageSize for MockCosmosChain { + fn estimate_message_size(_message: &Self::Message) -> Result { + // Only single messages are sent by the Mock Chain + Ok(1) + } +} + +impl HasChainId for MockCosmosChain { + fn chain_id(&self) -> &Self::ChainId { + &self.chain_id + } +} + +#[async_trait] +impl CanSendMessages for MockCosmosChain { + async fn send_messages( + &self, + messages: Vec, + ) -> Result>, Error> { + self.submit_messages(messages).await + } +} + +impl CanLogChainPacket for MockCosmosChain { + fn log_incoming_packet(packet: &Packet) -> LogValue<'_> { + LogValue::Display(packet) + } + + fn log_outgoing_packet(packet: &Packet) -> LogValue<'_> { + LogValue::Display(packet) + } +} + +impl HasCounterpartyMessageHeight for MockCosmosChain { + fn counterparty_message_height_for_update_client(_message: &Any) -> Option { + unimplemented!() + } +} + +#[async_trait] +impl CanQueryConsensusState for MockCosmosChain { + async fn query_consensus_state( + &self, + client_id: &ClientId, + height: &Height, + ) -> Result { + let path = ClientConsensusStatePath::new(client_id, height); + + let any_cons_state = self.ibc_context().consensus_state(&path)?; + + let tm_consensus_state = + TmConsensusState::try_from(any_cons_state).map_err(Error::source)?; + + Ok(tm_consensus_state) + } +} + +#[async_trait] +impl CanQueryReceivedPacket for MockCosmosChain { + async fn query_is_packet_received( + &self, + port_id: &Self::PortId, + channel_id: &Self::ChannelId, + sequence: &Self::Sequence, + ) -> Result { + let path = ReceiptPath::new(port_id, channel_id, *sequence); + + let receipt = self.ibc_context().get_packet_receipt(&path); + + Ok(receipt.is_ok()) + } +} + +#[async_trait] +impl CanQueryWriteAcknowledgement for MockCosmosChain { + async fn query_write_acknowledgement_event( + &self, + _packet: &Packet, + ) -> Result, Error> { + todo!() + } +} + +impl HasReceivePacketPayload for MockCosmosChain { + type ReceivePacketPayload = Any; +} + +#[async_trait] +impl CanBuildReceivePacketPayload for MockCosmosChain { + async fn build_receive_packet_payload( + &self, + _client_state: &Self::ClientState, + height: &Self::Height, + packet: &Self::IncomingPacket, + ) -> Result { + let receipt_path = ReceiptPath::new( + Self::incoming_packet_src_port(packet), + Self::incoming_packet_src_channel_id(packet), + *Self::incoming_packet_sequence(packet), + ); + + let (_, proof_commitment_on_a) = self.query(receipt_path, height).await?; + + let recv_packet_payload = MsgRecvPacket { + packet: packet.clone(), + proof_commitment_on_a, + proof_height_on_a: *height, + signer: dummy_signer(), + }; + + Ok(recv_packet_payload.to_any()) + } +} + +#[async_trait] +impl CanBuildReceivePacketMessage for MockCosmosChain { + async fn build_receive_packet_message( + &self, + _packet: &Packet, + payload: Any, + ) -> Result { + Ok(payload) + } +} + +impl HasAckPacketPayload for MockCosmosChain { + type AckPacketPayload = Any; +} + +#[async_trait] +impl CanBuildAckPacketPayload for MockCosmosChain { + async fn build_ack_packet_payload( + &self, + _client_state: &Self::ClientState, + height: &Self::Height, + packet: &Self::IncomingPacket, + ack: &Self::WriteAcknowledgementEvent, + ) -> Result { + let ack_path = AckPath::new( + Self::outgoing_packet_src_port(packet), + Self::outgoing_packet_src_channel_id(packet), + *Self::outgoing_packet_sequence(packet), + ); + + let (_, proof_acked_on_b) = self.query(ack_path, height).await?; + + let ack_packet_payload = MsgAcknowledgement { + packet: packet.clone(), + acknowledgement: ack.acknowledgement().clone(), + proof_acked_on_b, + proof_height_on_b: self.get_current_height(), + signer: dummy_signer(), + }; + + Ok(ack_packet_payload.to_any()) + } +} + +#[async_trait] +impl CanBuildAckPacketMessage for MockCosmosChain { + async fn build_ack_packet_message(&self, _packet: &Packet, payload: Any) -> Result { + Ok(payload) + } +} + +impl HasTimeoutUnorderedPacketPayload for MockCosmosChain { + type TimeoutUnorderedPacketPayload = Any; +} + +#[async_trait] +impl CanBuildTimeoutUnorderedPacketPayload for MockCosmosChain { + async fn build_timeout_unordered_packet_payload( + &self, + _client_state: &Self::ClientState, + height: &Self::Height, + packet: &Self::IncomingPacket, + ) -> Result { + let receipt_path = ReceiptPath::new( + Self::incoming_packet_src_port(packet), + Self::incoming_packet_src_channel_id(packet), + *Self::incoming_packet_sequence(packet), + ); + + let (_, proof_acked_on_b) = self.query(receipt_path, height).await?; + + let ack_packet_payload = MsgTimeout { + packet: packet.clone(), + next_seq_recv_on_b: packet.seq_on_a.increment(), + proof_unreceived_on_b: proof_acked_on_b, + proof_height_on_b: self.get_current_height(), + signer: dummy_signer(), + }; + + Ok(ack_packet_payload.to_any()) + } +} + +#[async_trait] +impl CanBuildTimeoutUnorderedPacketMessage for MockCosmosChain { + async fn build_timeout_unordered_packet_message( + &self, + _packet: &Packet, + payload: Any, + ) -> Result { + Ok(payload) + } +} diff --git a/crates/relayer-cosmos-mock/src/impls/components.rs b/crates/relayer-cosmos-mock/src/impls/components.rs new file mode 100644 index 0000000000..fe0e6ebfb9 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/components.rs @@ -0,0 +1,66 @@ +use ibc::core::ics04_channel::packet::Packet; +use ibc_relayer_components::relay::components::message_senders::chain_sender::SendIbcMessagesToChain; +use ibc_relayer_components::relay::components::message_senders::update_client::SendIbcMessagesWithUpdateClient; +use ibc_relayer_components::relay::components::update_client::skip::SkipUpdateClient; +use ibc_relayer_components::relay::components::update_client::wait::WaitUpdateClient; +use ibc_relayer_components::relay::components::packet_relayers::ack::base_ack_packet::BaseAckPacketRelayer; +use ibc_relayer_components::relay::components::packet_relayers::general::full_relay::FullCycleRelayer; +use ibc_relayer_components::relay::components::packet_relayers::receive::base_receive_packet::BaseReceivePacketRelayer; +use ibc_relayer_components::relay::components::packet_relayers::receive::skip_received_packet::SkipReceivedPacketRelayer; +use ibc_relayer_components::relay::components::packet_relayers::timeout_unordered::timeout_unordered_packet::BaseTimeoutUnorderedPacketRelayer; +use ibc_relayer_components::relay::traits::ibc_message_sender::{MainSink, IbcMessageSenderComponent}; +use ibc_relayer_components::relay::traits::update_client::UpdateClientMessageBuilderComponent; +use ibc_relayer_components::relay::traits::packet_relayer::PacketRelayerComponent; +use ibc_relayer_components::relay::traits::packet_relayer::PacketRelayer; +use ibc_relayer_components::relay::traits::packet_relayers::ack_packet::AckPacketRelayerComponent; +use ibc_relayer_components::relay::traits::packet_relayers::receive_packet::ReceivePacketRelayerComponnent; +use ibc_relayer_components::relay::traits::packet_relayers::timeout_unordered_packet::TimeoutUnorderedPacketRelayerComponent; + +use crate::contexts::relay::MockCosmosRelay; +use crate::impls::relay::MockCosmosBuildUpdateClientMessage; +use crate::types::error::Error; + +pub struct MockCosmosComponents; + +#[async_trait::async_trait] +impl PacketRelayer for MockCosmosComponents { + async fn relay_packet(_relay: &MockCosmosRelay, _packet: &Packet) -> Result<(), Error> { + unimplemented!() + } +} + +// ibc_relayer_components::delegate_component!( +// IbcMessageSenderComponent, +// MockCosmosComponents, +// SendIbcMessagesWithUpdateClient, +// ); + +// ibc_relayer_components::delegate_component!( +// PacketRelayerComponent, +// MockCosmosComponents, +// FullCycleRelayer, +// ); + +// ibc_relayer_components::delegate_component!( +// ReceivePacketRelayerComponnent, +// MockCosmosComponents, +// SkipReceivedPacketRelayer, +// ); + +// ibc_relayer_components::delegate_component!( +// AckPacketRelayerComponent, +// MockCosmosComponents, +// BaseAckPacketRelayer, +// ); + +// ibc_relayer_components::delegate_component!( +// TimeoutUnorderedPacketRelayerComponent, +// MockCosmosComponents, +// BaseTimeoutUnorderedPacketRelayer, +// ); + +// ibc_relayer_components::delegate_component!( +// UpdateClientMessageBuilderComponent, +// MockCosmosComponents, +// SkipUpdateClient>, +// ); diff --git a/crates/relayer-cosmos-mock/src/impls/endpoint.rs b/crates/relayer-cosmos-mock/src/impls/endpoint.rs new file mode 100644 index 0000000000..dc9350d44b --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/endpoint.rs @@ -0,0 +1,30 @@ +use crate::contexts::chain::MockCosmosChain; +use crate::traits::endpoint::Endpoint; +use crate::types::error::Error; + +use async_trait::async_trait; +use basecoin_app::modules::ibc::AnyConsensusState; +use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; +use ibc::core::ValidationContext; +use ibc::Height; + +#[async_trait] +impl Endpoint for MockCosmosChain { + fn query_host_consensus_state(&self, height: &Height) -> Result { + let consensus_state = self.ibc_context().host_consensus_state(height)?; + + match consensus_state { + AnyConsensusState::Tendermint(cs) => Ok(cs), + } + } + + // fn query_consensus_state(&self, client_id: &ClientId) -> Result { + // let current_height = self.get_current_height(); + + // let cons_state_path = ClientConsensusStatePath::new(client_id, ¤t_height); + + // let (value, _) = self.query(cons_state_path, ¤t_height).await?; + // let consensus_state = + // Protobuf::::decode_vec(&value).map_err(BaseError::source)?; + // } +} diff --git a/crates/relayer-cosmos-mock/src/impls/handler.rs b/crates/relayer-cosmos-mock/src/impls/handler.rs new file mode 100644 index 0000000000..839385af4c --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/handler.rs @@ -0,0 +1,189 @@ +use crate::contexts::chain::MockCosmosChain; +use crate::traits::handler::ChainHandler; +use crate::types::error::Error; +use crate::types::status::ChainStatus; +use crate::util::conversion::convert_tm_to_ics_merkle_proof; +use crate::util::dummy::generate_rand_app_hash; +use crate::util::dummy::genesis_app_state; +use crate::util::mutex::MutexUtil; + +use basecoin_app::modules::types::IdentifiedModule; +use basecoin_store::context::ProvableStore; +use basecoin_store::context::Store; + +use basecoin_store::utils::SharedRwExt; +use ibc::core::events::IbcEvent; +use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; +use ibc::core::ics24_host::path::Path; +use ibc::hosts::tendermint::IBC_QUERY_PATH; +use ibc::Any; +use ibc::Height; + +use tendermint::block::Height as TmHeight; +use tendermint::time::Time; +use tendermint::v0_37::abci::request::InitChain; +use tendermint::v0_37::abci::request::Query; +use tendermint::v0_37::abci::Request as AbciRequest; +use tendermint::v0_37::abci::Response as AbciResponse; +use tendermint::AppHash; +use tendermint_testgen::consensus::default_consensus_params; +use tendermint_testgen::Generator; +use tendermint_testgen::LightBlock; +use tower::Service; + +use async_trait::async_trait; +use std::time::Duration; + +#[async_trait] +impl ChainHandler for MockCosmosChain { + /// Initialize the chain with the app state. + async fn init(&self) { + let app_state = serde_json::to_vec(&genesis_app_state()).expect("infallible serialization"); + + let request = InitChain { + time: Time::now(), + chain_id: self.chain_id.to_string(), + consensus_params: default_consensus_params(), + validators: vec![], + app_state_bytes: app_state.into(), + initial_height: TmHeight::from(1_u8), + }; + + let mut app = self.app.clone(); + + app.call(AbciRequest::InitChain(request)) + .await + .expect("failed to initialize chain"); + } + + async fn begin_block(&self) -> Result<(), Error> { + let last_block = self.blocks.acquire_mutex().last().unwrap().clone(); + + let mut header = last_block + .header + .unwrap() + .generate() + .map_err(Error::source)?; + + header.app_hash = AppHash::try_from(generate_rand_app_hash()).map_err(Error::source)?; + + let mut events = Vec::new(); + + let mut modules = self.app.modules.write_access(); + + for IdentifiedModule { id: _, module } in modules.iter_mut() { + let event = module.begin_block(&header); + events.extend(event); + } + + Ok(()) + } + + /// Commits the chain state. + async fn commit(&self) -> Result<(), Error> { + let mut modules = self.app.modules.write_access(); + + for IdentifiedModule { id, module } in modules.iter_mut() { + module + .store_mut() + .commit() + .expect("failed to commit to state"); + + let mut state = self.app.store.write_access(); + + state + .set(id.clone().into(), module.store().root_hash()) + .expect("failed to update sub-store commitment"); + } + + let mut state = self.app.store.write_access(); + + state.commit().expect("failed to commit to state"); + + let current_revision_height = state.current_height(); + + let current_height = Height::new(self.chain_id.revision_number(), current_revision_height) + .expect("failed to create pending height"); + + // Update blocks + { + let mut blocks = self.blocks.acquire_mutex(); + + blocks.push(LightBlock::new_default(current_revision_height)); + } + + // Update current chain status + { + let mut current_state = self.current_state.acquire_mutex(); + + *current_state = ChainStatus::new(current_height, current_state.timestamp); + } + + Ok(()) + } + + async fn run(&self) -> Result<(), Error> { + self.init().await; + + // Grow blocks every one second + loop { + self.begin_block().await?; + + tokio::time::sleep(Duration::from_millis(1000)).await; + + self.runtime + .clock + .increment_timestamp(Duration::from_millis(1000))?; + + self.commit().await?; + } + } + + async fn submit_messages(&self, msgs: Vec) -> Result>, Error> { + let mut events = Vec::new(); + + for msg in msgs { + let ibc_events = self.app.ibc().process_message(msg)?; + + events.push(ibc_events); + } + + Ok(events) + } + + /// Queries the mock chain for the given path and height. + async fn query( + &self, + path: impl Into + Send, + height: &Height, + ) -> Result<(Vec, CommitmentProofBytes), Error> { + let request = Query { + path: IBC_QUERY_PATH.to_string(), + data: path.into().to_string().into_bytes().into(), + height: TmHeight::try_from(height.revision_height()).unwrap(), + prove: true, + }; + + let mut app = self.app.clone(); + + let response = match app + .call(AbciRequest::Query(request)) + .await + .map_err(Error::source)? + { + AbciResponse::Query(res) => res, + _ => panic!("unexpected response from query"), + }; + + let proof = match response.proof { + Some(proof) => proof, + None => return Err(Error::empty("proof")), + }; + + let merkle_proof = convert_tm_to_ics_merkle_proof(&proof)?; + + let commitment_proof = merkle_proof.try_into().map_err(Error::source)?; + + Ok((response.value.into(), commitment_proof)) + } +} diff --git a/crates/relayer-cosmos-mock/src/impls/mod.rs b/crates/relayer-cosmos-mock/src/impls/mod.rs new file mode 100644 index 0000000000..e8dec3afbb --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/mod.rs @@ -0,0 +1,7 @@ +pub mod birelay; +pub mod chain; +pub mod components; +pub mod endpoint; +pub mod handler; +pub mod relay; +pub mod runtime; diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs new file mode 100644 index 0000000000..5065d1e692 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -0,0 +1,397 @@ +use alloc::boxed::Box; +use alloc::vec::Vec; +use async_trait::async_trait; + +use ibc::core::ics04_channel::packet::Packet; +use ibc::core::ics24_host::identifier::ClientId; +use ibc::{Any, Height}; + +use ibc_relayer_components::core::traits::component::DelegateComponent; +use ibc_relayer_components::core::traits::error::HasErrorType; +use ibc_relayer_components::logger::traits::has_logger::HasLogger; +use ibc_relayer_components::logger::traits::has_logger::HasLoggerType; +use ibc_relayer_components::relay::traits::chains::HasRelayChains; +use ibc_relayer_components::relay::traits::packet_relayers::lock::HasPacketLock; +use ibc_relayer_components::relay::traits::target::{DestinationTarget, SourceTarget}; +use ibc_relayer_components::relay::traits::update_client::UpdateClientMessageBuilder; +use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_runtime::types::error::Error as TokioError; +use ibc_relayer_runtime::types::log::logger::TracingLogger; + +use crate::contexts::chain::MockCosmosChain; +use crate::contexts::relay::MockCosmosRelay; +use crate::contexts::runtime::MockRuntimeContext; +use crate::impls::components::MockCosmosComponents; +use crate::types::error::Error; + +impl DelegateComponent for MockCosmosRelay { + type Delegate = MockCosmosComponents; +} + +impl HasErrorType for MockCosmosRelay { + type Error = Error; +} + +impl HasRuntime for MockCosmosRelay { + type Runtime = MockRuntimeContext; + + fn runtime(&self) -> &Self::Runtime { + &self.runtime + } + + fn runtime_error(e: TokioError) -> Error { + Error::source(e) + } +} + +impl HasLoggerType for MockCosmosRelay { + type Logger = TracingLogger; +} + +impl HasLogger for MockCosmosRelay { + fn logger(&self) -> &TracingLogger { + &TracingLogger + } +} + +impl HasRelayChains for MockCosmosRelay { + type SrcChain = MockCosmosChain; + + type DstChain = MockCosmosChain; + + fn src_chain_error(e: Error) -> Self::Error { + e + } + + fn dst_chain_error(e: Error) -> Self::Error { + e + } + + fn src_chain(&self) -> &MockCosmosChain { + &self.src_chain + } + + fn dst_chain(&self) -> &MockCosmosChain { + &self.dst_chain + } + + fn src_client_id(&self) -> &ClientId { + self.src_client_id() + } + + fn dst_client_id(&self) -> &ClientId { + self.dst_client_id() + } +} + +pub struct MockCosmosBuildUpdateClientMessage; + +#[async_trait] +impl UpdateClientMessageBuilder + for MockCosmosBuildUpdateClientMessage +{ + async fn build_update_client_messages( + _context: &MockCosmosRelay, + _target: SourceTarget, + _height: &Height, + ) -> Result, Error> { + Ok(vec![]) + } +} + +#[async_trait] +impl UpdateClientMessageBuilder + for MockCosmosBuildUpdateClientMessage +{ + async fn build_update_client_messages( + _context: &MockCosmosRelay, + _target: DestinationTarget, + _height: &Height, + ) -> Result, Error> { + Ok(vec![]) + } +} + +#[async_trait] +impl HasPacketLock for MockCosmosRelay { + type PacketLock<'a> = (); + + async fn try_acquire_packet_lock<'a>(&'a self, _packet: &'a Packet) -> Option<()> { + Some(()) + } +} + +// #[async_trait] +// impl CanBuildUpdateClientMessage for MockCosmosRelay { +// async fn build_update_client_messages( +// &self, +// target: SourceTarget, +// height: &Height, +// ) -> Result, Error> { +// unimplemented!() +// } +// } + +// #[async_trait] +// impl CanBuildUpdateClientMessage for MockCosmosRelay { +// async fn build_update_client_messages( +// &self, +// target: DestinationTarget, +// height: &Height, +// ) -> Result, Error> { +// unimplemented!() +// } +// } + +// #[async_trait] +// impl CanSendIbcMessages for MockCosmosRelay { +// async fn send_messages( +// &self, +// _target: SourceTarget, +// messages: Vec, +// ) -> Result>, Error> { +// >::send_messages( +// self, messages, +// ) +// .await +// } +// } + +// #[async_trait] +// impl CanSendIbcMessages for MockCosmosRelay { +// async fn send_messages( +// &self, +// _target: DestinationTarget, +// messages: Vec, +// ) -> Result>, Error> { +// >::send_messages( +// self, messages, +// ) +// .await +// } +// } + +// #[async_trait] +// impl CanRelayAckPacket for MockCosmosRelay { +// async fn relay_ack_packet( +// &self, +// destination_height: &Height, +// packet: &Packet, +// ack: &WriteAcknowledgement, +// ) -> Result<(), Error> { +// AckPacketRelayer::relay_ack_packet(self, destination_height, packet, ack).await +// } +// } + +// #[async_trait] +// impl CanRelayReceivePacket for MockCosmosRelay { +// async fn relay_receive_packet( +// &self, +// source_height: &Height, +// packet: &Packet, +// ) -> Result, Error> { +// ReceivePacketRelayer::relay_receive_packet(self, source_height, packet).await +// } +// } + +// #[async_trait] +// impl CanRelayTimeoutUnorderedPacket for MockCosmosRelay { +// async fn relay_timeout_unordered_packet( +// &self, +// destination_height: &Height, +// packet: &Packet, +// ) -> Result<(), Self::Error> { +// TimeoutUnorderedPacketRelayer::relay_timeout_unordered_packet( +// self, +// destination_height, +// packet, +// ) +// .await +// } +// } + +// #[async_trait] +// impl CanRelayPacket for MockCosmosRelay { +// async fn relay_packet(&self, packet: &Packet) -> Result<(), Error> { +// PacketRelayer::relay_packet(self, packet).await +// } +// } + +// use async_trait::async_trait; +// use eyre::eyre; +// use futures::channel::oneshot::{channel, Sender}; +// use ibc::core::ics04_channel::packet::Packet; +// use ibc::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId}; + +// use ibc_relayer_all_in_one::one_for_all::traits::relay::OfaRelay; +// use ibc_relayer_all_in_one::one_for_all::types::batch::aliases::MessageBatchSender; +// use ibc_relayer_all_in_one::one_for_all::types::chain::OfaChainWrapper; +// use ibc_relayer_all_in_one::one_for_all::types::runtime::OfaRuntimeWrapper; +// use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; +// use ibc_relayer_runtime::tokio::error::Error as TokioError; +// use ibc_relayer_runtime::tokio::logger::tracing::TracingLogger; + +// use crate::contexts::chain::MockCosmosChain; +// use crate::contexts::relay::MockCosmosRelay; +// use crate::types::error::{BaseError, Error}; + +// pub struct PacketLock { +// pub release_sender: Option>, +// } + +// impl Drop for PacketLock { +// fn drop(&mut self) { +// if let Some(sender) = self.release_sender.take() { +// let _ = sender.send(()); +// } +// } +// } + +// #[async_trait] +// impl OfaRelay for MockCosmosRelay { +// type Error = Error; + +// type Runtime = TokioRuntimeContext; + +// type Logger = TracingLogger; + +// type Packet = Packet; + +// type SrcChain = MockCosmosChain; + +// type DstChain = MockCosmosChain; + +// type PacketLock<'a> = PacketLock; + +// fn runtime_error(e: TokioError) -> Error { +// BaseError::tokio(e).into() +// } + +// fn src_chain_error(e: Error) -> Error { +// e +// } + +// fn dst_chain_error(e: Error) -> Error { +// e +// } + +// fn runtime(&self) -> &OfaRuntimeWrapper { +// &self.runtime +// } + +// fn logger(&self) -> &TracingLogger { +// &TracingLogger +// } + +// fn src_client_id(&self) -> &ClientId { +// &self.src_client_id +// } + +// fn dst_client_id(&self) -> &ClientId { +// &self.dst_client_id +// } + +// fn src_chain(&self) -> &OfaChainWrapper { +// &self.src_chain +// } + +// fn dst_chain(&self) -> &OfaChainWrapper { +// &self.dst_chain +// } + +// async fn try_acquire_packet_lock<'a>(&'a self, packet: &'a Packet) -> Option { +// let packet_key = ( +// packet.source_channel.clone(), +// packet.source_port.clone(), +// packet.destination_channel.clone(), +// packet.destination_port.clone(), +// packet.sequence, +// ); + +// let mutex = &self.packet_lock_mutex; + +// let mut lock_table = mutex.lock().await; + +// if lock_table.contains(&packet_key) { +// None +// } else { +// lock_table.insert(packet_key.clone()); + +// let runtime = &self.runtime().runtime.runtime; + +// let (sender, receiver) = channel(); + +// let mutex = mutex.clone(); + +// runtime.spawn(async move { +// let _ = receiver.await; +// let mut lock_table = mutex.lock().await; +// lock_table.remove(&packet_key); +// }); + +// Some(PacketLock { +// release_sender: Some(sender), +// }) +// } +// } + +// fn is_retryable_error(_: &Error) -> bool { +// false +// } + +// fn max_retry_exceeded_error(e: Error) -> Error { +// e +// } + +// fn missing_connection_init_event_error(&self) -> Error { +// BaseError::generic(eyre!("missing_connection_init_event_error")).into() +// } + +// fn missing_src_create_client_event_error( +// src_chain: &Self::SrcChain, +// dst_chain: &Self::DstChain, +// ) -> Self::Error { +// BaseError::generic(eyre!("missing CreateClient event when creating client from chain {} with counterparty chain {}", +// src_chain.chain_id(), +// dst_chain.chain_id(), +// )).into() +// } + +// fn missing_dst_create_client_event_error( +// dst_chain: &Self::DstChain, +// src_chain: &Self::SrcChain, +// ) -> Self::Error { +// BaseError::generic(eyre!("missing CreateClient event when creating client from chain {} with counterparty chain {}", +// dst_chain.chain_id(), +// src_chain.chain_id(), +// )).into() +// } + +// fn missing_connection_try_event_error(&self, src_connection_id: &ConnectionId) -> Error { +// BaseError::generic(eyre!( +// "missing_connection_try_event_error: {}", +// src_connection_id +// )) +// .into() +// } + +// fn missing_channel_init_event_error(&self) -> Error { +// BaseError::generic(eyre!("missing_channel_init_event_error")).into() +// } + +// fn missing_channel_try_event_error(&self, src_channel_id: &ChannelId) -> Error { +// BaseError::generic(eyre!("missing_channel_try_event_error: {}", src_channel_id)).into() +// } + +// async fn should_relay_packet(&self, packet: &Packet) -> Result { +// unimplemented!() +// } + +// fn src_chain_message_batch_sender(&self) -> &MessageBatchSender { +// unimplemented!() +// } + +// fn dst_chain_message_batch_sender(&self) -> &MessageBatchSender { +// unimplemented!() +// } +// } diff --git a/crates/relayer-cosmos-mock/src/impls/runtime.rs b/crates/relayer-cosmos-mock/src/impls/runtime.rs new file mode 100644 index 0000000000..062bc170a4 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/impls/runtime.rs @@ -0,0 +1,34 @@ +use async_trait::async_trait; +use ibc::core::timestamp::Timestamp; +use ibc_relayer_components::core::traits::error::HasErrorType; +use ibc_relayer_components::runtime::traits::{sleep::CanSleep, time::HasTime}; +use ibc_relayer_runtime::types::error::Error as TokioError; +use std::time::Duration; + +use crate::contexts::runtime::MockRuntimeContext; + +#[async_trait] +impl CanSleep for MockRuntimeContext { + async fn sleep(&self, duration: Duration) { + // Increment the shared MockClock by the duration is milliseconds. + if self.clock.increment_timestamp(duration).is_err() { + tracing::warn!("MockClock failed to sleep for {}ms", duration.as_millis()); + } + } +} + +impl HasTime for MockRuntimeContext { + type Time = Timestamp; + + fn now(&self) -> Self::Time { + self.get_time() + } + + fn duration_since(current_time: &Self::Time, other_time: &Self::Time) -> Duration { + Duration::from_nanos(current_time.nanoseconds() - other_time.nanoseconds()) + } +} + +impl HasErrorType for MockRuntimeContext { + type Error = TokioError; +} diff --git a/crates/relayer-cosmos-mock/src/lib.rs b/crates/relayer-cosmos-mock/src/lib.rs new file mode 100644 index 0000000000..dcd8b229dd --- /dev/null +++ b/crates/relayer-cosmos-mock/src/lib.rs @@ -0,0 +1,11 @@ +extern crate alloc; +extern crate std; + +pub mod contexts; +pub mod impls; +pub mod traits; +pub mod types; +pub mod util; + +#[cfg(test)] +pub mod tests; diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs new file mode 100644 index 0000000000..85f1010660 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -0,0 +1,53 @@ +use ibc::core::ics24_host::identifier::ClientId; +use ibc::core::ValidationContext; + +use crate::tests::init::init_binary_stand; +use crate::traits::handler::ChainHandler; +use crate::types::error::Error; + +#[tokio::test] +async fn test_create_client() -> Result<(), Error> { + let builder = init_binary_stand(); + + tokio::time::sleep(tokio::time::Duration::from_millis(2500)).await; + + let msg_create_client = builder.chains[0].build_msg_create_client().await?; + + builder.chains[1] + .submit_messages(vec![msg_create_client]) + .await?; + + assert!(builder.chains[1] + .ibc_context() + .client_state(&ClientId::default()) + .is_ok()); + + builder.stop(); + + Ok(()) +} + +#[tokio::test] +async fn test_update_client() -> Result<(), Error> { + let builder = init_binary_stand(); + + tokio::time::sleep(tokio::time::Duration::from_millis(2500)).await; + + let msg_create_client = builder.chains[0].build_msg_create_client().await?; + + builder.chains[1] + .submit_messages(vec![msg_create_client]) + .await?; + + tokio::time::sleep(tokio::time::Duration::from_millis(2000)).await; + + let msg_update_client = builder.chains[0].build_msg_update_client().await?; + + builder.chains[1] + .submit_messages(vec![msg_update_client]) + .await?; + + builder.stop(); + + Ok(()) +} diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs new file mode 100644 index 0000000000..28473d9738 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -0,0 +1,18 @@ +use ibc::core::ics24_host::identifier::ChainId; +use std::str::FromStr; + +use crate::contexts::builder::MockCosmosBuilder; + +pub fn init_binary_stand() -> MockCosmosBuilder { + let mut builder = MockCosmosBuilder::new_default(); + + let src_chain = builder.build_chain(ChainId::from_str("mock-cosmos-chain-0").unwrap()); + + let dst_chain = builder.build_chain(ChainId::from_str("mock-cosmos-chain-1").unwrap()); + + builder.build_relayer(src_chain, dst_chain); + + builder.spawn_chains(); + + builder +} diff --git a/crates/relayer-cosmos-mock/src/tests/mod.rs b/crates/relayer-cosmos-mock/src/tests/mod.rs new file mode 100644 index 0000000000..92db88058c --- /dev/null +++ b/crates/relayer-cosmos-mock/src/tests/mod.rs @@ -0,0 +1,2 @@ +pub mod ics02_client; +pub mod init; diff --git a/crates/relayer-cosmos-mock/src/traits/endpoint.rs b/crates/relayer-cosmos-mock/src/traits/endpoint.rs new file mode 100644 index 0000000000..54e546a294 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/traits/endpoint.rs @@ -0,0 +1,9 @@ +use crate::types::error::Error; +use async_trait::async_trait; +use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; +use ibc::Height; + +#[async_trait] +pub trait Endpoint { + fn query_host_consensus_state(&self, height: &Height) -> Result; +} diff --git a/crates/relayer-cosmos-mock/src/traits/handler.rs b/crates/relayer-cosmos-mock/src/traits/handler.rs new file mode 100644 index 0000000000..e194181b16 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/traits/handler.rs @@ -0,0 +1,26 @@ +use async_trait::async_trait; +use ibc::core::events::IbcEvent; +use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; +use ibc::core::ics24_host::path::Path; +use ibc::{Any, Height}; + +use crate::types::error::Error; + +#[async_trait] +pub trait ChainHandler { + async fn init(&self); + + async fn begin_block(&self) -> Result<(), Error>; + + async fn commit(&self) -> Result<(), Error>; + + async fn run(&self) -> Result<(), Error>; + + async fn submit_messages(&self, msgs: Vec) -> Result>, Error>; + + async fn query( + &self, + path: impl Into + Send, + height: &Height, + ) -> Result<(Vec, CommitmentProofBytes), Error>; +} diff --git a/crates/relayer-cosmos-mock/src/traits/mod.rs b/crates/relayer-cosmos-mock/src/traits/mod.rs new file mode 100644 index 0000000000..9a520d1b61 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/traits/mod.rs @@ -0,0 +1,2 @@ +pub mod endpoint; +pub mod handler; diff --git a/crates/relayer-cosmos-mock/src/types/error.rs b/crates/relayer-cosmos-mock/src/types/error.rs new file mode 100644 index 0000000000..edc1843380 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/types/error.rs @@ -0,0 +1,180 @@ +use alloc::string::String; +use basecoin_app::types::error::Error as AppError; +use ibc::clients::ics07_tendermint::error::Error as ClientError; +use ibc::core::ics24_host::identifier::IdentifierError; +use ibc::core::ContextError; + +/// Defines the interchain account error type +#[derive(Clone, Debug)] +pub struct Error { + /// Error code. + pub code: Code, + /// Refers to the type or place that error originated from or pertains to. + pub origin: String, + /// (optional) The given value caused the error. + pub given: Option, + /// (optional) The expected value. + pub expected: Option, +} + +impl Error { + /// Constructs a new interchain account error instance with the given code and message. + pub fn new(code: Code, origin: impl Into) -> Self { + Self { + code, + origin: origin.into(), + given: None, + expected: None, + } + } + + /// Constructs an `Empty` error with the given message. + pub fn empty(origin: impl Into) -> Self { + Self::new(Code::Empty, origin) + } + + /// Constructs a `NotFound` error with the given message. + pub fn not_found(origin: impl Into) -> Self { + Self::new(Code::NotFound, origin) + } + + /// Constructs an `AlreadyExists` error with the given message. + pub fn already_exists(origin: impl Into) -> Self { + Self::new(Code::AlreadyExists, origin) + } + + /// Constructs an `Invalid` error with the given message. + pub fn invalid(origin: impl Into) -> Self { + Self::new(Code::Invalid, origin) + } + + /// Constructs a `MisMatch` error with the given message. + pub fn mismatch(origin: impl Into) -> Self { + Self::new(Code::Mismatch, origin) + } + + /// Constructs a `NotAllowed` error with the given message. + pub fn not_allowed(origin: impl Into) -> Self { + Self::new(Code::NotAllowed, origin) + } + + /// Constructs a `NotSupported` error with the given message. + pub fn not_supported(origin: impl Into) -> Self { + Self::new(Code::NotSupported, origin) + } + + /// Constructs a `Source` error with the given message. + pub fn source(origin: impl ToString) -> Self { + Self { + code: Code::Source, + origin: origin.to_string(), + expected: None, + given: None, + } + } + + /// Adds an expected value to the error message. + pub fn expected(&self, expected: &impl ToString) -> Self { + Self { + expected: Some(expected.to_string()), + ..self.clone() + } + } + + /// Adds a given value to the error message. + pub fn given(&self, given: &impl ToString) -> Self { + Self { + given: Some(given.to_string()), + ..self.clone() + } + } +} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "Code: {} Origin: {}", self.code, self.origin)?; + + if let Some(given) = &self.given { + write!(f, ", Given: {}", given)?; + } + + if let Some(expected) = &self.expected { + write!(f, ", Expected: {}", expected)?; + } + + Ok(()) + } +} + +#[derive(Clone, Debug)] +pub enum Code { + /// cannot be empty! + Empty = 0, + + /// not found! + NotFound = 1, + + /// already exists! + AlreadyExists = 2, + + /// has invalid state! + Invalid = 3, + + /// state mismatch! + Mismatch = 4, + + /// not allowed! + NotAllowed = 5, + + /// not supported! + NotSupported = 6, + + /// from other source! + Source = 7, +} + +impl Code { + /// Returns a string description of the error code. + pub fn description(&self) -> &'static str { + match self { + Code::Empty => "cannot be empty!", + Code::NotFound => "not found!", + Code::AlreadyExists => "already exists!", + Code::Invalid => "invalid state!", + Code::Mismatch => "state mismatch!", + Code::NotAllowed => "not allowed!", + Code::NotSupported => "not supported!", + Code::Source => "from other source!", + } + } +} + +impl std::fmt::Display for Code { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + core::fmt::Display::fmt(self.description(), f) + } +} + +impl From for Error { + fn from(err: AppError) -> Self { + Self::source(err) + } +} + +impl From for Error { + fn from(err: ContextError) -> Self { + Self::source(err) + } +} + +impl From for Error { + fn from(err: ClientError) -> Self { + Self::source(err) + } +} + +impl From for Error { + fn from(err: IdentifierError) -> Self { + Self::source(err) + } +} diff --git a/crates/relayer-cosmos-mock/src/types/mod.rs b/crates/relayer-cosmos-mock/src/types/mod.rs new file mode 100644 index 0000000000..f89278dd8c --- /dev/null +++ b/crates/relayer-cosmos-mock/src/types/mod.rs @@ -0,0 +1,2 @@ +pub mod error; +pub mod status; diff --git a/crates/relayer-cosmos-mock/src/types/status.rs b/crates/relayer-cosmos-mock/src/types/status.rs new file mode 100644 index 0000000000..74b0b2e680 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/types/status.rs @@ -0,0 +1,23 @@ +use ibc::core::timestamp::Timestamp; +use ibc::Height; + +#[derive(Clone)] +pub struct ChainStatus { + pub timestamp: Timestamp, + pub height: Height, +} + +impl ChainStatus { + pub fn new(height: Height, timestamp: Timestamp) -> Self { + Self { height, timestamp } + } +} + +impl From<(Height, Timestamp)> for ChainStatus { + fn from(s: (Height, Timestamp)) -> Self { + ChainStatus { + height: s.0, + timestamp: s.1, + } + } +} diff --git a/crates/relayer-cosmos-mock/src/util/conversion.rs b/crates/relayer-cosmos-mock/src/util/conversion.rs new file mode 100644 index 0000000000..e6a4dcb2ea --- /dev/null +++ b/crates/relayer-cosmos-mock/src/util/conversion.rs @@ -0,0 +1,20 @@ +use ibc::core::ics23_commitment::merkle::MerkleProof; +use ibc_proto::ibc::core::commitment::v1::MerkleProof as RawMerkleProof; +use ibc_proto::ics23::CommitmentProof; +use tendermint::merkle::proof::ProofOps; + +use crate::types::error::Error; + +pub fn convert_tm_to_ics_merkle_proof(tm_proof: &ProofOps) -> Result { + let mut proofs = Vec::new(); + + for op in &tm_proof.ops { + let mut parsed = CommitmentProof { proof: None }; + + prost::Message::merge(&mut parsed, op.data.as_slice()).map_err(Error::source)?; + + proofs.push(parsed); + } + + Ok(MerkleProof::from(RawMerkleProof { proofs })) +} diff --git a/crates/relayer-cosmos-mock/src/util/dummy.rs b/crates/relayer-cosmos-mock/src/util/dummy.rs new file mode 100644 index 0000000000..0466bf2c22 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/util/dummy.rs @@ -0,0 +1,53 @@ +use ibc::Signer; +use rand::RngCore; +use sha2::Digest; +use sha2::Sha256; + +pub fn genesis_app_state() -> serde_json::Value { + serde_json::json!({ + "cosmos12xpmzmfpf7tn57xg93rne2hc2q26lcfql5efws": { + "basecoin": "0x1000000000", + "othercoin": "0x1000000000", + "samoleans": "0x1000000000" + }, + "cosmos1t2e0nyjhwn3revunvf2uperhftvhzu4euuzva9": { + "basecoin": "0x250", + "othercoin": "0x5000" + }, + "cosmos1uawm90a5xm36kjmaazv89nxmfr8s8cyzkjqytd": { + "acidcoin": "0x500" + }, + "cosmos1ny9epydqnr7ymqhmgfvlshp3485cuqlmt7vsmf": {}, + "cosmos1xwgdxu4ahd9eevtfnq5f7w4td3rqnph4llnngw": { + "acidcoin": "0x500", + "basecoin": "0x0", + "othercoin": "0x100" + }, + "cosmos1mac8xqhun2c3y0njptdmmh3vy8nfjmtm6vua9u": { + "basecoin": "0x1000" + }, + "cosmos1wkvwnez6fkjn63xaz7nzpm4zxcd9cetqmyh2y8": { + "basecoin": "0x1" + }, + "cosmos166vcha998g7tl8j8cq0kwa8rfvm68cqmj88cff": { + "basecoin": "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + }, + "cosmos1as9ap057eellftptlhyw5ajna7uaeewzkk6fnz": { + "basecoin": "0x1000000000" + } + }) +} + +pub fn dummy_signer() -> Signer { + Signer::from("cosmos000000000000000000000000000000000000000".to_string()) +} + +pub fn generate_rand_app_hash() -> Vec { + let mut rng = rand::thread_rng(); + + let mut data = vec![0u8; 32]; + + rng.fill_bytes(&mut data); + + Sha256::digest(&data).to_vec() +} diff --git a/crates/relayer-cosmos-mock/src/util/mod.rs b/crates/relayer-cosmos-mock/src/util/mod.rs new file mode 100644 index 0000000000..50358a9049 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/util/mod.rs @@ -0,0 +1,4 @@ +pub mod conversion; +pub mod dummy; +pub mod msgs; +pub mod mutex; diff --git a/crates/relayer-cosmos-mock/src/util/msgs.rs b/crates/relayer-cosmos-mock/src/util/msgs.rs new file mode 100644 index 0000000000..6cbd7bba29 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/util/msgs.rs @@ -0,0 +1,52 @@ +use ibc::applications::transfer::msgs::transfer::MsgTransfer; +use ibc::applications::transfer::packet::PacketData; +use ibc::applications::transfer::BaseCoin; +use ibc::core::ics04_channel::packet::Packet; +use ibc::core::ics04_channel::packet::Sequence; +use ibc::core::ics24_host::identifier::ChannelId; +use ibc::core::ics24_host::identifier::PortId; +use ibc::core::timestamp::Timestamp; +use ibc::Height; + +use primitive_types::U256; +use std::ops::Add; +use std::time::Duration; + +use super::dummy::dummy_signer; + +pub fn build_msg_transfer() -> MsgTransfer { + MsgTransfer { + port_id_on_a: PortId::default(), + chan_id_on_a: ChannelId::default(), + packet_data: PacketData { + token: BaseCoin { + denom: "uatom".parse().unwrap(), + amount: U256::from(10).into(), + } + .into(), + sender: dummy_signer(), + receiver: dummy_signer(), + memo: "".to_string().into(), + }, + timeout_timestamp_on_b: Timestamp::now().add(Duration::from_secs(10)).unwrap(), + timeout_height_on_b: Height::new(0, 1000).unwrap().into(), + } +} + +pub fn build_transfer_packet(sequence: u64) -> Packet { + let msg = build_msg_transfer(); + + let data = serde_json::to_vec(&msg.packet_data) + .expect("PacketData's infallible Serialize impl failed"); + + Packet { + seq_on_a: Sequence::from(sequence), + port_id_on_a: msg.port_id_on_a.clone(), + chan_id_on_a: msg.chan_id_on_a.clone(), + port_id_on_b: PortId::default(), + chan_id_on_b: ChannelId::default(), + data, + timeout_height_on_b: msg.timeout_height_on_b, + timeout_timestamp_on_b: msg.timeout_timestamp_on_b, + } +} diff --git a/crates/relayer-cosmos-mock/src/util/mutex.rs b/crates/relayer-cosmos-mock/src/util/mutex.rs new file mode 100644 index 0000000000..cb5cd13e30 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/util/mutex.rs @@ -0,0 +1,21 @@ +//! MutexUtil is a helper trait to simplify the error handling +//! when locking a Mutex. + +use std::sync::{Arc, Mutex, MutexGuard}; + +use ibc_relayer_components::core::traits::sync::Async; + +pub trait MutexUtil { + fn acquire_mutex(&self) -> MutexGuard; +} + +impl MutexUtil for Arc> { + fn acquire_mutex(&self) -> MutexGuard { + match self.lock() { + Ok(locked_mutex) => locked_mutex, + Err(e) => { + panic!("poisoned mutex: {e}") + } + } + } +} From fc18085fcce0859c1825787de53420bfedb90c1d Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Fri, 25 Aug 2023 16:45:17 -0700 Subject: [PATCH 02/25] fix: clean up relay impls --- crates/relayer-cosmos-mock/src/impls/relay.rs | 275 ------------------ 1 file changed, 275 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index 5065d1e692..effb9ecb94 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -120,278 +120,3 @@ impl HasPacketLock for MockCosmosRelay { Some(()) } } - -// #[async_trait] -// impl CanBuildUpdateClientMessage for MockCosmosRelay { -// async fn build_update_client_messages( -// &self, -// target: SourceTarget, -// height: &Height, -// ) -> Result, Error> { -// unimplemented!() -// } -// } - -// #[async_trait] -// impl CanBuildUpdateClientMessage for MockCosmosRelay { -// async fn build_update_client_messages( -// &self, -// target: DestinationTarget, -// height: &Height, -// ) -> Result, Error> { -// unimplemented!() -// } -// } - -// #[async_trait] -// impl CanSendIbcMessages for MockCosmosRelay { -// async fn send_messages( -// &self, -// _target: SourceTarget, -// messages: Vec, -// ) -> Result>, Error> { -// >::send_messages( -// self, messages, -// ) -// .await -// } -// } - -// #[async_trait] -// impl CanSendIbcMessages for MockCosmosRelay { -// async fn send_messages( -// &self, -// _target: DestinationTarget, -// messages: Vec, -// ) -> Result>, Error> { -// >::send_messages( -// self, messages, -// ) -// .await -// } -// } - -// #[async_trait] -// impl CanRelayAckPacket for MockCosmosRelay { -// async fn relay_ack_packet( -// &self, -// destination_height: &Height, -// packet: &Packet, -// ack: &WriteAcknowledgement, -// ) -> Result<(), Error> { -// AckPacketRelayer::relay_ack_packet(self, destination_height, packet, ack).await -// } -// } - -// #[async_trait] -// impl CanRelayReceivePacket for MockCosmosRelay { -// async fn relay_receive_packet( -// &self, -// source_height: &Height, -// packet: &Packet, -// ) -> Result, Error> { -// ReceivePacketRelayer::relay_receive_packet(self, source_height, packet).await -// } -// } - -// #[async_trait] -// impl CanRelayTimeoutUnorderedPacket for MockCosmosRelay { -// async fn relay_timeout_unordered_packet( -// &self, -// destination_height: &Height, -// packet: &Packet, -// ) -> Result<(), Self::Error> { -// TimeoutUnorderedPacketRelayer::relay_timeout_unordered_packet( -// self, -// destination_height, -// packet, -// ) -// .await -// } -// } - -// #[async_trait] -// impl CanRelayPacket for MockCosmosRelay { -// async fn relay_packet(&self, packet: &Packet) -> Result<(), Error> { -// PacketRelayer::relay_packet(self, packet).await -// } -// } - -// use async_trait::async_trait; -// use eyre::eyre; -// use futures::channel::oneshot::{channel, Sender}; -// use ibc::core::ics04_channel::packet::Packet; -// use ibc::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId}; - -// use ibc_relayer_all_in_one::one_for_all::traits::relay::OfaRelay; -// use ibc_relayer_all_in_one::one_for_all::types::batch::aliases::MessageBatchSender; -// use ibc_relayer_all_in_one::one_for_all::types::chain::OfaChainWrapper; -// use ibc_relayer_all_in_one::one_for_all::types::runtime::OfaRuntimeWrapper; -// use ibc_relayer_runtime::tokio::context::TokioRuntimeContext; -// use ibc_relayer_runtime::tokio::error::Error as TokioError; -// use ibc_relayer_runtime::tokio::logger::tracing::TracingLogger; - -// use crate::contexts::chain::MockCosmosChain; -// use crate::contexts::relay::MockCosmosRelay; -// use crate::types::error::{BaseError, Error}; - -// pub struct PacketLock { -// pub release_sender: Option>, -// } - -// impl Drop for PacketLock { -// fn drop(&mut self) { -// if let Some(sender) = self.release_sender.take() { -// let _ = sender.send(()); -// } -// } -// } - -// #[async_trait] -// impl OfaRelay for MockCosmosRelay { -// type Error = Error; - -// type Runtime = TokioRuntimeContext; - -// type Logger = TracingLogger; - -// type Packet = Packet; - -// type SrcChain = MockCosmosChain; - -// type DstChain = MockCosmosChain; - -// type PacketLock<'a> = PacketLock; - -// fn runtime_error(e: TokioError) -> Error { -// BaseError::tokio(e).into() -// } - -// fn src_chain_error(e: Error) -> Error { -// e -// } - -// fn dst_chain_error(e: Error) -> Error { -// e -// } - -// fn runtime(&self) -> &OfaRuntimeWrapper { -// &self.runtime -// } - -// fn logger(&self) -> &TracingLogger { -// &TracingLogger -// } - -// fn src_client_id(&self) -> &ClientId { -// &self.src_client_id -// } - -// fn dst_client_id(&self) -> &ClientId { -// &self.dst_client_id -// } - -// fn src_chain(&self) -> &OfaChainWrapper { -// &self.src_chain -// } - -// fn dst_chain(&self) -> &OfaChainWrapper { -// &self.dst_chain -// } - -// async fn try_acquire_packet_lock<'a>(&'a self, packet: &'a Packet) -> Option { -// let packet_key = ( -// packet.source_channel.clone(), -// packet.source_port.clone(), -// packet.destination_channel.clone(), -// packet.destination_port.clone(), -// packet.sequence, -// ); - -// let mutex = &self.packet_lock_mutex; - -// let mut lock_table = mutex.lock().await; - -// if lock_table.contains(&packet_key) { -// None -// } else { -// lock_table.insert(packet_key.clone()); - -// let runtime = &self.runtime().runtime.runtime; - -// let (sender, receiver) = channel(); - -// let mutex = mutex.clone(); - -// runtime.spawn(async move { -// let _ = receiver.await; -// let mut lock_table = mutex.lock().await; -// lock_table.remove(&packet_key); -// }); - -// Some(PacketLock { -// release_sender: Some(sender), -// }) -// } -// } - -// fn is_retryable_error(_: &Error) -> bool { -// false -// } - -// fn max_retry_exceeded_error(e: Error) -> Error { -// e -// } - -// fn missing_connection_init_event_error(&self) -> Error { -// BaseError::generic(eyre!("missing_connection_init_event_error")).into() -// } - -// fn missing_src_create_client_event_error( -// src_chain: &Self::SrcChain, -// dst_chain: &Self::DstChain, -// ) -> Self::Error { -// BaseError::generic(eyre!("missing CreateClient event when creating client from chain {} with counterparty chain {}", -// src_chain.chain_id(), -// dst_chain.chain_id(), -// )).into() -// } - -// fn missing_dst_create_client_event_error( -// dst_chain: &Self::DstChain, -// src_chain: &Self::SrcChain, -// ) -> Self::Error { -// BaseError::generic(eyre!("missing CreateClient event when creating client from chain {} with counterparty chain {}", -// dst_chain.chain_id(), -// src_chain.chain_id(), -// )).into() -// } - -// fn missing_connection_try_event_error(&self, src_connection_id: &ConnectionId) -> Error { -// BaseError::generic(eyre!( -// "missing_connection_try_event_error: {}", -// src_connection_id -// )) -// .into() -// } - -// fn missing_channel_init_event_error(&self) -> Error { -// BaseError::generic(eyre!("missing_channel_init_event_error")).into() -// } - -// fn missing_channel_try_event_error(&self, src_channel_id: &ChannelId) -> Error { -// BaseError::generic(eyre!("missing_channel_try_event_error: {}", src_channel_id)).into() -// } - -// async fn should_relay_packet(&self, packet: &Packet) -> Result { -// unimplemented!() -// } - -// fn src_chain_message_batch_sender(&self) -> &MessageBatchSender { -// unimplemented!() -// } - -// fn dst_chain_message_batch_sender(&self) -> &MessageBatchSender { -// unimplemented!() -// } -// } From 9dcd199ea90f954ae2a5f7cf6e21d88a7596a6cc Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Fri, 25 Aug 2023 23:38:59 -0700 Subject: [PATCH 03/25] imp: chain handler refinement --- .../src/contexts/builder.rs | 2 +- .../relayer-cosmos-mock/src/contexts/chain.rs | 86 +++++++++++++------ .../src/contexts/runtime.rs | 6 ++ crates/relayer-cosmos-mock/src/impls/chain.rs | 2 +- .../relayer-cosmos-mock/src/impls/handler.rs | 58 +++---------- .../relayer-cosmos-mock/src/traits/handler.rs | 9 +- .../relayer-cosmos-mock/src/types/status.rs | 2 +- crates/relayer-cosmos-mock/src/util/dummy.rs | 7 +- 8 files changed, 89 insertions(+), 83 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/builder.rs b/crates/relayer-cosmos-mock/src/contexts/builder.rs index 4b9b5abf18..87a679037d 100644 --- a/crates/relayer-cosmos-mock/src/contexts/builder.rs +++ b/crates/relayer-cosmos-mock/src/contexts/builder.rs @@ -57,7 +57,7 @@ impl MockCosmosBuilder { let c_clone = c.clone(); let handle = tokio::spawn(async move { - c_clone.run().await.unwrap(); + c_clone.run().await; }); self.handlers.push(handle); diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index f33ab30d07..9f1092e623 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -21,21 +21,23 @@ use ibc::core::Msg; use ibc::core::ValidationContext; use ibc::Any; use ibc::Height; + +use tendermint::time::Time; +use tendermint_testgen::light_block::TmLightBlock; use tendermint_testgen::Generator; +use tendermint_testgen::LightBlock; use std::sync::Arc; use std::sync::Mutex; use std::time::Duration; -use tendermint::chain::Id; -use tendermint_testgen::LightBlock; - use super::runtime::MockClock; use crate::contexts::runtime::MockRuntimeContext; use crate::traits::endpoint::Endpoint; use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::dummy::dummy_signer; +use crate::util::dummy::generate_rand_app_hash; use crate::util::mutex::MutexUtil; #[derive(Clone)] @@ -43,11 +45,11 @@ pub struct MockCosmosChain { /// Chain identifier pub chain_id: ChainId, /// Current chain status - pub current_state: Arc>, + pub current_status: Arc>, /// Chain application pub app: BaseCoinApp, /// Chain blocks - pub blocks: Arc>>, + pub blocks: Arc>>, /// Chain runtime pub runtime: MockRuntimeContext, } @@ -77,22 +79,22 @@ impl MockCosmosChain { let runtime = MockRuntimeContext::new(clock.clone()); - let genesis_height = 1; - - let genesis_block = LightBlock::new_default(genesis_height); - - let current_state = Arc::new(Mutex::new(ChainStatus::new( - Height::new(chain_id.revision_number(), genesis_height).unwrap(), - clock.get_timestamp(), + let current_status = Arc::new(Mutex::new(ChainStatus::new( + Height::new(chain_id.revision_number(), 1).expect("never fails"), + Time::now().into(), ))); - Self { + let chain = Self { chain_id, - current_state, + current_status, app, - blocks: Arc::new(Mutex::new(vec![genesis_block])), + blocks: Arc::new(Mutex::new(vec![])), runtime, - } + }; + + chain.grow_blocks(); + + chain } pub fn chain_id(&self) -> &ChainId { @@ -104,17 +106,52 @@ impl MockCosmosChain { } pub fn get_current_timestamp(&self) -> Timestamp { - self.current_state.acquire_mutex().timestamp + self.current_status.acquire_mutex().timestamp } pub fn get_current_height(&self) -> Height { - self.current_state.acquire_mutex().height + self.current_status.acquire_mutex().height } pub fn ibc_context(&self) -> IbcContext> { self.app.ibc().ctx() } + pub fn grow_blocks(&self) { + let mut blocks = self.blocks.acquire_mutex(); + + let height = blocks.len() as u64 + 1; + + let current_time = Time::now(); + + let mut tm_light_block = LightBlock::new_default_with_time_and_chain_id( + self.chain_id.to_string(), + current_time, + height, + ) + .generate() + .expect("failed to generate light block"); + + tm_light_block.signed_header.header.app_hash = generate_rand_app_hash(); + + let header_hash = tm_light_block.signed_header.header.hash(); + + tm_light_block.signed_header.commit.block_id.hash = header_hash; + + blocks.push(tm_light_block); + + self.runtime.clock.set_timestamp(current_time); + + let current_status = ChainStatus::new( + Height::new(self.chain_id.revision_number(), height).expect("invalid height"), + current_time.into(), + ); + + let mut last_status = self.current_status.acquire_mutex(); + + *last_status = current_status; + } + pub async fn build_msg_create_client(&self) -> Result { let tm_client_state = ClientState::new( self.chain_id.clone(), @@ -149,18 +186,13 @@ impl MockCosmosChain { let client_id = ClientId::new(client_type(), client_counter)?; - let last_block = self.blocks.acquire_mutex().last().unwrap().clone(); - - let mut tm_light_block = last_block.generate().map_err(Error::source)?; - - tm_light_block.signed_header.header.chain_id = - Id::try_from(self.chain_id.to_string()).unwrap(); + let last_light_block = self.blocks.acquire_mutex().last().unwrap().clone(); let header = Header { - signed_header: tm_light_block.signed_header, - validator_set: tm_light_block.validators, + signed_header: last_light_block.signed_header, + validator_set: last_light_block.validators, trusted_height: self.get_current_height(), - trusted_next_validator_set: tm_light_block.next_validators, + trusted_next_validator_set: last_light_block.next_validators, }; let msg_update_client = MsgUpdateClient { diff --git a/crates/relayer-cosmos-mock/src/contexts/runtime.rs b/crates/relayer-cosmos-mock/src/contexts/runtime.rs index 3e583d0526..a8303ca96c 100644 --- a/crates/relayer-cosmos-mock/src/contexts/runtime.rs +++ b/crates/relayer-cosmos-mock/src/contexts/runtime.rs @@ -3,6 +3,7 @@ use core::time::Duration; use ibc::core::timestamp::Timestamp; use std::ops::Add; use std::sync::Mutex; +use tendermint::Time; use crate::types::error::Error; use crate::util::mutex::MutexUtil; @@ -41,8 +42,13 @@ impl Default for MockClock { } impl MockClock { + pub fn set_timestamp(&self, time: Time) { + *self.timestamp.acquire_mutex() = time.into(); + } + pub fn increment_timestamp(&self, duration: Duration) -> Result<(), Error> { let mut locked_timestamp = self.timestamp.acquire_mutex(); + *locked_timestamp = locked_timestamp.add(duration).map_err(|_| { Error::invalid(format!( "overflow when adding {} to {:?}", diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index 3cc4e16d29..d49d415ece 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -222,7 +222,7 @@ impl HasChainStatusType for MockCosmosChain { #[async_trait] impl CanQueryChainStatus for MockCosmosChain { async fn query_chain_status(&self) -> Result { - Ok(self.current_state.lock().unwrap().clone()) + Ok(self.current_status.lock().unwrap().clone()) } } diff --git a/crates/relayer-cosmos-mock/src/impls/handler.rs b/crates/relayer-cosmos-mock/src/impls/handler.rs index 839385af4c..23a6673bab 100644 --- a/crates/relayer-cosmos-mock/src/impls/handler.rs +++ b/crates/relayer-cosmos-mock/src/impls/handler.rs @@ -1,17 +1,15 @@ use crate::contexts::chain::MockCosmosChain; use crate::traits::handler::ChainHandler; use crate::types::error::Error; -use crate::types::status::ChainStatus; use crate::util::conversion::convert_tm_to_ics_merkle_proof; -use crate::util::dummy::generate_rand_app_hash; use crate::util::dummy::genesis_app_state; use crate::util::mutex::MutexUtil; use basecoin_app::modules::types::IdentifiedModule; use basecoin_store::context::ProvableStore; use basecoin_store::context::Store; - use basecoin_store::utils::SharedRwExt; + use ibc::core::events::IbcEvent; use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; use ibc::core::ics24_host::path::Path; @@ -25,10 +23,7 @@ use tendermint::v0_37::abci::request::InitChain; use tendermint::v0_37::abci::request::Query; use tendermint::v0_37::abci::Request as AbciRequest; use tendermint::v0_37::abci::Response as AbciResponse; -use tendermint::AppHash; use tendermint_testgen::consensus::default_consensus_params; -use tendermint_testgen::Generator; -use tendermint_testgen::LightBlock; use tower::Service; use async_trait::async_trait; @@ -54,33 +49,26 @@ impl ChainHandler for MockCosmosChain { app.call(AbciRequest::InitChain(request)) .await .expect("failed to initialize chain"); + + // Generates the genesis block + self.grow_blocks(); } - async fn begin_block(&self) -> Result<(), Error> { + async fn begin_block(&self) { let last_block = self.blocks.acquire_mutex().last().unwrap().clone(); - let mut header = last_block - .header - .unwrap() - .generate() - .map_err(Error::source)?; - - header.app_hash = AppHash::try_from(generate_rand_app_hash()).map_err(Error::source)?; - let mut events = Vec::new(); let mut modules = self.app.modules.write_access(); for IdentifiedModule { id: _, module } in modules.iter_mut() { - let event = module.begin_block(&header); + let event = module.begin_block(&last_block.signed_header.header); events.extend(event); } - - Ok(()) } /// Commits the chain state. - async fn commit(&self) -> Result<(), Error> { + async fn commit(&self) { let mut modules = self.app.modules.write_access(); for IdentifiedModule { id, module } in modules.iter_mut() { @@ -100,42 +88,18 @@ impl ChainHandler for MockCosmosChain { state.commit().expect("failed to commit to state"); - let current_revision_height = state.current_height(); - - let current_height = Height::new(self.chain_id.revision_number(), current_revision_height) - .expect("failed to create pending height"); - - // Update blocks - { - let mut blocks = self.blocks.acquire_mutex(); - - blocks.push(LightBlock::new_default(current_revision_height)); - } - - // Update current chain status - { - let mut current_state = self.current_state.acquire_mutex(); - - *current_state = ChainStatus::new(current_height, current_state.timestamp); - } - - Ok(()) + self.grow_blocks(); } - async fn run(&self) -> Result<(), Error> { + async fn run(&self) { self.init().await; - // Grow blocks every one second loop { - self.begin_block().await?; + self.begin_block().await; tokio::time::sleep(Duration::from_millis(1000)).await; - self.runtime - .clock - .increment_timestamp(Duration::from_millis(1000))?; - - self.commit().await?; + self.commit().await; } } diff --git a/crates/relayer-cosmos-mock/src/traits/handler.rs b/crates/relayer-cosmos-mock/src/traits/handler.rs index e194181b16..335101e7c5 100644 --- a/crates/relayer-cosmos-mock/src/traits/handler.rs +++ b/crates/relayer-cosmos-mock/src/traits/handler.rs @@ -2,7 +2,8 @@ use async_trait::async_trait; use ibc::core::events::IbcEvent; use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; use ibc::core::ics24_host::path::Path; -use ibc::{Any, Height}; +use ibc::Any; +use ibc::Height; use crate::types::error::Error; @@ -10,11 +11,11 @@ use crate::types::error::Error; pub trait ChainHandler { async fn init(&self); - async fn begin_block(&self) -> Result<(), Error>; + async fn begin_block(&self); - async fn commit(&self) -> Result<(), Error>; + async fn commit(&self); - async fn run(&self) -> Result<(), Error>; + async fn run(&self); async fn submit_messages(&self, msgs: Vec) -> Result>, Error>; diff --git a/crates/relayer-cosmos-mock/src/types/status.rs b/crates/relayer-cosmos-mock/src/types/status.rs index 74b0b2e680..dc11ad135e 100644 --- a/crates/relayer-cosmos-mock/src/types/status.rs +++ b/crates/relayer-cosmos-mock/src/types/status.rs @@ -1,7 +1,7 @@ use ibc::core::timestamp::Timestamp; use ibc::Height; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ChainStatus { pub timestamp: Timestamp, pub height: Height, diff --git a/crates/relayer-cosmos-mock/src/util/dummy.rs b/crates/relayer-cosmos-mock/src/util/dummy.rs index 0466bf2c22..68136f4936 100644 --- a/crates/relayer-cosmos-mock/src/util/dummy.rs +++ b/crates/relayer-cosmos-mock/src/util/dummy.rs @@ -2,6 +2,7 @@ use ibc::Signer; use rand::RngCore; use sha2::Digest; use sha2::Sha256; +use tendermint::AppHash; pub fn genesis_app_state() -> serde_json::Value { serde_json::json!({ @@ -42,12 +43,14 @@ pub fn dummy_signer() -> Signer { Signer::from("cosmos000000000000000000000000000000000000000".to_string()) } -pub fn generate_rand_app_hash() -> Vec { +pub fn generate_rand_app_hash() -> AppHash { let mut rng = rand::thread_rng(); let mut data = vec![0u8; 32]; rng.fill_bytes(&mut data); - Sha256::digest(&data).to_vec() + let value = Sha256::digest(&data).to_vec(); + + AppHash::try_from(value).expect("invalid app hash") } From 0b56aa0afee9177bcc82e0908b3023e055909d02 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Sat, 26 Aug 2023 15:28:58 -0700 Subject: [PATCH 04/25] feat: add update client test --- .../src/contexts/builder.rs | 8 +- .../relayer-cosmos-mock/src/contexts/chain.rs | 39 +-------- .../relayer-cosmos-mock/src/contexts/relay.rs | 22 +++-- .../src/impls/components.rs | 52 ++++++------ .../relayer-cosmos-mock/src/impls/handler.rs | 2 +- crates/relayer-cosmos-mock/src/impls/relay.rs | 81 +++++++++++++++++-- .../src/tests/ics02_client.rs | 19 +++-- 7 files changed, 129 insertions(+), 94 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/builder.rs b/crates/relayer-cosmos-mock/src/contexts/builder.rs index 87a679037d..9f99eeead8 100644 --- a/crates/relayer-cosmos-mock/src/contexts/builder.rs +++ b/crates/relayer-cosmos-mock/src/contexts/builder.rs @@ -3,13 +3,12 @@ use ibc::core::ics24_host::identifier::ChainId; use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket; use tokio::task::JoinHandle; -use crate::traits::handler::ChainHandler; -use crate::util::msgs::build_transfer_packet; - use super::chain::MockCosmosChain; use super::relay::MockCosmosRelay; use super::runtime::MockClock; use super::runtime::MockRuntimeContext; +use crate::traits::handler::ChainHandler; +use crate::util::msgs::build_transfer_packet; pub struct MockCosmosBuilder { pub chains: Vec>, @@ -45,7 +44,8 @@ impl MockCosmosBuilder { src_chain: Arc, dst_chain: Arc, ) -> MockCosmosRelay { - let relayer = MockCosmosRelay::new(src_chain, dst_chain, self.runtime.clone()); + let relayer = MockCosmosRelay::new(src_chain, dst_chain, self.runtime.clone()) + .expect("failed to build relayer"); self.relayers.push(Arc::new(relayer.clone())); diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 9f1092e623..118ce9499d 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -10,15 +10,10 @@ use basecoin_store::impls::RevertibleStore; use ibc::clients::ics07_tendermint::client_state::AllowUpdate; use ibc::clients::ics07_tendermint::client_state::ClientState; -use ibc::clients::ics07_tendermint::client_type; -use ibc::clients::ics07_tendermint::header::Header; use ibc::core::ics02_client::msgs::create_client::MsgCreateClient; -use ibc::core::ics02_client::msgs::update_client::MsgUpdateClient; use ibc::core::ics24_host::identifier::ChainId; -use ibc::core::ics24_host::identifier::ClientId; use ibc::core::timestamp::Timestamp; use ibc::core::Msg; -use ibc::core::ValidationContext; use ibc::Any; use ibc::Height; @@ -37,7 +32,6 @@ use crate::traits::endpoint::Endpoint; use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::dummy::dummy_signer; -use crate::util::dummy::generate_rand_app_hash; use crate::util::mutex::MutexUtil; #[derive(Clone)] @@ -92,8 +86,6 @@ impl MockCosmosChain { runtime, }; - chain.grow_blocks(); - chain } @@ -124,7 +116,7 @@ impl MockCosmosChain { let current_time = Time::now(); - let mut tm_light_block = LightBlock::new_default_with_time_and_chain_id( + let tm_light_block = LightBlock::new_default_with_time_and_chain_id( self.chain_id.to_string(), current_time, height, @@ -132,12 +124,6 @@ impl MockCosmosChain { .generate() .expect("failed to generate light block"); - tm_light_block.signed_header.header.app_hash = generate_rand_app_hash(); - - let header_hash = tm_light_block.signed_header.header.hash(); - - tm_light_block.signed_header.commit.block_id.hash = header_hash; - blocks.push(tm_light_block); self.runtime.clock.set_timestamp(current_time); @@ -180,27 +166,4 @@ impl MockCosmosChain { Ok(msg_create_client.to_any()) } - - pub async fn build_msg_update_client(&self) -> Result { - let client_counter = self.ibc_context().client_counter()?; - - let client_id = ClientId::new(client_type(), client_counter)?; - - let last_light_block = self.blocks.acquire_mutex().last().unwrap().clone(); - - let header = Header { - signed_header: last_light_block.signed_header, - validator_set: last_light_block.validators, - trusted_height: self.get_current_height(), - trusted_next_validator_set: last_light_block.next_validators, - }; - - let msg_update_client = MsgUpdateClient { - client_id, - client_message: header.into(), - signer: dummy_signer(), - }; - - Ok(msg_update_client.to_any()) - } } diff --git a/crates/relayer-cosmos-mock/src/contexts/relay.rs b/crates/relayer-cosmos-mock/src/contexts/relay.rs index ecc27aeae8..9146060356 100644 --- a/crates/relayer-cosmos-mock/src/contexts/relay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/relay.rs @@ -3,6 +3,8 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; use std::sync::Arc; +use crate::types::error::Error; + use super::chain::MockCosmosChain; use super::runtime::MockRuntimeContext; @@ -20,28 +22,22 @@ impl MockCosmosRelay { src_chain: Arc, dst_chain: Arc, runtime: MockRuntimeContext, - ) -> Self { - let src_client_counter = src_chain - .ibc_context() - .client_counter() - .expect("never fails"); + ) -> Result { + let src_client_counter = src_chain.ibc_context().client_counter()?; - let src_client_id = ClientId::new(client_type(), src_client_counter).expect("never fails"); + let src_client_id = ClientId::new(client_type(), src_client_counter)?; - let dst_client_counter = dst_chain - .ibc_context() - .client_counter() - .expect("never fails"); + let dst_client_counter = dst_chain.ibc_context().client_counter()?; - let dst_client_id = ClientId::new(client_type(), dst_client_counter).expect("never fails"); + let dst_client_id = ClientId::new(client_type(), dst_client_counter)?; - Self { + Ok(Self { src_chain, dst_chain, src_client_id, dst_client_id, runtime, - } + }) } pub fn src_chain(&self) -> &Arc { diff --git a/crates/relayer-cosmos-mock/src/impls/components.rs b/crates/relayer-cosmos-mock/src/impls/components.rs index fe0e6ebfb9..d691b6a36a 100644 --- a/crates/relayer-cosmos-mock/src/impls/components.rs +++ b/crates/relayer-cosmos-mock/src/impls/components.rs @@ -29,38 +29,38 @@ impl PacketRelayer for MockCosmosComponents { } } -// ibc_relayer_components::delegate_component!( -// IbcMessageSenderComponent, -// MockCosmosComponents, -// SendIbcMessagesWithUpdateClient, -// ); - // ibc_relayer_components::delegate_component!( // PacketRelayerComponent, // MockCosmosComponents, // FullCycleRelayer, // ); -// ibc_relayer_components::delegate_component!( -// ReceivePacketRelayerComponnent, -// MockCosmosComponents, -// SkipReceivedPacketRelayer, -// ); +ibc_relayer_components::delegate_component!( + IbcMessageSenderComponent, + MockCosmosComponents, + SendIbcMessagesWithUpdateClient, +); -// ibc_relayer_components::delegate_component!( -// AckPacketRelayerComponent, -// MockCosmosComponents, -// BaseAckPacketRelayer, -// ); +ibc_relayer_components::delegate_component!( + ReceivePacketRelayerComponnent, + MockCosmosComponents, + SkipReceivedPacketRelayer, +); -// ibc_relayer_components::delegate_component!( -// TimeoutUnorderedPacketRelayerComponent, -// MockCosmosComponents, -// BaseTimeoutUnorderedPacketRelayer, -// ); +ibc_relayer_components::delegate_component!( + AckPacketRelayerComponent, + MockCosmosComponents, + BaseAckPacketRelayer, +); -// ibc_relayer_components::delegate_component!( -// UpdateClientMessageBuilderComponent, -// MockCosmosComponents, -// SkipUpdateClient>, -// ); +ibc_relayer_components::delegate_component!( + TimeoutUnorderedPacketRelayerComponent, + MockCosmosComponents, + BaseTimeoutUnorderedPacketRelayer, +); + +ibc_relayer_components::delegate_component!( + UpdateClientMessageBuilderComponent, + MockCosmosComponents, + SkipUpdateClient>, +); diff --git a/crates/relayer-cosmos-mock/src/impls/handler.rs b/crates/relayer-cosmos-mock/src/impls/handler.rs index 23a6673bab..33df5bd3d5 100644 --- a/crates/relayer-cosmos-mock/src/impls/handler.rs +++ b/crates/relayer-cosmos-mock/src/impls/handler.rs @@ -97,7 +97,7 @@ impl ChainHandler for MockCosmosChain { loop { self.begin_block().await; - tokio::time::sleep(Duration::from_millis(1000)).await; + tokio::time::sleep(Duration::from_millis(100)).await; self.commit().await; } diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index effb9ecb94..3fb2bf362a 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -2,8 +2,12 @@ use alloc::boxed::Box; use alloc::vec::Vec; use async_trait::async_trait; +use ibc::clients::ics07_tendermint::client_type; +use ibc::clients::ics07_tendermint::header::Header; +use ibc::core::ics02_client::msgs::update_client::MsgUpdateClient; use ibc::core::ics04_channel::packet::Packet; use ibc::core::ics24_host::identifier::ClientId; +use ibc::core::{Msg, ValidationContext}; use ibc::{Any, Height}; use ibc_relayer_components::core::traits::component::DelegateComponent; @@ -23,6 +27,8 @@ use crate::contexts::relay::MockCosmosRelay; use crate::contexts::runtime::MockRuntimeContext; use crate::impls::components::MockCosmosComponents; use crate::types::error::Error; +use crate::util::dummy::dummy_signer; +use crate::util::mutex::MutexUtil; impl DelegateComponent for MockCosmosRelay { type Delegate = MockCosmosComponents; @@ -91,11 +97,42 @@ impl UpdateClientMessageBuilder for MockCosmosBuildUpdateClientMessage { async fn build_update_client_messages( - _context: &MockCosmosRelay, + context: &MockCosmosRelay, _target: SourceTarget, - _height: &Height, + height: &Height, ) -> Result, Error> { - Ok(vec![]) + let client_counter = context.dst_chain().ibc_context().client_counter()?; + + let client_id = ClientId::new(client_type(), client_counter)?; + + let client_state = context + .dst_chain() + .ibc_context() + .client_state(&ClientId::default())?; + + let revision_height = height.revision_height() as usize; + + let blocks = context.src_chain().blocks.acquire_mutex(); + + if revision_height > blocks.len() { + return Err(Error::invalid("block index out of bounds")); + } + let light_block = blocks[revision_height - 1].clone(); + + let header = Header { + signed_header: light_block.signed_header, + validator_set: light_block.validators, + trusted_height: client_state.latest_height, + trusted_next_validator_set: light_block.next_validators, + }; + + let msg_update_client = MsgUpdateClient { + client_id, + client_message: header.into(), + signer: dummy_signer(), + }; + + Ok(vec![msg_update_client.to_any()]) } } @@ -104,11 +141,43 @@ impl UpdateClientMessageBuilder for MockCosmosBuildUpdateClientMessage { async fn build_update_client_messages( - _context: &MockCosmosRelay, + context: &MockCosmosRelay, _target: DestinationTarget, - _height: &Height, + height: &Height, ) -> Result, Error> { - Ok(vec![]) + let client_counter = context.src_chain().ibc_context().client_counter()?; + + let client_id = ClientId::new(client_type(), client_counter)?; + + let client_state = context + .src_chain() + .ibc_context() + .client_state(&ClientId::default())?; + + let revision_height = height.revision_height() as usize; + + let blocks = context.dst_chain().blocks.acquire_mutex(); + + if revision_height > blocks.len() { + return Err(Error::invalid("block index out of bounds")); + } + + let light_block = blocks[revision_height - 1].clone(); + + let header = Header { + signed_header: light_block.signed_header, + validator_set: light_block.validators, + trusted_height: client_state.latest_height, + trusted_next_validator_set: light_block.next_validators, + }; + + let msg_update_client = MsgUpdateClient { + client_id, + client_message: header.into(), + signer: dummy_signer(), + }; + + Ok(vec![msg_update_client.to_any()]) } } diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs index 85f1010660..f9a59dd520 100644 --- a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -1,5 +1,7 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; +use ibc_relayer_components::relay::traits::target::SourceTarget; +use ibc_relayer_components::relay::traits::update_client::CanBuildUpdateClientMessage; use crate::tests::init::init_binary_stand; use crate::traits::handler::ChainHandler; @@ -9,7 +11,7 @@ use crate::types::error::Error; async fn test_create_client() -> Result<(), Error> { let builder = init_binary_stand(); - tokio::time::sleep(tokio::time::Duration::from_millis(2500)).await; + tokio::time::sleep(tokio::time::Duration::from_millis(150)).await; let msg_create_client = builder.chains[0].build_msg_create_client().await?; @@ -31,7 +33,7 @@ async fn test_create_client() -> Result<(), Error> { async fn test_update_client() -> Result<(), Error> { let builder = init_binary_stand(); - tokio::time::sleep(tokio::time::Duration::from_millis(2500)).await; + tokio::time::sleep(tokio::time::Duration::from_millis(150)).await; let msg_create_client = builder.chains[0].build_msg_create_client().await?; @@ -39,12 +41,17 @@ async fn test_update_client() -> Result<(), Error> { .submit_messages(vec![msg_create_client]) .await?; - tokio::time::sleep(tokio::time::Duration::from_millis(2000)).await; + tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; - let msg_update_client = builder.chains[0].build_msg_update_client().await?; + let src_current_height = builder.chains[0].get_current_height(); - builder.chains[1] - .submit_messages(vec![msg_update_client]) + let msg_update_client = builder.relayers[0] + .build_update_client_messages(SourceTarget, &src_current_height) + .await?; + + builder.relayers[0] + .dst_chain() + .submit_messages(msg_update_client) .await?; builder.stop(); From 78bcbf6ffe96ccef2939d3ad737fc56c366bf3c5 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Sat, 26 Aug 2023 15:30:55 -0700 Subject: [PATCH 05/25] fix: patch tendermint testgen --- Cargo.lock | 116 ++++++++++++++++++++++++++--------------------------- Cargo.toml | 11 ++--- 2 files changed, 59 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdb420417a..84e558048a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,24 +82,23 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" [[package]] name = "anstyle-parse" @@ -121,9 +120,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" dependencies = [ "anstyle", "windows-sys 0.48.0", @@ -320,9 +319,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" [[package]] name = "base64ct" @@ -335,9 +334,9 @@ name = "basecoin-app" version = "0.1.0" source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=e7f23d3#e7f23d381226ed5c395dd6124d0f9c50ae2adc48" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "basecoin-store", - "clap 4.3.23", + "clap 4.4.0", "cosmrs", "derive_more", "displaydoc", @@ -368,7 +367,7 @@ name = "basecoin-store" version = "0.1.0" source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=e7f23d3#e7f23d381226ed5c395dd6124d0f9c50ae2adc48" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "derive_more", "displaydoc", "ed25519", @@ -623,24 +622,24 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.23" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03aef18ddf7d879c15ce20f04826ef8418101c7e528014c3eeea13321047dca3" +checksum = "1d5f1946157a96594eb2d2c10eb7ad9a2b27518cb3000209dec700c35df9197d" dependencies = [ "clap_builder", - "clap_derive 4.3.12", + "clap_derive 4.4.0", "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.23" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ce6fffb678c9b80a70b6b6de0aad31df727623a70fd9a842c30cd573e2fa98" +checksum = "78116e32a042dd73c2901f0dc30790d20ff3447f3e3472fad359e8c3d282bcd6" dependencies = [ "anstream", "anstyle", - "clap_lex 0.5.0", + "clap_lex 0.5.1", "strsim", "terminal_size", ] @@ -669,9 +668,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.3.12" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +checksum = "c9fd1a5729c4548118d7d70ff234a44868d00489a4b6597b0b020918a0e91a1a" dependencies = [ "heck", "proc-macro2", @@ -690,9 +689,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "color-eyre" @@ -1212,9 +1211,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encoding_rs" -version = "0.8.32" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if 1.0.0", ] @@ -1240,9 +1239,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "erased-serde" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc978899517288e3ebbd1a3bfc1d9537dbb87eeab149e53ea490e63bcdff561a" +checksum = "6c138974f9d5e7fe373eb04df7cae98833802ae4b11c24ac7039a21d5af4b26c" dependencies = [ "serde", ] @@ -1917,7 +1916,7 @@ version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11c352715b36685c2543556a77091fb16af5d26257d5ce9c28e6756c1ccd71aa" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "bytes", "flex-error", "ics23", @@ -1934,7 +1933,7 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6e8625e1aa28e4da4a33505c6469747a9201f14ccd9012e2481313dfbbf9e2f" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "bytes", "flex-error", "ics23", @@ -2407,7 +2406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.2", - "rustix 0.38.8", + "rustix 0.38.9", "windows-sys 0.48.0", ] @@ -2959,9 +2958,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -3227,14 +3226,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.6", - "regex-syntax 0.7.4", + "regex-automata 0.3.7", + "regex-syntax 0.7.5", ] [[package]] @@ -3248,13 +3247,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] @@ -3265,17 +3264,17 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "reqwest" -version = "0.11.19" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b9b67e2ca7dd9e9f9285b759de30ff538aab981abaaf7bc9bd90b84a0126c3" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "bytes", "encoding_rs", "futures-core", @@ -3391,9 +3390,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.8" +version = "0.38.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +checksum = "9bfe0f2582b4931a45d1fa608f8a8722e8b3c7ac54dd6d5f3b3212791fedef49" dependencies = [ "bitflags 2.4.0", "errno", @@ -3469,7 +3468,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", ] [[package]] @@ -3673,9 +3672,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.185" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] @@ -3701,9 +3700,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.185" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc59dfdcbad1437773485e0367fea4b090a2e0a16d9ffc46af47764536a298ec" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -4078,7 +4077,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", "redox_syscall 0.3.5", - "rustix 0.38.8", + "rustix 0.38.9", "windows-sys 0.48.0", ] @@ -4116,8 +4115,7 @@ dependencies = [ [[package]] name = "tendermint" version = "0.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d550db02d6bec4ebcbbebc4301ec22181bc489c37fb3f167e64b14c1be8321" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#70fa55863e83f3059169ec76ec3b31a5293f7855" dependencies = [ "bytes", "digest 0.10.7", @@ -4266,8 +4264,7 @@ dependencies = [ [[package]] name = "tendermint-proto" version = "0.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1834fa2eb884ba69b9c0eea55f0178270bed421217596ca4e54c19ef75dcb660" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#70fa55863e83f3059169ec76ec3b31a5293f7855" dependencies = [ "bytes", "flex-error", @@ -4371,8 +4368,7 @@ dependencies = [ [[package]] name = "tendermint-testgen" version = "0.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23a1e92079f943bdb0868795e9550c5185b8d0c6222be1475548314cf4f44c49" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#70fa55863e83f3059169ec76ec3b31a5293f7855" dependencies = [ "ed25519-consensus", "gumdrop", @@ -4694,7 +4690,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64 0.21.2", + "base64 0.21.3", "bytes", "futures-core", "futures-util", @@ -5366,9 +5362,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.14" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 3ad5cb7da3..c67fe8f7a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,11 +29,6 @@ exclude = [ overflow-checks = true [patch.crates-io] -# ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", branch = "main" } -# tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } -# tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } -# tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } -# tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } -# tendermint-light-client-verifier = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } -# tendermint-light-client-detector = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } -# tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "romac/new-misbehavior-detector" } +tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "farhad/testgen-app-hash" } +tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "farhad/testgen-app-hash" } +tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "farhad/testgen-app-hash" } \ No newline at end of file From 29ddb0a341d2616ed6d36e245ff49ab19d71000a Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Sun, 27 Aug 2023 09:37:55 -0700 Subject: [PATCH 06/25] imp: use create client traits --- crates/relayer-cosmos-mock/Cargo.toml | 4 +- .../relayer-cosmos-mock/src/contexts/chain.rs | 38 --- crates/relayer-cosmos-mock/src/impls/chain.rs | 218 +++++++++++++----- .../src/tests/ics02_client.rs | 5 +- 4 files changed, 166 insertions(+), 99 deletions(-) diff --git a/crates/relayer-cosmos-mock/Cargo.toml b/crates/relayer-cosmos-mock/Cargo.toml index e6e4762579..64a365ec0c 100644 --- a/crates/relayer-cosmos-mock/Cargo.toml +++ b/crates/relayer-cosmos-mock/Cargo.toml @@ -16,8 +16,8 @@ description = """ [dependencies] async-trait = "0.1.56" -basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "e7f23d3" } -basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "e7f23d3" } +basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "c05c32b" } +basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "c05c32b" } ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev= "6ffe8ce", features = ["mocks"] } ibc-proto = "0.34.0" ibc-relayer-components = { version = "0.1.0", path = "../relayer-components" } diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 118ce9499d..82b7466b83 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -8,13 +8,8 @@ use basecoin_app::{BaseCoinApp, Builder}; use basecoin_store::impls::InMemoryStore; use basecoin_store::impls::RevertibleStore; -use ibc::clients::ics07_tendermint::client_state::AllowUpdate; -use ibc::clients::ics07_tendermint::client_state::ClientState; -use ibc::core::ics02_client::msgs::create_client::MsgCreateClient; use ibc::core::ics24_host::identifier::ChainId; use ibc::core::timestamp::Timestamp; -use ibc::core::Msg; -use ibc::Any; use ibc::Height; use tendermint::time::Time; @@ -24,14 +19,10 @@ use tendermint_testgen::LightBlock; use std::sync::Arc; use std::sync::Mutex; -use std::time::Duration; use super::runtime::MockClock; use crate::contexts::runtime::MockRuntimeContext; -use crate::traits::endpoint::Endpoint; -use crate::types::error::Error; use crate::types::status::ChainStatus; -use crate::util::dummy::dummy_signer; use crate::util::mutex::MutexUtil; #[derive(Clone)] @@ -137,33 +128,4 @@ impl MockCosmosChain { *last_status = current_status; } - - pub async fn build_msg_create_client(&self) -> Result { - let tm_client_state = ClientState::new( - self.chain_id.clone(), - Default::default(), - Duration::from_secs(64000), - Duration::from_secs(128000), - Duration::from_millis(3000), - self.get_current_height(), - Default::default(), - Default::default(), - AllowUpdate { - after_expiry: false, - after_misbehaviour: false, - }, - )?; - - let current_height = self.get_current_height(); - - let tm_consensus_state = self.query_host_consensus_state(¤t_height)?; - - let msg_create_client = MsgCreateClient { - client_state: tm_client_state.into(), - consensus_state: tm_consensus_state.into(), - signer: dummy_signer(), - }; - - Ok(msg_create_client.to_any()) - } } diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index d49d415ece..d49a5d8b2a 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -1,8 +1,12 @@ +use std::time::Duration; + use async_trait::async_trait; -use ibc::clients::ics07_tendermint::client_state::ClientState as TmClientState; +use ibc::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState as TmClientState}; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use ibc::core::events::IbcEvent; +use ibc::core::ics02_client::events::CreateClient; +use ibc::core::ics02_client::msgs::create_client::MsgCreateClient; use ibc::core::ics04_channel::events::{SendPacket, WriteAcknowledgement}; use ibc::core::ics04_channel::msgs::{MsgAcknowledgement, MsgRecvPacket, MsgTimeout}; use ibc::core::ics04_channel::packet::Packet; @@ -15,6 +19,11 @@ use ibc::core::{Msg, ValidationContext}; use ibc::Any; use ibc::Height; +use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientMessage; +use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientPayload; +use ibc_relayer_components::chain::traits::client::create::HasCreateClientEvent; +use ibc_relayer_components::chain::traits::client::create::HasCreateClientOptions; +use ibc_relayer_components::chain::traits::client::create::HasCreateClientPayload; use ibc_relayer_components::chain::traits::logs::event::CanLogChainEvent; use ibc_relayer_components::chain::traits::logs::packet::CanLogChainPacket; use ibc_relayer_components::chain::traits::message_builders::ack_packet::CanBuildAckPacketMessage; @@ -59,6 +68,7 @@ use ibc_relayer_runtime::types::log::value::LogValue; use crate::contexts::chain::MockCosmosChain; use crate::contexts::runtime::MockRuntimeContext; +use crate::traits::endpoint::Endpoint; use crate::traits::handler::ChainHandler; use crate::types::error::Error; use crate::types::status::ChainStatus; @@ -84,6 +94,22 @@ impl HasLoggerType for MockCosmosChain { type Logger = TracingLogger; } +impl HasLogger for MockCosmosChain { + fn logger(&self) -> &TracingLogger { + &TracingLogger + } +} + +impl HasChainIdType for MockCosmosChain { + type ChainId = ChainId; +} + +impl HasChainId for MockCosmosChain { + fn chain_id(&self) -> &Self::ChainId { + &self.chain_id + } +} + impl HasHeightType for MockCosmosChain { type Height = Height; } @@ -92,6 +118,12 @@ impl HasEventType for MockCosmosChain { type Event = IbcEvent; } +impl CanLogChainEvent for MockCosmosChain { + fn log_event<'a>(event: &Self::Event) -> LogValue<'_> { + LogValue::Debug(event) + } +} + impl HasTimestampType for MockCosmosChain { type Timestamp = Timestamp; } @@ -100,10 +132,6 @@ impl HasMessageType for MockCosmosChain { type Message = Any; } -impl HasChainIdType for MockCosmosChain { - type ChainId = ChainId; -} - impl HasIbcChainTypes for MockCosmosChain { type ClientId = ClientId; @@ -122,6 +150,16 @@ impl HasIbcPacketTypes for MockCosmosChain { type OutgoingPacket = Packet; } +impl CanLogChainPacket for MockCosmosChain { + fn log_incoming_packet(packet: &Packet) -> LogValue<'_> { + LogValue::Display(packet) + } + + fn log_outgoing_packet(packet: &Packet) -> LogValue<'_> { + LogValue::Display(packet) + } +} + impl HasIbcPacketFields for MockCosmosChain { fn incoming_packet_src_channel_id(packet: &Self::IncomingPacket) -> &Self::ChannelId { &packet.chan_id_on_a @@ -186,19 +224,6 @@ impl HasIbcPacketFields for MockCosmosChain { } } -impl HasWriteAcknowledgementEvent for MockCosmosChain { - type WriteAcknowledgementEvent = WriteAcknowledgement; - - fn try_extract_write_acknowledgement_event( - event: &Self::Event, - ) -> Option { - match event { - IbcEvent::WriteAcknowledgement(e) => Some(e.clone()), - _ => None, - } - } -} - impl HasConsensusStateType for MockCosmosChain { type ConsensusState = TmConsensusState; } @@ -226,6 +251,74 @@ impl CanQueryChainStatus for MockCosmosChain { } } +impl HasCreateClientOptions for MockCosmosChain { + type CreateClientPayloadOptions = (); +} + +impl HasCreateClientPayload for MockCosmosChain { + type CreateClientPayload = Any; +} + +impl HasCreateClientEvent for MockCosmosChain { + type CreateClientEvent = CreateClient; + + fn try_extract_create_client_event(event: Self::Event) -> Option { + match event { + IbcEvent::CreateClient(e) => Some(e.clone()), + _ => None, + } + } + + fn create_client_event_client_id(event: &Self::CreateClientEvent) -> &Self::ClientId { + event.client_id() + } +} + +#[async_trait] +impl CanBuildCreateClientPayload for MockCosmosChain { + async fn build_create_client_payload( + &self, + _create_client_options: &Self::CreateClientPayloadOptions, + ) -> Result { + let tm_client_state = TmClientState::new( + self.chain_id.clone(), + Default::default(), + Duration::from_secs(64000), + Duration::from_secs(128000), + Duration::from_millis(3000), + self.get_current_height(), + Default::default(), + Default::default(), + AllowUpdate { + after_expiry: false, + after_misbehaviour: false, + }, + )?; + + let current_height = self.get_current_height(); + + let tm_consensus_state = self.query_host_consensus_state(¤t_height)?; + + let msg_create_client = MsgCreateClient { + client_state: tm_client_state.into(), + consensus_state: tm_consensus_state.into(), + signer: dummy_signer(), + }; + + Ok(msg_create_client.to_any()) + } +} + +#[async_trait] +impl CanBuildCreateClientMessage for MockCosmosChain { + async fn build_create_client_message( + &self, + counterparty_payload: Any, + ) -> Result { + Ok(counterparty_payload) + } +} + impl HasSendPacketEvent for MockCosmosChain { type SendPacketEvent = SendPacket; @@ -252,18 +345,6 @@ impl HasSendPacketEvent for MockCosmosChain { } } -impl HasLogger for MockCosmosChain { - fn logger(&self) -> &TracingLogger { - &TracingLogger - } -} - -impl CanLogChainEvent for MockCosmosChain { - fn log_event<'a>(event: &Self::Event) -> LogValue<'_> { - LogValue::Debug(event) - } -} - impl CanIncrementHeight for MockCosmosChain { fn increment_height(height: &Self::Height) -> Result { Ok(height.increment()) @@ -277,12 +358,6 @@ impl CanEstimateMessageSize for MockCosmosChain { } } -impl HasChainId for MockCosmosChain { - fn chain_id(&self) -> &Self::ChainId { - &self.chain_id - } -} - #[async_trait] impl CanSendMessages for MockCosmosChain { async fn send_messages( @@ -293,19 +368,9 @@ impl CanSendMessages for MockCosmosChain { } } -impl CanLogChainPacket for MockCosmosChain { - fn log_incoming_packet(packet: &Packet) -> LogValue<'_> { - LogValue::Display(packet) - } - - fn log_outgoing_packet(packet: &Packet) -> LogValue<'_> { - LogValue::Display(packet) - } -} - impl HasCounterpartyMessageHeight for MockCosmosChain { fn counterparty_message_height_for_update_client(_message: &Any) -> Option { - unimplemented!() + None } } @@ -343,16 +408,6 @@ impl CanQueryReceivedPacket for MockCosmosChain { } } -#[async_trait] -impl CanQueryWriteAcknowledgement for MockCosmosChain { - async fn query_write_acknowledgement_event( - &self, - _packet: &Packet, - ) -> Result, Error> { - todo!() - } -} - impl HasReceivePacketPayload for MockCosmosChain { type ReceivePacketPayload = Any; } @@ -395,6 +450,55 @@ impl CanBuildReceivePacketMessage for MockCosmosChain { } } +#[async_trait] +impl CanQueryWriteAcknowledgement for MockCosmosChain { + async fn query_write_acknowledgement_event( + &self, + packet: &Packet, + ) -> Result, Error> { + let chan_counter = self.ibc_context().channel_counter()?; + + let chan_id = ChannelId::new(chan_counter); + + let port_id = PortId::transfer(); + + let ack_path = AckPath::new(&port_id, &chan_id, packet.seq_on_a); + + self.ibc_context().get_packet_acknowledgement(&ack_path)?; + + let events = self.ibc_context().events(); + + for e in events { + match e { + IbcEvent::WriteAcknowledgement(e) => { + if e.port_id_on_a() == &port_id + && e.chan_id_on_a() == &chan_id + && e.seq_on_a() == &packet.seq_on_a + { + return Ok(Some(e)); + } + } + _ => {} + } + } + + Ok(None) + } +} + +impl HasWriteAcknowledgementEvent for MockCosmosChain { + type WriteAcknowledgementEvent = WriteAcknowledgement; + + fn try_extract_write_acknowledgement_event( + event: &Self::Event, + ) -> Option { + match event { + IbcEvent::WriteAcknowledgement(e) => Some(e.clone()), + _ => None, + } + } +} + impl HasAckPacketPayload for MockCosmosChain { type AckPacketPayload = Any; } diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs index f9a59dd520..8797533aee 100644 --- a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -1,5 +1,6 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; +use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientPayload; use ibc_relayer_components::relay::traits::target::SourceTarget; use ibc_relayer_components::relay::traits::update_client::CanBuildUpdateClientMessage; @@ -13,7 +14,7 @@ async fn test_create_client() -> Result<(), Error> { tokio::time::sleep(tokio::time::Duration::from_millis(150)).await; - let msg_create_client = builder.chains[0].build_msg_create_client().await?; + let msg_create_client = builder.chains[0].build_create_client_payload(&()).await?; builder.chains[1] .submit_messages(vec![msg_create_client]) @@ -35,7 +36,7 @@ async fn test_update_client() -> Result<(), Error> { tokio::time::sleep(tokio::time::Duration::from_millis(150)).await; - let msg_create_client = builder.chains[0].build_msg_create_client().await?; + let msg_create_client = builder.chains[0].build_create_client_payload(&()).await?; builder.chains[1] .submit_messages(vec![msg_create_client]) From c471a1a9f0ff86232a4fbd5eeee0c0f1143dacf6 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Sun, 27 Aug 2023 19:31:11 -0700 Subject: [PATCH 07/25] imp: separate mock basecoin from chain context --- .../src/contexts/basecoin.rs | 69 +++++ .../src/contexts/birelay.rs | 17 +- .../src/contexts/builder.rs | 86 ------ .../relayer-cosmos-mock/src/contexts/chain.rs | 124 ++++----- .../relayer-cosmos-mock/src/contexts/mod.rs | 2 +- .../relayer-cosmos-mock/src/contexts/relay.rs | 44 ++- .../src/contexts/runtime.rs | 5 +- .../src/impls/{handler.rs => basecoin.rs} | 64 +++-- .../relayer-cosmos-mock/src/impls/birelay.rs | 21 +- crates/relayer-cosmos-mock/src/impls/chain.rs | 250 +++++++++++++----- .../src/impls/components.rs | 17 +- .../relayer-cosmos-mock/src/impls/endpoint.rs | 37 ++- crates/relayer-cosmos-mock/src/impls/mod.rs | 2 +- crates/relayer-cosmos-mock/src/impls/relay.rs | 90 ++++--- .../src/tests/ics02_client.rs | 51 ++-- crates/relayer-cosmos-mock/src/tests/init.rs | 37 ++- .../src/traits/endpoint.rs | 8 + .../relayer-cosmos-mock/src/traits/handle.rs | 41 +++ .../relayer-cosmos-mock/src/traits/handler.rs | 27 -- crates/relayer-cosmos-mock/src/traits/mod.rs | 2 +- 20 files changed, 607 insertions(+), 387 deletions(-) create mode 100644 crates/relayer-cosmos-mock/src/contexts/basecoin.rs delete mode 100644 crates/relayer-cosmos-mock/src/contexts/builder.rs rename crates/relayer-cosmos-mock/src/impls/{handler.rs => basecoin.rs} (76%) create mode 100644 crates/relayer-cosmos-mock/src/traits/handle.rs delete mode 100644 crates/relayer-cosmos-mock/src/traits/handler.rs diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs new file mode 100644 index 0000000000..e27ebeb3f2 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -0,0 +1,69 @@ +use std::fmt::Debug; +use std::sync::Arc; +use std::sync::Mutex; + +use basecoin_app::modules::auth::Auth; +use basecoin_app::modules::bank::Bank; +use basecoin_app::modules::context::prefix; +use basecoin_app::modules::context::Identifiable; +use basecoin_app::modules::ibc::Ibc; +use basecoin_app::BaseCoinApp; +use basecoin_app::Builder; +use basecoin_store::context::ProvableStore; +use ibc::core::ics24_host::identifier::ChainId; +use tendermint_testgen::light_block::TmLightBlock; +use tokio::task::JoinHandle; + +use crate::traits::handle::BasecoinHandle; + +#[derive(Clone)] +pub struct MockBasecoin +where + S: ProvableStore + Default + Debug, +{ + /// Chain identifier + pub chain_id: ChainId, + /// Chain application + pub app: BaseCoinApp, + /// Chain blocks + pub blocks: Arc>>, +} + +impl MockBasecoin { + /// Constructs a new mock cosmos chain instance. + pub fn new(chain_id: ChainId, store: S) -> Self { + let app_builder = Builder::new(store); + + let auth = Auth::new(app_builder.module_store(&prefix::Auth {}.identifier())); + let bank = Bank::new( + app_builder.module_store(&prefix::Bank {}.identifier()), + auth.account_reader().clone(), + auth.account_keeper().clone(), + ); + let ibc = Ibc::new( + app_builder.module_store(&prefix::Ibc {}.identifier()), + bank.bank_keeper().clone(), + ); + + // register modules with the app + let app = app_builder + .add_module(prefix::Auth {}.identifier(), auth.clone()) + .add_module(prefix::Bank {}.identifier(), bank.clone()) + .add_module(prefix::Ibc {}.identifier(), ibc) + .build(); + + Self { + chain_id, + app, + blocks: Arc::new(Mutex::new(vec![])), + } + } + + pub fn spawn(&self) -> JoinHandle<()> { + let chain = self.clone(); + + tokio::spawn(async move { + chain.run().await; + }) + } +} diff --git a/crates/relayer-cosmos-mock/src/contexts/birelay.rs b/crates/relayer-cosmos-mock/src/contexts/birelay.rs index a392834671..1bbac80bdb 100644 --- a/crates/relayer-cosmos-mock/src/contexts/birelay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/birelay.rs @@ -2,18 +2,19 @@ use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use std::sync::Arc; use super::relay::MockCosmosRelay; +use crate::traits::handle::BasecoinHandle; -pub struct MockCosmosBiRelay { +pub struct MockCosmosBiRelay { pub runtime: TokioRuntimeContext, - pub relay_a_to_b: Arc, - pub relay_b_to_a: Arc, + pub relay_a_to_b: Arc>, + pub relay_b_to_a: Arc>, } -impl MockCosmosBiRelay { +impl MockCosmosBiRelay { pub fn new( runtime: TokioRuntimeContext, - relay_a_to_b: Arc, - relay_b_to_a: Arc, + relay_a_to_b: Arc>, + relay_b_to_a: Arc>, ) -> Self { Self { runtime, @@ -22,11 +23,11 @@ impl MockCosmosBiRelay { } } - pub fn relay_a_to_b(&self) -> &Arc { + pub fn relay_a_to_b(&self) -> &Arc> { &self.relay_a_to_b } - pub fn relay_b_to_a(&self) -> &Arc { + pub fn relay_b_to_a(&self) -> &Arc> { &self.relay_b_to_a } } diff --git a/crates/relayer-cosmos-mock/src/contexts/builder.rs b/crates/relayer-cosmos-mock/src/contexts/builder.rs deleted file mode 100644 index 9f99eeead8..0000000000 --- a/crates/relayer-cosmos-mock/src/contexts/builder.rs +++ /dev/null @@ -1,86 +0,0 @@ -use alloc::sync::Arc; -use ibc::core::ics24_host::identifier::ChainId; -use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket; -use tokio::task::JoinHandle; - -use super::chain::MockCosmosChain; -use super::relay::MockCosmosRelay; -use super::runtime::MockClock; -use super::runtime::MockRuntimeContext; -use crate::traits::handler::ChainHandler; -use crate::util::msgs::build_transfer_packet; - -pub struct MockCosmosBuilder { - pub chains: Vec>, - pub relayers: Vec>, - pub handlers: Vec>, - pub runtime: MockRuntimeContext, -} - -impl MockCosmosBuilder { - pub fn new(clock: Arc) -> Self { - Self { - chains: Vec::new(), - relayers: Vec::new(), - handlers: Vec::new(), - runtime: MockRuntimeContext { clock }, - } - } - - pub fn new_default() -> Self { - Self::new(Arc::new(MockClock::default())) - } - - pub fn build_chain(&mut self, chain_id: ChainId) -> Arc { - let chain = Arc::new(MockCosmosChain::new(chain_id, self.runtime.clock.clone())); - - self.chains.push(chain.clone()); - - chain - } - - pub fn build_relayer( - &mut self, - src_chain: Arc, - dst_chain: Arc, - ) -> MockCosmosRelay { - let relayer = MockCosmosRelay::new(src_chain, dst_chain, self.runtime.clone()) - .expect("failed to build relayer"); - - self.relayers.push(Arc::new(relayer.clone())); - - relayer - } - - pub fn spawn_chains(&mut self) { - for c in self.chains.clone() { - let c_clone = c.clone(); - - let handle = tokio::spawn(async move { - c_clone.run().await; - }); - - self.handlers.push(handle); - } - } - - pub async fn relay_packet(&mut self) { - for r in &self.relayers { - let packet = build_transfer_packet(1); - - let relayer_clone = r.clone(); - - let handle = tokio::spawn(async move { - relayer_clone.relay_packet(&packet).await.unwrap(); - }); - - self.handlers.push(handle); - } - } - - pub fn stop(&self) { - for h in &self.handlers { - h.abort(); - } - } -} diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 82b7466b83..4d8311c15f 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -1,93 +1,56 @@ -use basecoin_app::modules::auth::Auth; -use basecoin_app::modules::bank::Bank; -use basecoin_app::modules::context::prefix; -use basecoin_app::modules::context::Identifiable; -use basecoin_app::modules::ibc::Ibc; use basecoin_app::modules::ibc::IbcContext; -use basecoin_app::{BaseCoinApp, Builder}; -use basecoin_store::impls::InMemoryStore; use basecoin_store::impls::RevertibleStore; - -use ibc::core::ics24_host::identifier::ChainId; +use ibc::core::events::IbcEvent; use ibc::core::timestamp::Timestamp; +use ibc::Any; use ibc::Height; -use tendermint::time::Time; -use tendermint_testgen::light_block::TmLightBlock; -use tendermint_testgen::Generator; -use tendermint_testgen::LightBlock; - use std::sync::Arc; use std::sync::Mutex; use super::runtime::MockClock; use crate::contexts::runtime::MockRuntimeContext; +use crate::traits::endpoint::Endpoint; +use crate::traits::handle::BasecoinHandle; +use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::mutex::MutexUtil; #[derive(Clone)] -pub struct MockCosmosChain { - /// Chain identifier - pub chain_id: ChainId, +pub struct MockCosmosContext { + /// Chain handle + pub handle: Arc, /// Current chain status pub current_status: Arc>, - /// Chain application - pub app: BaseCoinApp, - /// Chain blocks - pub blocks: Arc>>, /// Chain runtime pub runtime: MockRuntimeContext, } -impl MockCosmosChain { +impl MockCosmosContext { /// Constructs a new mock cosmos chain instance. - pub fn new(chain_id: ChainId, clock: Arc) -> Self { - let app_builder = Builder::new(InMemoryStore::default()); - - let auth = Auth::new(app_builder.module_store(&prefix::Auth {}.identifier())); - let bank = Bank::new( - app_builder.module_store(&prefix::Bank {}.identifier()), - auth.account_reader().clone(), - auth.account_keeper().clone(), - ); - let ibc: Ibc> = Ibc::new( - app_builder.module_store(&prefix::Ibc {}.identifier()), - bank.bank_keeper().clone(), - ); - - // register modules with the app - let app = app_builder - .add_module(prefix::Auth {}.identifier(), auth.clone()) - .add_module(prefix::Bank {}.identifier(), bank.clone()) - .add_module(prefix::Ibc {}.identifier(), ibc) - .build(); - + pub fn new(handle: Arc, clock: Arc) -> Self { let runtime = MockRuntimeContext::new(clock.clone()); let current_status = Arc::new(Mutex::new(ChainStatus::new( - Height::new(chain_id.revision_number(), 1).expect("never fails"), - Time::now().into(), + Height::new(handle.chain_id().revision_number(), 1).expect("never fails"), + clock.get_timestamp(), ))); - let chain = Self { - chain_id, + Self { + handle, current_status, - app, - blocks: Arc::new(Mutex::new(vec![])), runtime, - }; - - chain - } - - pub fn chain_id(&self) -> &ChainId { - &self.chain_id + } } pub fn runtime(&self) -> &MockRuntimeContext { &self.runtime } + pub fn ibc_context(&self) -> IbcContext::Store>> { + self.handle.ibc().ctx() + } + pub fn get_current_timestamp(&self) -> Timestamp { self.current_status.acquire_mutex().timestamp } @@ -96,36 +59,41 @@ impl MockCosmosChain { self.current_status.acquire_mutex().height } - pub fn ibc_context(&self) -> IbcContext> { - self.app.ibc().ctx() - } + pub fn subscribe(&self) { + let ctx = self.clone(); + tokio::spawn(async move { + let mut blocks_len = 1; + loop { + tokio::time::sleep(tokio::time::Duration::from_millis(200)).await; - pub fn grow_blocks(&self) { - let mut blocks = self.blocks.acquire_mutex(); + if ctx.handle.blocks().len() > blocks_len { + let current_time = ctx.query_current_timestamp().unwrap(); - let height = blocks.len() as u64 + 1; + let current_height = ctx.query_current_height().unwrap(); - let current_time = Time::now(); + ctx.runtime.clock.set_timestamp(current_time); - let tm_light_block = LightBlock::new_default_with_time_and_chain_id( - self.chain_id.to_string(), - current_time, - height, - ) - .generate() - .expect("failed to generate light block"); + let current_status = ChainStatus::new(current_height, current_time); - blocks.push(tm_light_block); + let mut last_status = ctx.current_status.acquire_mutex(); + + *last_status = current_status; + + blocks_len = ctx.handle.blocks().len(); + } + } + }); + } - self.runtime.clock.set_timestamp(current_time); + pub fn submit_messages(&self, msgs: Vec) -> Result>, Error> { + let mut events = Vec::new(); - let current_status = ChainStatus::new( - Height::new(self.chain_id.revision_number(), height).expect("invalid height"), - current_time.into(), - ); + for msg in msgs { + let ibc_events = self.handle.ibc().process_message(msg)?; - let mut last_status = self.current_status.acquire_mutex(); + events.push(ibc_events); + } - *last_status = current_status; + Ok(events) } } diff --git a/crates/relayer-cosmos-mock/src/contexts/mod.rs b/crates/relayer-cosmos-mock/src/contexts/mod.rs index cdcf68ace5..8213dd39b7 100644 --- a/crates/relayer-cosmos-mock/src/contexts/mod.rs +++ b/crates/relayer-cosmos-mock/src/contexts/mod.rs @@ -1,5 +1,5 @@ +pub mod basecoin; pub mod birelay; -pub mod builder; pub mod chain; pub mod relay; pub mod runtime; diff --git a/crates/relayer-cosmos-mock/src/contexts/relay.rs b/crates/relayer-cosmos-mock/src/contexts/relay.rs index 9146060356..7b5a1fb94b 100644 --- a/crates/relayer-cosmos-mock/src/contexts/relay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/relay.rs @@ -1,28 +1,36 @@ use ibc::clients::ics07_tendermint::client_type; use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; +use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket; use std::sync::Arc; +use tokio::task::JoinHandle; +use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; +use crate::util::msgs::build_transfer_packet; -use super::chain::MockCosmosChain; -use super::runtime::MockRuntimeContext; +use super::chain::MockCosmosContext; +use super::runtime::{MockClock, MockRuntimeContext}; #[derive(Clone)] -pub struct MockCosmosRelay { - pub src_chain: Arc, - pub dst_chain: Arc, +pub struct MockCosmosRelay { + pub src_chain: Arc>, + pub dst_chain: Arc>, pub src_client_id: ClientId, pub dst_client_id: ClientId, pub runtime: MockRuntimeContext, } -impl MockCosmosRelay { +impl MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ pub fn new( - src_chain: Arc, - dst_chain: Arc, - runtime: MockRuntimeContext, - ) -> Result { + src_chain: Arc>, + dst_chain: Arc>, + clock: Arc, + ) -> Result, Error> { let src_client_counter = src_chain.ibc_context().client_counter()?; let src_client_id = ClientId::new(client_type(), src_client_counter)?; @@ -31,6 +39,8 @@ impl MockCosmosRelay { let dst_client_id = ClientId::new(client_type(), dst_client_counter)?; + let runtime = MockRuntimeContext { clock }; + Ok(Self { src_chain, dst_chain, @@ -40,11 +50,11 @@ impl MockCosmosRelay { }) } - pub fn src_chain(&self) -> &Arc { + pub fn src_chain(&self) -> &Arc> { &self.src_chain } - pub fn dst_chain(&self) -> &Arc { + pub fn dst_chain(&self) -> &Arc> { &self.dst_chain } @@ -55,4 +65,14 @@ impl MockCosmosRelay { pub fn dst_client_id(&self) -> &ClientId { &self.dst_client_id } + + pub fn spawn(&mut self) -> JoinHandle<()> { + let packet = build_transfer_packet(1); + + let relayer = self.clone(); + + tokio::spawn(async move { + relayer.relay_packet(&packet).await.unwrap(); + }) + } } diff --git a/crates/relayer-cosmos-mock/src/contexts/runtime.rs b/crates/relayer-cosmos-mock/src/contexts/runtime.rs index a8303ca96c..c3b7582891 100644 --- a/crates/relayer-cosmos-mock/src/contexts/runtime.rs +++ b/crates/relayer-cosmos-mock/src/contexts/runtime.rs @@ -3,7 +3,6 @@ use core::time::Duration; use ibc::core::timestamp::Timestamp; use std::ops::Add; use std::sync::Mutex; -use tendermint::Time; use crate::types::error::Error; use crate::util::mutex::MutexUtil; @@ -42,8 +41,8 @@ impl Default for MockClock { } impl MockClock { - pub fn set_timestamp(&self, time: Time) { - *self.timestamp.acquire_mutex() = time.into(); + pub fn set_timestamp(&self, timestamp: Timestamp) { + *self.timestamp.acquire_mutex() = timestamp; } pub fn increment_timestamp(&self, duration: Duration) -> Result<(), Error> { diff --git a/crates/relayer-cosmos-mock/src/impls/handler.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs similarity index 76% rename from crates/relayer-cosmos-mock/src/impls/handler.rs rename to crates/relayer-cosmos-mock/src/impls/basecoin.rs index 33df5bd3d5..c75438ec75 100644 --- a/crates/relayer-cosmos-mock/src/impls/handler.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -1,20 +1,21 @@ -use crate::contexts::chain::MockCosmosChain; -use crate::traits::handler::ChainHandler; +use crate::contexts::basecoin::MockBasecoin; +use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; use crate::util::conversion::convert_tm_to_ics_merkle_proof; use crate::util::dummy::genesis_app_state; use crate::util::mutex::MutexUtil; +use basecoin_app::modules::ibc::Ibc; use basecoin_app::modules::types::IdentifiedModule; use basecoin_store::context::ProvableStore; use basecoin_store::context::Store; +use basecoin_store::impls::RevertibleStore; use basecoin_store::utils::SharedRwExt; -use ibc::core::events::IbcEvent; use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; +use ibc::core::ics24_host::identifier::ChainId; use ibc::core::ics24_host::path::Path; use ibc::hosts::tendermint::IBC_QUERY_PATH; -use ibc::Any; use ibc::Height; use tendermint::block::Height as TmHeight; @@ -24,13 +25,52 @@ use tendermint::v0_37::abci::request::Query; use tendermint::v0_37::abci::Request as AbciRequest; use tendermint::v0_37::abci::Response as AbciResponse; use tendermint_testgen::consensus::default_consensus_params; +use tendermint_testgen::light_block::TmLightBlock; +use tendermint_testgen::Generator; +use tendermint_testgen::LightBlock; use tower::Service; use async_trait::async_trait; +use std::fmt::Debug; use std::time::Duration; #[async_trait] -impl ChainHandler for MockCosmosChain { +impl BasecoinHandle for MockBasecoin +where + S: ProvableStore + Default + Debug, +{ + type Store = S; + + fn chain_id(&self) -> &ChainId { + &self.chain_id + } + + fn ibc(&self) -> Ibc> { + self.app.ibc() + } + + fn blocks(&self) -> Vec { + self.blocks.acquire_mutex().clone() + } + + fn grow_blocks(&self) { + let mut blocks = self.blocks.acquire_mutex(); + + let height = blocks.len() as u64 + 1; + + let current_time = Time::now(); + + let tm_light_block = LightBlock::new_default_with_time_and_chain_id( + self.chain_id.to_string(), + current_time, + height, + ) + .generate() + .expect("failed to generate light block"); + + blocks.push(tm_light_block); + } + /// Initialize the chain with the app state. async fn init(&self) { let app_state = serde_json::to_vec(&genesis_app_state()).expect("infallible serialization"); @@ -97,24 +137,12 @@ impl ChainHandler for MockCosmosChain { loop { self.begin_block().await; - tokio::time::sleep(Duration::from_millis(100)).await; + tokio::time::sleep(Duration::from_millis(200)).await; self.commit().await; } } - async fn submit_messages(&self, msgs: Vec) -> Result>, Error> { - let mut events = Vec::new(); - - for msg in msgs { - let ibc_events = self.app.ibc().process_message(msg)?; - - events.push(ibc_events); - } - - Ok(events) - } - /// Queries the mock chain for the given path and height. async fn query( &self, diff --git a/crates/relayer-cosmos-mock/src/impls/birelay.rs b/crates/relayer-cosmos-mock/src/impls/birelay.rs index 43a7545e8e..da0af43243 100644 --- a/crates/relayer-cosmos-mock/src/impls/birelay.rs +++ b/crates/relayer-cosmos-mock/src/impls/birelay.rs @@ -1,17 +1,30 @@ +use ibc_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketFields; use ibc_relayer_components::core::traits::error::HasErrorType; use ibc_relayer_components::relay::traits::two_way::HasTwoWayRelay; +use crate::contexts::chain::MockCosmosContext; use crate::contexts::{birelay::MockCosmosBiRelay, relay::MockCosmosRelay}; +use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; -impl HasErrorType for MockCosmosBiRelay { +impl HasErrorType + for MockCosmosBiRelay +{ type Error = Error; } -impl HasTwoWayRelay for MockCosmosBiRelay { - type RelayAToB = MockCosmosRelay; +impl HasTwoWayRelay for MockCosmosBiRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, + MockCosmosContext: HasIbcPacketFields>, + MockCosmosContext: HasIbcPacketFields>, + MockCosmosContext: HasIbcChainTypes>, +{ + type RelayAToB = MockCosmosRelay; - type RelayBToA = MockCosmosRelay; + type RelayBToA = MockCosmosRelay; fn relay_a_to_b(&self) -> &Self::RelayAToB { self.relay_a_to_b() diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index d49a5d8b2a..fdcf101562 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -66,19 +66,19 @@ use ibc_relayer_runtime::types::error::Error as TokioError; use ibc_relayer_runtime::types::log::logger::TracingLogger; use ibc_relayer_runtime::types::log::value::LogValue; -use crate::contexts::chain::MockCosmosChain; +use crate::contexts::chain::MockCosmosContext; use crate::contexts::runtime::MockRuntimeContext; use crate::traits::endpoint::Endpoint; -use crate::traits::handler::ChainHandler; +use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::dummy::dummy_signer; -impl HasErrorType for MockCosmosChain { +impl HasErrorType for MockCosmosContext { type Error = Error; } -impl HasRuntime for MockCosmosChain { +impl HasRuntime for MockCosmosContext { type Runtime = MockRuntimeContext; fn runtime(&self) -> &Self::Runtime { @@ -90,49 +90,54 @@ impl HasRuntime for MockCosmosChain { } } -impl HasLoggerType for MockCosmosChain { +impl HasLoggerType for MockCosmosContext { type Logger = TracingLogger; } -impl HasLogger for MockCosmosChain { +impl HasLogger for MockCosmosContext { fn logger(&self) -> &TracingLogger { &TracingLogger } } -impl HasChainIdType for MockCosmosChain { +impl HasChainIdType for MockCosmosContext { type ChainId = ChainId; } -impl HasChainId for MockCosmosChain { +impl HasChainId for MockCosmosContext { fn chain_id(&self) -> &Self::ChainId { - &self.chain_id + &self.handle.chain_id() } } -impl HasHeightType for MockCosmosChain { +impl HasHeightType for MockCosmosContext { type Height = Height; } -impl HasEventType for MockCosmosChain { +impl HasEventType for MockCosmosContext { type Event = IbcEvent; } -impl CanLogChainEvent for MockCosmosChain { +impl CanLogChainEvent for MockCosmosContext { fn log_event<'a>(event: &Self::Event) -> LogValue<'_> { LogValue::Debug(event) } } -impl HasTimestampType for MockCosmosChain { +impl HasTimestampType for MockCosmosContext { type Timestamp = Timestamp; } -impl HasMessageType for MockCosmosChain { +impl HasMessageType for MockCosmosContext { type Message = Any; } -impl HasIbcChainTypes for MockCosmosChain { +impl HasIbcChainTypes> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type ClientId = ClientId; type ConnectionId = ConnectionId; @@ -144,13 +149,23 @@ impl HasIbcChainTypes for MockCosmosChain { type Sequence = Sequence; } -impl HasIbcPacketTypes for MockCosmosChain { +impl HasIbcPacketTypes> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type IncomingPacket = Packet; type OutgoingPacket = Packet; } -impl CanLogChainPacket for MockCosmosChain { +impl CanLogChainPacket> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ fn log_incoming_packet(packet: &Packet) -> LogValue<'_> { LogValue::Display(packet) } @@ -160,7 +175,12 @@ impl CanLogChainPacket for MockCosmosChain { } } -impl HasIbcPacketFields for MockCosmosChain { +impl HasIbcPacketFields> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ fn incoming_packet_src_channel_id(packet: &Self::IncomingPacket) -> &Self::ChannelId { &packet.chan_id_on_a } @@ -224,15 +244,25 @@ impl HasIbcPacketFields for MockCosmosChain { } } -impl HasConsensusStateType for MockCosmosChain { +impl HasConsensusStateType> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type ConsensusState = TmConsensusState; } -impl HasClientStateType for MockCosmosChain { +impl HasClientStateType> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type ClientState = TmClientState; } -impl HasChainStatusType for MockCosmosChain { +impl HasChainStatusType for MockCosmosContext { type ChainStatus = ChainStatus; fn chain_status_height(status: &Self::ChainStatus) -> &Self::Height { @@ -245,21 +275,36 @@ impl HasChainStatusType for MockCosmosChain { } #[async_trait] -impl CanQueryChainStatus for MockCosmosChain { +impl CanQueryChainStatus for MockCosmosContext { async fn query_chain_status(&self) -> Result { Ok(self.current_status.lock().unwrap().clone()) } } -impl HasCreateClientOptions for MockCosmosChain { +impl HasCreateClientOptions> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type CreateClientPayloadOptions = (); } -impl HasCreateClientPayload for MockCosmosChain { +impl HasCreateClientPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type CreateClientPayload = Any; } -impl HasCreateClientEvent for MockCosmosChain { +impl HasCreateClientEvent> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type CreateClientEvent = CreateClient; fn try_extract_create_client_event(event: Self::Event) -> Option { @@ -275,13 +320,18 @@ impl HasCreateClientEvent for MockCosmosChain { } #[async_trait] -impl CanBuildCreateClientPayload for MockCosmosChain { +impl CanBuildCreateClientPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_create_client_payload( &self, _create_client_options: &Self::CreateClientPayloadOptions, ) -> Result { let tm_client_state = TmClientState::new( - self.chain_id.clone(), + self.handle.chain_id().clone(), Default::default(), Duration::from_secs(64000), Duration::from_secs(128000), @@ -310,7 +360,12 @@ impl CanBuildCreateClientPayload for MockCosmosChain { } #[async_trait] -impl CanBuildCreateClientMessage for MockCosmosChain { +impl CanBuildCreateClientMessage> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_create_client_message( &self, counterparty_payload: Any, @@ -319,7 +374,12 @@ impl CanBuildCreateClientMessage for MockCosmosChain { } } -impl HasSendPacketEvent for MockCosmosChain { +impl HasSendPacketEvent> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type SendPacketEvent = SendPacket; fn try_extract_send_packet_event(event: &Self::Event) -> Option { @@ -345,13 +405,13 @@ impl HasSendPacketEvent for MockCosmosChain { } } -impl CanIncrementHeight for MockCosmosChain { +impl CanIncrementHeight for MockCosmosContext { fn increment_height(height: &Self::Height) -> Result { Ok(height.increment()) } } -impl CanEstimateMessageSize for MockCosmosChain { +impl CanEstimateMessageSize for MockCosmosContext { fn estimate_message_size(_message: &Self::Message) -> Result { // Only single messages are sent by the Mock Chain Ok(1) @@ -359,23 +419,33 @@ impl CanEstimateMessageSize for MockCosmosChain { } #[async_trait] -impl CanSendMessages for MockCosmosChain { +impl CanSendMessages for MockCosmosContext { async fn send_messages( &self, messages: Vec, ) -> Result>, Error> { - self.submit_messages(messages).await + self.submit_messages(messages) } } -impl HasCounterpartyMessageHeight for MockCosmosChain { +impl HasCounterpartyMessageHeight> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ fn counterparty_message_height_for_update_client(_message: &Any) -> Option { None } } #[async_trait] -impl CanQueryConsensusState for MockCosmosChain { +impl CanQueryConsensusState> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn query_consensus_state( &self, client_id: &ClientId, @@ -393,7 +463,12 @@ impl CanQueryConsensusState for MockCosmosChain { } #[async_trait] -impl CanQueryReceivedPacket for MockCosmosChain { +impl CanQueryReceivedPacket> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn query_is_packet_received( &self, port_id: &Self::PortId, @@ -408,25 +483,32 @@ impl CanQueryReceivedPacket for MockCosmosChain { } } -impl HasReceivePacketPayload for MockCosmosChain { +impl HasReceivePacketPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type ReceivePacketPayload = Any; } #[async_trait] -impl CanBuildReceivePacketPayload for MockCosmosChain { +impl CanBuildReceivePacketPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_receive_packet_payload( &self, _client_state: &Self::ClientState, height: &Self::Height, packet: &Self::IncomingPacket, ) -> Result { - let receipt_path = ReceiptPath::new( - Self::incoming_packet_src_port(packet), - Self::incoming_packet_src_channel_id(packet), - *Self::incoming_packet_sequence(packet), - ); + let receipt_path = + ReceiptPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); - let (_, proof_commitment_on_a) = self.query(receipt_path, height).await?; + let (_, proof_commitment_on_a) = self.handle.query(receipt_path, height).await?; let recv_packet_payload = MsgRecvPacket { packet: packet.clone(), @@ -440,7 +522,12 @@ impl CanBuildReceivePacketPayload for MockCosmosChain { } #[async_trait] -impl CanBuildReceivePacketMessage for MockCosmosChain { +impl CanBuildReceivePacketMessage> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_receive_packet_message( &self, _packet: &Packet, @@ -451,7 +538,12 @@ impl CanBuildReceivePacketMessage for MockCosmosChain { } #[async_trait] -impl CanQueryWriteAcknowledgement for MockCosmosChain { +impl CanQueryWriteAcknowledgement> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn query_write_acknowledgement_event( &self, packet: &Packet, @@ -486,7 +578,12 @@ impl CanQueryWriteAcknowledgement for MockCosmosChain { } } -impl HasWriteAcknowledgementEvent for MockCosmosChain { +impl HasWriteAcknowledgementEvent> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type WriteAcknowledgementEvent = WriteAcknowledgement; fn try_extract_write_acknowledgement_event( @@ -499,12 +596,22 @@ impl HasWriteAcknowledgementEvent for MockCosmosChain { } } -impl HasAckPacketPayload for MockCosmosChain { +impl HasAckPacketPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type AckPacketPayload = Any; } #[async_trait] -impl CanBuildAckPacketPayload for MockCosmosChain { +impl CanBuildAckPacketPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_ack_packet_payload( &self, _client_state: &Self::ClientState, @@ -512,13 +619,9 @@ impl CanBuildAckPacketPayload for MockCosmosChain { packet: &Self::IncomingPacket, ack: &Self::WriteAcknowledgementEvent, ) -> Result { - let ack_path = AckPath::new( - Self::outgoing_packet_src_port(packet), - Self::outgoing_packet_src_channel_id(packet), - *Self::outgoing_packet_sequence(packet), - ); + let ack_path = AckPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); - let (_, proof_acked_on_b) = self.query(ack_path, height).await?; + let (_, proof_acked_on_b) = self.handle.query(ack_path, height).await?; let ack_packet_payload = MsgAcknowledgement { packet: packet.clone(), @@ -533,31 +636,43 @@ impl CanBuildAckPacketPayload for MockCosmosChain { } #[async_trait] -impl CanBuildAckPacketMessage for MockCosmosChain { +impl CanBuildAckPacketMessage> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_ack_packet_message(&self, _packet: &Packet, payload: Any) -> Result { Ok(payload) } } -impl HasTimeoutUnorderedPacketPayload for MockCosmosChain { +impl HasTimeoutUnorderedPacketPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type TimeoutUnorderedPacketPayload = Any; } #[async_trait] -impl CanBuildTimeoutUnorderedPacketPayload for MockCosmosChain { +impl CanBuildTimeoutUnorderedPacketPayload> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_timeout_unordered_packet_payload( &self, _client_state: &Self::ClientState, height: &Self::Height, packet: &Self::IncomingPacket, ) -> Result { - let receipt_path = ReceiptPath::new( - Self::incoming_packet_src_port(packet), - Self::incoming_packet_src_channel_id(packet), - *Self::incoming_packet_sequence(packet), - ); + let receipt_path = + ReceiptPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); - let (_, proof_acked_on_b) = self.query(receipt_path, height).await?; + let (_, proof_acked_on_b) = self.handle.query(receipt_path, height).await?; let ack_packet_payload = MsgTimeout { packet: packet.clone(), @@ -572,7 +687,12 @@ impl CanBuildTimeoutUnorderedPacketPayload for MockCosmosChain } #[async_trait] -impl CanBuildTimeoutUnorderedPacketMessage for MockCosmosChain { +impl CanBuildTimeoutUnorderedPacketMessage> + for MockCosmosContext +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ async fn build_timeout_unordered_packet_message( &self, _packet: &Packet, diff --git a/crates/relayer-cosmos-mock/src/impls/components.rs b/crates/relayer-cosmos-mock/src/impls/components.rs index d691b6a36a..5fae9f5201 100644 --- a/crates/relayer-cosmos-mock/src/impls/components.rs +++ b/crates/relayer-cosmos-mock/src/impls/components.rs @@ -1,4 +1,6 @@ use ibc::core::ics04_channel::packet::Packet; +use ibc_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; +use ibc_relayer_components::chain::traits::types::packet::{HasIbcPacketFields, HasIbcPacketTypes}; use ibc_relayer_components::relay::components::message_senders::chain_sender::SendIbcMessagesToChain; use ibc_relayer_components::relay::components::message_senders::update_client::SendIbcMessagesWithUpdateClient; use ibc_relayer_components::relay::components::update_client::skip::SkipUpdateClient; @@ -16,15 +18,26 @@ use ibc_relayer_components::relay::traits::packet_relayers::ack_packet::AckPacke use ibc_relayer_components::relay::traits::packet_relayers::receive_packet::ReceivePacketRelayerComponnent; use ibc_relayer_components::relay::traits::packet_relayers::timeout_unordered_packet::TimeoutUnorderedPacketRelayerComponent; +use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; use crate::impls::relay::MockCosmosBuildUpdateClientMessage; +use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; pub struct MockCosmosComponents; #[async_trait::async_trait] -impl PacketRelayer for MockCosmosComponents { - async fn relay_packet(_relay: &MockCosmosRelay, _packet: &Packet) -> Result<(), Error> { +impl PacketRelayer> for MockCosmosComponents +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, + MockCosmosContext: HasIbcChainTypes>, + MockCosmosContext: HasIbcPacketFields>, +{ + async fn relay_packet( + _relay: &MockCosmosRelay, + _packet: & as HasIbcPacketTypes>>::OutgoingPacket, + ) -> Result<(), Error> { unimplemented!() } } diff --git a/crates/relayer-cosmos-mock/src/impls/endpoint.rs b/crates/relayer-cosmos-mock/src/impls/endpoint.rs index dc9350d44b..1967a210a5 100644 --- a/crates/relayer-cosmos-mock/src/impls/endpoint.rs +++ b/crates/relayer-cosmos-mock/src/impls/endpoint.rs @@ -1,15 +1,38 @@ -use crate::contexts::chain::MockCosmosChain; +use crate::contexts::chain::MockCosmosContext; use crate::traits::endpoint::Endpoint; +use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; use async_trait::async_trait; use basecoin_app::modules::ibc::AnyConsensusState; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; +use ibc::core::timestamp::Timestamp; use ibc::core::ValidationContext; use ibc::Height; +use tendermint_testgen::light_block::TmLightBlock; #[async_trait] -impl Endpoint for MockCosmosChain { +impl Endpoint for MockCosmosContext { + fn query_current_height(&self) -> Result { + self.ibc_context().host_height().map_err(Error::from) + } + + fn query_current_timestamp(&self) -> Result { + self.ibc_context().host_timestamp().map_err(Error::from) + } + + fn query_light_block(&self, height: &Height) -> Result { + let blocks = self.handle.blocks(); + + let revision_height = height.revision_height() as usize; + + if revision_height > blocks.len() { + return Err(Error::invalid("block index out of bounds")); + } + + Ok(blocks[revision_height - 1].clone()) + } + fn query_host_consensus_state(&self, height: &Height) -> Result { let consensus_state = self.ibc_context().host_consensus_state(height)?; @@ -17,14 +40,4 @@ impl Endpoint for MockCosmosChain { AnyConsensusState::Tendermint(cs) => Ok(cs), } } - - // fn query_consensus_state(&self, client_id: &ClientId) -> Result { - // let current_height = self.get_current_height(); - - // let cons_state_path = ClientConsensusStatePath::new(client_id, ¤t_height); - - // let (value, _) = self.query(cons_state_path, ¤t_height).await?; - // let consensus_state = - // Protobuf::::decode_vec(&value).map_err(BaseError::source)?; - // } } diff --git a/crates/relayer-cosmos-mock/src/impls/mod.rs b/crates/relayer-cosmos-mock/src/impls/mod.rs index e8dec3afbb..74b8c7aa2a 100644 --- a/crates/relayer-cosmos-mock/src/impls/mod.rs +++ b/crates/relayer-cosmos-mock/src/impls/mod.rs @@ -1,7 +1,7 @@ +pub mod basecoin; pub mod birelay; pub mod chain; pub mod components; pub mod endpoint; -pub mod handler; pub mod relay; pub mod runtime; diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index 3fb2bf362a..99add41556 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -22,23 +22,36 @@ use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_runtime::types::error::Error as TokioError; use ibc_relayer_runtime::types::log::logger::TracingLogger; -use crate::contexts::chain::MockCosmosChain; +use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; use crate::contexts::runtime::MockRuntimeContext; use crate::impls::components::MockCosmosComponents; +use crate::traits::endpoint::Endpoint; +use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; use crate::util::dummy::dummy_signer; -use crate::util::mutex::MutexUtil; -impl DelegateComponent for MockCosmosRelay { +impl DelegateComponent for MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type Delegate = MockCosmosComponents; } -impl HasErrorType for MockCosmosRelay { +impl HasErrorType for MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type Error = Error; } -impl HasRuntime for MockCosmosRelay { +impl HasRuntime for MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type Runtime = MockRuntimeContext; fn runtime(&self) -> &Self::Runtime { @@ -50,20 +63,32 @@ impl HasRuntime for MockCosmosRelay { } } -impl HasLoggerType for MockCosmosRelay { +impl HasLoggerType for MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type Logger = TracingLogger; } -impl HasLogger for MockCosmosRelay { +impl HasLogger for MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ fn logger(&self) -> &TracingLogger { &TracingLogger } } -impl HasRelayChains for MockCosmosRelay { - type SrcChain = MockCosmosChain; +impl HasRelayChains for MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ + type SrcChain = MockCosmosContext; - type DstChain = MockCosmosChain; + type DstChain = MockCosmosContext; fn src_chain_error(e: Error) -> Self::Error { e @@ -73,11 +98,11 @@ impl HasRelayChains for MockCosmosRelay { e } - fn src_chain(&self) -> &MockCosmosChain { + fn src_chain(&self) -> &MockCosmosContext { &self.src_chain } - fn dst_chain(&self) -> &MockCosmosChain { + fn dst_chain(&self) -> &MockCosmosContext { &self.dst_chain } @@ -93,11 +118,15 @@ impl HasRelayChains for MockCosmosRelay { pub struct MockCosmosBuildUpdateClientMessage; #[async_trait] -impl UpdateClientMessageBuilder +impl + UpdateClientMessageBuilder, SourceTarget> for MockCosmosBuildUpdateClientMessage +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, { async fn build_update_client_messages( - context: &MockCosmosRelay, + context: &MockCosmosRelay, _target: SourceTarget, height: &Height, ) -> Result, Error> { @@ -110,14 +139,7 @@ impl UpdateClientMessageBuilder .ibc_context() .client_state(&ClientId::default())?; - let revision_height = height.revision_height() as usize; - - let blocks = context.src_chain().blocks.acquire_mutex(); - - if revision_height > blocks.len() { - return Err(Error::invalid("block index out of bounds")); - } - let light_block = blocks[revision_height - 1].clone(); + let light_block = context.src_chain().query_light_block(height)?; let header = Header { signed_header: light_block.signed_header, @@ -137,11 +159,15 @@ impl UpdateClientMessageBuilder } #[async_trait] -impl UpdateClientMessageBuilder +impl + UpdateClientMessageBuilder, DestinationTarget> for MockCosmosBuildUpdateClientMessage +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, { async fn build_update_client_messages( - context: &MockCosmosRelay, + context: &MockCosmosRelay, _target: DestinationTarget, height: &Height, ) -> Result, Error> { @@ -154,15 +180,7 @@ impl UpdateClientMessageBuilder .ibc_context() .client_state(&ClientId::default())?; - let revision_height = height.revision_height() as usize; - - let blocks = context.dst_chain().blocks.acquire_mutex(); - - if revision_height > blocks.len() { - return Err(Error::invalid("block index out of bounds")); - } - - let light_block = blocks[revision_height - 1].clone(); + let light_block = context.dst_chain().query_light_block(height)?; let header = Header { signed_header: light_block.signed_header, @@ -182,7 +200,11 @@ impl UpdateClientMessageBuilder } #[async_trait] -impl HasPacketLock for MockCosmosRelay { +impl HasPacketLock for MockCosmosRelay +where + SrcChain: BasecoinHandle, + DstChain: BasecoinHandle, +{ type PacketLock<'a> = (); async fn try_acquire_packet_lock<'a>(&'a self, _packet: &'a Packet) -> Option<()> { diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs index 8797533aee..cf3cc227e0 100644 --- a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -1,61 +1,60 @@ +use basecoin_store::impls::InMemoryStore; use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientPayload; use ibc_relayer_components::relay::traits::target::SourceTarget; use ibc_relayer_components::relay::traits::update_client::CanBuildUpdateClientMessage; -use crate::tests::init::init_binary_stand; -use crate::traits::handler::ChainHandler; +use crate::contexts::basecoin::MockBasecoin; +use crate::contexts::chain::MockCosmosContext; +use crate::tests::init::binary_mock_basecoin_stand; use crate::types::error::Error; #[tokio::test] async fn test_create_client() -> Result<(), Error> { - let builder = init_binary_stand(); + let (src_chain_ctx, dst_chain_ctx, _) = binary_mock_basecoin_stand(); - tokio::time::sleep(tokio::time::Duration::from_millis(150)).await; + tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; - let msg_create_client = builder.chains[0].build_create_client_payload(&()).await?; - - builder.chains[1] - .submit_messages(vec![msg_create_client]) + let msg_create_client = + > as CanBuildCreateClientPayload< + MockCosmosContext>, + >>::build_create_client_payload(&src_chain_ctx, &()) .await?; - assert!(builder.chains[1] + dst_chain_ctx.submit_messages(vec![msg_create_client])?; + + assert!(dst_chain_ctx .ibc_context() .client_state(&ClientId::default()) .is_ok()); - builder.stop(); - Ok(()) } #[tokio::test] async fn test_update_client() -> Result<(), Error> { - let builder = init_binary_stand(); - - tokio::time::sleep(tokio::time::Duration::from_millis(150)).await; + let (src_chain_ctx, dst_chain_ctx, relayer) = binary_mock_basecoin_stand(); - let msg_create_client = builder.chains[0].build_create_client_payload(&()).await?; + tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; - builder.chains[1] - .submit_messages(vec![msg_create_client]) + let msg_create_client = + > as CanBuildCreateClientPayload< + MockCosmosContext>, + >>::build_create_client_payload(&src_chain_ctx, &()) .await?; - tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; + dst_chain_ctx.submit_messages(vec![msg_create_client])?; - let src_current_height = builder.chains[0].get_current_height(); + tokio::time::sleep(tokio::time::Duration::from_millis(200)).await; - let msg_update_client = builder.relayers[0] - .build_update_client_messages(SourceTarget, &src_current_height) - .await?; + let src_current_height = src_chain_ctx.get_current_height(); - builder.relayers[0] - .dst_chain() - .submit_messages(msg_update_client) + let msg_update_client = relayer + .build_update_client_messages(SourceTarget, &src_current_height) .await?; - builder.stop(); + relayer.dst_chain().submit_messages(msg_update_client)?; Ok(()) } diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index 28473d9738..4bd1903380 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -1,18 +1,37 @@ +use basecoin_store::impls::InMemoryStore; use ibc::core::ics24_host::identifier::ChainId; use std::str::FromStr; +use std::sync::Arc; -use crate::contexts::builder::MockCosmosBuilder; +use crate::contexts::basecoin::MockBasecoin; +use crate::contexts::chain::MockCosmosContext; +use crate::contexts::relay::MockCosmosRelay; +use crate::contexts::runtime::MockClock; -pub fn init_binary_stand() -> MockCosmosBuilder { - let mut builder = MockCosmosBuilder::new_default(); +pub fn binary_mock_basecoin_stand() -> ( + Arc>>, + Arc>>, + MockCosmosRelay, MockBasecoin>, +) { + let clock = Arc::new(MockClock::default()); - let src_chain = builder.build_chain(ChainId::from_str("mock-cosmos-chain-0").unwrap()); + // Source chain setup + let src_chain_id = ChainId::from_str("mock-cosmos-chain-0").unwrap(); + let src_chain = Arc::new(MockBasecoin::new(src_chain_id, InMemoryStore::default())); + src_chain.spawn(); + let src_chain_ctx = Arc::new(MockCosmosContext::new(src_chain, clock.clone())); + src_chain_ctx.subscribe(); - let dst_chain = builder.build_chain(ChainId::from_str("mock-cosmos-chain-1").unwrap()); + // Destination chain setup + let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").unwrap(); + let dst_chain = Arc::new(MockBasecoin::new(dst_chain_id, InMemoryStore::default())); + dst_chain.spawn(); + let dst_chain_ctx = Arc::new(MockCosmosContext::new(dst_chain, clock.clone())); + dst_chain_ctx.subscribe(); - builder.build_relayer(src_chain, dst_chain); + // Relayer setup + let relayer = MockCosmosRelay::new(src_chain_ctx.clone(), dst_chain_ctx.clone(), clock) + .expect("failed to build relayer"); - builder.spawn_chains(); - - builder + (src_chain_ctx, dst_chain_ctx, relayer) } diff --git a/crates/relayer-cosmos-mock/src/traits/endpoint.rs b/crates/relayer-cosmos-mock/src/traits/endpoint.rs index 54e546a294..bac3521a60 100644 --- a/crates/relayer-cosmos-mock/src/traits/endpoint.rs +++ b/crates/relayer-cosmos-mock/src/traits/endpoint.rs @@ -1,9 +1,17 @@ use crate::types::error::Error; use async_trait::async_trait; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; +use ibc::core::timestamp::Timestamp; use ibc::Height; +use tendermint_testgen::light_block::TmLightBlock; #[async_trait] pub trait Endpoint { + fn query_current_height(&self) -> Result; + + fn query_current_timestamp(&self) -> Result; + + fn query_light_block(&self, height: &Height) -> Result; + fn query_host_consensus_state(&self, height: &Height) -> Result; } diff --git a/crates/relayer-cosmos-mock/src/traits/handle.rs b/crates/relayer-cosmos-mock/src/traits/handle.rs new file mode 100644 index 0000000000..dbcb3b0d46 --- /dev/null +++ b/crates/relayer-cosmos-mock/src/traits/handle.rs @@ -0,0 +1,41 @@ +use async_trait::async_trait; +use std::fmt::Debug; + +use basecoin_app::modules::ibc::Ibc; +use basecoin_store::context::ProvableStore; +use basecoin_store::impls::RevertibleStore; +use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; +use ibc::core::ics24_host::identifier::ChainId; +use ibc::core::ics24_host::path::Path; +use ibc::Height; +use ibc_relayer_components::core::traits::sync::Async; +use tendermint_testgen::light_block::TmLightBlock; + +use crate::types::error::Error; + +#[async_trait] +pub trait BasecoinHandle: Async + Clone { + type Store: ProvableStore + Debug; + + fn chain_id(&self) -> &ChainId; + + fn ibc(&self) -> Ibc>; + + fn blocks(&self) -> Vec; + + fn grow_blocks(&self); + + async fn init(&self); + + async fn begin_block(&self); + + async fn commit(&self); + + async fn run(&self); + + async fn query( + &self, + path: impl Into + Send, + height: &Height, + ) -> Result<(Vec, CommitmentProofBytes), Error>; +} diff --git a/crates/relayer-cosmos-mock/src/traits/handler.rs b/crates/relayer-cosmos-mock/src/traits/handler.rs deleted file mode 100644 index 335101e7c5..0000000000 --- a/crates/relayer-cosmos-mock/src/traits/handler.rs +++ /dev/null @@ -1,27 +0,0 @@ -use async_trait::async_trait; -use ibc::core::events::IbcEvent; -use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; -use ibc::core::ics24_host::path::Path; -use ibc::Any; -use ibc::Height; - -use crate::types::error::Error; - -#[async_trait] -pub trait ChainHandler { - async fn init(&self); - - async fn begin_block(&self); - - async fn commit(&self); - - async fn run(&self); - - async fn submit_messages(&self, msgs: Vec) -> Result>, Error>; - - async fn query( - &self, - path: impl Into + Send, - height: &Height, - ) -> Result<(Vec, CommitmentProofBytes), Error>; -} diff --git a/crates/relayer-cosmos-mock/src/traits/mod.rs b/crates/relayer-cosmos-mock/src/traits/mod.rs index 9a520d1b61..56431f6577 100644 --- a/crates/relayer-cosmos-mock/src/traits/mod.rs +++ b/crates/relayer-cosmos-mock/src/traits/mod.rs @@ -1,2 +1,2 @@ pub mod endpoint; -pub mod handler; +pub mod handle; From ff40564123c5f64e8647ea911eb6950a203e1747 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 28 Aug 2023 13:10:30 -0700 Subject: [PATCH 08/25] imp: separate chain handles from endpoints --- .../src/contexts/basecoin.rs | 4 +- .../src/contexts/birelay.rs | 6 +- .../relayer-cosmos-mock/src/contexts/chain.rs | 34 ++-- .../relayer-cosmos-mock/src/contexts/relay.rs | 17 +- .../relayer-cosmos-mock/src/impls/basecoin.rs | 77 +++++--- .../relayer-cosmos-mock/src/impls/birelay.rs | 14 +- crates/relayer-cosmos-mock/src/impls/chain.rs | 183 ++++++++++-------- .../src/impls/components.rs | 14 +- .../relayer-cosmos-mock/src/impls/endpoint.rs | 43 ---- crates/relayer-cosmos-mock/src/impls/mod.rs | 1 - crates/relayer-cosmos-mock/src/impls/relay.rs | 43 ++-- .../src/tests/ics02_client.rs | 14 +- crates/relayer-cosmos-mock/src/tests/init.rs | 8 +- .../src/traits/endpoint.rs | 73 ++++++- .../relayer-cosmos-mock/src/traits/handle.rs | 31 +-- 15 files changed, 290 insertions(+), 272 deletions(-) delete mode 100644 crates/relayer-cosmos-mock/src/impls/endpoint.rs diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index e27ebeb3f2..d621a6c8bb 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -19,7 +19,7 @@ use crate::traits::handle::BasecoinHandle; #[derive(Clone)] pub struct MockBasecoin where - S: ProvableStore + Default + Debug, + S: ProvableStore + Debug, { /// Chain identifier pub chain_id: ChainId, @@ -59,7 +59,7 @@ impl MockBasecoin { } } - pub fn spawn(&self) -> JoinHandle<()> { + pub fn start(&self) -> JoinHandle<()> { let chain = self.clone(); tokio::spawn(async move { diff --git a/crates/relayer-cosmos-mock/src/contexts/birelay.rs b/crates/relayer-cosmos-mock/src/contexts/birelay.rs index 1bbac80bdb..dc86b3eb2d 100644 --- a/crates/relayer-cosmos-mock/src/contexts/birelay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/birelay.rs @@ -2,15 +2,15 @@ use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use std::sync::Arc; use super::relay::MockCosmosRelay; -use crate::traits::handle::BasecoinHandle; +use crate::traits::endpoint::BasecoinEndpoint; -pub struct MockCosmosBiRelay { +pub struct MockCosmosBiRelay { pub runtime: TokioRuntimeContext, pub relay_a_to_b: Arc>, pub relay_b_to_a: Arc>, } -impl MockCosmosBiRelay { +impl MockCosmosBiRelay { pub fn new( runtime: TokioRuntimeContext, relay_a_to_b: Arc>, diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 4d8311c15f..91c73e1e15 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -2,6 +2,7 @@ use basecoin_app::modules::ibc::IbcContext; use basecoin_store::impls::RevertibleStore; use ibc::core::events::IbcEvent; use ibc::core::timestamp::Timestamp; +use ibc::core::ValidationContext; use ibc::Any; use ibc::Height; @@ -10,34 +11,33 @@ use std::sync::Mutex; use super::runtime::MockClock; use crate::contexts::runtime::MockRuntimeContext; -use crate::traits::endpoint::Endpoint; -use crate::traits::handle::BasecoinHandle; +use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::mutex::MutexUtil; #[derive(Clone)] -pub struct MockCosmosContext { +pub struct MockCosmosContext { /// Chain handle - pub handle: Arc, + pub querier: Arc, /// Current chain status pub current_status: Arc>, /// Chain runtime pub runtime: MockRuntimeContext, } -impl MockCosmosContext { +impl MockCosmosContext { /// Constructs a new mock cosmos chain instance. - pub fn new(handle: Arc, clock: Arc) -> Self { + pub fn new(querier: Arc, clock: Arc) -> Self { let runtime = MockRuntimeContext::new(clock.clone()); let current_status = Arc::new(Mutex::new(ChainStatus::new( - Height::new(handle.chain_id().revision_number(), 1).expect("never fails"), + Height::new(querier.get_chain_id().revision_number(), 1).expect("never fails"), clock.get_timestamp(), ))); Self { - handle, + querier, current_status, runtime, } @@ -47,8 +47,10 @@ impl MockCosmosContext { &self.runtime } - pub fn ibc_context(&self) -> IbcContext::Store>> { - self.handle.ibc().ctx() + pub fn ibc_context( + &self, + ) -> IbcContext::Store>> { + self.ibc().ctx() } pub fn get_current_timestamp(&self) -> Timestamp { @@ -66,10 +68,10 @@ impl MockCosmosContext { loop { tokio::time::sleep(tokio::time::Duration::from_millis(200)).await; - if ctx.handle.blocks().len() > blocks_len { - let current_time = ctx.query_current_timestamp().unwrap(); + if ctx.get_blocks().len() > blocks_len { + let current_time = ctx.ibc_context().host_timestamp().unwrap(); - let current_height = ctx.query_current_height().unwrap(); + let current_height = ctx.ibc_context().host_height().unwrap(); ctx.runtime.clock.set_timestamp(current_time); @@ -79,7 +81,7 @@ impl MockCosmosContext { *last_status = current_status; - blocks_len = ctx.handle.blocks().len(); + blocks_len = ctx.get_blocks().len(); } } }); @@ -88,8 +90,10 @@ impl MockCosmosContext { pub fn submit_messages(&self, msgs: Vec) -> Result>, Error> { let mut events = Vec::new(); + self.ibc_context().host_height()?; + for msg in msgs { - let ibc_events = self.handle.ibc().process_message(msg)?; + let ibc_events = self.ibc().process_message(msg)?; events.push(ibc_events); } diff --git a/crates/relayer-cosmos-mock/src/contexts/relay.rs b/crates/relayer-cosmos-mock/src/contexts/relay.rs index 7b5a1fb94b..1fb3154c20 100644 --- a/crates/relayer-cosmos-mock/src/contexts/relay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/relay.rs @@ -5,7 +5,7 @@ use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket; use std::sync::Arc; use tokio::task::JoinHandle; -use crate::traits::handle::BasecoinHandle; +use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use crate::util::msgs::build_transfer_packet; @@ -13,7 +13,11 @@ use super::chain::MockCosmosContext; use super::runtime::{MockClock, MockRuntimeContext}; #[derive(Clone)] -pub struct MockCosmosRelay { +pub struct MockCosmosRelay +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ pub src_chain: Arc>, pub dst_chain: Arc>, pub src_client_id: ClientId, @@ -23,8 +27,8 @@ pub struct MockCosmosRelay { impl MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { pub fn new( src_chain: Arc>, @@ -72,7 +76,10 @@ where let relayer = self.clone(); tokio::spawn(async move { - relayer.relay_packet(&packet).await.unwrap(); + relayer + .relay_packet(&packet) + .await + .expect("failed to relay packet"); }) } } diff --git a/crates/relayer-cosmos-mock/src/impls/basecoin.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs index c75438ec75..55a7777014 100644 --- a/crates/relayer-cosmos-mock/src/impls/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -1,4 +1,5 @@ use crate::contexts::basecoin::MockBasecoin; +use crate::traits::endpoint::BasecoinEndpoint; use crate::traits::handle::BasecoinHandle; use crate::types::error::Error; use crate::util::conversion::convert_tm_to_ics_merkle_proof; @@ -41,36 +42,6 @@ where { type Store = S; - fn chain_id(&self) -> &ChainId { - &self.chain_id - } - - fn ibc(&self) -> Ibc> { - self.app.ibc() - } - - fn blocks(&self) -> Vec { - self.blocks.acquire_mutex().clone() - } - - fn grow_blocks(&self) { - let mut blocks = self.blocks.acquire_mutex(); - - let height = blocks.len() as u64 + 1; - - let current_time = Time::now(); - - let tm_light_block = LightBlock::new_default_with_time_and_chain_id( - self.chain_id.to_string(), - current_time, - height, - ) - .generate() - .expect("failed to generate light block"); - - blocks.push(tm_light_block); - } - /// Initialize the chain with the app state. async fn init(&self) { let app_state = serde_json::to_vec(&genesis_app_state()).expect("infallible serialization"); @@ -107,6 +78,24 @@ where } } + fn grow_blocks(&self) { + let mut blocks = self.blocks.acquire_mutex(); + + let height = blocks.len() as u64 + 1; + + let current_time = Time::now(); + + let tm_light_block = LightBlock::new_default_with_time_and_chain_id( + self.chain_id.to_string(), + current_time, + height, + ) + .generate() + .expect("failed to generate light block"); + + blocks.push(tm_light_block); + } + /// Commits the chain state. async fn commit(&self) { let mut modules = self.app.modules.write_access(); @@ -142,7 +131,11 @@ where self.commit().await; } } +} +#[async_trait] +impl BasecoinEndpoint for MockBasecoin { + type Store = S; /// Queries the mock chain for the given path and height. async fn query( &self, @@ -178,4 +171,28 @@ where Ok((response.value.into(), commitment_proof)) } + + fn ibc(&self) -> Ibc> { + self.app.ibc() + } + + fn get_chain_id(&self) -> &ChainId { + &self.chain_id + } + + fn get_blocks(&self) -> Vec { + self.blocks.acquire_mutex().clone() + } + + fn get_light_block(&self, height: &Height) -> Result { + let blocks = self.get_blocks(); + + let revision_height = height.revision_height() as usize; + + if revision_height > blocks.len() { + return Err(Error::invalid("block index out of bounds")); + } + + Ok(blocks[revision_height - 1].clone()) + } } diff --git a/crates/relayer-cosmos-mock/src/impls/birelay.rs b/crates/relayer-cosmos-mock/src/impls/birelay.rs index da0af43243..8bd94889aa 100644 --- a/crates/relayer-cosmos-mock/src/impls/birelay.rs +++ b/crates/relayer-cosmos-mock/src/impls/birelay.rs @@ -1,14 +1,11 @@ -use ibc_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; -use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketFields; use ibc_relayer_components::core::traits::error::HasErrorType; use ibc_relayer_components::relay::traits::two_way::HasTwoWayRelay; -use crate::contexts::chain::MockCosmosContext; use crate::contexts::{birelay::MockCosmosBiRelay, relay::MockCosmosRelay}; -use crate::traits::handle::BasecoinHandle; +use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; -impl HasErrorType +impl HasErrorType for MockCosmosBiRelay { type Error = Error; @@ -16,11 +13,8 @@ impl HasErrorType impl HasTwoWayRelay for MockCosmosBiRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, - MockCosmosContext: HasIbcPacketFields>, - MockCosmosContext: HasIbcPacketFields>, - MockCosmosContext: HasIbcChainTypes>, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type RelayAToB = MockCosmosRelay; diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index fdcf101562..438a9ba872 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -1,7 +1,9 @@ +use std::sync::Arc; use std::time::Duration; use async_trait::async_trait; +use basecoin_app::modules::ibc::AnyConsensusState; use ibc::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState as TmClientState}; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use ibc::core::events::IbcEvent; @@ -68,17 +70,16 @@ use ibc_relayer_runtime::types::log::value::LogValue; use crate::contexts::chain::MockCosmosContext; use crate::contexts::runtime::MockRuntimeContext; -use crate::traits::endpoint::Endpoint; -use crate::traits::handle::BasecoinHandle; +use crate::traits::endpoint::{BasecoinEndpoint, QueryService}; use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::dummy::dummy_signer; -impl HasErrorType for MockCosmosContext { +impl HasErrorType for MockCosmosContext { type Error = Error; } -impl HasRuntime for MockCosmosContext { +impl HasRuntime for MockCosmosContext { type Runtime = MockRuntimeContext; fn runtime(&self) -> &Self::Runtime { @@ -90,53 +91,53 @@ impl HasRuntime for MockCosmosContext { } } -impl HasLoggerType for MockCosmosContext { +impl HasLoggerType for MockCosmosContext { type Logger = TracingLogger; } -impl HasLogger for MockCosmosContext { +impl HasLogger for MockCosmosContext { fn logger(&self) -> &TracingLogger { &TracingLogger } } -impl HasChainIdType for MockCosmosContext { +impl HasChainIdType for MockCosmosContext { type ChainId = ChainId; } -impl HasChainId for MockCosmosContext { +impl HasChainId for MockCosmosContext { fn chain_id(&self) -> &Self::ChainId { - &self.handle.chain_id() + self.get_chain_id() } } -impl HasHeightType for MockCosmosContext { +impl HasHeightType for MockCosmosContext { type Height = Height; } -impl HasEventType for MockCosmosContext { +impl HasEventType for MockCosmosContext { type Event = IbcEvent; } -impl CanLogChainEvent for MockCosmosContext { +impl CanLogChainEvent for MockCosmosContext { fn log_event<'a>(event: &Self::Event) -> LogValue<'_> { LogValue::Debug(event) } } -impl HasTimestampType for MockCosmosContext { +impl HasTimestampType for MockCosmosContext { type Timestamp = Timestamp; } -impl HasMessageType for MockCosmosContext { +impl HasMessageType for MockCosmosContext { type Message = Any; } impl HasIbcChainTypes> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type ClientId = ClientId; @@ -152,8 +153,8 @@ where impl HasIbcPacketTypes> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type IncomingPacket = Packet; @@ -163,8 +164,8 @@ where impl CanLogChainPacket> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { fn log_incoming_packet(packet: &Packet) -> LogValue<'_> { LogValue::Display(packet) @@ -178,8 +179,8 @@ where impl HasIbcPacketFields> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { fn incoming_packet_src_channel_id(packet: &Self::IncomingPacket) -> &Self::ChannelId { &packet.chan_id_on_a @@ -247,8 +248,8 @@ where impl HasConsensusStateType> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type ConsensusState = TmConsensusState; } @@ -256,13 +257,13 @@ where impl HasClientStateType> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type ClientState = TmClientState; } -impl HasChainStatusType for MockCosmosContext { +impl HasChainStatusType for MockCosmosContext { type ChainStatus = ChainStatus; fn chain_status_height(status: &Self::ChainStatus) -> &Self::Height { @@ -275,7 +276,7 @@ impl HasChainStatusType for MockCosmosContext { } #[async_trait] -impl CanQueryChainStatus for MockCosmosContext { +impl CanQueryChainStatus for MockCosmosContext { async fn query_chain_status(&self) -> Result { Ok(self.current_status.lock().unwrap().clone()) } @@ -284,8 +285,8 @@ impl CanQueryChainStatus for MockCosmosContext { impl HasCreateClientOptions> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type CreateClientPayloadOptions = (); } @@ -293,8 +294,8 @@ where impl HasCreateClientPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type CreateClientPayload = Any; } @@ -302,8 +303,8 @@ where impl HasCreateClientEvent> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type CreateClientEvent = CreateClient; @@ -323,15 +324,15 @@ where impl CanBuildCreateClientPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_create_client_payload( &self, _create_client_options: &Self::CreateClientPayloadOptions, ) -> Result { let tm_client_state = TmClientState::new( - self.handle.chain_id().clone(), + self.get_chain_id().clone(), Default::default(), Duration::from_secs(64000), Duration::from_secs(128000), @@ -347,7 +348,9 @@ where let current_height = self.get_current_height(); - let tm_consensus_state = self.query_host_consensus_state(¤t_height)?; + let any_consensus_state = self.ibc_context().host_consensus_state(¤t_height)?; + + let AnyConsensusState::Tendermint(tm_consensus_state) = any_consensus_state; let msg_create_client = MsgCreateClient { client_state: tm_client_state.into(), @@ -363,8 +366,8 @@ where impl CanBuildCreateClientMessage> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_create_client_message( &self, @@ -377,8 +380,8 @@ where impl HasSendPacketEvent> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type SendPacketEvent = SendPacket; @@ -405,13 +408,13 @@ where } } -impl CanIncrementHeight for MockCosmosContext { +impl CanIncrementHeight for MockCosmosContext { fn increment_height(height: &Self::Height) -> Result { Ok(height.increment()) } } -impl CanEstimateMessageSize for MockCosmosContext { +impl CanEstimateMessageSize for MockCosmosContext { fn estimate_message_size(_message: &Self::Message) -> Result { // Only single messages are sent by the Mock Chain Ok(1) @@ -419,7 +422,7 @@ impl CanEstimateMessageSize for MockCosmosContext } #[async_trait] -impl CanSendMessages for MockCosmosContext { +impl CanSendMessages for MockCosmosContext { async fn send_messages( &self, messages: Vec, @@ -431,8 +434,8 @@ impl CanSendMessages for MockCosmosContext { impl HasCounterpartyMessageHeight> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { fn counterparty_message_height_for_update_client(_message: &Any) -> Option { None @@ -443,8 +446,8 @@ where impl CanQueryConsensusState> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn query_consensus_state( &self, @@ -453,7 +456,7 @@ where ) -> Result { let path = ClientConsensusStatePath::new(client_id, height); - let any_cons_state = self.ibc_context().consensus_state(&path)?; + let any_cons_state: AnyConsensusState = self.ibc_context().consensus_state(&path)?; let tm_consensus_state = TmConsensusState::try_from(any_cons_state).map_err(Error::source)?; @@ -466,8 +469,8 @@ where impl CanQueryReceivedPacket> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn query_is_packet_received( &self, @@ -486,8 +489,8 @@ where impl HasReceivePacketPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type ReceivePacketPayload = Any; } @@ -496,8 +499,8 @@ where impl CanBuildReceivePacketPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_receive_packet_payload( &self, @@ -508,7 +511,7 @@ where let receipt_path = ReceiptPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); - let (_, proof_commitment_on_a) = self.handle.query(receipt_path, height).await?; + let (_, proof_commitment_on_a) = self.query(receipt_path, height).await?; let recv_packet_payload = MsgRecvPacket { packet: packet.clone(), @@ -525,8 +528,8 @@ where impl CanBuildReceivePacketMessage> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_receive_packet_message( &self, @@ -541,8 +544,8 @@ where impl CanQueryWriteAcknowledgement> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn query_write_acknowledgement_event( &self, @@ -561,16 +564,13 @@ where let events = self.ibc_context().events(); for e in events { - match e { - IbcEvent::WriteAcknowledgement(e) => { - if e.port_id_on_a() == &port_id - && e.chan_id_on_a() == &chan_id - && e.seq_on_a() == &packet.seq_on_a - { - return Ok(Some(e)); - } + if let IbcEvent::WriteAcknowledgement(e) = e { + if e.port_id_on_a() == &port_id + && e.chan_id_on_a() == &chan_id + && e.seq_on_a() == &packet.seq_on_a + { + return Ok(Some(e)); } - _ => {} } } @@ -581,8 +581,8 @@ where impl HasWriteAcknowledgementEvent> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type WriteAcknowledgementEvent = WriteAcknowledgement; @@ -599,8 +599,8 @@ where impl HasAckPacketPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type AckPacketPayload = Any; } @@ -609,8 +609,8 @@ where impl CanBuildAckPacketPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_ack_packet_payload( &self, @@ -621,7 +621,7 @@ where ) -> Result { let ack_path = AckPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); - let (_, proof_acked_on_b) = self.handle.query(ack_path, height).await?; + let (_, proof_acked_on_b) = self.query(ack_path, height).await?; let ack_packet_payload = MsgAcknowledgement { packet: packet.clone(), @@ -639,8 +639,8 @@ where impl CanBuildAckPacketMessage> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_ack_packet_message(&self, _packet: &Packet, payload: Any) -> Result { Ok(payload) @@ -650,8 +650,8 @@ where impl HasTimeoutUnorderedPacketPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type TimeoutUnorderedPacketPayload = Any; } @@ -660,8 +660,8 @@ where impl CanBuildTimeoutUnorderedPacketPayload> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_timeout_unordered_packet_payload( &self, @@ -672,7 +672,7 @@ where let receipt_path = ReceiptPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); - let (_, proof_acked_on_b) = self.handle.query(receipt_path, height).await?; + let (_, proof_acked_on_b) = self.query(receipt_path, height).await?; let ack_packet_payload = MsgTimeout { packet: packet.clone(), @@ -690,8 +690,8 @@ where impl CanBuildTimeoutUnorderedPacketMessage> for MockCosmosContext where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_timeout_unordered_packet_message( &self, @@ -701,3 +701,14 @@ where Ok(payload) } } + +impl QueryService for MockCosmosContext +where + Endpoint: BasecoinEndpoint, +{ + type Endpoint = Endpoint; + + fn service(&self) -> &Arc { + &self.querier + } +} diff --git a/crates/relayer-cosmos-mock/src/impls/components.rs b/crates/relayer-cosmos-mock/src/impls/components.rs index 5fae9f5201..75131e7144 100644 --- a/crates/relayer-cosmos-mock/src/impls/components.rs +++ b/crates/relayer-cosmos-mock/src/impls/components.rs @@ -1,6 +1,5 @@ use ibc::core::ics04_channel::packet::Packet; -use ibc_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; -use ibc_relayer_components::chain::traits::types::packet::{HasIbcPacketFields, HasIbcPacketTypes}; +use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketTypes; use ibc_relayer_components::relay::components::message_senders::chain_sender::SendIbcMessagesToChain; use ibc_relayer_components::relay::components::message_senders::update_client::SendIbcMessagesWithUpdateClient; use ibc_relayer_components::relay::components::update_client::skip::SkipUpdateClient; @@ -18,10 +17,9 @@ use ibc_relayer_components::relay::traits::packet_relayers::ack_packet::AckPacke use ibc_relayer_components::relay::traits::packet_relayers::receive_packet::ReceivePacketRelayerComponnent; use ibc_relayer_components::relay::traits::packet_relayers::timeout_unordered_packet::TimeoutUnorderedPacketRelayerComponent; -use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; use crate::impls::relay::MockCosmosBuildUpdateClientMessage; -use crate::traits::handle::BasecoinHandle; +use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; pub struct MockCosmosComponents; @@ -29,14 +27,12 @@ pub struct MockCosmosComponents; #[async_trait::async_trait] impl PacketRelayer> for MockCosmosComponents where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, - MockCosmosContext: HasIbcChainTypes>, - MockCosmosContext: HasIbcPacketFields>, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn relay_packet( _relay: &MockCosmosRelay, - _packet: & as HasIbcPacketTypes>>::OutgoingPacket, + _packet: &Packet, ) -> Result<(), Error> { unimplemented!() } diff --git a/crates/relayer-cosmos-mock/src/impls/endpoint.rs b/crates/relayer-cosmos-mock/src/impls/endpoint.rs deleted file mode 100644 index 1967a210a5..0000000000 --- a/crates/relayer-cosmos-mock/src/impls/endpoint.rs +++ /dev/null @@ -1,43 +0,0 @@ -use crate::contexts::chain::MockCosmosContext; -use crate::traits::endpoint::Endpoint; -use crate::traits::handle::BasecoinHandle; -use crate::types::error::Error; - -use async_trait::async_trait; -use basecoin_app::modules::ibc::AnyConsensusState; -use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; -use ibc::core::timestamp::Timestamp; -use ibc::core::ValidationContext; -use ibc::Height; -use tendermint_testgen::light_block::TmLightBlock; - -#[async_trait] -impl Endpoint for MockCosmosContext { - fn query_current_height(&self) -> Result { - self.ibc_context().host_height().map_err(Error::from) - } - - fn query_current_timestamp(&self) -> Result { - self.ibc_context().host_timestamp().map_err(Error::from) - } - - fn query_light_block(&self, height: &Height) -> Result { - let blocks = self.handle.blocks(); - - let revision_height = height.revision_height() as usize; - - if revision_height > blocks.len() { - return Err(Error::invalid("block index out of bounds")); - } - - Ok(blocks[revision_height - 1].clone()) - } - - fn query_host_consensus_state(&self, height: &Height) -> Result { - let consensus_state = self.ibc_context().host_consensus_state(height)?; - - match consensus_state { - AnyConsensusState::Tendermint(cs) => Ok(cs), - } - } -} diff --git a/crates/relayer-cosmos-mock/src/impls/mod.rs b/crates/relayer-cosmos-mock/src/impls/mod.rs index 74b8c7aa2a..7d328d08a3 100644 --- a/crates/relayer-cosmos-mock/src/impls/mod.rs +++ b/crates/relayer-cosmos-mock/src/impls/mod.rs @@ -2,6 +2,5 @@ pub mod basecoin; pub mod birelay; pub mod chain; pub mod components; -pub mod endpoint; pub mod relay; pub mod runtime; diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index 99add41556..17048bf271 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -26,31 +26,30 @@ use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; use crate::contexts::runtime::MockRuntimeContext; use crate::impls::components::MockCosmosComponents; -use crate::traits::endpoint::Endpoint; -use crate::traits::handle::BasecoinHandle; +use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use crate::util::dummy::dummy_signer; impl DelegateComponent for MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type Delegate = MockCosmosComponents; } impl HasErrorType for MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type Error = Error; } impl HasRuntime for MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type Runtime = MockRuntimeContext; @@ -65,16 +64,16 @@ where impl HasLoggerType for MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type Logger = TracingLogger; } impl HasLogger for MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { fn logger(&self) -> &TracingLogger { &TracingLogger @@ -83,8 +82,8 @@ where impl HasRelayChains for MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type SrcChain = MockCosmosContext; @@ -122,8 +121,8 @@ impl UpdateClientMessageBuilder, SourceTarget> for MockCosmosBuildUpdateClientMessage where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_update_client_messages( context: &MockCosmosRelay, @@ -139,7 +138,7 @@ where .ibc_context() .client_state(&ClientId::default())?; - let light_block = context.src_chain().query_light_block(height)?; + let light_block = context.src_chain().get_light_block(height)?; let header = Header { signed_header: light_block.signed_header, @@ -163,8 +162,8 @@ impl UpdateClientMessageBuilder, DestinationTarget> for MockCosmosBuildUpdateClientMessage where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { async fn build_update_client_messages( context: &MockCosmosRelay, @@ -180,7 +179,7 @@ where .ibc_context() .client_state(&ClientId::default())?; - let light_block = context.dst_chain().query_light_block(height)?; + let light_block = context.dst_chain().get_light_block(height)?; let header = Header { signed_header: light_block.signed_header, @@ -202,8 +201,8 @@ where #[async_trait] impl HasPacketLock for MockCosmosRelay where - SrcChain: BasecoinHandle, - DstChain: BasecoinHandle, + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type PacketLock<'a> = (); diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs index cf3cc227e0..a5c83eb36d 100644 --- a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -1,3 +1,8 @@ +use crate::contexts::basecoin::MockBasecoin; +use crate::contexts::chain::MockCosmosContext; +use crate::tests::init::mock_basecoin_binary_stand; +use crate::types::error::Error; + use basecoin_store::impls::InMemoryStore; use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; @@ -5,14 +10,9 @@ use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientP use ibc_relayer_components::relay::traits::target::SourceTarget; use ibc_relayer_components::relay::traits::update_client::CanBuildUpdateClientMessage; -use crate::contexts::basecoin::MockBasecoin; -use crate::contexts::chain::MockCosmosContext; -use crate::tests::init::binary_mock_basecoin_stand; -use crate::types::error::Error; - #[tokio::test] async fn test_create_client() -> Result<(), Error> { - let (src_chain_ctx, dst_chain_ctx, _) = binary_mock_basecoin_stand(); + let (src_chain_ctx, dst_chain_ctx, _) = mock_basecoin_binary_stand(); tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; @@ -34,7 +34,7 @@ async fn test_create_client() -> Result<(), Error> { #[tokio::test] async fn test_update_client() -> Result<(), Error> { - let (src_chain_ctx, dst_chain_ctx, relayer) = binary_mock_basecoin_stand(); + let (src_chain_ctx, dst_chain_ctx, relayer) = mock_basecoin_binary_stand(); tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index 4bd1903380..4755f5c09f 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -8,7 +8,7 @@ use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; use crate::contexts::runtime::MockClock; -pub fn binary_mock_basecoin_stand() -> ( +pub fn mock_basecoin_binary_stand() -> ( Arc>>, Arc>>, MockCosmosRelay, MockBasecoin>, @@ -18,14 +18,16 @@ pub fn binary_mock_basecoin_stand() -> ( // Source chain setup let src_chain_id = ChainId::from_str("mock-cosmos-chain-0").unwrap(); let src_chain = Arc::new(MockBasecoin::new(src_chain_id, InMemoryStore::default())); - src_chain.spawn(); + src_chain.start(); + let src_chain_ctx = Arc::new(MockCosmosContext::new(src_chain, clock.clone())); src_chain_ctx.subscribe(); // Destination chain setup let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").unwrap(); let dst_chain = Arc::new(MockBasecoin::new(dst_chain_id, InMemoryStore::default())); - dst_chain.spawn(); + dst_chain.start(); + let dst_chain_ctx = Arc::new(MockCosmosContext::new(dst_chain, clock.clone())); dst_chain_ctx.subscribe(); diff --git a/crates/relayer-cosmos-mock/src/traits/endpoint.rs b/crates/relayer-cosmos-mock/src/traits/endpoint.rs index bac3521a60..1cf68d6e11 100644 --- a/crates/relayer-cosmos-mock/src/traits/endpoint.rs +++ b/crates/relayer-cosmos-mock/src/traits/endpoint.rs @@ -1,17 +1,72 @@ -use crate::types::error::Error; -use async_trait::async_trait; -use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; -use ibc::core::timestamp::Timestamp; +use basecoin_app::modules::ibc::Ibc; +use basecoin_store::context::ProvableStore; +use basecoin_store::impls::RevertibleStore; +use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; +use ibc::core::ics24_host::identifier::ChainId; +use ibc::core::ics24_host::path::Path; use ibc::Height; +use ibc_relayer_components::core::traits::sync::Async; use tendermint_testgen::light_block::TmLightBlock; +use async_trait::async_trait; +use std::fmt::Debug; +use std::sync::Arc; + +use crate::types::error::Error; + +pub trait QueryService: Async { + type Endpoint: BasecoinEndpoint; + + fn service(&self) -> &Arc; +} + #[async_trait] -pub trait Endpoint { - fn query_current_height(&self) -> Result; +pub trait BasecoinEndpoint: Async + Clone { + type Store: ProvableStore + Debug + Default; + + async fn query( + &self, + path: impl Into + Send, + height: &Height, + ) -> Result<(Vec, CommitmentProofBytes), Error>; + + fn ibc(&self) -> Ibc>; + + fn get_chain_id(&self) -> &ChainId; + + fn get_blocks(&self) -> Vec; + + fn get_light_block(&self, height: &Height) -> Result; +} + +#[async_trait] +impl BasecoinEndpoint for Ctx +where + Ctx: QueryService + Async + Clone, +{ + type Store = <::Endpoint as BasecoinEndpoint>::Store; + + async fn query( + &self, + path: impl Into + Send, + height: &Height, + ) -> Result<(Vec, CommitmentProofBytes), Error> { + Ctx::service(self).query(path, height).await + } + + fn ibc(&self) -> Ibc> { + Ctx::service(self).ibc() + } - fn query_current_timestamp(&self) -> Result; + fn get_chain_id(&self) -> &ChainId { + Ctx::service(self).get_chain_id() + } - fn query_light_block(&self, height: &Height) -> Result; + fn get_blocks(&self) -> Vec { + Ctx::service(self).get_blocks() + } - fn query_host_consensus_state(&self, height: &Height) -> Result; + fn get_light_block(&self, height: &Height) -> Result { + Ctx::service(self).get_light_block(height) + } } diff --git a/crates/relayer-cosmos-mock/src/traits/handle.rs b/crates/relayer-cosmos-mock/src/traits/handle.rs index dbcb3b0d46..0647594af2 100644 --- a/crates/relayer-cosmos-mock/src/traits/handle.rs +++ b/crates/relayer-cosmos-mock/src/traits/handle.rs @@ -1,41 +1,18 @@ use async_trait::async_trait; -use std::fmt::Debug; - -use basecoin_app::modules::ibc::Ibc; use basecoin_store::context::ProvableStore; -use basecoin_store::impls::RevertibleStore; -use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; -use ibc::core::ics24_host::identifier::ChainId; -use ibc::core::ics24_host::path::Path; -use ibc::Height; -use ibc_relayer_components::core::traits::sync::Async; -use tendermint_testgen::light_block::TmLightBlock; - -use crate::types::error::Error; +use std::fmt::Debug; #[async_trait] -pub trait BasecoinHandle: Async + Clone { +pub trait BasecoinHandle { type Store: ProvableStore + Debug; - fn chain_id(&self) -> &ChainId; - - fn ibc(&self) -> Ibc>; - - fn blocks(&self) -> Vec; - - fn grow_blocks(&self); - async fn init(&self); async fn begin_block(&self); + fn grow_blocks(&self); + async fn commit(&self); async fn run(&self); - - async fn query( - &self, - path: impl Into + Send, - height: &Height, - ) -> Result<(Vec, CommitmentProofBytes), Error>; } From b0717a76ad62bc25a5965ef15cb91e99e41de6d8 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 28 Aug 2023 13:22:35 -0700 Subject: [PATCH 09/25] fix: update cargo.lock --- Cargo.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84e558048a..6f2536bd7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,11 +332,11 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basecoin-app" version = "0.1.0" -source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=e7f23d3#e7f23d381226ed5c395dd6124d0f9c50ae2adc48" +source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=c05c32b#c05c32b959401bf2eeb4387743041745f048a708" dependencies = [ "base64 0.21.3", "basecoin-store", - "clap 4.4.0", + "clap 4.4.1", "cosmrs", "derive_more", "displaydoc", @@ -365,7 +365,7 @@ dependencies = [ [[package]] name = "basecoin-store" version = "0.1.0" -source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=e7f23d3#e7f23d381226ed5c395dd6124d0f9c50ae2adc48" +source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=c05c32b#c05c32b959401bf2eeb4387743041745f048a708" dependencies = [ "base64 0.21.3", "derive_more", @@ -622,9 +622,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d5f1946157a96594eb2d2c10eb7ad9a2b27518cb3000209dec700c35df9197d" +checksum = "7c8d502cbaec4595d2e7d5f61e318f05417bd2b66fdc3809498f0d3fdf0bea27" dependencies = [ "clap_builder", "clap_derive 4.4.0", @@ -633,9 +633,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.0" +version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78116e32a042dd73c2901f0dc30790d20ff3447f3e3472fad359e8c3d282bcd6" +checksum = "5891c7bc0edb3e1c2204fc5e94009affabeb1821c9e5fdc3959536c5c0bb984d" dependencies = [ "anstream", "anstyle", @@ -2529,9 +2529,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "76fc44e2588d5b436dbc3c6cf62aef290f90dab6235744a93dfe1cc18f451e2c" [[package]] name = "memoffset" @@ -2980,9 +2980,9 @@ dependencies = [ [[package]] name = "platforms" -version = "3.0.2" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" [[package]] name = "polling" @@ -4971,9 +4971,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", From e6f38fa2358ae36fe594d4c397ee963aaaa94782 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 28 Aug 2023 13:34:16 -0700 Subject: [PATCH 10/25] imp: better break down of methods for basecoin --- .../src/contexts/basecoin.rs | 35 +++++++++++++++++-- .../relayer-cosmos-mock/src/contexts/chain.rs | 12 ++++--- .../relayer-cosmos-mock/src/impls/basecoin.rs | 33 ----------------- crates/relayer-cosmos-mock/src/tests/init.rs | 8 ++--- .../relayer-cosmos-mock/src/traits/handle.rs | 4 --- 5 files changed, 44 insertions(+), 48 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index d621a6c8bb..a02b8d572b 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -1,6 +1,7 @@ use std::fmt::Debug; use std::sync::Arc; use std::sync::Mutex; +use std::time::Duration; use basecoin_app::modules::auth::Auth; use basecoin_app::modules::bank::Bank; @@ -11,10 +12,14 @@ use basecoin_app::BaseCoinApp; use basecoin_app::Builder; use basecoin_store::context::ProvableStore; use ibc::core::ics24_host::identifier::ChainId; +use tendermint::Time; use tendermint_testgen::light_block::TmLightBlock; +use tendermint_testgen::Generator; +use tendermint_testgen::LightBlock; use tokio::task::JoinHandle; use crate::traits::handle::BasecoinHandle; +use crate::util::mutex::MutexUtil; #[derive(Clone)] pub struct MockBasecoin @@ -59,11 +64,37 @@ impl MockBasecoin { } } - pub fn start(&self) -> JoinHandle<()> { + pub fn grow_blocks(&self) { + let mut blocks = self.blocks.acquire_mutex(); + + let height = blocks.len() as u64 + 1; + + let current_time = Time::now(); + + let tm_light_block = LightBlock::new_default_with_time_and_chain_id( + self.chain_id.to_string(), + current_time, + height, + ) + .generate() + .expect("failed to generate light block"); + + blocks.push(tm_light_block); + } + + pub fn run(&self) -> JoinHandle<()> { let chain = self.clone(); tokio::spawn(async move { - chain.run().await; + chain.init().await; + + loop { + chain.begin_block().await; + + tokio::time::sleep(Duration::from_millis(200)).await; + + chain.commit().await; + } }) } } diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 91c73e1e15..dcee7f7248 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -5,6 +5,7 @@ use ibc::core::timestamp::Timestamp; use ibc::core::ValidationContext; use ibc::Any; use ibc::Height; +use tendermint::Time; use std::sync::Arc; use std::sync::Mutex; @@ -61,7 +62,8 @@ impl MockCosmosContext { self.current_status.acquire_mutex().height } - pub fn subscribe(&self) { + /// Keeps mock chain context tracking the latest status of the chain. + pub fn connect(&self) { let ctx = self.clone(); tokio::spawn(async move { let mut blocks_len = 1; @@ -69,13 +71,13 @@ impl MockCosmosContext { tokio::time::sleep(tokio::time::Duration::from_millis(200)).await; if ctx.get_blocks().len() > blocks_len { - let current_time = ctx.ibc_context().host_timestamp().unwrap(); + ctx.runtime.clock.set_timestamp(Time::now().into()); - let current_height = ctx.ibc_context().host_height().unwrap(); + let current_timestamp = ctx.ibc_context().host_timestamp().unwrap(); - ctx.runtime.clock.set_timestamp(current_time); + let current_height = ctx.ibc_context().host_height().unwrap(); - let current_status = ChainStatus::new(current_height, current_time); + let current_status = ChainStatus::new(current_height, current_timestamp); let mut last_status = ctx.current_status.acquire_mutex(); diff --git a/crates/relayer-cosmos-mock/src/impls/basecoin.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs index 55a7777014..74d3b1c7ef 100644 --- a/crates/relayer-cosmos-mock/src/impls/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -27,13 +27,10 @@ use tendermint::v0_37::abci::Request as AbciRequest; use tendermint::v0_37::abci::Response as AbciResponse; use tendermint_testgen::consensus::default_consensus_params; use tendermint_testgen::light_block::TmLightBlock; -use tendermint_testgen::Generator; -use tendermint_testgen::LightBlock; use tower::Service; use async_trait::async_trait; use std::fmt::Debug; -use std::time::Duration; #[async_trait] impl BasecoinHandle for MockBasecoin @@ -78,24 +75,6 @@ where } } - fn grow_blocks(&self) { - let mut blocks = self.blocks.acquire_mutex(); - - let height = blocks.len() as u64 + 1; - - let current_time = Time::now(); - - let tm_light_block = LightBlock::new_default_with_time_and_chain_id( - self.chain_id.to_string(), - current_time, - height, - ) - .generate() - .expect("failed to generate light block"); - - blocks.push(tm_light_block); - } - /// Commits the chain state. async fn commit(&self) { let mut modules = self.app.modules.write_access(); @@ -119,18 +98,6 @@ where self.grow_blocks(); } - - async fn run(&self) { - self.init().await; - - loop { - self.begin_block().await; - - tokio::time::sleep(Duration::from_millis(200)).await; - - self.commit().await; - } - } } #[async_trait] diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index 4755f5c09f..cd7714790e 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -18,18 +18,18 @@ pub fn mock_basecoin_binary_stand() -> ( // Source chain setup let src_chain_id = ChainId::from_str("mock-cosmos-chain-0").unwrap(); let src_chain = Arc::new(MockBasecoin::new(src_chain_id, InMemoryStore::default())); - src_chain.start(); + src_chain.run(); let src_chain_ctx = Arc::new(MockCosmosContext::new(src_chain, clock.clone())); - src_chain_ctx.subscribe(); + src_chain_ctx.connect(); // Destination chain setup let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").unwrap(); let dst_chain = Arc::new(MockBasecoin::new(dst_chain_id, InMemoryStore::default())); - dst_chain.start(); + dst_chain.run(); let dst_chain_ctx = Arc::new(MockCosmosContext::new(dst_chain, clock.clone())); - dst_chain_ctx.subscribe(); + dst_chain_ctx.connect(); // Relayer setup let relayer = MockCosmosRelay::new(src_chain_ctx.clone(), dst_chain_ctx.clone(), clock) diff --git a/crates/relayer-cosmos-mock/src/traits/handle.rs b/crates/relayer-cosmos-mock/src/traits/handle.rs index 0647594af2..b8db7b9172 100644 --- a/crates/relayer-cosmos-mock/src/traits/handle.rs +++ b/crates/relayer-cosmos-mock/src/traits/handle.rs @@ -10,9 +10,5 @@ pub trait BasecoinHandle { async fn begin_block(&self); - fn grow_blocks(&self); - async fn commit(&self); - - async fn run(&self); } From 9016fff48d805136bc643101028b83ecdce9f987 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 28 Aug 2023 19:20:05 -0700 Subject: [PATCH 11/25] imp: use random generated app_hash --- Cargo.lock | 36 +++++++++---------- .../src/contexts/basecoin.rs | 30 ++++++++++------ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f2536bd7a..a9bb7180e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1248,9 +1248,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", @@ -1787,7 +1787,7 @@ dependencies = [ "futures-util", "http", "hyper", - "rustls 0.21.6", + "rustls 0.21.7", "tokio", "tokio-rustls 0.24.1", ] @@ -2406,7 +2406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.2", - "rustix 0.38.9", + "rustix 0.38.10", "windows-sys 0.48.0", ] @@ -3291,7 +3291,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.6", + "rustls 0.21.7", "rustls-pemfile", "serde", "serde_json", @@ -3390,9 +3390,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.9" +version = "0.38.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bfe0f2582b4931a45d1fa608f8a8722e8b3c7ac54dd6d5f3b3212791fedef49" +checksum = "ed6248e1caa625eb708e266e06159f135e8c26f2bb7ceb72dc4b2766d0340964" dependencies = [ "bitflags 2.4.0", "errno", @@ -3416,9 +3416,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" dependencies = [ "log", "ring", @@ -3428,9 +3428,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", @@ -4077,7 +4077,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", "redox_syscall 0.3.5", - "rustix 0.38.9", + "rustix 0.38.10", "windows-sys 0.48.0", ] @@ -4115,7 +4115,7 @@ dependencies = [ [[package]] name = "tendermint" version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#70fa55863e83f3059169ec76ec3b31a5293f7855" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#a5cddcad6bb4cc6e2f9de28a0273489e383cd269" dependencies = [ "bytes", "digest 0.10.7", @@ -4264,7 +4264,7 @@ dependencies = [ [[package]] name = "tendermint-proto" version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#70fa55863e83f3059169ec76ec3b31a5293f7855" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#a5cddcad6bb4cc6e2f9de28a0273489e383cd269" dependencies = [ "bytes", "flex-error", @@ -4368,7 +4368,7 @@ dependencies = [ [[package]] name = "tendermint-testgen" version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#70fa55863e83f3059169ec76ec3b31a5293f7855" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#a5cddcad6bb4cc6e2f9de28a0273489e383cd269" dependencies = [ "ed25519-consensus", "gumdrop", @@ -4584,7 +4584,7 @@ version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.20.8", + "rustls 0.20.9", "tokio", "webpki 0.22.0", ] @@ -4595,7 +4595,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.6", + "rustls 0.21.7", "tokio", ] @@ -4889,7 +4889,7 @@ dependencies = [ "httparse", "log", "rand", - "rustls 0.20.8", + "rustls 0.20.9", "sha1", "thiserror", "url", diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index a02b8d572b..a64cf5c5e8 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -15,10 +15,13 @@ use ibc::core::ics24_host::identifier::ChainId; use tendermint::Time; use tendermint_testgen::light_block::TmLightBlock; use tendermint_testgen::Generator; +use tendermint_testgen::Header; use tendermint_testgen::LightBlock; +use tendermint_testgen::Validator; use tokio::task::JoinHandle; use crate::traits::handle::BasecoinHandle; +use crate::util::dummy::generate_rand_app_hash; use crate::util::mutex::MutexUtil; #[derive(Clone)] @@ -67,17 +70,22 @@ impl MockBasecoin { pub fn grow_blocks(&self) { let mut blocks = self.blocks.acquire_mutex(); - let height = blocks.len() as u64 + 1; - - let current_time = Time::now(); - - let tm_light_block = LightBlock::new_default_with_time_and_chain_id( - self.chain_id.to_string(), - current_time, - height, - ) - .generate() - .expect("failed to generate light block"); + let validators = [ + Validator::new("1").voting_power(40), + Validator::new("2").voting_power(30), + Validator::new("3").voting_power(30), + ]; + + let header = Header::new(&validators) + .height(blocks.len() as u64 + 1) + .chain_id(&self.chain_id.to_string()) + .next_validators(&validators) + .time(Time::now()) + .app_hash(generate_rand_app_hash()); + + let tm_light_block = LightBlock::new_default_with_header(header) + .generate() + .expect("failed to generate light block"); blocks.push(tm_light_block); } From 235a06dbff938cd54c837da751636bdcdf9323a3 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 29 Aug 2023 12:26:08 -0700 Subject: [PATCH 12/25] fix: apply suggestions from code review Co-authored-by: Sean Chen Signed-off-by: Farhad Shabani --- .../relayer-cosmos-mock/src/contexts/basecoin.rs | 14 ++++++++++++++ crates/relayer-cosmos-mock/src/contexts/birelay.rs | 3 ++- crates/relayer-cosmos-mock/src/contexts/chain.rs | 3 ++- crates/relayer-cosmos-mock/src/impls/basecoin.rs | 2 +- crates/relayer-cosmos-mock/src/types/error.rs | 2 ++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index a64cf5c5e8..0e90c230ba 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -24,6 +24,20 @@ use crate::traits::handle::BasecoinHandle; use crate::util::dummy::generate_rand_app_hash; use crate::util::mutex::MutexUtil; +#[derive(Clone)] +/// A mock ABCI application that includes simplified store, application, +/// consensus layers. +/// +/// The store consists of an in-memory AVL implementation that facilitates +/// proof verification. +/// +/// The application layer includes Authentication, Bank, and IBC modules, +/// resulting in a fully operational ibc-rs implementation that runs in a +/// lightweight manner. +/// +/// The consensus layer consists of a simple block production engine that +/// forgoes voting, validation, and transaction phases for the sake of +/// simplicity. #[derive(Clone)] pub struct MockBasecoin where diff --git a/crates/relayer-cosmos-mock/src/contexts/birelay.rs b/crates/relayer-cosmos-mock/src/contexts/birelay.rs index dc86b3eb2d..b9381d37d8 100644 --- a/crates/relayer-cosmos-mock/src/contexts/birelay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/birelay.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use super::relay::MockCosmosRelay; use crate::traits::endpoint::BasecoinEndpoint; - +/// Bi-directional relayer for relaying between +/// [`crates::relayer-cosmos-mock::contexts::MockCosmosRelay`]s pub struct MockCosmosBiRelay { pub runtime: TokioRuntimeContext, pub relay_a_to_b: Arc>, diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index dcee7f7248..472ac4c866 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -16,7 +16,8 @@ use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::mutex::MutexUtil; - +/// Holds the necessary fields for querying a mock Cosmos +/// chain endpoint. #[derive(Clone)] pub struct MockCosmosContext { /// Chain handle diff --git a/crates/relayer-cosmos-mock/src/impls/basecoin.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs index 74d3b1c7ef..19b97877b5 100644 --- a/crates/relayer-cosmos-mock/src/impls/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -75,7 +75,7 @@ where } } - /// Commits the chain state. + /// Commits the chain state to the store. async fn commit(&self) { let mut modules = self.app.modules.write_access(); diff --git a/crates/relayer-cosmos-mock/src/types/error.rs b/crates/relayer-cosmos-mock/src/types/error.rs index edc1843380..36e6bf8894 100644 --- a/crates/relayer-cosmos-mock/src/types/error.rs +++ b/crates/relayer-cosmos-mock/src/types/error.rs @@ -106,6 +106,8 @@ impl std::fmt::Display for Error { } } +/// Defines all the possible error types and their corresponding codes for +/// interchain account errors. #[derive(Clone, Debug)] pub enum Code { /// cannot be empty! From 19414099d43946f7948a807855692410218ed735 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 29 Aug 2023 12:43:58 -0700 Subject: [PATCH 13/25] imp: add more docstings + change the naming of BasecoinHandler to BasecoinRunner --- crates/relayer-cosmos-mock/src/contexts/basecoin.rs | 9 ++++----- crates/relayer-cosmos-mock/src/contexts/chain.rs | 1 + crates/relayer-cosmos-mock/src/impls/basecoin.rs | 4 ++-- crates/relayer-cosmos-mock/src/traits/endpoint.rs | 4 ++++ crates/relayer-cosmos-mock/src/traits/mod.rs | 2 +- .../src/traits/{handle.rs => runner.rs} | 3 ++- crates/relayer-cosmos-mock/src/types/error.rs | 9 +++++---- crates/relayer-cosmos-mock/src/types/status.rs | 1 + 8 files changed, 20 insertions(+), 13 deletions(-) rename crates/relayer-cosmos-mock/src/traits/{handle.rs => runner.rs} (73%) diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index 0e90c230ba..5c287bbc39 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -20,24 +20,23 @@ use tendermint_testgen::LightBlock; use tendermint_testgen::Validator; use tokio::task::JoinHandle; -use crate::traits::handle::BasecoinHandle; +use crate::traits::runner::BasecoinRunner; use crate::util::dummy::generate_rand_app_hash; use crate::util::mutex::MutexUtil; -#[derive(Clone)] /// A mock ABCI application that includes simplified store, application, /// consensus layers. /// /// The store consists of an in-memory AVL implementation that facilitates /// proof verification. -/// +/// /// The application layer includes Authentication, Bank, and IBC modules, -/// resulting in a fully operational ibc-rs implementation that runs in a +/// resulting in a fully operational ibc-rs implementation that runs in a /// lightweight manner. /// /// The consensus layer consists of a simple block production engine that /// forgoes voting, validation, and transaction phases for the sake of -/// simplicity. +/// simplicity. #[derive(Clone)] pub struct MockBasecoin where diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 472ac4c866..06edebc018 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -16,6 +16,7 @@ use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use crate::types::status::ChainStatus; use crate::util::mutex::MutexUtil; + /// Holds the necessary fields for querying a mock Cosmos /// chain endpoint. #[derive(Clone)] diff --git a/crates/relayer-cosmos-mock/src/impls/basecoin.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs index 19b97877b5..86330c7a7b 100644 --- a/crates/relayer-cosmos-mock/src/impls/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -1,6 +1,6 @@ use crate::contexts::basecoin::MockBasecoin; use crate::traits::endpoint::BasecoinEndpoint; -use crate::traits::handle::BasecoinHandle; +use crate::traits::runner::BasecoinRunner; use crate::types::error::Error; use crate::util::conversion::convert_tm_to_ics_merkle_proof; use crate::util::dummy::genesis_app_state; @@ -33,7 +33,7 @@ use async_trait::async_trait; use std::fmt::Debug; #[async_trait] -impl BasecoinHandle for MockBasecoin +impl BasecoinRunner for MockBasecoin where S: ProvableStore + Default + Debug, { diff --git a/crates/relayer-cosmos-mock/src/traits/endpoint.rs b/crates/relayer-cosmos-mock/src/traits/endpoint.rs index 1cf68d6e11..17f5a1e833 100644 --- a/crates/relayer-cosmos-mock/src/traits/endpoint.rs +++ b/crates/relayer-cosmos-mock/src/traits/endpoint.rs @@ -14,12 +14,16 @@ use std::sync::Arc; use crate::types::error::Error; +/// Defines the interface that empowers a chain context with the ability to +/// query different states of a chain. pub trait QueryService: Async { type Endpoint: BasecoinEndpoint; fn service(&self) -> &Arc; } +/// Defines the interface that enables a mock Cosmos chain to provide query +/// endpoints. #[async_trait] pub trait BasecoinEndpoint: Async + Clone { type Store: ProvableStore + Debug + Default; diff --git a/crates/relayer-cosmos-mock/src/traits/mod.rs b/crates/relayer-cosmos-mock/src/traits/mod.rs index 56431f6577..f2e5fcf0fa 100644 --- a/crates/relayer-cosmos-mock/src/traits/mod.rs +++ b/crates/relayer-cosmos-mock/src/traits/mod.rs @@ -1,2 +1,2 @@ pub mod endpoint; -pub mod handle; +pub mod runner; diff --git a/crates/relayer-cosmos-mock/src/traits/handle.rs b/crates/relayer-cosmos-mock/src/traits/runner.rs similarity index 73% rename from crates/relayer-cosmos-mock/src/traits/handle.rs rename to crates/relayer-cosmos-mock/src/traits/runner.rs index b8db7b9172..f12de90374 100644 --- a/crates/relayer-cosmos-mock/src/traits/handle.rs +++ b/crates/relayer-cosmos-mock/src/traits/runner.rs @@ -2,8 +2,9 @@ use async_trait::async_trait; use basecoin_store::context::ProvableStore; use std::fmt::Debug; +/// Defines the interface for running a mock Cosmos chain. #[async_trait] -pub trait BasecoinHandle { +pub trait BasecoinRunner { type Store: ProvableStore + Debug; async fn init(&self); diff --git a/crates/relayer-cosmos-mock/src/types/error.rs b/crates/relayer-cosmos-mock/src/types/error.rs index 36e6bf8894..b63f1b24a7 100644 --- a/crates/relayer-cosmos-mock/src/types/error.rs +++ b/crates/relayer-cosmos-mock/src/types/error.rs @@ -4,7 +4,8 @@ use ibc::clients::ics07_tendermint::error::Error as ClientError; use ibc::core::ics24_host::identifier::IdentifierError; use ibc::core::ContextError; -/// Defines the interchain account error type +/// Defines the error type for errors can occur when relaying between two mock +/// Cosmos chains. #[derive(Clone, Debug)] pub struct Error { /// Error code. @@ -18,7 +19,7 @@ pub struct Error { } impl Error { - /// Constructs a new interchain account error instance with the given code and message. + /// Constructs a new error instance with the given code and message. pub fn new(code: Code, origin: impl Into) -> Self { Self { code, @@ -106,8 +107,8 @@ impl std::fmt::Display for Error { } } -/// Defines all the possible error types and their corresponding codes for -/// interchain account errors. +/// Defines all the possible error types and their corresponding codes for +/// errors can occur relaying between two mock Cosmos chains. #[derive(Clone, Debug)] pub enum Code { /// cannot be empty! diff --git a/crates/relayer-cosmos-mock/src/types/status.rs b/crates/relayer-cosmos-mock/src/types/status.rs index dc11ad135e..b8652a3d6d 100644 --- a/crates/relayer-cosmos-mock/src/types/status.rs +++ b/crates/relayer-cosmos-mock/src/types/status.rs @@ -1,6 +1,7 @@ use ibc::core::timestamp::Timestamp; use ibc::Height; +/// Defines the type that tracks the current status of a mock Cosmos chain. #[derive(Clone, Debug)] pub struct ChainStatus { pub timestamp: Timestamp, From cd438ec5775774bf71457a103726b39bba8f7edc Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 29 Aug 2023 12:46:58 -0700 Subject: [PATCH 14/25] nit: drop redundant state declaration --- crates/relayer-cosmos-mock/src/impls/basecoin.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/impls/basecoin.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs index 86330c7a7b..b026dde345 100644 --- a/crates/relayer-cosmos-mock/src/impls/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -79,21 +79,19 @@ where async fn commit(&self) { let mut modules = self.app.modules.write_access(); + let mut state = self.app.store.write_access(); + for IdentifiedModule { id, module } in modules.iter_mut() { module .store_mut() .commit() .expect("failed to commit to state"); - let mut state = self.app.store.write_access(); - state .set(id.clone().into(), module.store().root_hash()) .expect("failed to update sub-store commitment"); } - let mut state = self.app.store.write_access(); - state.commit().expect("failed to commit to state"); self.grow_blocks(); From bba1b847d512e2ddfc102294c08467da07b49c56 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 29 Aug 2023 13:11:49 -0700 Subject: [PATCH 15/25] fix: add validators field to MockBasecoin --- .../src/contexts/basecoin.rs | 29 ++++++++++++------- .../src/contexts/birelay.rs | 3 +- crates/relayer-cosmos-mock/src/tests/init.rs | 8 ++--- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index 5c287bbc39..8c0cb4e5ea 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -44,15 +44,17 @@ where { /// Chain identifier pub chain_id: ChainId, - /// Chain application - pub app: BaseCoinApp, + /// Chain validators + pub validators: Arc>>, /// Chain blocks pub blocks: Arc>>, + /// Chain application + pub app: BaseCoinApp, } impl MockBasecoin { /// Constructs a new mock cosmos chain instance. - pub fn new(chain_id: ChainId, store: S) -> Self { + pub fn new(chain_id: ChainId, validators: Vec, store: S) -> Self { let app_builder = Builder::new(store); let auth = Auth::new(app_builder.module_store(&prefix::Auth {}.identifier())); @@ -75,25 +77,32 @@ impl MockBasecoin { Self { chain_id, - app, + validators: Arc::new(Mutex::new(validators)), blocks: Arc::new(Mutex::new(vec![])), + app, } } - pub fn grow_blocks(&self) { - let mut blocks = self.blocks.acquire_mutex(); - - let validators = [ + pub fn new_default(chain_id: ChainId) -> Self { + let validators = vec![ Validator::new("1").voting_power(40), Validator::new("2").voting_power(30), Validator::new("3").voting_power(30), ]; + Self::new(chain_id, validators, S::default()) + } + + pub fn grow_blocks(&self) { + let mut blocks = self.blocks.acquire_mutex(); + + let validators = self.validators.acquire_mutex(); + let header = Header::new(&validators) - .height(blocks.len() as u64 + 1) .chain_id(&self.chain_id.to_string()) - .next_validators(&validators) + .height(blocks.len() as u64 + 1) .time(Time::now()) + .next_validators(&validators) .app_hash(generate_rand_app_hash()); let tm_light_block = LightBlock::new_default_with_header(header) diff --git a/crates/relayer-cosmos-mock/src/contexts/birelay.rs b/crates/relayer-cosmos-mock/src/contexts/birelay.rs index b9381d37d8..501d19ce90 100644 --- a/crates/relayer-cosmos-mock/src/contexts/birelay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/birelay.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use super::relay::MockCosmosRelay; use crate::traits::endpoint::BasecoinEndpoint; -/// Bi-directional relayer for relaying between + +/// Bi-directional relayer for relaying between /// [`crates::relayer-cosmos-mock::contexts::MockCosmosRelay`]s pub struct MockCosmosBiRelay { pub runtime: TokioRuntimeContext, diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index cd7714790e..fbd8e28736 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -16,16 +16,16 @@ pub fn mock_basecoin_binary_stand() -> ( let clock = Arc::new(MockClock::default()); // Source chain setup - let src_chain_id = ChainId::from_str("mock-cosmos-chain-0").unwrap(); - let src_chain = Arc::new(MockBasecoin::new(src_chain_id, InMemoryStore::default())); + let src_chain_id = ChainId::from_str("mock-cosmos-chain-0").expect("never fails"); + let src_chain = Arc::new(MockBasecoin::new_default(src_chain_id)); src_chain.run(); let src_chain_ctx = Arc::new(MockCosmosContext::new(src_chain, clock.clone())); src_chain_ctx.connect(); // Destination chain setup - let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").unwrap(); - let dst_chain = Arc::new(MockBasecoin::new(dst_chain_id, InMemoryStore::default())); + let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").expect("never fails"); + let dst_chain = Arc::new(MockBasecoin::new_default(dst_chain_id)); dst_chain.run(); let dst_chain_ctx = Arc::new(MockCosmosContext::new(dst_chain, clock.clone())); From d07e117efc51d6b45d6a12d90552754e07f45f21 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 29 Aug 2023 16:28:58 -0700 Subject: [PATCH 16/25] imp: rename connect method to sync --- .../relayer-cosmos-mock/src/contexts/chain.rs | 27 ++++++++++--------- crates/relayer-cosmos-mock/src/tests/init.rs | 4 +-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 06edebc018..b96db0adb9 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -6,6 +6,7 @@ use ibc::core::ValidationContext; use ibc::Any; use ibc::Height; use tendermint::Time; +use tokio::task::JoinHandle; use std::sync::Arc; use std::sync::Mutex; @@ -64,31 +65,33 @@ impl MockCosmosContext { self.current_status.acquire_mutex().height } - /// Keeps mock chain context tracking the latest status of the chain. - pub fn connect(&self) { + /// Keeps the chain context updated by continuously tracking the latest generated block. + pub fn sync(&self) -> JoinHandle<()> { let ctx = self.clone(); tokio::spawn(async move { let mut blocks_len = 1; loop { tokio::time::sleep(tokio::time::Duration::from_millis(200)).await; - if ctx.get_blocks().len() > blocks_len { - ctx.runtime.clock.set_timestamp(Time::now().into()); + if ctx.get_blocks().len() <= blocks_len { + continue; + } - let current_timestamp = ctx.ibc_context().host_timestamp().unwrap(); + ctx.runtime.clock.set_timestamp(Time::now().into()); - let current_height = ctx.ibc_context().host_height().unwrap(); + let current_timestamp = ctx.ibc_context().host_timestamp().unwrap(); - let current_status = ChainStatus::new(current_height, current_timestamp); + let current_height = ctx.ibc_context().host_height().unwrap(); - let mut last_status = ctx.current_status.acquire_mutex(); + let current_status = ChainStatus::new(current_height, current_timestamp); - *last_status = current_status; + let mut last_status = ctx.current_status.acquire_mutex(); - blocks_len = ctx.get_blocks().len(); - } + *last_status = current_status; + + blocks_len = ctx.get_blocks().len(); } - }); + }) } pub fn submit_messages(&self, msgs: Vec) -> Result>, Error> { diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index fbd8e28736..806f3ec83e 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -21,7 +21,7 @@ pub fn mock_basecoin_binary_stand() -> ( src_chain.run(); let src_chain_ctx = Arc::new(MockCosmosContext::new(src_chain, clock.clone())); - src_chain_ctx.connect(); + src_chain_ctx.sync(); // Destination chain setup let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").expect("never fails"); @@ -29,7 +29,7 @@ pub fn mock_basecoin_binary_stand() -> ( dst_chain.run(); let dst_chain_ctx = Arc::new(MockCosmosContext::new(dst_chain, clock.clone())); - dst_chain_ctx.connect(); + dst_chain_ctx.sync(); // Relayer setup let relayer = MockCosmosRelay::new(src_chain_ctx.clone(), dst_chain_ctx.clone(), clock) From 5373f2ba4069609764b3b0575a3db7bdfd03a0d6 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 29 Aug 2023 17:12:54 -0700 Subject: [PATCH 17/25] imp: use TokioRuntimeContext instead --- Cargo.lock | 5 +- crates/relayer-cosmos-mock/Cargo.toml | 9 +-- .../src/contexts/basecoin.rs | 29 +++++++-- .../relayer-cosmos-mock/src/contexts/chain.rs | 32 +++++----- .../relayer-cosmos-mock/src/contexts/mod.rs | 1 - .../relayer-cosmos-mock/src/contexts/relay.rs | 20 +++--- .../src/contexts/runtime.rs | 64 ------------------- crates/relayer-cosmos-mock/src/impls/chain.rs | 4 +- crates/relayer-cosmos-mock/src/impls/mod.rs | 1 - crates/relayer-cosmos-mock/src/impls/relay.rs | 4 +- .../relayer-cosmos-mock/src/impls/runtime.rs | 34 ---------- crates/relayer-cosmos-mock/src/tests/init.rs | 13 ++-- 12 files changed, 70 insertions(+), 146 deletions(-) delete mode 100644 crates/relayer-cosmos-mock/src/contexts/runtime.rs delete mode 100644 crates/relayer-cosmos-mock/src/impls/runtime.rs diff --git a/Cargo.lock b/Cargo.lock index a9bb7180e2..1109696ad3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,7 +332,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basecoin-app" version = "0.1.0" -source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=c05c32b#c05c32b959401bf2eeb4387743041745f048a708" +source = "git+https://github.com/informalsystems/basecoin-rs.git#aa59797863272119a7bcb63bdf13b6d037dcd5cf" dependencies = [ "base64 0.21.3", "basecoin-store", @@ -365,7 +365,7 @@ dependencies = [ [[package]] name = "basecoin-store" version = "0.1.0" -source = "git+https://github.com/informalsystems/basecoin-rs.git?rev=c05c32b#c05c32b959401bf2eeb4387743041745f048a708" +source = "git+https://github.com/informalsystems/basecoin-rs.git#aa59797863272119a7bcb63bdf13b6d037dcd5cf" dependencies = [ "base64 0.21.3", "derive_more", @@ -2127,6 +2127,7 @@ dependencies = [ "ibc", "ibc-proto 0.34.0", "ibc-relayer-components", + "ibc-relayer-components-extra", "ibc-relayer-runtime", "ibc-relayer-types", "primitive-types", diff --git a/crates/relayer-cosmos-mock/Cargo.toml b/crates/relayer-cosmos-mock/Cargo.toml index 64a365ec0c..173e7f2ec3 100644 --- a/crates/relayer-cosmos-mock/Cargo.toml +++ b/crates/relayer-cosmos-mock/Cargo.toml @@ -16,13 +16,14 @@ description = """ [dependencies] async-trait = "0.1.56" -basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "c05c32b" } -basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "c05c32b" } +basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git" } +basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git" } ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev= "6ffe8ce", features = ["mocks"] } ibc-proto = "0.34.0" ibc-relayer-components = { version = "0.1.0", path = "../relayer-components" } -ibc-relayer-runtime = { path = "../relayer-runtime" } -ibc-relayer-types = { path = "../relayer-types" } +ibc-relayer-components-extra = { version = "0.1.0", path = "../relayer-components-extra" } +ibc-relayer-runtime = { version = "0.1.0", path = "../relayer-runtime" } +ibc-relayer-types = { version = "0.25.0", path = "../relayer-types" } primitive-types = { version = "0.12.0", default-features = false} prost = "0.11.0" serde_json = "1.0" diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index 8c0cb4e5ea..b232ea89c2 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -12,13 +12,16 @@ use basecoin_app::BaseCoinApp; use basecoin_app::Builder; use basecoin_store::context::ProvableStore; use ibc::core::ics24_host::identifier::ChainId; +use ibc_relayer_components_extra::runtime::traits::spawn::Spawner; +use ibc_relayer_components_extra::runtime::traits::spawn::TaskHandle; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use tendermint::Time; use tendermint_testgen::light_block::TmLightBlock; use tendermint_testgen::Generator; use tendermint_testgen::Header; use tendermint_testgen::LightBlock; use tendermint_testgen::Validator; -use tokio::task::JoinHandle; +use tokio::runtime::Runtime as TokioRuntime; use crate::traits::runner::BasecoinRunner; use crate::util::dummy::generate_rand_app_hash; @@ -42,6 +45,8 @@ pub struct MockBasecoin where S: ProvableStore + Debug, { + /// Chain runtime + pub runtime: TokioRuntimeContext, /// Chain identifier pub chain_id: ChainId, /// Chain validators @@ -54,7 +59,12 @@ where impl MockBasecoin { /// Constructs a new mock cosmos chain instance. - pub fn new(chain_id: ChainId, validators: Vec, store: S) -> Self { + pub fn new( + runtime: TokioRuntimeContext, + chain_id: ChainId, + validators: Vec, + store: S, + ) -> Self { let app_builder = Builder::new(store); let auth = Auth::new(app_builder.module_store(&prefix::Auth {}.identifier())); @@ -76,6 +86,7 @@ impl MockBasecoin { .build(); Self { + runtime, chain_id, validators: Arc::new(Mutex::new(validators)), blocks: Arc::new(Mutex::new(vec![])), @@ -90,7 +101,15 @@ impl MockBasecoin { Validator::new("3").voting_power(30), ]; - Self::new(chain_id, validators, S::default()) + let runtime = TokioRuntimeContext::new(Arc::new( + TokioRuntime::new().expect("failed to build runtime"), + )); + + Self::new(runtime, chain_id, validators, S::default()) + } + + pub fn runtime(&self) -> &TokioRuntimeContext { + &self.runtime } pub fn grow_blocks(&self) { @@ -112,10 +131,10 @@ impl MockBasecoin { blocks.push(tm_light_block); } - pub fn run(&self) -> JoinHandle<()> { + pub fn run(&self) -> Box { let chain = self.clone(); - tokio::spawn(async move { + self.runtime().spawn(async move { chain.init().await; loop { diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index b96db0adb9..3cfe7a3dcb 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -5,14 +5,14 @@ use ibc::core::timestamp::Timestamp; use ibc::core::ValidationContext; use ibc::Any; use ibc::Height; -use tendermint::Time; -use tokio::task::JoinHandle; +use ibc_relayer_components::runtime::traits::sleep::CanSleep; +use ibc_relayer_components_extra::runtime::traits::spawn::Spawner; +use ibc_relayer_components_extra::runtime::traits::spawn::TaskHandle; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use std::sync::Arc; use std::sync::Mutex; -use super::runtime::MockClock; -use crate::contexts::runtime::MockRuntimeContext; use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use crate::types::status::ChainStatus; @@ -22,32 +22,30 @@ use crate::util::mutex::MutexUtil; /// chain endpoint. #[derive(Clone)] pub struct MockCosmosContext { + /// Chain runtime + pub runtime: TokioRuntimeContext, /// Chain handle pub querier: Arc, /// Current chain status pub current_status: Arc>, - /// Chain runtime - pub runtime: MockRuntimeContext, } impl MockCosmosContext { /// Constructs a new mock cosmos chain instance. - pub fn new(querier: Arc, clock: Arc) -> Self { - let runtime = MockRuntimeContext::new(clock.clone()); - + pub fn new(runtime: TokioRuntimeContext, querier: Arc) -> Self { let current_status = Arc::new(Mutex::new(ChainStatus::new( Height::new(querier.get_chain_id().revision_number(), 1).expect("never fails"), - clock.get_timestamp(), + Timestamp::now(), ))); Self { + runtime, querier, current_status, - runtime, } } - pub fn runtime(&self) -> &MockRuntimeContext { + pub fn runtime(&self) -> &TokioRuntimeContext { &self.runtime } @@ -66,19 +64,19 @@ impl MockCosmosContext { } /// Keeps the chain context updated by continuously tracking the latest generated block. - pub fn sync(&self) -> JoinHandle<()> { + pub fn sync(&self) -> Box { let ctx = self.clone(); - tokio::spawn(async move { + self.runtime().spawn(async move { let mut blocks_len = 1; loop { - tokio::time::sleep(tokio::time::Duration::from_millis(200)).await; + ctx.runtime() + .sleep(tokio::time::Duration::from_millis(200)) + .await; if ctx.get_blocks().len() <= blocks_len { continue; } - ctx.runtime.clock.set_timestamp(Time::now().into()); - let current_timestamp = ctx.ibc_context().host_timestamp().unwrap(); let current_height = ctx.ibc_context().host_height().unwrap(); diff --git a/crates/relayer-cosmos-mock/src/contexts/mod.rs b/crates/relayer-cosmos-mock/src/contexts/mod.rs index 8213dd39b7..506538660c 100644 --- a/crates/relayer-cosmos-mock/src/contexts/mod.rs +++ b/crates/relayer-cosmos-mock/src/contexts/mod.rs @@ -2,4 +2,3 @@ pub mod basecoin; pub mod birelay; pub mod chain; pub mod relay; -pub mod runtime; diff --git a/crates/relayer-cosmos-mock/src/contexts/relay.rs b/crates/relayer-cosmos-mock/src/contexts/relay.rs index 1fb3154c20..2153caef3f 100644 --- a/crates/relayer-cosmos-mock/src/contexts/relay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/relay.rs @@ -2,15 +2,15 @@ use ibc::clients::ics07_tendermint::client_type; use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket; +use ibc_relayer_components_extra::runtime::traits::spawn::{Spawner, TaskHandle}; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use std::sync::Arc; -use tokio::task::JoinHandle; use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use crate::util::msgs::build_transfer_packet; use super::chain::MockCosmosContext; -use super::runtime::{MockClock, MockRuntimeContext}; #[derive(Clone)] pub struct MockCosmosRelay @@ -18,11 +18,11 @@ where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { + pub runtime: TokioRuntimeContext, pub src_chain: Arc>, pub dst_chain: Arc>, pub src_client_id: ClientId, pub dst_client_id: ClientId, - pub runtime: MockRuntimeContext, } impl MockCosmosRelay @@ -31,9 +31,9 @@ where DstChain: BasecoinEndpoint, { pub fn new( + runtime: TokioRuntimeContext, src_chain: Arc>, dst_chain: Arc>, - clock: Arc, ) -> Result, Error> { let src_client_counter = src_chain.ibc_context().client_counter()?; @@ -43,17 +43,19 @@ where let dst_client_id = ClientId::new(client_type(), dst_client_counter)?; - let runtime = MockRuntimeContext { clock }; - Ok(Self { + runtime, src_chain, dst_chain, src_client_id, dst_client_id, - runtime, }) } + pub fn runtime(&self) -> &TokioRuntimeContext { + &self.runtime + } + pub fn src_chain(&self) -> &Arc> { &self.src_chain } @@ -70,12 +72,12 @@ where &self.dst_client_id } - pub fn spawn(&mut self) -> JoinHandle<()> { + pub fn spawn(&mut self) -> Box { let packet = build_transfer_packet(1); let relayer = self.clone(); - tokio::spawn(async move { + self.runtime().spawn(async move { relayer .relay_packet(&packet) .await diff --git a/crates/relayer-cosmos-mock/src/contexts/runtime.rs b/crates/relayer-cosmos-mock/src/contexts/runtime.rs deleted file mode 100644 index c3b7582891..0000000000 --- a/crates/relayer-cosmos-mock/src/contexts/runtime.rs +++ /dev/null @@ -1,64 +0,0 @@ -use alloc::sync::Arc; -use core::time::Duration; -use ibc::core::timestamp::Timestamp; -use std::ops::Add; -use std::sync::Mutex; - -use crate::types::error::Error; -use crate::util::mutex::MutexUtil; - -pub struct MockRuntimeContext { - pub clock: Arc, -} - -impl MockRuntimeContext { - pub fn new(clock: Arc) -> Self { - Self { clock } - } - - pub fn get_time(&self) -> Timestamp { - self.clock.get_timestamp() - } -} - -impl Clone for MockRuntimeContext { - fn clone(&self) -> Self { - let clock = self.clock.clone(); - Self::new(clock) - } -} - -pub struct MockClock { - timestamp: Arc>, -} - -impl Default for MockClock { - fn default() -> Self { - Self { - timestamp: Arc::new(Mutex::new(Timestamp::now())), - } - } -} - -impl MockClock { - pub fn set_timestamp(&self, timestamp: Timestamp) { - *self.timestamp.acquire_mutex() = timestamp; - } - - pub fn increment_timestamp(&self, duration: Duration) -> Result<(), Error> { - let mut locked_timestamp = self.timestamp.acquire_mutex(); - - *locked_timestamp = locked_timestamp.add(duration).map_err(|_| { - Error::invalid(format!( - "overflow when adding {} to {:?}", - locked_timestamp, duration - )) - })?; - - Ok(()) - } - - pub fn get_timestamp(&self) -> Timestamp { - *self.timestamp.acquire_mutex() - } -} diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index 438a9ba872..a0a9414989 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -67,9 +67,9 @@ use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_runtime::types::error::Error as TokioError; use ibc_relayer_runtime::types::log::logger::TracingLogger; use ibc_relayer_runtime::types::log::value::LogValue; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::chain::MockCosmosContext; -use crate::contexts::runtime::MockRuntimeContext; use crate::traits::endpoint::{BasecoinEndpoint, QueryService}; use crate::types::error::Error; use crate::types::status::ChainStatus; @@ -80,7 +80,7 @@ impl HasErrorType for MockCosmosContext { } impl HasRuntime for MockCosmosContext { - type Runtime = MockRuntimeContext; + type Runtime = TokioRuntimeContext; fn runtime(&self) -> &Self::Runtime { &self.runtime diff --git a/crates/relayer-cosmos-mock/src/impls/mod.rs b/crates/relayer-cosmos-mock/src/impls/mod.rs index 7d328d08a3..bf3e88fd3a 100644 --- a/crates/relayer-cosmos-mock/src/impls/mod.rs +++ b/crates/relayer-cosmos-mock/src/impls/mod.rs @@ -3,4 +3,3 @@ pub mod birelay; pub mod chain; pub mod components; pub mod relay; -pub mod runtime; diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index 17048bf271..82c3c417f7 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -21,10 +21,10 @@ use ibc_relayer_components::relay::traits::update_client::UpdateClientMessageBui use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_runtime::types::error::Error as TokioError; use ibc_relayer_runtime::types::log::logger::TracingLogger; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; -use crate::contexts::runtime::MockRuntimeContext; use crate::impls::components::MockCosmosComponents; use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; @@ -51,7 +51,7 @@ where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { - type Runtime = MockRuntimeContext; + type Runtime = TokioRuntimeContext; fn runtime(&self) -> &Self::Runtime { &self.runtime diff --git a/crates/relayer-cosmos-mock/src/impls/runtime.rs b/crates/relayer-cosmos-mock/src/impls/runtime.rs deleted file mode 100644 index 062bc170a4..0000000000 --- a/crates/relayer-cosmos-mock/src/impls/runtime.rs +++ /dev/null @@ -1,34 +0,0 @@ -use async_trait::async_trait; -use ibc::core::timestamp::Timestamp; -use ibc_relayer_components::core::traits::error::HasErrorType; -use ibc_relayer_components::runtime::traits::{sleep::CanSleep, time::HasTime}; -use ibc_relayer_runtime::types::error::Error as TokioError; -use std::time::Duration; - -use crate::contexts::runtime::MockRuntimeContext; - -#[async_trait] -impl CanSleep for MockRuntimeContext { - async fn sleep(&self, duration: Duration) { - // Increment the shared MockClock by the duration is milliseconds. - if self.clock.increment_timestamp(duration).is_err() { - tracing::warn!("MockClock failed to sleep for {}ms", duration.as_millis()); - } - } -} - -impl HasTime for MockRuntimeContext { - type Time = Timestamp; - - fn now(&self) -> Self::Time { - self.get_time() - } - - fn duration_since(current_time: &Self::Time, other_time: &Self::Time) -> Duration { - Duration::from_nanos(current_time.nanoseconds() - other_time.nanoseconds()) - } -} - -impl HasErrorType for MockRuntimeContext { - type Error = TokioError; -} diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index 806f3ec83e..ef387f178c 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -1,26 +1,29 @@ use basecoin_store::impls::InMemoryStore; use ibc::core::ics24_host::identifier::ChainId; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use std::str::FromStr; use std::sync::Arc; +use tokio::runtime::Runtime as TokioRuntime; use crate::contexts::basecoin::MockBasecoin; use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; -use crate::contexts::runtime::MockClock; pub fn mock_basecoin_binary_stand() -> ( Arc>>, Arc>>, MockCosmosRelay, MockBasecoin>, ) { - let clock = Arc::new(MockClock::default()); + let runtime = TokioRuntimeContext::new(Arc::new( + TokioRuntime::new().expect("failed to build runtime"), + )); // Source chain setup let src_chain_id = ChainId::from_str("mock-cosmos-chain-0").expect("never fails"); let src_chain = Arc::new(MockBasecoin::new_default(src_chain_id)); src_chain.run(); - let src_chain_ctx = Arc::new(MockCosmosContext::new(src_chain, clock.clone())); + let src_chain_ctx = Arc::new(MockCosmosContext::new(runtime.clone(), src_chain)); src_chain_ctx.sync(); // Destination chain setup @@ -28,11 +31,11 @@ pub fn mock_basecoin_binary_stand() -> ( let dst_chain = Arc::new(MockBasecoin::new_default(dst_chain_id)); dst_chain.run(); - let dst_chain_ctx = Arc::new(MockCosmosContext::new(dst_chain, clock.clone())); + let dst_chain_ctx = Arc::new(MockCosmosContext::new(runtime.clone(), dst_chain)); dst_chain_ctx.sync(); // Relayer setup - let relayer = MockCosmosRelay::new(src_chain_ctx.clone(), dst_chain_ctx.clone(), clock) + let relayer = MockCosmosRelay::new(runtime, src_chain_ctx.clone(), dst_chain_ctx.clone()) .expect("failed to build relayer"); (src_chain_ctx, dst_chain_ctx, relayer) From c422ce2eaefaaa490bad173242544b1fa2d470f9 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 29 Aug 2023 20:18:55 -0700 Subject: [PATCH 18/25] imp: incorporate MockCosmosBuilder --- .../src/contexts/basecoin.rs | 95 ++++++++++++++----- .../src/contexts/builder.rs | 46 +++++++++ .../relayer-cosmos-mock/src/contexts/chain.rs | 58 +---------- .../relayer-cosmos-mock/src/contexts/mod.rs | 1 + .../relayer-cosmos-mock/src/impls/basecoin.rs | 13 ++- .../relayer-cosmos-mock/src/impls/birelay.rs | 24 ++++- crates/relayer-cosmos-mock/src/impls/chain.rs | 5 +- .../src/tests/ics02_client.rs | 34 ++++--- crates/relayer-cosmos-mock/src/tests/init.rs | 58 ++++++----- .../src/traits/endpoint.rs | 13 ++- 10 files changed, 214 insertions(+), 133 deletions(-) create mode 100644 crates/relayer-cosmos-mock/src/contexts/builder.rs diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index b232ea89c2..0210b0eee6 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -12,6 +12,7 @@ use basecoin_app::BaseCoinApp; use basecoin_app::Builder; use basecoin_store::context::ProvableStore; use ibc::core::ics24_host::identifier::ChainId; +use ibc::Height; use ibc_relayer_components_extra::runtime::traits::spawn::Spawner; use ibc_relayer_components_extra::runtime::traits::spawn::TaskHandle; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; @@ -21,9 +22,9 @@ use tendermint_testgen::Generator; use tendermint_testgen::Header; use tendermint_testgen::LightBlock; use tendermint_testgen::Validator; -use tokio::runtime::Runtime as TokioRuntime; use crate::traits::runner::BasecoinRunner; +use crate::types::status::ChainStatus; use crate::util::dummy::generate_rand_app_hash; use crate::util::mutex::MutexUtil; @@ -55,6 +56,8 @@ where pub blocks: Arc>>, /// Chain application pub app: BaseCoinApp, + /// Current chain status + pub current_status: Arc>, } impl MockBasecoin { @@ -85,31 +88,77 @@ impl MockBasecoin { .add_module(prefix::Ibc {}.identifier(), ibc) .build(); + let genesis_height = Height::new(chain_id.revision_number(), 1).expect("never fails"); + + let genesis_time = Time::now(); + + let genesis_block = Self::generate_block( + &chain_id, + genesis_height.revision_height(), + genesis_time, + &validators, + ); + + let genesis_status = Arc::new(Mutex::new(ChainStatus::new( + genesis_height, + genesis_time.into(), + ))); + Self { runtime, chain_id, validators: Arc::new(Mutex::new(validators)), - blocks: Arc::new(Mutex::new(vec![])), + blocks: Arc::new(Mutex::new(vec![genesis_block])), app, + current_status: genesis_status, } } - pub fn new_default(chain_id: ChainId) -> Self { - let validators = vec![ - Validator::new("1").voting_power(40), - Validator::new("2").voting_power(30), - Validator::new("3").voting_power(30), - ]; + pub fn runtime(&self) -> &TokioRuntimeContext { + &self.runtime + } - let runtime = TokioRuntimeContext::new(Arc::new( - TokioRuntime::new().expect("failed to build runtime"), - )); + pub fn get_blocks(&self) -> Vec { + self.blocks.acquire_mutex().clone() + } - Self::new(runtime, chain_id, validators, S::default()) + pub fn get_current_status(&self) -> ChainStatus { + self.current_status.acquire_mutex().clone() } - pub fn runtime(&self) -> &TokioRuntimeContext { - &self.runtime + pub fn update_status(&self) { + let blocks = self.blocks.acquire_mutex(); + + let last_block = blocks.last().expect("never fails"); + + let current_revision_height = last_block.signed_header.header.height.value(); + + let current_time = last_block.signed_header.header.time; + + let current_height = Height::new(self.chain_id.revision_number(), current_revision_height) + .expect("never fails"); + + let mut last_status = self.current_status.acquire_mutex(); + + *last_status = ChainStatus::new(current_height, current_time.into()); + } + + pub fn generate_block( + chain_id: &ChainId, + height: u64, + time: Time, + validators: &[Validator], + ) -> TmLightBlock { + let header = Header::new(validators) + .chain_id(&chain_id.to_string()) + .height(height) + .time(time) + .next_validators(validators) + .app_hash(generate_rand_app_hash()); + + LightBlock::new_default_with_header(header) + .generate() + .expect("failed to generate light block") } pub fn grow_blocks(&self) { @@ -117,18 +166,14 @@ impl MockBasecoin { let validators = self.validators.acquire_mutex(); - let header = Header::new(&validators) - .chain_id(&self.chain_id.to_string()) - .height(blocks.len() as u64 + 1) - .time(Time::now()) - .next_validators(&validators) - .app_hash(generate_rand_app_hash()); - - let tm_light_block = LightBlock::new_default_with_header(header) - .generate() - .expect("failed to generate light block"); + let new_tm_light_block = Self::generate_block( + &self.chain_id, + blocks.len() as u64 + 1, + Time::now(), + &validators, + ); - blocks.push(tm_light_block); + blocks.push(new_tm_light_block); } pub fn run(&self) -> Box { diff --git a/crates/relayer-cosmos-mock/src/contexts/builder.rs b/crates/relayer-cosmos-mock/src/contexts/builder.rs new file mode 100644 index 0000000000..8caf6f40af --- /dev/null +++ b/crates/relayer-cosmos-mock/src/contexts/builder.rs @@ -0,0 +1,46 @@ +use alloc::sync::Arc; +use basecoin_store::impls::InMemoryStore; +use ibc::core::ics24_host::identifier::ChainId; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; +use tendermint_testgen::Validator; +use tokio::runtime::Runtime as TokioRuntime; + +use super::{basecoin::MockBasecoin, chain::MockCosmosContext, relay::MockCosmosRelay}; +use crate::{traits::endpoint::BasecoinEndpoint, types::error::Error}; + +pub struct MockCosmosBuilder { + pub runtime: TokioRuntimeContext, +} + +impl MockCosmosBuilder { + pub fn new(runtime: TokioRuntime) -> Self { + Self { + runtime: TokioRuntimeContext::new(Arc::new(runtime)), + } + } + + pub fn build_chain( + &mut self, + chain_id: ChainId, + validators: Vec, + ) -> Arc> { + let chain = Arc::new(MockBasecoin::new( + self.runtime.clone(), + chain_id, + validators, + InMemoryStore::default(), + )); + + chain.run(); + + chain + } + + pub fn build_relay( + &self, + src_chain_ctx: Arc>, + dst_chain_ctx: Arc>, + ) -> Result, Error> { + MockCosmosRelay::new(self.runtime.clone(), src_chain_ctx, dst_chain_ctx) + } +} diff --git a/crates/relayer-cosmos-mock/src/contexts/chain.rs b/crates/relayer-cosmos-mock/src/contexts/chain.rs index 3cfe7a3dcb..d93d8603ed 100644 --- a/crates/relayer-cosmos-mock/src/contexts/chain.rs +++ b/crates/relayer-cosmos-mock/src/contexts/chain.rs @@ -1,22 +1,14 @@ use basecoin_app::modules::ibc::IbcContext; use basecoin_store::impls::RevertibleStore; use ibc::core::events::IbcEvent; -use ibc::core::timestamp::Timestamp; use ibc::core::ValidationContext; use ibc::Any; -use ibc::Height; -use ibc_relayer_components::runtime::traits::sleep::CanSleep; -use ibc_relayer_components_extra::runtime::traits::spawn::Spawner; -use ibc_relayer_components_extra::runtime::traits::spawn::TaskHandle; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use std::sync::Arc; -use std::sync::Mutex; use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; -use crate::types::status::ChainStatus; -use crate::util::mutex::MutexUtil; /// Holds the necessary fields for querying a mock Cosmos /// chain endpoint. @@ -26,23 +18,12 @@ pub struct MockCosmosContext { pub runtime: TokioRuntimeContext, /// Chain handle pub querier: Arc, - /// Current chain status - pub current_status: Arc>, } impl MockCosmosContext { /// Constructs a new mock cosmos chain instance. pub fn new(runtime: TokioRuntimeContext, querier: Arc) -> Self { - let current_status = Arc::new(Mutex::new(ChainStatus::new( - Height::new(querier.get_chain_id().revision_number(), 1).expect("never fails"), - Timestamp::now(), - ))); - - Self { - runtime, - querier, - current_status, - } + Self { runtime, querier } } pub fn runtime(&self) -> &TokioRuntimeContext { @@ -55,43 +36,6 @@ impl MockCosmosContext { self.ibc().ctx() } - pub fn get_current_timestamp(&self) -> Timestamp { - self.current_status.acquire_mutex().timestamp - } - - pub fn get_current_height(&self) -> Height { - self.current_status.acquire_mutex().height - } - - /// Keeps the chain context updated by continuously tracking the latest generated block. - pub fn sync(&self) -> Box { - let ctx = self.clone(); - self.runtime().spawn(async move { - let mut blocks_len = 1; - loop { - ctx.runtime() - .sleep(tokio::time::Duration::from_millis(200)) - .await; - - if ctx.get_blocks().len() <= blocks_len { - continue; - } - - let current_timestamp = ctx.ibc_context().host_timestamp().unwrap(); - - let current_height = ctx.ibc_context().host_height().unwrap(); - - let current_status = ChainStatus::new(current_height, current_timestamp); - - let mut last_status = ctx.current_status.acquire_mutex(); - - *last_status = current_status; - - blocks_len = ctx.get_blocks().len(); - } - }) - } - pub fn submit_messages(&self, msgs: Vec) -> Result>, Error> { let mut events = Vec::new(); diff --git a/crates/relayer-cosmos-mock/src/contexts/mod.rs b/crates/relayer-cosmos-mock/src/contexts/mod.rs index 506538660c..9fb62048cc 100644 --- a/crates/relayer-cosmos-mock/src/contexts/mod.rs +++ b/crates/relayer-cosmos-mock/src/contexts/mod.rs @@ -1,4 +1,5 @@ pub mod basecoin; pub mod birelay; +pub mod builder; pub mod chain; pub mod relay; diff --git a/crates/relayer-cosmos-mock/src/impls/basecoin.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs index b026dde345..a54c42b72d 100644 --- a/crates/relayer-cosmos-mock/src/impls/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -16,6 +16,7 @@ use basecoin_store::utils::SharedRwExt; use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; use ibc::core::ics24_host::identifier::ChainId; use ibc::core::ics24_host::path::Path; +use ibc::core::timestamp::Timestamp; use ibc::hosts::tendermint::IBC_QUERY_PATH; use ibc::Height; @@ -57,9 +58,6 @@ where app.call(AbciRequest::InitChain(request)) .await .expect("failed to initialize chain"); - - // Generates the genesis block - self.grow_blocks(); } async fn begin_block(&self) { @@ -95,6 +93,7 @@ where state.commit().expect("failed to commit to state"); self.grow_blocks(); + self.update_status(); } } @@ -145,8 +144,12 @@ impl BasecoinEndpoint for MockBasecoin { &self.chain_id } - fn get_blocks(&self) -> Vec { - self.blocks.acquire_mutex().clone() + fn get_current_height(&self) -> Height { + self.get_current_status().height + } + + fn get_current_timestamp(&self) -> Timestamp { + self.get_current_status().timestamp } fn get_light_block(&self, height: &Height) -> Result { diff --git a/crates/relayer-cosmos-mock/src/impls/birelay.rs b/crates/relayer-cosmos-mock/src/impls/birelay.rs index 8bd94889aa..8ba6012db2 100644 --- a/crates/relayer-cosmos-mock/src/impls/birelay.rs +++ b/crates/relayer-cosmos-mock/src/impls/birelay.rs @@ -1,16 +1,36 @@ use ibc_relayer_components::core::traits::error::HasErrorType; use ibc_relayer_components::relay::traits::two_way::HasTwoWayRelay; +use ibc_relayer_components::runtime::traits::runtime::HasRuntime; +use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use crate::contexts::{birelay::MockCosmosBiRelay, relay::MockCosmosRelay}; use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; -impl HasErrorType - for MockCosmosBiRelay +impl HasErrorType for MockCosmosBiRelay +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, { type Error = Error; } +impl HasRuntime for MockCosmosBiRelay +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + type Runtime = TokioRuntimeContext; + + fn runtime(&self) -> &Self::Runtime { + &self.runtime + } + + fn runtime_error(e: ::Error) -> Self::Error { + Error::source(e) + } +} + impl HasTwoWayRelay for MockCosmosBiRelay where SrcChain: BasecoinEndpoint, diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index a0a9414989..8b0c88ff64 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -278,7 +278,10 @@ impl HasChainStatusType for MockCosmosContext { #[async_trait] impl CanQueryChainStatus for MockCosmosContext { async fn query_chain_status(&self) -> Result { - Ok(self.current_status.lock().unwrap().clone()) + Ok(ChainStatus::new( + self.get_current_height(), + self.get_current_timestamp(), + )) } } diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs index a5c83eb36d..d4a0c10390 100644 --- a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -1,6 +1,7 @@ use crate::contexts::basecoin::MockBasecoin; use crate::contexts::chain::MockCosmosContext; -use crate::tests::init::mock_basecoin_binary_stand; +use crate::tests::init::binary_setup; +use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use basecoin_store::impls::InMemoryStore; @@ -9,22 +10,24 @@ use ibc::core::ValidationContext; use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientPayload; use ibc_relayer_components::relay::traits::target::SourceTarget; use ibc_relayer_components::relay::traits::update_client::CanBuildUpdateClientMessage; +use ibc_relayer_components::runtime::traits::sleep::CanSleep; #[tokio::test] async fn test_create_client() -> Result<(), Error> { - let (src_chain_ctx, dst_chain_ctx, _) = mock_basecoin_binary_stand(); - - tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; + let relayer = binary_setup().await; let msg_create_client = > as CanBuildCreateClientPayload< MockCosmosContext>, - >>::build_create_client_payload(&src_chain_ctx, &()) + >>::build_create_client_payload(relayer.src_chain(), &()) .await?; - dst_chain_ctx.submit_messages(vec![msg_create_client])?; + relayer + .dst_chain() + .submit_messages(vec![msg_create_client])?; - assert!(dst_chain_ctx + assert!(relayer + .dst_chain() .ibc_context() .client_state(&ClientId::default()) .is_ok()); @@ -34,21 +37,24 @@ async fn test_create_client() -> Result<(), Error> { #[tokio::test] async fn test_update_client() -> Result<(), Error> { - let (src_chain_ctx, dst_chain_ctx, relayer) = mock_basecoin_binary_stand(); - - tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; + let relayer = binary_setup().await; let msg_create_client = > as CanBuildCreateClientPayload< MockCosmosContext>, - >>::build_create_client_payload(&src_chain_ctx, &()) + >>::build_create_client_payload(relayer.src_chain(), &()) .await?; - dst_chain_ctx.submit_messages(vec![msg_create_client])?; + relayer + .dst_chain() + .submit_messages(vec![msg_create_client])?; - tokio::time::sleep(tokio::time::Duration::from_millis(200)).await; + relayer + .runtime() + .sleep(tokio::time::Duration::from_millis(200)) + .await; - let src_current_height = src_chain_ctx.get_current_height(); + let src_current_height = relayer.src_chain().get_current_height(); let msg_update_client = relayer .build_update_client_messages(SourceTarget, &src_current_height) diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index ef387f178c..5d2c360e47 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -1,42 +1,48 @@ use basecoin_store::impls::InMemoryStore; use ibc::core::ics24_host::identifier::ChainId; -use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; +use ibc_relayer_components::runtime::traits::sleep::CanSleep; use std::str::FromStr; use std::sync::Arc; +use tendermint_testgen::Validator; use tokio::runtime::Runtime as TokioRuntime; use crate::contexts::basecoin::MockBasecoin; +use crate::contexts::builder::MockCosmosBuilder; use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; -pub fn mock_basecoin_binary_stand() -> ( - Arc>>, - Arc>>, - MockCosmosRelay, MockBasecoin>, -) { - let runtime = TokioRuntimeContext::new(Arc::new( - TokioRuntime::new().expect("failed to build runtime"), - )); +pub async fn binary_setup( +) -> MockCosmosRelay, MockBasecoin> { + let mut builder = MockCosmosBuilder::new(TokioRuntime::new().expect("failed to build runtime")); - // Source chain setup + // Setup and run the source chain let src_chain_id = ChainId::from_str("mock-cosmos-chain-0").expect("never fails"); - let src_chain = Arc::new(MockBasecoin::new_default(src_chain_id)); - src_chain.run(); - - let src_chain_ctx = Arc::new(MockCosmosContext::new(runtime.clone(), src_chain)); - src_chain_ctx.sync(); - - // Destination chain setup + let src_validators = vec![ + Validator::new("1").voting_power(40), + Validator::new("2").voting_power(30), + Validator::new("3").voting_power(30), + ]; + let src_chain = builder.build_chain(src_chain_id, src_validators); + + // Setup and run the destination chain let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").expect("never fails"); - let dst_chain = Arc::new(MockBasecoin::new_default(dst_chain_id)); - dst_chain.run(); - - let dst_chain_ctx = Arc::new(MockCosmosContext::new(runtime.clone(), dst_chain)); - dst_chain_ctx.sync(); - - // Relayer setup - let relayer = MockCosmosRelay::new(runtime, src_chain_ctx.clone(), dst_chain_ctx.clone()) + let dst_validators = vec![ + Validator::new("1").voting_power(50), + Validator::new("2").voting_power(50), + ]; + let dst_chain = builder.build_chain(dst_chain_id, dst_validators); + + // Setup relayer + let src_chain_ctx = Arc::new(MockCosmosContext::new(builder.runtime.clone(), src_chain)); + let dst_chain_ctx = Arc::new(MockCosmosContext::new(builder.runtime.clone(), dst_chain)); + let relayer = MockCosmosRelay::new(builder.runtime.clone(), src_chain_ctx, dst_chain_ctx) .expect("failed to build relayer"); - (src_chain_ctx, dst_chain_ctx, relayer) + // Wait for chains to produce some initial blocks + relayer + .runtime() + .sleep(std::time::Duration::from_millis(500)) + .await; + + relayer } diff --git a/crates/relayer-cosmos-mock/src/traits/endpoint.rs b/crates/relayer-cosmos-mock/src/traits/endpoint.rs index 17f5a1e833..d6710f0243 100644 --- a/crates/relayer-cosmos-mock/src/traits/endpoint.rs +++ b/crates/relayer-cosmos-mock/src/traits/endpoint.rs @@ -4,6 +4,7 @@ use basecoin_store::impls::RevertibleStore; use ibc::core::ics23_commitment::commitment::CommitmentProofBytes; use ibc::core::ics24_host::identifier::ChainId; use ibc::core::ics24_host::path::Path; +use ibc::core::timestamp::Timestamp; use ibc::Height; use ibc_relayer_components::core::traits::sync::Async; use tendermint_testgen::light_block::TmLightBlock; @@ -38,7 +39,9 @@ pub trait BasecoinEndpoint: Async + Clone { fn get_chain_id(&self) -> &ChainId; - fn get_blocks(&self) -> Vec; + fn get_current_height(&self) -> Height; + + fn get_current_timestamp(&self) -> Timestamp; fn get_light_block(&self, height: &Height) -> Result; } @@ -66,8 +69,12 @@ where Ctx::service(self).get_chain_id() } - fn get_blocks(&self) -> Vec { - Ctx::service(self).get_blocks() + fn get_current_height(&self) -> Height { + Ctx::service(self).get_current_height() + } + + fn get_current_timestamp(&self) -> Timestamp { + Ctx::service(self).get_current_timestamp() } fn get_light_block(&self, height: &Height) -> Result { From d31f34c46c2bf0c1b1c3cb285fd5c8db19d4bb6b Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Wed, 30 Aug 2023 14:25:52 -0700 Subject: [PATCH 19/25] Add docstring for `MockCosmosRelay` Co-authored-by: Sean Chen Signed-off-by: Farhad Shabani --- crates/relayer-cosmos-mock/src/contexts/relay.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/relayer-cosmos-mock/src/contexts/relay.rs b/crates/relayer-cosmos-mock/src/contexts/relay.rs index 2153caef3f..a0b7b40228 100644 --- a/crates/relayer-cosmos-mock/src/contexts/relay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/relay.rs @@ -12,6 +12,11 @@ use crate::util::msgs::build_transfer_packet; use super::chain::MockCosmosContext; +/// The relay context for relaying between `BasecoinEndpoint`s. +/// +/// The `SrcChain` and `DstChain` endpoints are wrapped in +/// `MockCosmosContext`, which bundles the `BasecoinEndpoint` with +/// the runtime. #[derive(Clone)] pub struct MockCosmosRelay where From d12f332a58a31ac806434c35206744770cc1ec97 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Wed, 30 Aug 2023 14:47:52 -0700 Subject: [PATCH 20/25] imp: some clean-ups --- .../src/contexts/builder.rs | 20 +++++++++---- .../relayer-cosmos-mock/src/contexts/relay.rs | 22 ++------------- .../src/impls/components.rs | 28 ------------------- crates/relayer-cosmos-mock/src/tests/init.rs | 8 ++---- 4 files changed, 19 insertions(+), 59 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/builder.rs b/crates/relayer-cosmos-mock/src/contexts/builder.rs index 8caf6f40af..26fa53c8b5 100644 --- a/crates/relayer-cosmos-mock/src/contexts/builder.rs +++ b/crates/relayer-cosmos-mock/src/contexts/builder.rs @@ -5,8 +5,10 @@ use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use tendermint_testgen::Validator; use tokio::runtime::Runtime as TokioRuntime; -use super::{basecoin::MockBasecoin, chain::MockCosmosContext, relay::MockCosmosRelay}; -use crate::{traits::endpoint::BasecoinEndpoint, types::error::Error}; +use crate::contexts::basecoin::MockBasecoin; +use crate::contexts::chain::MockCosmosContext; +use crate::contexts::relay::MockCosmosRelay; +use crate::traits::endpoint::BasecoinEndpoint; pub struct MockCosmosBuilder { pub runtime: TokioRuntimeContext, @@ -38,9 +40,15 @@ impl MockCosmosBuilder { pub fn build_relay( &self, - src_chain_ctx: Arc>, - dst_chain_ctx: Arc>, - ) -> Result, Error> { - MockCosmosRelay::new(self.runtime.clone(), src_chain_ctx, dst_chain_ctx) + src_chain: Arc, + dst_chain: Arc, + ) -> Arc> { + let src_chain_ctx = Arc::new(MockCosmosContext::new(self.runtime.clone(), src_chain)); + let dst_chain_ctx = Arc::new(MockCosmosContext::new(self.runtime.clone(), dst_chain)); + + Arc::new( + MockCosmosRelay::new(self.runtime.clone(), src_chain_ctx, dst_chain_ctx) + .expect("failed to build relay"), + ) } } diff --git a/crates/relayer-cosmos-mock/src/contexts/relay.rs b/crates/relayer-cosmos-mock/src/contexts/relay.rs index a0b7b40228..6a4d71e6be 100644 --- a/crates/relayer-cosmos-mock/src/contexts/relay.rs +++ b/crates/relayer-cosmos-mock/src/contexts/relay.rs @@ -1,22 +1,19 @@ use ibc::clients::ics07_tendermint::client_type; use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; -use ibc_relayer_components::relay::traits::packet_relayer::CanRelayPacket; -use ibc_relayer_components_extra::runtime::traits::spawn::{Spawner, TaskHandle}; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; use std::sync::Arc; use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; -use crate::util::msgs::build_transfer_packet; use super::chain::MockCosmosContext; -/// The relay context for relaying between `BasecoinEndpoint`s. +/// The relay context for relaying between `BasecoinEndpoint`s. /// /// The `SrcChain` and `DstChain` endpoints are wrapped in -/// `MockCosmosContext`, which bundles the `BasecoinEndpoint` with -/// the runtime. +/// `MockCosmosContext`, which bundles the `BasecoinEndpoint` with +/// the runtime. #[derive(Clone)] pub struct MockCosmosRelay where @@ -76,17 +73,4 @@ where pub fn dst_client_id(&self) -> &ClientId { &self.dst_client_id } - - pub fn spawn(&mut self) -> Box { - let packet = build_transfer_packet(1); - - let relayer = self.clone(); - - self.runtime().spawn(async move { - relayer - .relay_packet(&packet) - .await - .expect("failed to relay packet"); - }) - } } diff --git a/crates/relayer-cosmos-mock/src/impls/components.rs b/crates/relayer-cosmos-mock/src/impls/components.rs index 75131e7144..77645ecbae 100644 --- a/crates/relayer-cosmos-mock/src/impls/components.rs +++ b/crates/relayer-cosmos-mock/src/impls/components.rs @@ -1,49 +1,21 @@ -use ibc::core::ics04_channel::packet::Packet; -use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketTypes; use ibc_relayer_components::relay::components::message_senders::chain_sender::SendIbcMessagesToChain; use ibc_relayer_components::relay::components::message_senders::update_client::SendIbcMessagesWithUpdateClient; use ibc_relayer_components::relay::components::update_client::skip::SkipUpdateClient; use ibc_relayer_components::relay::components::update_client::wait::WaitUpdateClient; use ibc_relayer_components::relay::components::packet_relayers::ack::base_ack_packet::BaseAckPacketRelayer; -use ibc_relayer_components::relay::components::packet_relayers::general::full_relay::FullCycleRelayer; use ibc_relayer_components::relay::components::packet_relayers::receive::base_receive_packet::BaseReceivePacketRelayer; use ibc_relayer_components::relay::components::packet_relayers::receive::skip_received_packet::SkipReceivedPacketRelayer; use ibc_relayer_components::relay::components::packet_relayers::timeout_unordered::timeout_unordered_packet::BaseTimeoutUnorderedPacketRelayer; use ibc_relayer_components::relay::traits::ibc_message_sender::{MainSink, IbcMessageSenderComponent}; use ibc_relayer_components::relay::traits::update_client::UpdateClientMessageBuilderComponent; -use ibc_relayer_components::relay::traits::packet_relayer::PacketRelayerComponent; -use ibc_relayer_components::relay::traits::packet_relayer::PacketRelayer; use ibc_relayer_components::relay::traits::packet_relayers::ack_packet::AckPacketRelayerComponent; use ibc_relayer_components::relay::traits::packet_relayers::receive_packet::ReceivePacketRelayerComponnent; use ibc_relayer_components::relay::traits::packet_relayers::timeout_unordered_packet::TimeoutUnorderedPacketRelayerComponent; -use crate::contexts::relay::MockCosmosRelay; use crate::impls::relay::MockCosmosBuildUpdateClientMessage; -use crate::traits::endpoint::BasecoinEndpoint; -use crate::types::error::Error; pub struct MockCosmosComponents; -#[async_trait::async_trait] -impl PacketRelayer> for MockCosmosComponents -where - SrcChain: BasecoinEndpoint, - DstChain: BasecoinEndpoint, -{ - async fn relay_packet( - _relay: &MockCosmosRelay, - _packet: &Packet, - ) -> Result<(), Error> { - unimplemented!() - } -} - -// ibc_relayer_components::delegate_component!( -// PacketRelayerComponent, -// MockCosmosComponents, -// FullCycleRelayer, -// ); - ibc_relayer_components::delegate_component!( IbcMessageSenderComponent, MockCosmosComponents, diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index 5d2c360e47..7f4c1d5a60 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -8,11 +8,10 @@ use tokio::runtime::Runtime as TokioRuntime; use crate::contexts::basecoin::MockBasecoin; use crate::contexts::builder::MockCosmosBuilder; -use crate::contexts::chain::MockCosmosContext; use crate::contexts::relay::MockCosmosRelay; pub async fn binary_setup( -) -> MockCosmosRelay, MockBasecoin> { +) -> Arc, MockBasecoin>> { let mut builder = MockCosmosBuilder::new(TokioRuntime::new().expect("failed to build runtime")); // Setup and run the source chain @@ -33,10 +32,7 @@ pub async fn binary_setup( let dst_chain = builder.build_chain(dst_chain_id, dst_validators); // Setup relayer - let src_chain_ctx = Arc::new(MockCosmosContext::new(builder.runtime.clone(), src_chain)); - let dst_chain_ctx = Arc::new(MockCosmosContext::new(builder.runtime.clone(), dst_chain)); - let relayer = MockCosmosRelay::new(builder.runtime.clone(), src_chain_ctx, dst_chain_ctx) - .expect("failed to build relayer"); + let relayer = builder.build_relay(src_chain, dst_chain); // Wait for chains to produce some initial blocks relayer From 07074a83b82007f2cedd2eaeba9958350957089e Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Mon, 4 Sep 2023 22:46:54 -0700 Subject: [PATCH 21/25] nit: cargo fmt --- crates/relayer-cosmos/src/contexts/builder.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/relayer-cosmos/src/contexts/builder.rs b/crates/relayer-cosmos/src/contexts/builder.rs index 1b5354cf22..9b4122f63e 100644 --- a/crates/relayer-cosmos/src/contexts/builder.rs +++ b/crates/relayer-cosmos/src/contexts/builder.rs @@ -164,7 +164,9 @@ pub fn get_keypair( let keypair = handle.get_key().map_err(BaseError::relayer)?; let AnySigningKeyPair::Secp256k1(key) = keypair else { - return Err(BaseError::generic(eyre!("no Secp256k1 key pair for chain {}", chain_id)).into()); + return Err( + BaseError::generic(eyre!("no Secp256k1 key pair for chain {}", chain_id)).into(), + ); }; Ok(key) From f0675bc4375c8238d1612907d6f87f8c22ddea33 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 7 Sep 2023 12:16:17 -0700 Subject: [PATCH 22/25] fix: implement missed traits for chain and component --- .../src/contexts/builder.rs | 13 +- crates/relayer-cosmos-mock/src/impls/chain.rs | 186 ++++++++++++++---- .../src/impls/components.rs | 32 ++- crates/relayer-cosmos-mock/src/impls/relay.rs | 27 ++- .../src/tests/ics02_client.rs | 15 +- crates/relayer-cosmos-mock/src/tests/init.rs | 4 +- 6 files changed, 217 insertions(+), 60 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/builder.rs b/crates/relayer-cosmos-mock/src/contexts/builder.rs index 26fa53c8b5..012cce63af 100644 --- a/crates/relayer-cosmos-mock/src/contexts/builder.rs +++ b/crates/relayer-cosmos-mock/src/contexts/builder.rs @@ -1,7 +1,8 @@ use alloc::sync::Arc; -use basecoin_store::impls::InMemoryStore; +use basecoin_store::context::ProvableStore; use ibc::core::ics24_host::identifier::ChainId; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; +use std::fmt::Debug; use tendermint_testgen::Validator; use tokio::runtime::Runtime as TokioRuntime; @@ -21,16 +22,20 @@ impl MockCosmosBuilder { } } - pub fn build_chain( + pub fn build_chain( &mut self, chain_id: ChainId, validators: Vec, - ) -> Arc> { + store: S, + ) -> Arc> + where + S: ProvableStore + Debug + Default, + { let chain = Arc::new(MockBasecoin::new( self.runtime.clone(), chain_id, validators, - InMemoryStore::default(), + store, )); chain.run(); diff --git a/crates/relayer-cosmos-mock/src/impls/chain.rs b/crates/relayer-cosmos-mock/src/impls/chain.rs index 8b0c88ff64..c0db69e3ce 100644 --- a/crates/relayer-cosmos-mock/src/impls/chain.rs +++ b/crates/relayer-cosmos-mock/src/impls/chain.rs @@ -6,9 +6,11 @@ use async_trait::async_trait; use basecoin_app::modules::ibc::AnyConsensusState; use ibc::clients::ics07_tendermint::client_state::{AllowUpdate, ClientState as TmClientState}; use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; +use ibc::clients::ics07_tendermint::header::Header; use ibc::core::events::IbcEvent; use ibc::core::ics02_client::events::CreateClient; use ibc::core::ics02_client::msgs::create_client::MsgCreateClient; +use ibc::core::ics02_client::msgs::update_client::MsgUpdateClient; use ibc::core::ics04_channel::events::{SendPacket, WriteAcknowledgement}; use ibc::core::ics04_channel::msgs::{MsgAcknowledgement, MsgRecvPacket, MsgTimeout}; use ibc::core::ics04_channel::packet::Packet; @@ -21,11 +23,20 @@ use ibc::core::{Msg, ValidationContext}; use ibc::Any; use ibc::Height; +use ibc_relayer_components::chain::traits::client::client_state::CanQueryClientState; +use ibc_relayer_components::chain::traits::client::consensus_state::CanFindConsensusStateHeight; use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientMessage; use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientPayload; use ibc_relayer_components::chain::traits::client::create::HasCreateClientEvent; use ibc_relayer_components::chain::traits::client::create::HasCreateClientOptions; use ibc_relayer_components::chain::traits::client::create::HasCreateClientPayload; +use ibc_relayer_components::chain::traits::client::update::{ + CanBuildUpdateClientMessage, CanBuildUpdateClientPayload, HasUpdateClientPayload, +}; +use ibc_relayer_components::chain::traits::components::chain_status_querier::CanQueryChainStatus; +use ibc_relayer_components::chain::traits::components::consensus_state_querier::CanQueryConsensusState; +use ibc_relayer_components::chain::traits::components::message_sender::CanSendMessages; +use ibc_relayer_components::chain::traits::components::packet_fields_reader::CanReadPacketFields; use ibc_relayer_components::chain::traits::logs::event::CanLogChainEvent; use ibc_relayer_components::chain::traits::logs::packet::CanLogChainPacket; use ibc_relayer_components::chain::traits::message_builders::ack_packet::CanBuildAckPacketMessage; @@ -34,14 +45,13 @@ use ibc_relayer_components::chain::traits::message_builders::receive_packet::Can use ibc_relayer_components::chain::traits::message_builders::receive_packet::CanBuildReceivePacketPayload; use ibc_relayer_components::chain::traits::message_builders::timeout_unordered_packet::CanBuildTimeoutUnorderedPacketMessage; use ibc_relayer_components::chain::traits::message_builders::timeout_unordered_packet::CanBuildTimeoutUnorderedPacketPayload; -use ibc_relayer_components::chain::traits::message_sender::CanSendMessages; -use ibc_relayer_components::chain::traits::queries::consensus_state::CanQueryConsensusState; use ibc_relayer_components::chain::traits::queries::received_packet::CanQueryReceivedPacket; -use ibc_relayer_components::chain::traits::queries::status::CanQueryChainStatus; use ibc_relayer_components::chain::traits::queries::write_ack::CanQueryWriteAcknowledgement; use ibc_relayer_components::chain::traits::types::chain_id::HasChainId; use ibc_relayer_components::chain::traits::types::chain_id::HasChainIdType; -use ibc_relayer_components::chain::traits::types::client_state::HasClientStateType; +use ibc_relayer_components::chain::traits::types::client_state::{ + HasClientStateFields, HasClientStateType, +}; use ibc_relayer_components::chain::traits::types::consensus_state::HasConsensusStateType; use ibc_relayer_components::chain::traits::types::event::HasEventType; use ibc_relayer_components::chain::traits::types::height::CanIncrementHeight; @@ -52,7 +62,6 @@ use ibc_relayer_components::chain::traits::types::ibc_events::send_packet::HasSe use ibc_relayer_components::chain::traits::types::ibc_events::write_ack::HasWriteAcknowledgementEvent; use ibc_relayer_components::chain::traits::types::message::CanEstimateMessageSize; use ibc_relayer_components::chain::traits::types::message::HasMessageType; -use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketFields; use ibc_relayer_components::chain::traits::types::packet::HasIbcPacketTypes; use ibc_relayer_components::chain::traits::types::packets::ack::HasAckPacketPayload; use ibc_relayer_components::chain::traits::types::packets::receive::HasReceivePacketPayload; @@ -161,97 +170,88 @@ where type OutgoingPacket = Packet; } -impl CanLogChainPacket> - for MockCosmosContext -where - SrcChain: BasecoinEndpoint, - DstChain: BasecoinEndpoint, -{ - fn log_incoming_packet(packet: &Packet) -> LogValue<'_> { - LogValue::Display(packet) - } - - fn log_outgoing_packet(packet: &Packet) -> LogValue<'_> { - LogValue::Display(packet) - } -} - -impl HasIbcPacketFields> +impl CanReadPacketFields> for MockCosmosContext where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { - fn incoming_packet_src_channel_id(packet: &Self::IncomingPacket) -> &Self::ChannelId { + fn incoming_packet_src_channel_id(packet: &Packet) -> &ChannelId { &packet.chan_id_on_a } - fn incoming_packet_src_port(packet: &Self::IncomingPacket) -> &Self::PortId { + fn incoming_packet_src_port(packet: &Packet) -> &PortId { &packet.port_id_on_a } - fn incoming_packet_dst_channel_id(packet: &Self::IncomingPacket) -> &Self::ChannelId { + fn incoming_packet_dst_channel_id(packet: &Packet) -> &ChannelId { &packet.chan_id_on_b } - fn incoming_packet_dst_port(packet: &Self::IncomingPacket) -> &Self::PortId { + fn incoming_packet_dst_port(packet: &Packet) -> &PortId { &packet.port_id_on_b } - fn incoming_packet_sequence(packet: &Self::IncomingPacket) -> &Self::Sequence { + fn incoming_packet_sequence(packet: &Packet) -> &Sequence { &packet.seq_on_a } - fn incoming_packet_timeout_height(packet: &Self::IncomingPacket) -> Option<&Self::Height> { + fn incoming_packet_timeout_height(packet: &Packet) -> Option<&Height> { match &packet.timeout_height_on_b { TimeoutHeight::Never => None, TimeoutHeight::At(height) => Some(height), } } - fn incoming_packet_timeout_timestamp(packet: &Self::IncomingPacket) -> &Self::Timestamp { + fn incoming_packet_timeout_timestamp(packet: &Packet) -> &Timestamp { &packet.timeout_timestamp_on_b } - fn outgoing_packet_src_channel_id(packet: &Self::OutgoingPacket) -> &Self::ChannelId { + fn outgoing_packet_src_channel_id(packet: &Packet) -> &ChannelId { &packet.chan_id_on_a } - fn outgoing_packet_src_port(packet: &Self::OutgoingPacket) -> &Self::PortId { + fn outgoing_packet_src_port(packet: &Packet) -> &PortId { &packet.port_id_on_a } - fn outgoing_packet_dst_port(packet: &Self::OutgoingPacket) -> &Self::PortId { + fn outgoing_packet_dst_port(packet: &Packet) -> &PortId { &packet.port_id_on_b } - fn outgoing_packet_dst_channel_id(packet: &Self::OutgoingPacket) -> &Self::ChannelId { + fn outgoing_packet_dst_channel_id(packet: &Packet) -> &ChannelId { &packet.chan_id_on_b } - fn outgoing_packet_sequence(packet: &Self::OutgoingPacket) -> &Self::Sequence { + fn outgoing_packet_sequence(packet: &Packet) -> &Sequence { &packet.seq_on_a } - fn outgoing_packet_timeout_height(packet: &Self::OutgoingPacket) -> Option<&Self::Height> { + fn outgoing_packet_timeout_height(packet: &Packet) -> Option<&Height> { match &packet.timeout_height_on_b { TimeoutHeight::Never => None, TimeoutHeight::At(height) => Some(height), } } - fn outgoing_packet_timeout_timestamp(packet: &Self::OutgoingPacket) -> &Self::Timestamp { + fn outgoing_packet_timeout_timestamp(packet: &Packet) -> &Timestamp { &packet.timeout_timestamp_on_b } } -impl HasConsensusStateType> +impl CanLogChainPacket> for MockCosmosContext where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { - type ConsensusState = TmConsensusState; + fn log_incoming_packet(packet: &Packet) -> LogValue<'_> { + LogValue::Display(packet) + } + + fn log_outgoing_packet(packet: &Packet) -> LogValue<'_> { + LogValue::Display(packet) + } } impl HasClientStateType> @@ -263,6 +263,56 @@ where type ClientState = TmClientState; } +impl HasClientStateFields> + for MockCosmosContext +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + fn client_state_latest_height(client_state: &TmClientState) -> &Self::Height { + &client_state.latest_height + } +} + +#[async_trait] +impl CanQueryClientState> + for MockCosmosContext +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + async fn query_client_state(&self, client_id: &ClientId) -> Result { + self.ibc_context() + .client_state(client_id) + .map_err(Error::source) + } +} + +impl HasConsensusStateType> + for MockCosmosContext +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + type ConsensusState = TmConsensusState; +} + +#[async_trait] +impl CanFindConsensusStateHeight> + for MockCosmosContext +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + async fn find_consensus_state_height_before( + &self, + _client_id: &ClientId, + target_height: &Height, + ) -> Result { + target_height.decrement().map_err(Error::source) + } +} + impl HasChainStatusType for MockCosmosContext { type ChainStatus = ChainStatus; @@ -380,6 +430,68 @@ where } } +impl HasUpdateClientPayload> + for MockCosmosContext +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + type UpdateClientPayload = MsgUpdateClient; +} + +#[async_trait] +impl CanBuildUpdateClientPayload> + for MockCosmosContext +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + async fn build_update_client_payload( + &self, + trusted_height: &Height, + target_height: &Height, + _client_state: TmClientState, + ) -> Result { + let light_block = self.get_light_block(target_height)?; + + let header = Header { + signed_header: light_block.signed_header, + validator_set: light_block.validators, + trusted_height: *trusted_height, + trusted_next_validator_set: light_block.next_validators, + }; + + let default_client_id = ClientId::default(); + + let msg_update_client = MsgUpdateClient { + client_id: default_client_id, + client_message: header.into(), + signer: dummy_signer(), + }; + + Ok(msg_update_client) + } +} + +#[async_trait] +impl CanBuildUpdateClientMessage> + for MockCosmosContext +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + async fn build_update_client_message( + &self, + client_id: &ClientId, + payload: MsgUpdateClient, + ) -> Result, Self::Error> { + let mut message = payload; + message.client_id = client_id.clone(); + + Ok(vec![message.to_any()]) + } +} + impl HasSendPacketEvent> for MockCosmosContext where diff --git a/crates/relayer-cosmos-mock/src/impls/components.rs b/crates/relayer-cosmos-mock/src/impls/components.rs index 77645ecbae..a55163cc58 100644 --- a/crates/relayer-cosmos-mock/src/impls/components.rs +++ b/crates/relayer-cosmos-mock/src/impls/components.rs @@ -1,21 +1,37 @@ use ibc_relayer_components::relay::components::message_senders::chain_sender::SendIbcMessagesToChain; use ibc_relayer_components::relay::components::message_senders::update_client::SendIbcMessagesWithUpdateClient; +use ibc_relayer_components::relay::components::packet_filters::allow_all::AllowAll; +use ibc_relayer_components::relay::components::packet_relayers::general::full_relay::FullCycleRelayer; use ibc_relayer_components::relay::components::update_client::skip::SkipUpdateClient; use ibc_relayer_components::relay::components::update_client::wait::WaitUpdateClient; use ibc_relayer_components::relay::components::packet_relayers::ack::base_ack_packet::BaseAckPacketRelayer; use ibc_relayer_components::relay::components::packet_relayers::receive::base_receive_packet::BaseReceivePacketRelayer; use ibc_relayer_components::relay::components::packet_relayers::receive::skip_received_packet::SkipReceivedPacketRelayer; use ibc_relayer_components::relay::components::packet_relayers::timeout_unordered::timeout_unordered_packet::BaseTimeoutUnorderedPacketRelayer; -use ibc_relayer_components::relay::traits::ibc_message_sender::{MainSink, IbcMessageSenderComponent}; -use ibc_relayer_components::relay::traits::update_client::UpdateClientMessageBuilderComponent; -use ibc_relayer_components::relay::traits::packet_relayers::ack_packet::AckPacketRelayerComponent; -use ibc_relayer_components::relay::traits::packet_relayers::receive_packet::ReceivePacketRelayerComponnent; -use ibc_relayer_components::relay::traits::packet_relayers::timeout_unordered_packet::TimeoutUnorderedPacketRelayerComponent; +use ibc_relayer_components::relay::traits::components::ibc_message_sender::{IbcMessageSenderComponent, MainSink}; +use ibc_relayer_components::relay::traits::components::packet_filter::PacketFilterComponent; +use ibc_relayer_components::relay::traits::components::packet_relayer::PacketRelayerComponent; +use ibc_relayer_components::relay::traits::components::packet_relayers::ack_packet::AckPacketRelayerComponent; +use ibc_relayer_components::relay::traits::components::packet_relayers::receive_packet::ReceivePacketRelayerComponnent; +use ibc_relayer_components::relay::traits::components::packet_relayers::timeout_unordered_packet::TimeoutUnorderedPacketRelayerComponent; +use ibc_relayer_components::relay::traits::components::update_client_message_builder::UpdateClientMessageBuilderComponent; use crate::impls::relay::MockCosmosBuildUpdateClientMessage; pub struct MockCosmosComponents; +ibc_relayer_components::delegate_component!( + PacketRelayerComponent, + MockCosmosComponents, + FullCycleRelayer, +); + +ibc_relayer_components::delegate_component!( + UpdateClientMessageBuilderComponent, + MockCosmosComponents, + SkipUpdateClient>, +); + ibc_relayer_components::delegate_component!( IbcMessageSenderComponent, MockCosmosComponents, @@ -40,8 +56,4 @@ ibc_relayer_components::delegate_component!( BaseTimeoutUnorderedPacketRelayer, ); -ibc_relayer_components::delegate_component!( - UpdateClientMessageBuilderComponent, - MockCosmosComponents, - SkipUpdateClient>, -); +ibc_relayer_components::delegate_component!(PacketFilterComponent, MockCosmosComponents, AllowAll); diff --git a/crates/relayer-cosmos-mock/src/impls/relay.rs b/crates/relayer-cosmos-mock/src/impls/relay.rs index 82c3c417f7..b828d9d651 100644 --- a/crates/relayer-cosmos-mock/src/impls/relay.rs +++ b/crates/relayer-cosmos-mock/src/impls/relay.rs @@ -10,14 +10,16 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::{Msg, ValidationContext}; use ibc::{Any, Height}; -use ibc_relayer_components::core::traits::component::DelegateComponent; +use ibc_relayer_components::components::default::closures::relay::packet_relayer::CanUseDefaultPacketRelayer; +use ibc_relayer_components::components::default::relay::DefaultRelayComponents; +use ibc_relayer_components::core::traits::component::{DelegateComponent, HasComponents}; use ibc_relayer_components::core::traits::error::HasErrorType; use ibc_relayer_components::logger::traits::has_logger::HasLogger; use ibc_relayer_components::logger::traits::has_logger::HasLoggerType; use ibc_relayer_components::relay::traits::chains::HasRelayChains; -use ibc_relayer_components::relay::traits::packet_relayers::lock::HasPacketLock; +use ibc_relayer_components::relay::traits::components::update_client_message_builder::UpdateClientMessageBuilder; +use ibc_relayer_components::relay::traits::packet_lock::HasPacketLock; use ibc_relayer_components::relay::traits::target::{DestinationTarget, SourceTarget}; -use ibc_relayer_components::relay::traits::update_client::UpdateClientMessageBuilder; use ibc_relayer_components::runtime::traits::runtime::HasRuntime; use ibc_relayer_runtime::types::error::Error as TokioError; use ibc_relayer_runtime::types::log::logger::TracingLogger; @@ -35,7 +37,22 @@ where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { - type Delegate = MockCosmosComponents; + type Delegate = DefaultRelayComponents; +} + +impl HasComponents for MockCosmosRelay +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ + type Components = DefaultRelayComponents; +} + +impl CanUseDefaultPacketRelayer for MockCosmosRelay +where + SrcChain: BasecoinEndpoint, + DstChain: BasecoinEndpoint, +{ } impl HasErrorType for MockCosmosRelay @@ -85,6 +102,8 @@ where SrcChain: BasecoinEndpoint, DstChain: BasecoinEndpoint, { + type Packet = Packet; + type SrcChain = MockCosmosContext; type DstChain = MockCosmosContext; diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs index d4a0c10390..8052512746 100644 --- a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -7,9 +7,10 @@ use crate::types::error::Error; use basecoin_store::impls::InMemoryStore; use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; +use ibc_relayer_components::chain::traits::client::client_state::CanQueryClientState; use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientPayload; -use ibc_relayer_components::relay::traits::target::SourceTarget; -use ibc_relayer_components::relay::traits::update_client::CanBuildUpdateClientMessage; +use ibc_relayer_components::relay::traits::components::update_client_message_builder::CanBuildUpdateClientMessage; +use ibc_relayer_components::relay::traits::target::DestinationTarget; use ibc_relayer_components::runtime::traits::sleep::CanSleep; #[tokio::test] @@ -57,10 +58,18 @@ async fn test_update_client() -> Result<(), Error> { let src_current_height = relayer.src_chain().get_current_height(); let msg_update_client = relayer - .build_update_client_messages(SourceTarget, &src_current_height) + .build_update_client_messages(DestinationTarget, &src_current_height) .await?; relayer.dst_chain().submit_messages(msg_update_client)?; + let latest_client_state = + > as CanQueryClientState< + MockCosmosContext>, + >>::query_client_state(relayer.src_chain(), &ClientId::default()) + .await?; + + assert_eq!(latest_client_state.latest_height, src_current_height); + Ok(()) } diff --git a/crates/relayer-cosmos-mock/src/tests/init.rs b/crates/relayer-cosmos-mock/src/tests/init.rs index 7f4c1d5a60..a5ab8a9339 100644 --- a/crates/relayer-cosmos-mock/src/tests/init.rs +++ b/crates/relayer-cosmos-mock/src/tests/init.rs @@ -21,7 +21,7 @@ pub async fn binary_setup( Validator::new("2").voting_power(30), Validator::new("3").voting_power(30), ]; - let src_chain = builder.build_chain(src_chain_id, src_validators); + let src_chain = builder.build_chain(src_chain_id, src_validators, InMemoryStore::default()); // Setup and run the destination chain let dst_chain_id = ChainId::from_str("mock-cosmos-chain-1").expect("never fails"); @@ -29,7 +29,7 @@ pub async fn binary_setup( Validator::new("1").voting_power(50), Validator::new("2").voting_power(50), ]; - let dst_chain = builder.build_chain(dst_chain_id, dst_validators); + let dst_chain = builder.build_chain(dst_chain_id, dst_validators, InMemoryStore::default()); // Setup relayer let relayer = builder.build_relay(src_chain, dst_chain); From 1a2c24c11ed1b009412465612d5daf13faa156f4 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Tue, 12 Sep 2023 16:59:41 -0700 Subject: [PATCH 23/25] fix: test_update_client should query dst_chain to see client_state updated --- Cargo.lock | 6 +++--- .../relayer-cosmos-mock/src/tests/ics02_client.rs | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89fc1cc42e..0c3519ea67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4114,7 +4114,7 @@ dependencies = [ [[package]] name = "tendermint" version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#a5cddcad6bb4cc6e2f9de28a0273489e383cd269" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#c62142685e4583db4d09c89c20bb1ddc95c920ac" dependencies = [ "bytes", "digest 0.10.7", @@ -4238,7 +4238,7 @@ dependencies = [ [[package]] name = "tendermint-proto" version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#a5cddcad6bb4cc6e2f9de28a0273489e383cd269" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#c62142685e4583db4d09c89c20bb1ddc95c920ac" dependencies = [ "bytes", "flex-error", @@ -4291,7 +4291,7 @@ dependencies = [ [[package]] name = "tendermint-testgen" version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#a5cddcad6bb4cc6e2f9de28a0273489e383cd269" +source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#c62142685e4583db4d09c89c20bb1ddc95c920ac" dependencies = [ "ed25519-consensus", "gumdrop", diff --git a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs index 8052512746..10566d2298 100644 --- a/crates/relayer-cosmos-mock/src/tests/ics02_client.rs +++ b/crates/relayer-cosmos-mock/src/tests/ics02_client.rs @@ -1,7 +1,6 @@ use crate::contexts::basecoin::MockBasecoin; use crate::contexts::chain::MockCosmosContext; use crate::tests::init::binary_setup; -use crate::traits::endpoint::BasecoinEndpoint; use crate::types::error::Error; use basecoin_store::impls::InMemoryStore; @@ -9,6 +8,8 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ValidationContext; use ibc_relayer_components::chain::traits::client::client_state::CanQueryClientState; use ibc_relayer_components::chain::traits::client::create::CanBuildCreateClientPayload; +use ibc_relayer_components::chain::traits::components::chain_status_querier::CanQueryChainStatus; +use ibc_relayer_components::chain::traits::components::message_sender::CanSendMessages; use ibc_relayer_components::relay::traits::components::update_client_message_builder::CanBuildUpdateClientMessage; use ibc_relayer_components::relay::traits::target::DestinationTarget; use ibc_relayer_components::runtime::traits::sleep::CanSleep; @@ -25,7 +26,8 @@ async fn test_create_client() -> Result<(), Error> { relayer .dst_chain() - .submit_messages(vec![msg_create_client])?; + .send_messages(vec![msg_create_client]) + .await?; assert!(relayer .dst_chain() @@ -48,25 +50,26 @@ async fn test_update_client() -> Result<(), Error> { relayer .dst_chain() - .submit_messages(vec![msg_create_client])?; + .send_messages(vec![msg_create_client]) + .await?; relayer .runtime() .sleep(tokio::time::Duration::from_millis(200)) .await; - let src_current_height = relayer.src_chain().get_current_height(); + let src_current_height = relayer.src_chain().query_chain_status().await?.height; let msg_update_client = relayer .build_update_client_messages(DestinationTarget, &src_current_height) .await?; - relayer.dst_chain().submit_messages(msg_update_client)?; + relayer.dst_chain().send_messages(msg_update_client).await?; let latest_client_state = > as CanQueryClientState< MockCosmosContext>, - >>::query_client_state(relayer.src_chain(), &ClientId::default()) + >>::query_client_state(relayer.dst_chain(), &ClientId::default()) .await?; assert_eq!(latest_client_state.latest_height, src_current_height); From 6d34e4b90fd4e9aa3214be84ba1fa7b2689aeafb Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Wed, 13 Sep 2023 20:52:00 -0700 Subject: [PATCH 24/25] fix: use store's root_hash as app_hash for headers --- .../relayer-cosmos-mock/src/contexts/basecoin.rs | 11 +++++++++-- crates/relayer-cosmos-mock/src/impls/basecoin.rs | 7 ++++--- crates/relayer-cosmos-mock/src/util/dummy.rs | 16 ---------------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs index 0210b0eee6..9895ed52d2 100644 --- a/crates/relayer-cosmos-mock/src/contexts/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/contexts/basecoin.rs @@ -16,6 +16,7 @@ use ibc::Height; use ibc_relayer_components_extra::runtime::traits::spawn::Spawner; use ibc_relayer_components_extra::runtime::traits::spawn::TaskHandle; use ibc_relayer_runtime::types::runtime::TokioRuntimeContext; +use tendermint::AppHash; use tendermint::Time; use tendermint_testgen::light_block::TmLightBlock; use tendermint_testgen::Generator; @@ -25,7 +26,6 @@ use tendermint_testgen::Validator; use crate::traits::runner::BasecoinRunner; use crate::types::status::ChainStatus; -use crate::util::dummy::generate_rand_app_hash; use crate::util::mutex::MutexUtil; /// A mock ABCI application that includes simplified store, application, @@ -97,6 +97,7 @@ impl MockBasecoin { genesis_height.revision_height(), genesis_time, &validators, + AppHash::default(), ); let genesis_status = Arc::new(Mutex::new(ChainStatus::new( @@ -148,13 +149,14 @@ impl MockBasecoin { height: u64, time: Time, validators: &[Validator], + app_hash: AppHash, ) -> TmLightBlock { let header = Header::new(validators) .chain_id(&chain_id.to_string()) .height(height) .time(time) .next_validators(validators) - .app_hash(generate_rand_app_hash()); + .app_hash(app_hash); LightBlock::new_default_with_header(header) .generate() @@ -162,6 +164,10 @@ impl MockBasecoin { } pub fn grow_blocks(&self) { + let root_hash = self.app.store.root_hash(); + + let app_hash = AppHash::try_from(root_hash).expect("invalid app hash"); + let mut blocks = self.blocks.acquire_mutex(); let validators = self.validators.acquire_mutex(); @@ -171,6 +177,7 @@ impl MockBasecoin { blocks.len() as u64 + 1, Time::now(), &validators, + app_hash, ); blocks.push(new_tm_light_block); diff --git a/crates/relayer-cosmos-mock/src/impls/basecoin.rs b/crates/relayer-cosmos-mock/src/impls/basecoin.rs index a54c42b72d..50a20fc0ac 100644 --- a/crates/relayer-cosmos-mock/src/impls/basecoin.rs +++ b/crates/relayer-cosmos-mock/src/impls/basecoin.rs @@ -61,6 +61,10 @@ where } async fn begin_block(&self) { + self.grow_blocks(); + + self.update_status(); + let last_block = self.blocks.acquire_mutex().last().unwrap().clone(); let mut events = Vec::new(); @@ -91,9 +95,6 @@ where } state.commit().expect("failed to commit to state"); - - self.grow_blocks(); - self.update_status(); } } diff --git a/crates/relayer-cosmos-mock/src/util/dummy.rs b/crates/relayer-cosmos-mock/src/util/dummy.rs index 68136f4936..0a6bcd7723 100644 --- a/crates/relayer-cosmos-mock/src/util/dummy.rs +++ b/crates/relayer-cosmos-mock/src/util/dummy.rs @@ -1,8 +1,4 @@ use ibc::Signer; -use rand::RngCore; -use sha2::Digest; -use sha2::Sha256; -use tendermint::AppHash; pub fn genesis_app_state() -> serde_json::Value { serde_json::json!({ @@ -42,15 +38,3 @@ pub fn genesis_app_state() -> serde_json::Value { pub fn dummy_signer() -> Signer { Signer::from("cosmos000000000000000000000000000000000000000".to_string()) } - -pub fn generate_rand_app_hash() -> AppHash { - let mut rng = rand::thread_rng(); - - let mut data = vec![0u8; 32]; - - rng.fill_bytes(&mut data); - - let value = Sha256::digest(&data).to_vec(); - - AppHash::try_from(value).expect("invalid app hash") -} From 6040462cbcd7023eeb1f8c540d3dc7bb16587cc0 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Fri, 22 Sep 2023 13:11:43 -0700 Subject: [PATCH 25/25] deps: bump ibc, ibc-proto, tendermint, basecoin --- Cargo.lock | 425 +++++++++++++------------- Cargo.toml | 11 +- crates/relayer-cosmos-mock/Cargo.toml | 10 +- crates/relayer-cosmos/Cargo.toml | 4 +- 4 files changed, 234 insertions(+), 216 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c3519ea67..b06164ed8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,9 +58,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "1.0.5" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr", ] @@ -96,9 +96,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" [[package]] name = "anstyle-parse" @@ -194,7 +194,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -205,7 +205,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -319,9 +319,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.3" +version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" +checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" [[package]] name = "base64ct" @@ -332,16 +332,16 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basecoin-app" version = "0.1.0" -source = "git+https://github.com/informalsystems/basecoin-rs.git#aa59797863272119a7bcb63bdf13b6d037dcd5cf" +source = "git+https://github.com/informalsystems/basecoin-rs.git#1787492a261680bce57e3ce040c7b5b589de2e05" dependencies = [ - "base64 0.21.3", + "base64 0.21.4", "basecoin-store", - "clap 4.4.2", + "clap 4.4.4", "cosmrs", "derive_more", "displaydoc", "ibc", - "ibc-proto 0.34.1", + "ibc-proto 0.35.0", "ics23", "primitive-types", "prost", @@ -349,11 +349,11 @@ dependencies = [ "serde_derive", "serde_json", "sha2 0.10.7", - "tendermint 0.33.0", - "tendermint-proto 0.33.0", + "tendermint 0.33.2", + "tendermint-proto 0.33.2", "tendermint-rpc", "tokio", - "toml 0.7.6", + "toml 0.8.0", "tonic", "tonic-reflection", "tower", @@ -365,9 +365,9 @@ dependencies = [ [[package]] name = "basecoin-store" version = "0.1.0" -source = "git+https://github.com/informalsystems/basecoin-rs.git#aa59797863272119a7bcb63bdf13b6d037dcd5cf" +source = "git+https://github.com/informalsystems/basecoin-rs.git#1787492a261680bce57e3ce040c7b5b589de2e05" dependencies = [ - "base64 0.21.3", + "base64 0.21.4", "derive_more", "displaydoc", "ed25519", @@ -377,7 +377,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.10.7", - "tendermint 0.33.0", + "tendermint 0.33.2", "tracing", ] @@ -489,9 +489,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byte-slice-cast" @@ -523,9 +523,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" dependencies = [ "serde", ] @@ -590,15 +590,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.28" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", - "time 0.1.45", "wasm-bindgen", "windows-targets 0.48.5", ] @@ -622,9 +621,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.2" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6" +checksum = "b1d7b8d5ec32af0fadc644bf1fd509a688c2103b185644bb1e29d164e0703136" dependencies = [ "clap_builder", "clap_derive 4.4.2", @@ -632,9 +631,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.2" +version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +checksum = "5179bb514e4d7c2051749d8fcefa2ed6d06a9f4e6d69faf3805f5d80b8cf8d56" dependencies = [ "anstream", "anstyle", @@ -674,7 +673,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -912,9 +911,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f711ade317dd348950a9910f81c5947e3d8907ebd2b83f76203ff1807e6a2bc2" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" dependencies = [ "cfg-if 1.0.0", "cpufeatures", @@ -935,7 +934,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -972,7 +971,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -983,7 +982,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -1104,14 +1103,14 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] name = "dyn-clone" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" +checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" [[package]] name = "ecdsa" @@ -1318,9 +1317,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.1.20" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" +checksum = "d0870c84016d4b481be5c9f323c24f65e31e901ae618f0e80f4308fb00de1d2d" [[package]] name = "fixed-hash" @@ -1443,7 +1442,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -1496,7 +1495,7 @@ dependencies = [ "cfg-if 1.0.0", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] @@ -1558,7 +1557,7 @@ dependencies = [ "indexmap 1.9.3", "slab", "tokio", - "tokio-util 0.7.8", + "tokio-util 0.7.9", "tracing", ] @@ -1605,7 +1604,7 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" dependencies = [ - "base64 0.21.3", + "base64 0.21.4", "bytes", "headers-core", "http", @@ -1640,9 +1639,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -1827,14 +1826,15 @@ dependencies = [ [[package]] name = "ibc" -version = "0.44.1" -source = "git+https://github.com/cosmos/ibc-rs.git?rev=6ffe8ce#6ffe8ce26f40b029e176d8fe92dde13467fb3735" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ac37443194c5b5167e56cc10b79c69b9a08b2386a14a9788449f0754db4c590" dependencies = [ "bytes", "derive_more", "displaydoc", "ibc-derive", - "ibc-proto 0.34.1", + "ibc-proto 0.35.0", "ics23", "num-traits", "parking_lot", @@ -1846,11 +1846,12 @@ dependencies = [ "serde_json", "sha2 0.10.7", "subtle-encoding", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-light-client-verifier", - "tendermint-proto 0.33.0", + "tendermint-proto 0.33.2", "tendermint-testgen", - "time 0.3.25", + "time", + "tonic", "tracing", "uint", ] @@ -1877,12 +1878,13 @@ dependencies = [ [[package]] name = "ibc-derive" version = "0.3.0" -source = "git+https://github.com/cosmos/ibc-rs.git?rev=6ffe8ce#6ffe8ce26f40b029e176d8fe92dde13467fb3735" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92f1528535e9ca495badb76c143bdd4763c1c9d987f59d1f8b47963ba0c11674" dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -1902,9 +1904,9 @@ dependencies = [ "serde", "serde_json", "tempfile", - "time 0.3.25", + "time", "tokio", - "toml 0.7.6", + "toml 0.7.8", "tonic", ] @@ -1914,31 +1916,31 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59d0bc49ee5fc8e5d0e668765d470cb201fd0cdee4166f49c6cbcf3100466137" dependencies = [ - "base64 0.21.3", + "base64 0.21.4", "bytes", "flex-error", "ics23", "prost", "serde", "subtle-encoding", - "tendermint-proto 0.33.0", + "tendermint-proto 0.33.2", "tonic", ] [[package]] name = "ibc-proto" -version = "0.34.1" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46349dc9a3baa6c72c4c9e7e137bb3f679ccef2e25d84261624bbebc982be184" +checksum = "459ccbab879b749bf500ae13244593fa16fc64c1b3159f6b0753c169625a1e23" dependencies = [ - "base64 0.21.3", + "base64 0.21.4", "bytes", "flex-error", "ics23", "prost", "serde", "subtle-encoding", - "tendermint-proto 0.33.0", + "tendermint-proto 0.33.2", "tonic", ] @@ -1990,7 +1992,7 @@ dependencies = [ "signature", "strum", "subtle-encoding", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-light-client", "tendermint-light-client-detector", "tendermint-rpc", @@ -2001,7 +2003,7 @@ dependencies = [ "tiny-keccak", "tokio", "tokio-stream", - "toml 0.7.6", + "toml 0.7.8", "tonic", "tracing", "tracing-subscriber", @@ -2058,10 +2060,10 @@ dependencies = [ "serial_test", "signal-hook", "subtle-encoding", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-light-client-verifier", "tendermint-rpc", - "time 0.3.25", + "time", "tokio", "tracing", "tracing-subscriber", @@ -2108,7 +2110,7 @@ dependencies = [ "prost", "serde", "serde_derive", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-rpc", "tokio", "tonic", @@ -2123,7 +2125,7 @@ dependencies = [ "basecoin-app", "basecoin-store", "ibc", - "ibc-proto 0.34.1", + "ibc-proto 0.35.0", "ibc-relayer-components", "ibc-relayer-components-extra", "ibc-relayer-runtime", @@ -2134,7 +2136,7 @@ dependencies = [ "serde_json", "sha2 0.10.7", "subtle-encoding", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-testgen", "tokio", "tower", @@ -2166,7 +2168,7 @@ dependencies = [ "reqwest", "serde", "tokio", - "toml 0.7.6", + "toml 0.7.8", "tracing", ] @@ -2206,13 +2208,13 @@ dependencies = [ "serde_derive", "serde_json", "subtle-encoding", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-light-client-verifier", - "tendermint-proto 0.33.0", + "tendermint-proto 0.33.2", "tendermint-rpc", "tendermint-testgen", "test-log", - "time 0.3.25", + "time", "tracing", "tracing-subscriber", "uint", @@ -2232,7 +2234,7 @@ dependencies = [ "prometheus", "serde", "serde_json", - "tendermint 0.33.0", + "tendermint 0.33.2", "tokio", "tracing", ] @@ -2268,7 +2270,7 @@ dependencies = [ "subtle-encoding", "tendermint-rpc", "tokio", - "toml 0.7.6", + "toml 0.7.8", "tonic", "tracing", "tracing-subscriber", @@ -2387,7 +2389,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", "windows-sys 0.48.0", ] @@ -2404,8 +2406,8 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.2", - "rustix 0.38.11", + "hermit-abi 0.3.3", + "rustix 0.38.14", "windows-sys 0.48.0", ] @@ -2464,9 +2466,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "linux-raw-sys" @@ -2476,9 +2478,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" [[package]] name = "lock_api" @@ -2516,9 +2518,9 @@ dependencies = [ [[package]] name = "matchit" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "maybe-uninit" @@ -2563,7 +2565,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.48.0", ] @@ -2686,7 +2688,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi 0.3.3", "libc", ] @@ -2952,7 +2954,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -3024,7 +3026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit", + "toml_edit 0.19.15", ] [[package]] @@ -3053,9 +3055,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -3135,7 +3137,7 @@ dependencies = [ "mach2", "once_cell", "raw-cpuid", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "web-sys", "winapi", ] @@ -3273,7 +3275,7 @@ version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ - "base64 0.21.3", + "base64 0.21.4", "bytes", "encoding_rs", "futures-core", @@ -3389,14 +3391,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.11" +version = "0.38.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0c3dde1fc030af041adc40e79c0e7fbcf431dd24870053d187d7c66e4b87453" +checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.5", + "linux-raw-sys 0.4.7", "windows-sys 0.48.0", ] @@ -3467,14 +3469,14 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.3", + "base64 0.21.4", ] [[package]] name = "rustls-webpki" -version = "0.101.4" +version = "0.101.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d93931baf2d282fff8d3a532bbfd7653f734643161b87e3e01e59a04439bf0d" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" dependencies = [ "ring", "untrusted", @@ -3494,11 +3496,11 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "safe-proc-macro2" -version = "1.0.36" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "814c536dcd27acf03296c618dab7ad62d28e70abd7ba41d3f34a2ce707a2c666" +checksum = "7fd85be67db87168aa3c13fd0da99f48f2ab005dccad5af5626138dc1df20eb6" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -3705,14 +3707,14 @@ checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -3737,7 +3739,7 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -3796,14 +3798,14 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] name = "sha1" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if 1.0.0", "cpufeatures", @@ -3920,9 +3922,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "socket2" @@ -3936,9 +3938,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" dependencies = [ "libc", "windows-sys 0.48.0", @@ -3991,7 +3993,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -4028,9 +4030,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.31" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -4076,7 +4078,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", "redox_syscall 0.3.5", - "rustix 0.38.11", + "rustix 0.38.14", "windows-sys 0.48.0", ] @@ -4107,14 +4109,15 @@ dependencies = [ "subtle", "subtle-encoding", "tendermint-proto 0.32.2", - "time 0.3.25", + "time", "zeroize", ] [[package]] name = "tendermint" -version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#c62142685e4583db4d09c89c20bb1ddc95c920ac" +version = "0.33.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c35fe4fd24a7715571814c22416dbc40ec0f2a6e3cce75d73e19699faecd246" dependencies = [ "bytes", "digest 0.10.7", @@ -4136,30 +4139,30 @@ dependencies = [ "signature", "subtle", "subtle-encoding", - "tendermint-proto 0.33.0", - "time 0.3.25", + "tendermint-proto 0.33.2", + "time", "zeroize", ] [[package]] name = "tendermint-config" -version = "0.33.0" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36a787b139f314c92756becbcae855bef6772227d97d8ecee948ad90327fe6e7" +checksum = "6a213a026dfc1c68468160bee24bf128e26002170abc123678ecfbe5ff37f91d" dependencies = [ "flex-error", "serde", "serde_json", - "tendermint 0.33.0", + "tendermint 0.33.2", "toml 0.5.11", "url", ] [[package]] name = "tendermint-light-client" -version = "0.33.0" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5907c615802bcd54a9e209caada2abe9b945fb1031744d7c8643996239cec6e" +checksum = "4f4ca7fd6b7533e44f18efcff6385d6eceff990b3828e232d8da8ca519514d73" dependencies = [ "contracts", "crossbeam-channel 0.4.4", @@ -4172,19 +4175,19 @@ dependencies = [ "serde_derive", "serde_json", "static_assertions", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-light-client-verifier", "tendermint-rpc", - "time 0.3.25", + "time", "tokio", "tracing", ] [[package]] name = "tendermint-light-client-detector" -version = "0.33.0" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af6153c010c32cbd4ff8f97f106c66da773343808965fe4b74ca365c370d426f" +checksum = "7224bbe497d9d5e698e197c9992a44ee60472c80bf3fb053a7d732cb691e805f" dependencies = [ "contracts", "crossbeam-channel 0.4.4", @@ -4196,25 +4199,25 @@ dependencies = [ "serde_derive", "serde_json", "static_assertions", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-light-client", - "tendermint-proto 0.33.0", + "tendermint-proto 0.33.2", "tendermint-rpc", - "time 0.3.25", + "time", "tracing", ] [[package]] name = "tendermint-light-client-verifier" -version = "0.33.0" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bc1e4e3dd6f65cfa7979cf721b5afa1d79d32c4a2fe5fddb6416a98638634a9" +checksum = "680639f67d51eceb700bff18b45b584373ec94ee0d7ffe61f4ca6c54ed7787ff" dependencies = [ "derive_more", "flex-error", "serde", - "tendermint 0.33.0", - "time 0.3.25", + "tendermint 0.33.2", + "time", ] [[package]] @@ -4232,13 +4235,14 @@ dependencies = [ "serde", "serde_bytes", "subtle-encoding", - "time 0.3.25", + "time", ] [[package]] name = "tendermint-proto" -version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#c62142685e4583db4d09c89c20bb1ddc95c920ac" +version = "0.33.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "639e5adffd77220d238a800a72c74c98d7e869290a6e4494c10b6b4e8f702f02" dependencies = [ "bytes", "flex-error", @@ -4249,14 +4253,14 @@ dependencies = [ "serde", "serde_bytes", "subtle-encoding", - "time 0.3.25", + "time", ] [[package]] name = "tendermint-rpc" -version = "0.33.0" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03f8ff62948110e58d6df12c3bb73a00e74553384255d6413deed4c21d7480bf" +checksum = "e4df40d6d298fdca6cc5af67c85eb62c1113b5834ca321bde30240c919d4912b" dependencies = [ "async-trait", "async-tungstenite", @@ -4276,11 +4280,11 @@ dependencies = [ "serde_json", "subtle", "subtle-encoding", - "tendermint 0.33.0", + "tendermint 0.33.2", "tendermint-config", - "tendermint-proto 0.33.0", + "tendermint-proto 0.33.2", "thiserror", - "time 0.3.25", + "time", "tokio", "tracing", "url", @@ -4290,8 +4294,9 @@ dependencies = [ [[package]] name = "tendermint-testgen" -version = "0.33.0" -source = "git+https://github.com/informalsystems/tendermint-rs.git?branch=farhad/testgen-app-hash#c62142685e4583db4d09c89c20bb1ddc95c920ac" +version = "0.33.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6768bef6580abe3987cda669dc02fdfb18593e763ff2f4976ef6c58f20bde90a" dependencies = [ "ed25519-consensus", "gumdrop", @@ -4299,26 +4304,26 @@ dependencies = [ "serde_json", "simple-error", "tempfile", - "tendermint 0.33.0", - "time 0.3.25", + "tendermint 0.33.2", + "time", ] [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] [[package]] name = "terminal_size" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "rustix 0.37.23", + "rustix 0.38.14", "windows-sys 0.48.0", ] @@ -4356,7 +4361,7 @@ checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -4371,20 +4376,9 @@ dependencies = [ [[package]] name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "time" -version = "0.3.25" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" dependencies = [ "deranged", "serde", @@ -4400,9 +4394,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.11" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" dependencies = [ "time-core", ] @@ -4464,7 +4458,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.3", + "socket2 0.5.4", "tokio-macros", "windows-sys 0.48.0", ] @@ -4487,7 +4481,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -4549,9 +4543,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -4572,14 +4566,26 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.19.15", +] + +[[package]] +name = "toml" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c226a7bba6d859b63c92c4b4fe69c5b6b72d0cb897dbc8e6012298e6154cb56e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.20.0", ] [[package]] @@ -4593,9 +4599,22 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.14" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.0.0", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "toml_edit" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +checksum = "8ff63e60a958cefbb518ae1fd6566af80d9d4be430a33f3723dfc47d1d411d95" dependencies = [ "indexmap 2.0.0", "serde", @@ -4613,7 +4632,7 @@ dependencies = [ "async-stream", "async-trait", "axum", - "base64 0.21.3", + "base64 0.21.4", "bytes", "futures-core", "futures-util", @@ -4664,7 +4683,7 @@ dependencies = [ "rand", "slab", "tokio", - "tokio-util 0.7.8", + "tokio-util 0.7.9", "tower-layer", "tower-service", "tracing", @@ -4672,16 +4691,16 @@ dependencies = [ [[package]] name = "tower-abci" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42c629f4e6844d9c506d4b3b7894821015c72c818fc4e7e66275d34e5e0b43a2" +checksum = "a27715826a50956390a46848fe47ece6f75ec19384afd4da98b740873630f4e4" dependencies = [ "bytes", "futures", "pin-project", "prost", - "tendermint 0.33.0", - "tendermint-proto 0.33.0", + "tendermint 0.33.2", + "tendermint-proto 0.33.2", "tokio", "tokio-stream", "tokio-util 0.6.10", @@ -4722,7 +4741,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] [[package]] @@ -4822,9 +4841,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "uint" @@ -4855,9 +4874,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" @@ -4870,9 +4889,9 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "unicode-xid" @@ -4971,9 +4990,9 @@ checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "walkdir" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", "winapi-util", @@ -4988,12 +5007,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -5021,7 +5034,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", "wasm-bindgen-shared", ] @@ -5055,7 +5068,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5129,9 +5142,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -5328,5 +5341,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.31", + "syn 2.0.37", ] diff --git a/Cargo.toml b/Cargo.toml index c67fe8f7a8..593cc2ec5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,11 @@ exclude = [ overflow-checks = true [patch.crates-io] -tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "farhad/testgen-app-hash" } -tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "farhad/testgen-app-hash" } -tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "farhad/testgen-app-hash" } \ No newline at end of file +# ibc-proto = { git = "https://github.com/cosmos/ibc-proto-rs.git", branch = "main" } +# tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } +# tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } +# tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } +# tendermint-light-client = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } +# tendermint-light-client-verifier = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } +# tendermint-light-client-detector = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } +# tendermint-testgen = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "main" } diff --git a/crates/relayer-cosmos-mock/Cargo.toml b/crates/relayer-cosmos-mock/Cargo.toml index 173e7f2ec3..f2b28b3911 100644 --- a/crates/relayer-cosmos-mock/Cargo.toml +++ b/crates/relayer-cosmos-mock/Cargo.toml @@ -18,8 +18,8 @@ description = """ async-trait = "0.1.56" basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git" } basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git" } -ibc = { git = "https://github.com/cosmos/ibc-rs.git", rev= "6ffe8ce", features = ["mocks"] } -ibc-proto = "0.34.0" +ibc = { version = "0.45", features = ["mocks"] } +ibc-proto = "0.35.0" ibc-relayer-components = { version = "0.1.0", path = "../relayer-components" } ibc-relayer-components-extra = { version = "0.1.0", path = "../relayer-components-extra" } ibc-relayer-runtime = { version = "0.1.0", path = "../relayer-runtime" } @@ -30,9 +30,9 @@ serde_json = "1.0" sha2 = { version = "0.10", default-features = false } subtle-encoding = { version = "0.5", default-features = false } rand = "0.8.5" -tendermint = { version = "0.33.0", features = ["rust-crypto"] } -tendermint-testgen = "0.33.0" +tendermint = { version = "0.33.2", features = ["rust-crypto"] } +tendermint-testgen = "0.33.2" tracing = "0.1.36" tokio = { version = "1.0", features = ["full"] } -tower-abci = "0.9" +tower-abci = "0.10" tower = { version = "0.4", features = ["full"] } diff --git a/crates/relayer-cosmos/Cargo.toml b/crates/relayer-cosmos/Cargo.toml index 2e70b00287..20f6ede18c 100644 --- a/crates/relayer-cosmos/Cargo.toml +++ b/crates/relayer-cosmos/Cargo.toml @@ -43,10 +43,10 @@ tonic = { version = "0.9", features = ["tls", "tls-roots"] } moka = { version = "0.10", features = ["future"] } [dependencies.tendermint] -version = "=0.33.0" +version = "0.33.0" features = ["secp256k1"] [dependencies.tendermint-rpc] -version = "=0.33.0" +version = "0.33.0" features = ["http-client", "websocket-client"]