From 1c3d037c888857799b60a49a52506637d7569e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Terenti=C4=87?= Date: Wed, 9 Oct 2024 11:41:14 +0200 Subject: [PATCH] Support WASM in avail-light-core --- Cargo.lock | 562 ++++++++++---------------- Cargo.toml | 18 +- core/CHANGELOG.md | 2 + core/Cargo.toml | 50 ++- core/src/finality.rs | 33 +- core/src/lib.rs | 5 - core/src/light_client.rs | 6 + core/src/network.rs | 9 +- core/src/network/p2p.rs | 38 +- core/src/network/p2p/client.rs | 5 + core/src/network/p2p/configuration.rs | 5 +- core/src/network/p2p/event_loop.rs | 63 ++- core/src/network/rpc.rs | 11 +- core/src/network/rpc/client.rs | 66 +-- core/src/network/rpc/configuration.rs | 3 + core/src/network/rpc/subscriptions.rs | 3 + core/src/types.rs | 36 +- core/src/utils.rs | 7 + 18 files changed, 472 insertions(+), 450 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a468acb56..39dddfa20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -910,7 +910,7 @@ version = "0.6.2" source = "git+https://github.com/availproject/avail-core?tag=core-node-4#b845db8a6c46cb00e21396ae26f4d72ffdd6e567" dependencies = [ "binary-merkle-tree", - "bounded-collections 0.2.0", + "bounded-collections", "derive_more 0.99.18", "ethabi-decode", "frame-support", @@ -921,8 +921,8 @@ dependencies = [ "scale-info", "serde", "sp-arithmetic", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", - "sp-io 30.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", + "sp-io", "sp-runtime", "sp-runtime-interface 24.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "sp-std 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", @@ -1015,6 +1015,8 @@ dependencies = [ "derive_more 1.0.0", "dusk-bytes", "dusk-plonk", + "ed25519-compact", + "fluvio-wasm-timer", "futures", "getrandom", "hex", @@ -1026,6 +1028,7 @@ dependencies = [ "libp2p", "libp2p-allow-block-list", "libp2p-webrtc", + "libp2p-webrtc-websys", "mockall", "multihash 0.14.0", "num", @@ -1060,6 +1063,7 @@ dependencies = [ "uuid", "void", "warp", + "wasm-bindgen", "web-time", ] @@ -1124,7 +1128,7 @@ source = "git+https://github.com/availproject/avail.git?branch=main#834836052062 dependencies = [ "avail-core", "base58", - "bounded-collections 0.2.0", + "bounded-collections", "derive_more 1.0.0", "hex", "kate-recovery", @@ -1133,8 +1137,8 @@ dependencies = [ "scale-info", "serde", "serde_json", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", - "sp-io 30.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sp-core", + "sp-io", "subxt", "subxt-core", "subxt-signer", @@ -1502,17 +1506,6 @@ dependencies = [ "piper", ] -[[package]] -name = "bounded-collections" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca548b6163b872067dc5eb82fd130c56881435e30367d2073594a3d9744120dd" -dependencies = [ - "log", - "parity-scale-codec", - "scale-info", -] - [[package]] name = "bounded-collections" version = "0.2.0" @@ -2081,6 +2074,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ct-codecs" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "026ac6ceace6298d2c557ef5ed798894962296469ec7842288ea64674201a2d1" + [[package]] name = "ctr" version = "0.9.2" @@ -2546,6 +2545,16 @@ dependencies = [ "signature", ] +[[package]] +name = "ed25519-compact" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9b3460f44bea8cd47f45a0c70892f1eff856d97cd55358b2f73f663789f6190" +dependencies = [ + "ct-codecs", + "getrandom", +] + [[package]] name = "ed25519-dalek" version = "2.1.1" @@ -2848,6 +2857,21 @@ dependencies = [ "num-traits", ] +[[package]] +name = "fluvio-wasm-timer" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b768c170dc045fa587a8f948c91f9bcfb87f774930477c6215addf54317f137f" +dependencies = [ + "futures", + "js-sys", + "parking_lot 0.11.2", + "pin-utils", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "fnv" version = "1.0.7" @@ -2931,12 +2955,12 @@ dependencies = [ "smallvec", "sp-api", "sp-arithmetic", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", "sp-crypto-hashing-proc-macro", "sp-debug-derive 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "sp-genesis-builder", "sp-inherents", - "sp-io 30.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-io", "sp-metadata-ir", "sp-runtime", "sp-staking", @@ -3497,7 +3521,7 @@ dependencies = [ "ipconfig", "lru-cache", "once_cell", - "parking_lot", + "parking_lot 0.12.3", "rand", "resolv-conf", "smallvec", @@ -3792,16 +3816,18 @@ dependencies = [ [[package]] name = "igd-next" -version = "0.14.3" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064d90fec10d541084e7b39ead8875a5a80d9114a2b18791565253bae25f49e4" +checksum = "76b0d7d4541def58a37bf8efc559683f21edce7c82f0d866c93ac21f7e098f93" dependencies = [ "async-trait", "attohttpc", "bytes", "futures", - "http 0.2.12", - "hyper 0.14.29", + "http 1.1.0", + "http-body-util", + "hyper 1.4.1", + "hyper-util", "log", "rand", "tokio", @@ -3936,6 +3962,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -4227,7 +4256,7 @@ dependencies = [ "rand_chacha", "serde", "sp-arithmetic", - "sp-io 30.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-io", "sp-std 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "static_assertions", "thiserror-no-std", @@ -4308,8 +4337,7 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libp2p" version = "0.54.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbbe80f9c7e00526cd6b838075b9c171919404a4732cb2fa8ece0a093223bfc4" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "bytes", "either", @@ -4319,7 +4347,7 @@ dependencies = [ "libp2p-allow-block-list", "libp2p-autonat", "libp2p-connection-limits", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-dcutr", "libp2p-dns", "libp2p-gossipsub", @@ -4328,7 +4356,7 @@ dependencies = [ "libp2p-kad", "libp2p-mdns", "libp2p-metrics", - "libp2p-noise 0.45.0", + "libp2p-noise", "libp2p-ping", "libp2p-quic", "libp2p-relay", @@ -4345,11 +4373,10 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1027ccf8d70320ed77e984f273bc8ce952f623762cb9bf2d126df73caef8041" +version = "0.4.1" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "void", @@ -4357,9 +4384,8 @@ dependencies = [ [[package]] name = "libp2p-autonat" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a083675f189803d0682a2726131628e808144911dad076858bfbe30b13065499" +version = "0.13.1" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "async-trait", "asynchronous-codec", @@ -4368,7 +4394,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-request-response", "libp2p-swarm", @@ -4385,48 +4411,18 @@ dependencies = [ [[package]] name = "libp2p-connection-limits" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d003540ee8baef0d254f7b6bfd79bac3ddf774662ca0abf69186d517ef82ad8" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "void", ] -[[package]] -name = "libp2p-core" -version = "0.41.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8130a8269e65a2554d55131c770bdf4bcd94d2b8d4efb24ca23699be65066c05" -dependencies = [ - "either", - "fnv", - "futures", - "futures-timer", - "instant", - "libp2p-identity", - "multiaddr", - "multihash 0.19.1", - "multistream-select", - "once_cell", - "parking_lot", - "pin-project", - "quick-protobuf", - "rand", - "rw-stream-sink", - "smallvec", - "thiserror", - "tracing", - "unsigned-varint 0.8.0", - "void", -] - [[package]] name = "libp2p-core" version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61f26c83ed111104cd820fe9bc3aaabbac5f1652a1d213ed6e900b7918a1298" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "either", "fnv", @@ -4437,7 +4433,7 @@ dependencies = [ "multihash 0.19.1", "multistream-select", "once_cell", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "quick-protobuf", "rand", @@ -4454,15 +4450,14 @@ dependencies = [ [[package]] name = "libp2p-dcutr" version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3236a2e24cbcf2d05b398b003ed920e1e8cedede13784d90fa3961b109647ce0" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "asynchronous-codec", "either", "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "lru", @@ -4477,24 +4472,22 @@ dependencies = [ [[package]] name = "libp2p-dns" version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97f37f30d5c7275db282ecd86e54f29dd2176bd3ac656f06abf43bedb21eb8bd" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "async-trait", "futures", "hickory-resolver", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", - "parking_lot", + "parking_lot 0.12.3", "smallvec", "tracing", ] [[package]] name = "libp2p-gossipsub" -version = "0.47.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4e830fdf24ac8c444c12415903174d506e1e077fbe3875c404a78c5935a8543" +version = "0.47.1" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "asynchronous-codec", "base64 0.22.1", @@ -4506,7 +4499,7 @@ dependencies = [ "futures-ticker", "getrandom", "hex_fmt", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "prometheus-client", @@ -4524,16 +4517,15 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1711b004a273be4f30202778856368683bd9a83c4c7dcc8f848847606831a4e3" +version = "0.45.1" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "asynchronous-codec", "either", "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "lru", @@ -4566,9 +4558,8 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.46.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced237d0bd84bbebb7c2cad4c073160dacb4fe40534963c32ed6d4c6bb7702a3" +version = "0.47.0" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "arrayvec 0.7.4", "asynchronous-codec", @@ -4578,7 +4569,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", @@ -4597,14 +4588,13 @@ dependencies = [ [[package]] name = "libp2p-mdns" version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b8546b6644032565eb29046b42744aee1e9f261ed99671b2c93fb140dba417" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "data-encoding", "futures", "hickory-proto", "if-watch", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "rand", @@ -4618,11 +4608,10 @@ dependencies = [ [[package]] name = "libp2p-metrics" version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ebafa94a717c8442d8db8d3ae5d1c6a15e30f2d347e0cd31d057ca72e42566" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "futures", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-dcutr", "libp2p-identify", "libp2p-identity", @@ -4635,43 +4624,16 @@ dependencies = [ "web-time", ] -[[package]] -name = "libp2p-noise" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecd0545ce077f6ea5434bcb76e8d0fe942693b4380aaad0d34a358c2bd05793" -dependencies = [ - "asynchronous-codec", - "bytes", - "curve25519-dalek", - "futures", - "libp2p-core 0.41.2", - "libp2p-identity", - "multiaddr", - "multihash 0.19.1", - "once_cell", - "quick-protobuf", - "rand", - "sha2 0.10.8", - "snow", - "static_assertions", - "thiserror", - "tracing", - "x25519-dalek", - "zeroize", -] - [[package]] name = "libp2p-noise" version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36b137cb1ae86ee39f8e5d6245a296518912014eaa87427d24e6ff58cfc1b28c" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "asynchronous-codec", "bytes", "curve25519-dalek", "futures", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "multiaddr", "multihash 0.19.1", @@ -4690,13 +4652,12 @@ dependencies = [ [[package]] name = "libp2p-ping" version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "005a34420359223b974ee344457095f027e51346e992d1e0dcd35173f4cdd422" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "either", "futures", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "rand", @@ -4708,17 +4669,16 @@ dependencies = [ [[package]] name = "libp2p-quic" version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46352ac5cd040c70e88e7ff8257a2ae2f891a4076abad2c439584a31c15fd24e" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "bytes", "futures", "futures-timer", "if-watch", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-tls", - "parking_lot", + "parking_lot 0.12.3", "quinn", "rand", "ring 0.17.8", @@ -4732,8 +4692,7 @@ dependencies = [ [[package]] name = "libp2p-relay" version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10df23d7f5b5adcc129f4a69d6fbd05209e356ccf9e8f4eb10b2692b79c77247" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "asynchronous-codec", "bytes", @@ -4741,7 +4700,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", @@ -4757,14 +4716,13 @@ dependencies = [ [[package]] name = "libp2p-request-response" version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1356c9e376a94a75ae830c42cdaea3d4fe1290ba409a22c809033d1b7dcab0a6" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "async-trait", "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "rand", @@ -4776,15 +4734,15 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.45.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7dd6741793d2c1fb2088f67f82cf07261f25272ebe3c0b0c311e0c6b50e851a" +version = "0.45.2" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "either", "fnv", "futures", "futures-timer", - "libp2p-core 0.42.0", + "getrandom", + "libp2p-core", "libp2p-identity", "libp2p-swarm-derive", "lru", @@ -4795,14 +4753,14 @@ dependencies = [ "tokio", "tracing", "void", + "wasm-bindgen-futures", "web-time", ] [[package]] name = "libp2p-swarm-derive" version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "206e0aa0ebe004d778d79fb0966aa0de996c19894e2c0605ba2f8524dd4443d8" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -4813,14 +4771,13 @@ dependencies = [ [[package]] name = "libp2p-tcp" version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad964f312c59dcfcac840acd8c555de8403e295d39edf96f5240048b5fcaa314" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "futures", "futures-timer", "if-watch", "libc", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "socket2 0.5.7", "tokio", @@ -4830,12 +4787,11 @@ dependencies = [ [[package]] name = "libp2p-tls" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b23dddc2b9c355f73c1e36eb0c3ae86f7dc964a3715f0731cfad352db4d847" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "futures", "futures-rustls", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "rcgen", "ring 0.17.8", @@ -4848,14 +4804,13 @@ dependencies = [ [[package]] name = "libp2p-upnp" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01bf2d1b772bd3abca049214a3304615e6a36fa6ffc742bdd1ba774486200b8f" +version = "0.3.1" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "futures", "futures-timer", "igd-next", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-swarm", "tokio", "tracing", @@ -4865,8 +4820,7 @@ dependencies = [ [[package]] name = "libp2p-webrtc" version = "0.8.0-alpha" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24bd4834f4560c12e79028dbb6b8c15d45f37303bb92bd99cb7c225b06cd9bda" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "async-trait", "bytes", @@ -4874,9 +4828,9 @@ dependencies = [ "futures-timer", "hex", "if-watch", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", - "libp2p-noise 0.44.0", + "libp2p-noise", "libp2p-webrtc-utils", "multihash 0.19.1", "rand", @@ -4893,17 +4847,16 @@ dependencies = [ [[package]] name = "libp2p-webrtc-utils" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95eb35ba4991eab0284c2fc2d535b0a53fe10005001284c89f3cb01c5b0e1249" +version = "0.3.0" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "asynchronous-codec", "bytes", "futures", "hex", - "libp2p-core 0.41.2", + "libp2p-core", "libp2p-identity", - "libp2p-noise 0.44.0", + "libp2p-noise", "quick-protobuf", "quick-protobuf-codec", "rand", @@ -4914,18 +4867,38 @@ dependencies = [ "tracing", ] +[[package]] +name = "libp2p-webrtc-websys" +version = "0.4.0-alpha.2" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" +dependencies = [ + "bytes", + "futures", + "getrandom", + "hex", + "js-sys", + "libp2p-core", + "libp2p-identity", + "libp2p-webrtc-utils", + "send_wrapper 0.6.0", + "thiserror", + "tracing", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "libp2p-websocket" version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "888b2ff2e5d8dcef97283daab35ad1043d18952b65e05279eecbe02af4c6e347" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "either", "futures", "futures-rustls", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", - "parking_lot", + "parking_lot 0.12.3", "pin-project-lite", "rw-stream-sink", "soketto", @@ -4938,12 +4911,11 @@ dependencies = [ [[package]] name = "libp2p-yamux" version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "788b61c80789dba9760d8c669a5bedb642c8267555c803fabd8396e4ca5c5882" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "either", "futures", - "libp2p-core 0.42.0", + "libp2p-core", "thiserror", "tracing", "yamux 0.12.1", @@ -5409,15 +5381,14 @@ dependencies = [ [[package]] name = "multistream-select" version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0df8e5eec2298a62b326ee4f0d7fe1a6b90a09dfcf9df37b38f947a8c42f19" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "bytes", "futures", - "log", "pin-project", "smallvec", - "unsigned-varint 0.7.2", + "tracing", + "unsigned-varint 0.8.0", ] [[package]] @@ -5865,6 +5836,17 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.6", +] + [[package]] name = "parking_lot" version = "0.12.3" @@ -5872,7 +5854,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.10", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "winapi", ] [[package]] @@ -5883,7 +5879,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.5.2", "smallvec", "windows-targets 0.52.6", ] @@ -6164,15 +6160,15 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" [[package]] name = "predicates-tree" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" dependencies = [ "predicates-core", "termtree", @@ -6307,7 +6303,7 @@ checksum = "c1ca959da22a332509f2a73ae9e5f23f9dcfc31fd3a54d71f159495bd5909baa" dependencies = [ "dtoa", "itoa", - "parking_lot", + "parking_lot 0.12.3", "prometheus-client-derive-encode", ] @@ -6392,8 +6388,7 @@ dependencies = [ [[package]] name = "quick-protobuf-codec" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15a0580ab32b169745d7a39db2ba969226ca16738931be152a3209b409de2474" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "asynchronous-codec", "bytes", @@ -6537,6 +6532,15 @@ dependencies = [ "yasna", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.2" @@ -6968,8 +6972,7 @@ dependencies = [ [[package]] name = "rw-stream-sink" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8c9026ff5d2f23da5e45bbc283f156383001bfb09c4e44256d02c1a685fe9a1" +source = "git+https://github.com/libp2p/rust-libp2p?rev=9a45db3f82b760c93099e66ec77a7a772d1f6cd3#9a45db3f82b760c93099e66ec77a7a772d1f6cd3" dependencies = [ "futures", "pin-project", @@ -7332,6 +7335,9 @@ name = "send_wrapper" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" +dependencies = [ + "futures-core", +] [[package]] name = "serde" @@ -7615,7 +7621,7 @@ dependencies = [ "itertools 0.13.0", "log", "lru", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "rand", "rand_chacha", @@ -7690,7 +7696,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api-proc-macro", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", "sp-externalities 0.25.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "sp-metadata-ir", "sp-runtime", @@ -7723,8 +7729,8 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", - "sp-io 30.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", + "sp-io", "sp-std 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", ] @@ -7760,33 +7766,6 @@ dependencies = [ "sp-crypto-ec-utils", ] -[[package]] -name = "sp-core" -version = "28.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f230cb12575455070da0fc174815958423a0b9a641d5e304a9457113c7cb4007" -dependencies = [ - "bip39", - "bitflags 1.3.2", - "bounded-collections 0.1.9", - "hash-db", - "hash256-std-hasher", - "log", - "merlin", - "parity-scale-codec", - "paste", - "primitive-types 0.12.2", - "scale-info", - "schnorrkel", - "secrecy 0.8.0", - "sp-debug-derive 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime-interface 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-std 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-storage 19.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ss58-registry", - "zeroize", -] - [[package]] name = "sp-core" version = "28.0.0" @@ -7797,7 +7776,7 @@ dependencies = [ "bip39", "bitflags 1.3.2", "blake2", - "bounded-collections 0.2.0", + "bounded-collections", "bs58", "dyn-clonable", "ed25519-zebra", @@ -7810,7 +7789,7 @@ dependencies = [ "log", "merlin", "parity-scale-codec", - "parking_lot", + "parking_lot 0.12.3", "paste", "primitive-types 0.12.2", "rand", @@ -7890,17 +7869,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "sp-debug-derive" -version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d09fa0a5f7299fb81ee25ae3853d26200f7a348148aed6de76be905c007dbe" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "sp-debug-derive" version = "14.0.0" @@ -7921,18 +7889,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "sp-externalities" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63867ec85950ced90d4ab1bba902a47db1b1efdf2829f653945669b2bb470a9c" -dependencies = [ - "environmental", - "parity-scale-codec", - "sp-std 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-storage 19.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sp-externalities" version = "0.25.0" @@ -7979,24 +7935,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "sp-io" -version = "30.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55f26d89feedaf0faf81688b6e1e1e81329cd8b4c6a4fd6c5b97ed9dd068b8a" -dependencies = [ - "bytes", - "parity-scale-codec", - "rustversion", - "sp-core 28.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-externalities 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime-interface 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-std 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-tracing 16.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing", - "tracing-core", -] - [[package]] name = "sp-io" version = "30.0.0" @@ -8009,7 +7947,7 @@ dependencies = [ "parity-scale-codec", "rustversion", "secp256k1 0.28.2", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", "sp-crypto-hashing 0.0.0", "sp-externalities 0.25.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "sp-keystore", @@ -8028,8 +7966,8 @@ version = "0.34.0" source = "git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10#f5587b380ee596f90482d402844c49aa140781d8" dependencies = [ "parity-scale-codec", - "parking_lot", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "parking_lot 0.12.3", + "sp-core", "sp-externalities 0.25.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "thiserror", ] @@ -8073,31 +8011,12 @@ dependencies = [ "simple-mermaid", "sp-application-crypto", "sp-arithmetic", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", - "sp-io 30.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", + "sp-io", "sp-std 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "sp-weights", ] -[[package]] -name = "sp-runtime-interface" -version = "24.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f66b66d8cec3d785fa6289336c1d9cbd4305d5d84f7134378c4d79ed7983e6fb" -dependencies = [ - "bytes", - "impl-trait-for-tuples", - "parity-scale-codec", - "primitive-types 0.12.2", - "sp-externalities 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime-interface-proc-macro 17.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-std 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-storage 19.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-tracing 16.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-wasm-interface 20.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "static_assertions", -] - [[package]] name = "sp-runtime-interface" version = "24.0.0" @@ -8135,20 +8054,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "sp-runtime-interface-proc-macro" -version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfaf6e85b2ec12a4b99cd6d8d57d083e30c94b7f1b0d8f93547121495aae6f0c" -dependencies = [ - "Inflector", - "expander", - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" @@ -8184,7 +8089,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", "sp-runtime", "sp-std 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", ] @@ -8197,10 +8102,10 @@ dependencies = [ "hash-db", "log", "parity-scale-codec", - "parking_lot", + "parking_lot 0.12.3", "rand", "smallvec", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", "sp-externalities 0.25.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "sp-panic-handler", "sp-std 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", @@ -8210,12 +8115,6 @@ dependencies = [ "trie-db", ] -[[package]] -name = "sp-std" -version = "14.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f8ee986414b0a9ad741776762f4083cd3a5128449b982a3919c4df36874834" - [[package]] name = "sp-std" version = "14.0.0" @@ -8226,18 +8125,6 @@ name = "sp-std" version = "14.0.0" source = "git+https://github.com/paritytech/polkadot-sdk#0e09ad448bce27fcd255370cc2827ea5d2cf3892" -[[package]] -name = "sp-storage" -version = "19.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb92d7b24033a8a856d6e20dd980b653cbd7af7ec471cc988b1b7c1d2e3a32b" -dependencies = [ - "parity-scale-codec", - "ref-cast", - "sp-debug-derive 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-std 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sp-storage" version = "19.0.0" @@ -8263,18 +8150,6 @@ dependencies = [ "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", ] -[[package]] -name = "sp-tracing" -version = "16.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0351810b9d074df71c4514c5228ed05c250607cba131c1c9d1526760ab69c05c" -dependencies = [ - "parity-scale-codec", - "sp-std 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing", - "tracing-core", -] - [[package]] name = "sp-tracing" version = "16.0.0" @@ -8309,11 +8184,11 @@ dependencies = [ "memory-db", "nohash-hasher", "parity-scale-codec", - "parking_lot", + "parking_lot 0.12.3", "rand", "scale-info", "schnellru", - "sp-core 28.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", + "sp-core", "sp-externalities 0.25.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "sp-std 14.0.0 (git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10)", "thiserror", @@ -8350,17 +8225,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "sp-wasm-interface" -version = "20.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ef97172c42eb4c6c26506f325f48463e9bc29b2034a587f1b9e48c751229bee" -dependencies = [ - "impl-trait-for-tuples", - "parity-scale-codec", - "sp-std 14.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sp-wasm-interface" version = "20.0.0" @@ -8390,7 +8254,7 @@ name = "sp-weights" version = "27.0.0" source = "git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7.1-patch-10#f5587b380ee596f90482d402844c49aa140781d8" dependencies = [ - "bounded-collections 0.2.0", + "bounded-collections", "parity-scale-codec", "scale-info", "serde", @@ -8803,9 +8667,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.12" +version = "0.30.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732ffa00f53e6b2af46208fba5718d9662a421049204e156328b66791ffa15ae" +checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" dependencies = [ "cfg-if 1.0.0", "core-foundation-sys", @@ -9063,7 +8927,7 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot", + "parking_lot 0.12.3", "pin-project-lite", "signal-hook-registry", "socket2 0.5.7", @@ -10744,7 +10608,7 @@ dependencies = [ "futures", "log", "nohash-hasher", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "rand", "static_assertions", @@ -10759,7 +10623,7 @@ dependencies = [ "futures", "log", "nohash-hasher", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "rand", "static_assertions", diff --git a/Cargo.toml b/Cargo.toml index 49a901d0d..73dc649b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,13 +25,17 @@ anyhow = "1.0.71" async-std = { version = "1.12.0", features = ["attributes"] } async-trait = "0.1.73" clap = { version = "4.4.4", features = ["derive", "cargo"] } -color-eyre = "0.6.2" +color-eyre = { version = "0.6.2", default-features = false } confy = "0.5.1" hex = "0.4.3" rand = { version = "0.8.5", default-features = false } -libp2p = { version = "0.54", features = ["kad", "identify", "ping", "mdns", "autonat", "relay", "dcutr", "upnp", "noise", "yamux", "dns", "metrics", "tokio", "macros", "tcp", "quic", "serde", "websocket"] } -libp2p-allow-block-list = "0.4" -libp2p-webrtc = { version = "=0.8.0-alpha", features = ["tokio"] } +# libp2p = { version = "0.54", features = ["kad", "identify", "ping", "mdns", "autonat", "relay", "dcutr", "upnp", "noise", "yamux", "dns", "metrics", "tokio", "macros", "tcp", "quic", "serde", "websocket"] } +# libp2p-allow-block-list = "0.4" +# libp2p-webrtc = { version = "=0.8.0-alpha", features = ["tokio"] } +libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "9a45db3f82b760c93099e66ec77a7a772d1f6cd3", features = ["kad", "identify", "ping", "mdns", "autonat", "relay", "dcutr", "upnp", "noise", "yamux", "dns", "metrics", "tokio", "macros", "tcp", "quic", "serde", "websocket"] } +libp2p-allow-block-list = { git = "https://github.com/libp2p/rust-libp2p", rev = "9a45db3f82b760c93099e66ec77a7a772d1f6cd3" } +libp2p-webrtc = { git = "https://github.com/libp2p/rust-libp2p", rev = "9a45db3f82b760c93099e66ec77a7a772d1f6cd3" } +libp2p-webrtc-websys = { git = "https://github.com/libp2p/rust-libp2p", rev = "9a45db3f82b760c93099e66ec77a7a772d1f6cd3" } multihash = { version = "0.14.0", default-features = false, features = ["blake3", "sha3"] } semver = "1.0.23" serde = { version = "1.0", features = ["derive"] } @@ -60,3 +64,9 @@ incremental = false inherits = "release" lto = "fat" codegen-units = 1 + +[patch.crates-io] +# Patching sp-io since some dependencies references patched and some non-patched versions, +# and we need to specify `disable-allocator` feature to enable wasm compilation. +# Patch needs to match patched tag of dependencies, for feature toggle to be applied. +sp-io = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-10" } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 67e880ce8..f4f787878 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,6 +2,8 @@ ## 1.0.5 +- Enable WASM compilation of the light client +- Enable WASM compilation on network, types and finality mods - Enable WASM compilation on proof mod - Enable WASM compilation on utils and shutdown mods - Allocate new port on each new dial attempt diff --git a/core/Cargo.toml b/core/Cargo.toml index 11eabe732..2832233a4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -13,37 +13,47 @@ avail-rust = { workspace = true } dusk-plonk = { workspace = true } # 3rd-party +async-stream = "0.3.5" +async-trait = { workspace = true } +base64 = "0.21.0" better-panic = "0.3.0" +chrono = "0.4.19" +clap = { workspace = true } codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] } -color-eyre = { workspace = true } +color-eyre = { workspace = true, default-features = true } +confy = { workspace = true } +convert_case = "0.6.0" derive_more = { version = "1", features = ["from"] } dusk-bytes = "0.1.7" futures = { workspace = true } getrandom = { version = "0.2.15", features = ["js"] } +hex = { workspace = true } itertools = "0.10.5" +libp2p-allow-block-list = { workspace = true } +mockall = "0.11.3" +semver = { workspace = true } +serde = { workspace = true } +serde_json = "1.0.125" +smallvec = "1.6.1" strip-ansi-escapes = "0.2.0" +strum = { version = "0.26.3", features = ["derive"] } +sysinfo = "0.30.12" tokio = { workspace = true } +tokio-retry = "0.3" +tokio-stream = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } +uuid = { workspace = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] async-std = { workspace = true } -async-stream = "0.3.5" -async-trait = { workspace = true } -base64 = "0.21.0" chrono = "0.4.19" confy = { workspace = true } -convert_case = "0.6.0" -derive_more = { version = "1", features = ["from"] } -futures = { workspace = true } -hex = { workspace = true } hyper = { version = "0.14.23", features = ["full", "http1"] } jsonrpsee-core = { version = "0.21.0", features = ["client"] } libc = "0.2.150" libp2p = { workspace = true } -libp2p-allow-block-list = { workspace = true } -libp2p-webrtc = { version = "=0.8.0-alpha", features = ["tokio"] } -mockall = "0.11.3" +libp2p-webrtc = { workspace = true, features = ["tokio"] } multihash = { workspace = true } num = "0.4.0" num_cpus = "1.13.0" @@ -51,35 +61,33 @@ pcap = "1.1.0" rand = { workspace = true, default-features = true } rand_chacha = "0.3" rocksdb = { version = "0.21.0", features = ["snappy", "multi-threaded-cf"], optional = true } -semver = { workspace = true } -serde = { workspace = true } -serde_json = "1.0.125" -smallvec = "1.6.1" strip-ansi-escapes = "0.2.0" -sysinfo = "0.30.12" thiserror = "1.0.64" threadpool = "1.8.1" -tokio-retry = "0.3" -tokio-stream = { workspace = true } tokio-util = "0.7.10" tracing = { workspace = true } -uuid = { workspace = true } +tracing-subscriber = { workspace = true } void = { workspace = true } warp = { workspace = true } # OpenTelemetry -clap = { workspace = true } opentelemetry = { workspace = true } opentelemetry-otlp = { workspace = true } opentelemetry_sdk = { workspace = true } -strum = { version = "0.26.3", features = ["derive"] } [target.'cfg(target_arch = "wasm32")'.dependencies] blake2b_simd = "1.0.2" +color-eyre = { workspace = true } +ed25519-compact = "2.1.1" +# NOTE: This is used due bug explained at: https://github.com/tomaka/wasm-timer/pull/13 +fluvio-wasm-timer = "0.2.5" +libp2p = { workspace = true, features = ["wasm-bindgen"] } +libp2p-webrtc-websys = { workspace = true } rand = { workspace = true, features = ["std_rng"] } thiserror-no-std = "2.0.2" tokio_with_wasm = { version = "0.7.1", default-features = false, features = ["sync", "macros", "rt", "time"] } web-time = "1.1.0" +wasm-bindgen = "0.2.90" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] hex-literal = "0.4.1" diff --git a/core/src/finality.rs b/core/src/finality.rs index 12353ec33..3d3bc8a32 100644 --- a/core/src/finality.rs +++ b/core/src/finality.rs @@ -1,12 +1,8 @@ use std::collections::HashMap; -use avail_rust::{ - sp_core::{ - ed25519::{self, Public}, - Pair, - }, - H256, -}; +#[cfg(not(target_arch = "wasm32"))] +use avail_rust::sp_core::ed25519; +use avail_rust::{sp_core::ed25519::Public, H256}; use codec::Encode; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -24,6 +20,22 @@ pub struct ValidatorSet { pub validator_set: Vec, } +#[cfg(not(target_arch = "wasm32"))] +fn verify_signature(public_key: [u8; 32], signature: [u8; 64], message: Vec) -> bool { + ::verify( + &ed25519::Signature(signature), + message, + &ed25519::Public(public_key), + ) +} + +#[cfg(target_arch = "wasm32")] +fn verify_signature(public_key: [u8; 32], signature: [u8; 64], message: Vec) -> bool { + let public_key = ed25519_compact::PublicKey::from_slice(&public_key).unwrap(); + let signature = ed25519_compact::Signature::from_slice(&signature).unwrap(); + public_key.verify(message, &signature).is_ok() +} + pub fn check_finality( validator_set: &ValidatorSet, justification: &GrandpaJustification, @@ -52,12 +64,7 @@ pub fn check_finality( &justification.round, &validator_set.set_id, // Set ID is needed here. )); - let is_ok = ::verify( - &precommit.signature, - signed_message, - &precommit.id, - ); - + let is_ok = verify_signature(precommit.id.0, precommit.signature.0, signed_message); let ancestry = confirm_ancestry( &precommit.precommit.target_hash, &justification.commit.target_hash, diff --git a/core/src/lib.rs b/core/src/lib.rs index 36e891042..0b79a0ea5 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -6,17 +6,13 @@ pub mod app_client; #[cfg(feature = "crawl")] #[cfg(not(target_arch = "wasm32"))] pub mod crawl_client; -#[cfg(not(target_arch = "wasm32"))] pub mod data; #[cfg(not(target_arch = "wasm32"))] pub mod fat_client; -#[cfg(not(target_arch = "wasm32"))] pub mod finality; -#[cfg(not(target_arch = "wasm32"))] pub mod light_client; #[cfg(not(target_arch = "wasm32"))] pub mod maintenance; -#[cfg(not(target_arch = "wasm32"))] pub mod network; pub mod proof; pub mod shutdown; @@ -26,6 +22,5 @@ pub mod sync_client; pub mod sync_finality; #[cfg(not(target_arch = "wasm32"))] pub mod telemetry; -#[cfg(not(target_arch = "wasm32"))] pub mod types; pub mod utils; diff --git a/core/src/light_client.rs b/core/src/light_client.rs index 14f3adbfb..8caee33be 100644 --- a/core/src/light_client.rs +++ b/core/src/light_client.rs @@ -23,9 +23,14 @@ use avail_rust::{ }; use codec::Encode; use color_eyre::Result; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; use tokio::sync::mpsc::UnboundedSender; +#[cfg(target_arch = "wasm32")] +use tokio_with_wasm::alias as tokio; use tracing::{error, info}; +#[cfg(target_arch = "wasm32")] +use web_time::Instant; use crate::{ data::{AchievedConfidenceKey, BlockHeaderKey, Database, VerifiedCellCountKey}, @@ -38,6 +43,7 @@ use crate::{ utils::{blake2_256, calculate_confidence, extract_kate}, }; +#[derive(Debug)] pub enum OutputEvent { RecordBlockProcessingDelay(f64), CountSessionBlocks, diff --git a/core/src/network.rs b/core/src/network.rs index 1d958a478..6771d26e3 100644 --- a/core/src/network.rs +++ b/core/src/network.rs @@ -12,10 +12,17 @@ use color_eyre::{eyre::WrapErr, Result}; use dusk_plonk::prelude::PublicParameters; use libp2p::{Multiaddr, PeerId}; use mockall::automock; -use std::{str::FromStr, sync::Arc, time::Duration}; +#[cfg(not(target_arch = "wasm32"))] +use std::time::Duration; +use std::{str::FromStr, sync::Arc}; use strum::Display; +#[cfg(not(target_arch = "wasm32"))] use tokio::time::Instant; use tracing::{debug, info}; +#[cfg(target_arch = "wasm32")] +use web_time::Duration; +#[cfg(target_arch = "wasm32")] +use web_time::Instant; use crate::{data::Database, proof}; diff --git a/core/src/network/p2p.rs b/core/src/network/p2p.rs index a94cae598..4cc8a1746 100644 --- a/core/src/network/p2p.rs +++ b/core/src/network/p2p.rs @@ -8,23 +8,35 @@ use libp2p::{ autonat, dcutr, identify, identity::{self, ed25519, Keypair}, kad::{self, Mode, PeerRecord, QueryStats, Record, RecordKey}, - mdns, noise, ping, relay, + noise, ping, relay, swarm::NetworkBehaviour, - tcp, upnp, yamux, Multiaddr, PeerId, Swarm, SwarmBuilder, + yamux, Multiaddr, PeerId, Swarm, SwarmBuilder, }; +#[cfg(not(target_arch = "wasm32"))] +use libp2p::{mdns, tcp, upnp}; +#[cfg(not(target_arch = "wasm32"))] use libp2p_webrtc as webrtc; +#[cfg(not(target_arch = "wasm32"))] use multihash::{self, Hasher}; +#[cfg(not(target_arch = "wasm32"))] use rand::thread_rng; use semver::Version; use serde::{Deserialize, Serialize}; -use std::{fmt, net::Ipv4Addr, str::FromStr, time::Duration}; +#[cfg(not(target_arch = "wasm32"))] +use std::time::Duration; +use std::{fmt, net::Ipv4Addr, str::FromStr}; use tokio::sync::{ mpsc::{self, UnboundedReceiver}, oneshot, }; +#[cfg(target_arch = "wasm32")] +use tokio_with_wasm::alias as tokio; use tracing::{info, warn}; +#[cfg(target_arch = "wasm32")] +use web_time::Duration; #[cfg(feature = "network-analysis")] +#[cfg(not(target_arch = "wasm32"))] pub mod analyzer; mod client; pub mod configuration; @@ -170,10 +182,12 @@ pub struct Behaviour { kademlia: kad::Behaviour, identify: identify::Behaviour, ping: ping::Behaviour, + #[cfg(not(target_arch = "wasm32"))] mdns: mdns::tokio::Behaviour, auto_nat: autonat::Behaviour, relay_client: relay::client::Behaviour, dcutr: dcutr::Behaviour, + #[cfg(not(target_arch = "wasm32"))] upnp: upnp::tokio::Behaviour, blocked_peers: allow_block_list::Behaviour, } @@ -274,8 +288,12 @@ async fn build_swarm( // build the Swarm, connecting the lower transport logic with the // higher layer network behaviour logic + #[cfg(not(target_arch = "wasm32"))] let tokio_swarm = SwarmBuilder::with_existing_identity(id_keys.clone()).with_tokio(); + #[cfg(target_arch = "wasm32")] + let tokio_swarm = SwarmBuilder::with_existing_identity(id_keys.clone()).with_wasm_bindgen(); + let mut swarm; let kad_cfg: kad::Config = kad_config(cfg, genesis_hash); @@ -288,12 +306,25 @@ async fn build_swarm( dcutr: dcutr::Behaviour::new(key.public().to_peer_id()), kademlia: kad::Behaviour::with_config(key.public().to_peer_id(), kad_store, kad_cfg), auto_nat: autonat::Behaviour::new(key.public().to_peer_id(), autonat_cfg), + #[cfg(not(target_arch = "wasm32"))] mdns: mdns::Behaviour::new(mdns::Config::default(), key.public().to_peer_id())?, + #[cfg(not(target_arch = "wasm32"))] upnp: upnp::tokio::Behaviour::default(), blocked_peers: allow_block_list::Behaviour::default(), }) }; + #[cfg(target_arch = "wasm32")] + { + use libp2p_webrtc_websys as webrtc; + swarm = tokio_swarm + .with_other_transport(|key| webrtc::Transport::new(webrtc::Config::new(&key)))? + .with_relay_client(noise::Config::new, yamux::Config::default)? + .with_behaviour(behaviour)? + .with_swarm_config(|c| generate_config(c, cfg)) + .build(); + } + #[cfg(not(target_arch = "wasm32"))] if cfg.ws_transport_enable { swarm = tokio_swarm .with_websocket(noise::Config::new, yamux::Config::default) @@ -340,6 +371,7 @@ async fn build_swarm( // From such generated keypair it derives multihash identifier of the local peer. fn keypair(secret_key: &SecretKey) -> Result { let keypair = match secret_key { + #[cfg(not(target_arch = "wasm32"))] // If seed is provided, generate secret key from seed SecretKey::Seed { seed } => { let seed_digest = multihash::Sha3_256::digest(seed.as_bytes()); diff --git a/core/src/network/p2p/client.rs b/core/src/network/p2p/client.rs index 14edb0094..d2b304551 100644 --- a/core/src/network/p2p/client.rs +++ b/core/src/network/p2p/client.rs @@ -16,10 +16,15 @@ use libp2p::{ swarm::dial_opts::{DialOpts, PeerCondition}, Multiaddr, PeerId, }; +#[cfg(not(target_arch = "wasm32"))] use std::time::{Duration, Instant}; use sysinfo::System; use tokio::sync::{mpsc::UnboundedSender, oneshot}; +#[cfg(target_arch = "wasm32")] +use tokio_with_wasm::alias as tokio; use tracing::{debug, info, trace, warn}; +#[cfg(target_arch = "wasm32")] +use web_time::{Duration, Instant}; use super::{ event_loop::ConnectionEstablishedInfo, is_global, is_multiaddr_global, Command, EventLoop, diff --git a/core/src/network/p2p/configuration.rs b/core/src/network/p2p/configuration.rs index 03c782dfb..79034afc2 100644 --- a/core/src/network/p2p/configuration.rs +++ b/core/src/network/p2p/configuration.rs @@ -3,12 +3,15 @@ use crate::network::p2p::MemoryStoreConfig; use crate::types::{duration_seconds_format, KademliaMode, MultiaddrConfig, SecretKey}; use libp2p::{kad, multiaddr::Protocol, Multiaddr}; use serde::{Deserialize, Serialize}; +#[cfg(not(target_arch = "wasm32"))] +use std::time::Duration; use std::{ borrow::Cow, net::Ipv4Addr, num::{NonZeroU8, NonZeroUsize}, - time::Duration, }; +#[cfg(target_arch = "wasm32")] +use web_time::Duration; /// Libp2p AutoNAT configuration (see [RuntimeConfig] for details) #[derive(Clone, Serialize, Deserialize, Debug)] diff --git a/core/src/network/p2p/event_loop.rs b/core/src/network/p2p/event_loop.rs index 26a63debe..291766b77 100644 --- a/core/src/network/p2p/event_loop.rs +++ b/core/src/network/p2p/event_loop.rs @@ -9,25 +9,33 @@ use libp2p::{ self, store::RecordStore, BootstrapOk, GetRecordOk, InboundRequest, Mode, PutRecordOk, QueryId, QueryResult, RecordKey, }, - mdns, multiaddr::Protocol, ping, swarm::{ dial_opts::{DialOpts, PeerCondition}, SwarmEvent, }, - upnp, Multiaddr, PeerId, Swarm, + Multiaddr, PeerId, Swarm, }; +#[cfg(not(target_arch = "wasm32"))] +use libp2p::{mdns, upnp}; use rand::seq::SliceRandom; -use std::{collections::HashMap, str::FromStr, time::Duration}; -use tokio::{ - sync::{ - mpsc::{UnboundedReceiver, UnboundedSender}, - oneshot, - }, - time::{self, Instant}, +#[cfg(not(target_arch = "wasm32"))] +use std::time::Duration; +use std::{collections::HashMap, str::FromStr}; +use tokio::sync::{ + mpsc::{UnboundedReceiver, UnboundedSender}, + oneshot, }; +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::{interval, Instant}; +#[cfg(target_arch = "wasm32")] +use tokio_with_wasm::alias as tokio; use tracing::{debug, error, info, trace, warn}; +#[cfg(target_arch = "wasm32")] +use fluvio_wasm_timer::Interval; +#[cfg(target_arch = "wasm32")] +use web_time::{Duration, Instant}; use super::{ configuration::LibP2PConfig, Behaviour, BehaviourEvent, Command, OutputEvent, QueryChannel, @@ -194,9 +202,14 @@ impl EventLoop { .delay_token() .expect("There should not be any shutdowns at the begging of the P2P Event Loop"); let mut event_counter = EventCounter::new(30); - let mut report_timer = time::interval(event_counter.report_interval); + + #[cfg(not(target_arch = "wasm32"))] + let mut report_timer = interval(event_counter.report_interval); + #[cfg(target_arch = "wasm32")] + let mut report_timer = Interval::new(event_counter.report_interval); loop { + #[cfg(not(target_arch = "wasm32"))] tokio::select! { event = self.swarm.next() => { self.handle_event(event.expect("Swarm stream should be infinite")).await; @@ -223,6 +236,34 @@ impl EventLoop { break; } } + + #[cfg(target_arch = "wasm32")] + tokio::select! { + event = self.swarm.next() => { + self.handle_event(event.expect("Swarm stream should be infinite")).await; + event_counter.add_event(); + + _ = self.event_sender.send(OutputEvent::Count); + }, + command = self.command_receiver.recv() => match command { + Some(c) => _ = (c)(&mut self), + // + None => { + warn!("Command channel closed, exiting the network event loop"); + break; + }, + }, + _ = report_timer.next() => { + debug!("Events per {}s: {:.2}", event_counter.duration_secs(), event_counter.count_events()); + event_counter.reset_counter(); + }, + // if the shutdown was triggered, + // break the loop immediately, proceed to the cleanup phase + _ = self.shutdown.triggered_shutdown() => { + info!("Shutdown triggered, exiting the network event loop"); + break; + } + } } self.disconnect_peers(); } @@ -422,6 +463,7 @@ impl EventLoop { trace!("Identify Error event. PeerId: {peer_id:?}. Error: {error:?}"); }, }, + #[cfg(not(target_arch = "wasm32"))] SwarmEvent::Behaviour(BehaviourEvent::Mdns(event)) => { match event { mdns::Event::Discovered(addrs_list) => { @@ -482,6 +524,7 @@ impl EventLoop { _ = self.event_sender.send(OutputEvent::Ping(rtt)); } }, + #[cfg(not(target_arch = "wasm32"))] SwarmEvent::Behaviour(BehaviourEvent::Upnp(event)) => match event { upnp::Event::NewExternalAddr(addr) => { trace!("[UPnP] New external address: {addr}"); diff --git a/core/src/network/rpc.rs b/core/src/network/rpc.rs index cdb9c7ff9..b10e4b34e 100644 --- a/core/src/network/rpc.rs +++ b/core/src/network/rpc.rs @@ -8,12 +8,16 @@ use color_eyre::{eyre::eyre, Result}; use configuration::RPCConfig; use rand::{seq::SliceRandom, thread_rng, Rng}; use serde::{de, Deserialize, Serialize}; -use std::{collections::HashSet, fmt::Display, time::Instant}; +use std::{collections::HashSet, fmt::Display}; +#[cfg(not(target_arch = "wasm32"))] +use std::time::Instant; use tokio::{ sync::broadcast::{Receiver, Sender}, - time::{self, timeout}, + time::{timeout, Duration}, }; use tracing::{debug, info}; +#[cfg(target_arch = "wasm32")] +use web_time::Instant; mod client; pub mod configuration; @@ -273,7 +277,7 @@ pub async fn wait_for_finalized_header( mut rpc_events_receiver: Receiver, timeout_seconds: u64, ) -> Result { - let timeout_seconds = time::Duration::from_secs(timeout_seconds); + let timeout_seconds = Duration::from_secs(timeout_seconds); let result = timeout(timeout_seconds, async { while let Ok(event) = rpc_events_receiver.recv().await { @@ -288,6 +292,7 @@ pub async fn wait_for_finalized_header( match result { Ok(header) => header, + // Ok(Err(error)) => Err(eyre!("Failed to receive finalized header: {error}")), Err(_) => Err(eyre!("Timeout while waiting for first finalized header")), } } diff --git a/core/src/network/rpc/client.rs b/core/src/network/rpc/client.rs index bab7f11c7..e8cb29d68 100644 --- a/core/src/network/rpc/client.rs +++ b/core/src/network/rpc/client.rs @@ -16,6 +16,10 @@ use color_eyre::{ }; use futures::{Stream, TryStreamExt}; use std::{iter::Iterator, pin::Pin, sync::Arc, time::Duration}; +#[cfg(not(target_arch = "wasm32"))] +use thiserror::Error; +#[cfg(target_arch = "wasm32")] +use thiserror_no_std::Error; use tokio::sync::{broadcast::Sender, RwLock}; use tokio_retry::Retry; use tokio_stream::{Elapsed, StreamExt, StreamMap}; @@ -29,7 +33,7 @@ use crate::{ types::{Base64, DEV_FLAG_GENHASH}, }; -#[derive(Debug, thiserror::Error)] +#[derive(Debug, Error)] enum RetryError { #[error("No previously connected node found in database")] NoPreviousNode, @@ -39,7 +43,7 @@ enum RetryError { Shutdown(String), } -#[derive(Debug, thiserror::Error)] +#[derive(Debug, Error)] enum ClientCreationError { #[error("SDK failed to provide new RPC client: {0}")] SdkFailure(Report), @@ -96,9 +100,11 @@ impl GenesisHash { } let bytes: [u8; 32] = from_hex(hex_str) - .map_err(|_| ClientCreationError::InvalidGenesisHash(hex_str.to_string()))? + .map_err(|_| Report::msg(ClientCreationError::InvalidGenesisHash(hex_str.to_string())))? .try_into() - .map_err(|_| ClientCreationError::InvalidGenesisHash(hex_str.to_string()))?; + .map_err(|_| { + Report::msg(ClientCreationError::InvalidGenesisHash(hex_str.to_string())) + })?; Ok(Self::Hash(H256::from(bytes))) } @@ -188,8 +194,8 @@ impl Client { match connection_result { Ok(Ok(ConnectionAttempt { client, node, .. })) => Ok((client, node)), - Ok(Err(err)) => Err(RetryError::ConnectionFailed(err).into()), - Err(err) => Err(RetryError::Shutdown(err.to_string()).into()), + Ok(Err(err)) => Err(Report::msg(RetryError::ConnectionFailed(err))), + Err(err) => Err(Report::msg(RetryError::Shutdown(err.to_string()))), } } @@ -222,7 +228,7 @@ impl Client { Fut: std::future::Future>, { if nodes.is_empty() { - return Err(ClientCreationError::NoNodesAvailable.into()); + return Err(Report::msg(ClientCreationError::NoNodesAvailable)); } let mut last_error = None; @@ -242,10 +248,9 @@ impl Client { } } - Err(ClientCreationError::AllNodesFailed { + Err(Report::msg(ClientCreationError::AllNodesFailed { last_error: last_error.unwrap_or_else(|| eyre!("No error recorded")), - } - .into()) + })) } // Tries to connect to the provided RPC host, verifies the genesis hash, @@ -262,13 +267,12 @@ impl Client { match Self::create_rpc_client(&node.host, expected_genesis_hash).await { Ok((client, node)) => { // Execute the provided RPC function call with the created client - let result = - f(client.clone()) - .await - .map_err(|e| ClientCreationError::RpcCallFailed { - host: node.host.clone(), - error: e, - })?; + let result = f(client.clone()).await.map_err(|e| { + Report::msg(ClientCreationError::RpcCallFailed { + host: node.host.clone(), + error: e, + }) + })?; Ok(ConnectionAttempt { client, @@ -276,11 +280,10 @@ impl Client { result, }) }, - Err(err) => Err(ClientCreationError::ConnectionFailed { + Err(err) => Err(Report::msg(ClientCreationError::ConnectionFailed { host: node.host.clone(), error: err, - } - .into()), + })), } } @@ -288,7 +291,7 @@ impl Client { async fn create_rpc_client(host: &str, expected_genesis_hash: &str) -> Result<(SDK, Node)> { let client = SDK::new_insecure(host) .await - .map_err(|e| ClientCreationError::SdkFailure(eyre!("{e}")))?; + .map_err(|e| Report::msg(ClientCreationError::SdkFailure(eyre!("{e}"))))?; // Verify genesis hash let genesis_hash = client.api.genesis_hash(); @@ -297,12 +300,11 @@ impl Client { let expected_hash = GenesisHash::from_hex(expected_genesis_hash)?; if !expected_hash.matches(&genesis_hash) { - return Err(ClientCreationError::GenesisHashMismatch { + return Err(Report::msg(ClientCreationError::GenesisHashMismatch { host: host.to_string(), expected: expected_genesis_hash.to_string(), found: format!("{:?}", genesis_hash), - } - .into()); + })); } // Fetch system and runtime information @@ -311,7 +313,7 @@ impl Client { .system .version() .await - .map_err(|e| ClientCreationError::SystemVersionError(e.into()))?; + .map_err(|e| Report::msg(ClientCreationError::SystemVersionError(e.into())))?; let runtime_version = client.api.runtime_version(); @@ -338,7 +340,11 @@ impl Client { } // If current client failed try to reconnect using stored node - let connected_node = self.db.get(RpcNodeKey).ok_or(RetryError::NoPreviousNode)?; + let connected_node = self + .db + .get(RpcNodeKey) + .ok_or(RetryError::NoPreviousNode) + .map_err(Report::msg)?; warn!( "Executing RPC call with host: {} failed. Trying to create a new RPC connection.", @@ -372,8 +378,8 @@ impl Client { match retry_result { Ok(Ok(result)) => Ok(result), - Ok(Err(err)) => Err(RetryError::ConnectionFailed(err).into()), - Err(err) => Err(RetryError::Shutdown(err.to_string()).into()), + Ok(Err(err)) => Err(Report::msg(RetryError::ConnectionFailed(err))), + Err(err) => Err(Report::msg(RetryError::Shutdown(err.to_string()))), } } @@ -407,8 +413,8 @@ impl Client { self.db.put(RpcNodeKey, node); Ok(result) }, - Ok(Err(err)) => Err(RetryError::ConnectionFailed(err).into()), - Err(err) => Err(RetryError::Shutdown(err.to_string()).into()), + Ok(Err(err)) => Err(Report::msg(RetryError::ConnectionFailed(err))), + Err(err) => Err(Report::msg(RetryError::Shutdown(err.to_string()))), } } diff --git a/core/src/network/rpc/configuration.rs b/core/src/network/rpc/configuration.rs index 96683349e..1dad0c2a8 100644 --- a/core/src/network/rpc/configuration.rs +++ b/core/src/network/rpc/configuration.rs @@ -1,7 +1,10 @@ use crate::types::duration_millis_format; use serde::{Deserialize, Serialize}; +#[cfg(not(target_arch = "wasm32"))] use std::time::Duration; use tokio_retry::strategy::{jitter, ExponentialBackoff, FibonacciBackoff}; +#[cfg(target_arch = "wasm32")] +use web_time::Duration; #[derive(Clone, Serialize, Deserialize, Debug)] #[serde(default)] diff --git a/core/src/network/rpc/subscriptions.rs b/core/src/network/rpc/subscriptions.rs index 81ecabd6a..38bfead47 100644 --- a/core/src/network/rpc/subscriptions.rs +++ b/core/src/network/rpc/subscriptions.rs @@ -5,10 +5,13 @@ use avail_rust::{ }; use codec::Encode; use color_eyre::{eyre::eyre, Result}; +#[cfg(not(target_arch = "wasm32"))] use std::time::Instant; use tokio::sync::broadcast::Sender; use tokio_stream::StreamExt; use tracing::{debug, info, trace}; +#[cfg(target_arch = "wasm32")] +use web_time::Instant; use super::{Client, OutputEvent, Subscription}; use crate::{ diff --git a/core/src/types.rs b/core/src/types.rs index b19549904..880a4ab14 100644 --- a/core/src/types.rs +++ b/core/src/types.rs @@ -5,15 +5,17 @@ use avail_rust::{ avail::runtime_types::bounded_collections::bounded_vec::BoundedVec, avail_core::DataLookup, kate_recovery::{commitments, matrix::Dimensions}, - sp_core::{ - crypto::{self, Ss58Codec}, - {bytes, ed25519}, - }, + sp_core::{bytes, ed25519}, + AvailHeader, H256, +}; +#[cfg(not(target_arch = "wasm32"))] +use avail_rust::{ + sp_core::crypto::{self, Ss58Codec}, subxt_signer::{ bip39::{Language, Mnemonic}, SecretString, SecretUri, }, - AvailHeader, Keypair, H256, + Keypair, }; use base64::{engine::general_purpose, DecodeError, Engine}; use codec::{Decode, Encode, Input}; @@ -24,9 +26,15 @@ use libp2p::{Multiaddr, PeerId}; use serde::{de::Error, Deserialize, Serialize}; use std::fmt::{self, Display, Formatter}; use std::str::FromStr; +#[cfg(not(target_arch = "wasm32"))] use std::time::{Duration, Instant}; use tokio::sync::broadcast; +#[cfg(target_arch = "wasm32")] +use tokio_with_wasm::alias as tokio; +#[cfg(not(target_arch = "wasm32"))] use tracing::{info, warn}; +#[cfg(target_arch = "wasm32")] +use web_time::{Duration, Instant}; const CELL_SIZE: usize = 32; const PROOF_SIZE: usize = 48; @@ -213,8 +221,8 @@ pub mod tracing_level_format { pub mod option_duration_seconds_format { use super::duration_seconds_format; + use super::Duration; use serde::{self, Deserialize, Deserializer, Serializer}; - use std::time::Duration; pub fn serialize(duration: &Option, serializer: S) -> Result where @@ -236,8 +244,8 @@ pub mod option_duration_seconds_format { } pub mod duration_seconds_format { + use super::Duration; use serde::{self, Deserialize, Deserializer, Serializer}; - use std::time::Duration; pub fn serialize(duration: &Duration, serializer: S) -> Result where @@ -256,8 +264,8 @@ pub mod duration_seconds_format { } pub mod duration_millis_format { + use super::Duration; use serde::{self, Deserialize, Deserializer, Serializer}; - use std::time::Duration; pub fn serialize(duration: &Duration, serializer: S) -> Result where @@ -350,8 +358,13 @@ impl From<&MultiaddrConfig> for (PeerId, Multiaddr) { #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(untagged)] pub enum SecretKey { - Seed { seed: String }, - Key { key: String }, + #[cfg(not(target_arch = "wasm32"))] + Seed { + seed: String, + }, + Key { + key: String, + }, } pub struct Delay(pub Option); @@ -409,6 +422,7 @@ pub struct MaintenanceConfig { pub num_cpus_threshold: usize, } +#[cfg(not(target_arch = "wasm32"))] #[derive(Clone)] pub struct IdentityConfig { /// Avail account secret key. (secret is generated if it is not configured) @@ -419,6 +433,7 @@ pub struct IdentityConfig { pub avail_public_key: String, } +#[cfg(not(target_arch = "wasm32"))] pub fn load_or_init_suri(path: &str) -> Result { #[derive(Default, Serialize, Deserialize)] struct Config { @@ -453,6 +468,7 @@ pub fn load_or_init_suri(path: &str) -> Result { Ok(mnemonic.to_string()) } +#[cfg(not(target_arch = "wasm32"))] impl IdentityConfig { pub fn from_suri(suri: String, password: Option) -> Result { let mut suri = SecretUri::from_str(&suri)?; diff --git a/core/src/utils.rs b/core/src/utils.rs index ff7bcf85a..21ef5e296 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -119,12 +119,19 @@ pub fn filter_auth_set_changes(header: &AvailHeader) -> Vec) -> Result<()> { + #[cfg(not(target_arch = "wasm32"))] // initialize color-eyre hooks let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default() .display_location_section(true) .display_env_section(true) .into_hooks(); + #[cfg(target_arch = "wasm32")] + // initialize color-eyre hooks + let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default() + .display_env_section(true) + .into_hooks(); + // install hook as global handler eyre_hook.install()?;