From ab8ba97f15c7dcba586acc283d2d6405adb94447 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 | 736 +++++++++++--------------- Cargo.toml | 17 +- core/Cargo.toml | 63 ++- core/src/api/v2/mod.rs | 3 +- core/src/finality.rs | 36 +- core/src/lib.rs | 8 + core/src/light_client.rs | 8 +- core/src/network.rs | 9 +- core/src/network/p2p.rs | 39 +- core/src/network/p2p/client.rs | 5 + core/src/network/p2p/configuration.rs | 5 +- core/src/network/p2p/event_loop.rs | 73 ++- core/src/network/rpc.rs | 4 +- core/src/network/rpc/client.rs | 8 +- core/src/network/rpc/configuration.rs | 3 + core/src/network/rpc/subscriptions.rs | 10 +- core/src/proof.rs | 45 +- core/src/proof/core.rs | 73 +++ core/src/shutdown.rs | 4 + core/src/shutdown/utils.rs | 1 + core/src/types.rs | 38 +- core/src/utils.rs | 38 +- 22 files changed, 705 insertions(+), 521 deletions(-) create mode 100644 core/src/proof/core.rs diff --git a/Cargo.lock b/Cargo.lock index 3f61928cd..c6fb9e384 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,7 +195,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -576,7 +576,7 @@ checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", "synstructure 0.13.1", ] @@ -599,7 +599,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -828,7 +828,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -845,7 +845,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -896,7 +896,7 @@ version = "0.6.2" source = "git+https://github.com/availproject/avail-core?branch=main#b845db8a6c46cb00e21396ae26f4d72ffdd6e567" dependencies = [ "binary-merkle-tree", - "bounded-collections 0.2.0", + "bounded-collections", "derive_more 0.99.18", "ethabi-decode", "frame-support", @@ -907,8 +907,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)", @@ -992,13 +992,17 @@ dependencies = [ "avail-rust", "base64 0.21.7", "better-panic", + "blake2b_simd", "chrono", "clap", "color-eyre", "confy 0.5.1", - "derive_more 0.99.18", + "derive_more 1.0.0", + "dusk-bytes", "dusk-plonk", + "ed25519-compact", "futures", + "getrandom", "hex", "hex-literal", "hyper 0.14.29", @@ -1008,6 +1012,7 @@ dependencies = [ "libp2p", "libp2p-allow-block-list", "libp2p-webrtc", + "libp2p-webrtc-websys", "mockall", "multihash 0.14.0", "num", @@ -1030,16 +1035,21 @@ dependencies = [ "sysinfo", "test-case", "thiserror", + "thiserror-no-std", "threadpool", "tokio", "tokio-retry", "tokio-stream", "tokio-util", + "tokio_with_wasm", "tracing", "tracing-subscriber 0.3.18", "uuid", "void", "warp", + "wasm-bindgen", + "wasm-timer", + "web-time", ] [[package]] @@ -1103,7 +1113,7 @@ source = "git+https://github.com/availproject/avail.git?branch=avail-rust-wasm#d dependencies = [ "avail-core", "base58", - "bounded-collections 0.2.0", + "bounded-collections", "derive_more 1.0.0", "hex", "kate-recovery", @@ -1111,8 +1121,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", @@ -1301,7 +1311,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -1454,17 +1464,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" @@ -1689,7 +1688,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2025,6 +2024,12 @@ dependencies = [ "subtle", ] +[[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" @@ -2058,7 +2063,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2106,7 +2111,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.11.1", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2128,7 +2133,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core 0.20.9", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2246,7 +2251,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2257,7 +2262,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2270,7 +2275,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2291,7 +2296,7 @@ dependencies = [ "convert_case 0.6.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", "unicode-xid", ] @@ -2360,7 +2365,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2400,7 +2405,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.68", + "syn 2.0.85", "termcolor", "toml 0.8.14", "walkdir", @@ -2525,6 +2530,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" @@ -2606,7 +2621,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2733,7 +2748,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2905,12 +2920,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", @@ -2938,7 +2953,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing 0.0.0", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2950,7 +2965,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -2960,7 +2975,7 @@ source = "git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7. dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -3073,7 +3088,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -3456,7 +3471,7 @@ dependencies = [ "ipconfig", "lru-cache", "once_cell", - "parking_lot", + "parking_lot 0.12.3", "rand", "resolv-conf", "smallvec", @@ -3767,16 +3782,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", @@ -4014,9 +4031,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] @@ -4270,7 +4287,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", @@ -4341,8 +4358,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", @@ -4352,7 +4368,7 @@ dependencies = [ "libp2p-allow-block-list", "libp2p-autonat", "libp2p-connection-limits", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-dcutr", "libp2p-dns", "libp2p-gossipsub", @@ -4361,7 +4377,7 @@ dependencies = [ "libp2p-kad", "libp2p-mdns", "libp2p-metrics", - "libp2p-noise 0.45.0", + "libp2p-noise", "libp2p-ping", "libp2p-quic", "libp2p-relay", @@ -4378,11 +4394,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", @@ -4390,9 +4405,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", @@ -4401,7 +4415,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-request-response", "libp2p-swarm", @@ -4418,48 +4432,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", @@ -4470,7 +4454,7 @@ dependencies = [ "multihash 0.19.1", "multistream-select", "once_cell", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "quick-protobuf", "rand", @@ -4487,15 +4471,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", @@ -4510,24 +4493,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", @@ -4539,7 +4520,7 @@ dependencies = [ "futures-ticker", "getrandom", "hex_fmt", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "prometheus-client", @@ -4557,16 +4538,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", @@ -4599,9 +4579,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", @@ -4611,7 +4590,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", @@ -4630,14 +4609,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", @@ -4651,11 +4629,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", @@ -4668,43 +4645,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", @@ -4723,13 +4673,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", @@ -4741,17 +4690,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", @@ -4765,8 +4713,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", @@ -4774,7 +4721,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.42.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", @@ -4790,14 +4737,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", @@ -4809,15 +4755,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", @@ -4828,32 +4774,31 @@ 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", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[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", @@ -4863,12 +4808,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", @@ -4881,14 +4825,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", @@ -4898,8 +4841,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", @@ -4907,9 +4849,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", @@ -4926,17 +4868,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", @@ -4947,18 +4888,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 0.8.0", @@ -4971,12 +4932,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", @@ -5158,7 +5118,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -5172,7 +5132,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -5183,7 +5143,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -5194,7 +5154,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -5435,15 +5395,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]] @@ -5886,6 +5845,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" @@ -5893,7 +5863,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]] @@ -5904,7 +5888,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.5.2", "smallvec", "windows-targets 0.52.6", ] @@ -6008,7 +5992,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -6074,7 +6058,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -6084,7 +6068,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -6196,7 +6180,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -6272,7 +6256,7 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -6292,7 +6276,7 @@ checksum = "c1ca959da22a332509f2a73ae9e5f23f9dcfc31fd3a54d71f159495bd5909baa" dependencies = [ "dtoa", "itoa", - "parking_lot", + "parking_lot 0.12.3", "prometheus-client-derive-encode", ] @@ -6304,7 +6288,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -6347,7 +6331,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -6377,8 +6361,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", @@ -6437,9 +6420,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -6539,6 +6522,15 @@ dependencies = [ "wasm-bindgen-futures", ] +[[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" @@ -6576,7 +6568,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -7000,8 +6992,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", @@ -7135,7 +7126,7 @@ dependencies = [ "proc-macro2", "quote", "scale-info", - "syn 2.0.68", + "syn 2.0.85", "thiserror", ] @@ -7315,6 +7306,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" @@ -7342,7 +7336,7 @@ checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -7612,7 +7606,7 @@ dependencies = [ "log", "lru", "no-std-net", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "rand", "rand_chacha", @@ -7702,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", @@ -7724,7 +7718,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -7735,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)", ] @@ -7772,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", - "scale-info", - "schnorrkel", - "secrecy", - "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" @@ -7809,7 +7776,7 @@ dependencies = [ "bip39", "bitflags 1.3.2", "blake2", - "bounded-collections 0.2.0", + "bounded-collections", "bs58", "dyn-clonable", "ed25519-zebra", @@ -7822,7 +7789,7 @@ dependencies = [ "log", "merlin", "parity-scale-codec", - "parking_lot", + "parking_lot 0.12.3", "paste", "primitive-types", "rand", @@ -7899,18 +7866,7 @@ source = "git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7. dependencies = [ "quote", "sp-crypto-hashing 0.0.0", - "syn 2.0.68", -] - -[[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.68", + "syn 2.0.85", ] [[package]] @@ -7920,7 +7876,7 @@ source = "git+https://github.com/availproject/polkadot-sdk.git?tag=polkadot-1.7. dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -7930,19 +7886,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk#3d4a3355f0d31aeab7b79c2 dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", -] - -[[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)", + "syn 2.0.85", ] [[package]] @@ -7991,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" @@ -8021,7 +7947,7 @@ dependencies = [ "parity-scale-codec", "rustversion", "secp256k1", - "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", @@ -8040,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", ] @@ -8085,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", - "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" @@ -8147,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 3.1.0", - "proc-macro2", - "quote", - "syn 2.0.68", -] - [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" @@ -8171,7 +8064,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -8184,7 +8077,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -8196,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)", ] @@ -8209,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)", @@ -8222,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" @@ -8238,18 +8125,6 @@ name = "sp-std" version = "14.0.0" source = "git+https://github.com/paritytech/polkadot-sdk#3d4a3355f0d31aeab7b79c23d6b269b5ea669f75" -[[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" @@ -8275,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" @@ -8321,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", @@ -8359,18 +8222,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.68", -] - -[[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)", + "syn 2.0.85", ] [[package]] @@ -8402,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", @@ -8501,7 +8353,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -8624,7 +8476,7 @@ dependencies = [ "scale-info", "scale-typegen", "subxt-metadata", - "syn 2.0.68", + "syn 2.0.85", "thiserror", "tokio", ] @@ -8695,7 +8547,7 @@ dependencies = [ "quote", "scale-typegen", "subxt-codegen", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -8747,9 +8599,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", @@ -8788,7 +8640,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -8884,7 +8736,7 @@ dependencies = [ "cfg-if 1.0.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -8895,7 +8747,7 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", "test-case-core", ] @@ -8916,7 +8768,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -9054,7 +8906,7 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot", + "parking_lot 0.12.3", "pin-project-lite", "signal-hook-registry", "socket2 0.5.7", @@ -9070,7 +8922,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -9154,6 +9006,30 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio_with_wasm" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "660450fdbb1f84b197fafe53d64566f2b8b10a972f70b53bd1ba2bafdea6928c" +dependencies = [ + "js-sys", + "tokio", + "tokio_with_wasm_proc", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "tokio_with_wasm_proc" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907a7822b53d3581eebb1c8ad9e8a2647f1ea1bfe0bd5c92983e46e1c0a9a87e" +dependencies = [ + "quote", + "syn 2.0.85", +] + [[package]] name = "toml" version = "0.5.11" @@ -9301,7 +9177,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -9628,7 +9504,7 @@ checksum = "a3ff64d5cde1e2cb5268bdb497235b6bd255ba8244f910dbc3574e59593de68c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -9785,34 +9661,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if 1.0.0", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -9822,9 +9699,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -9832,22 +9709,37 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + +[[package]] +name = "wasm-timer" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" +dependencies = [ + "futures", + "js-sys", + "parking_lot 0.11.2", + "pin-utils", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] [[package]] name = "wasmi" @@ -10033,9 +9925,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" dependencies = [ "js-sys", "wasm-bindgen", @@ -10721,7 +10613,7 @@ dependencies = [ "futures", "log", "nohash-hasher", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "rand", "static_assertions", @@ -10736,7 +10628,7 @@ dependencies = [ "futures", "log", "nohash-hasher", - "parking_lot", + "parking_lot 0.12.3", "pin-project", "rand", "static_assertions", @@ -10775,7 +10667,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] @@ -10795,7 +10687,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.85", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 5b5bae853..b949c6ca0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,13 +29,16 @@ color-eyre = "0.6.2" confy = "0.5.1" hex = "0.4.3" rand = "0.8.4" -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" } +# 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" multihash = { version = "0.14.0", default-features = false, features = ["blake3", "sha3"] } semver = "1.0.23" serde = { version = "1.0", features = ["derive"] } -tokio = { version = "1.35", features = ["full"] } +tokio = { version = "1.35", default-features = false, features = ["sync", "macros", "io-util", "rt", "time"] } tokio-stream = { version = "0.1.15", features = ["sync"] } tracing = "0.1.35" tracing-subscriber = { version = "0.3.17", features = ["json", "env-filter"] } @@ -60,3 +63,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/Cargo.toml b/core/Cargo.toml index 6989c70aa..81ba17faa 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -4,66 +4,85 @@ version = "1.0.3" edition = "2021" description = "Avail Light core driving library" +[lib] +crate-type = ["cdylib", "rlib"] + [dependencies] # Internal deps avail-rust = { workspace = true } dusk-plonk = { workspace = true } # 3rd-party -async-std = { workspace = true } async-stream = "0.3.5" async-trait = { workspace = true } base64 = "0.21.0" better-panic = "0.3.0" -chrono = "0.4.19" +blake2b_simd = "1.0.2" +clap = { workspace = true } codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] } color-eyre = { workspace = true } confy = { workspace = true } -derive_more = { version = "0.99.17", features = ["from"] } +derive_more = { version = "1", features = ["from"] } +dusk-bytes = { version = "0.1.6", default-features = false } futures = { workspace = true } +getrandom = { version = "0.2.15", features = ["js"] } hex = { workspace = true } -hyper = { version = "0.14.23", features = ["full", "http1"] } itertools = "0.10.5" -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" -multihash = { workspace = true } -num = "0.4.0" -num_cpus = "1.13.0" -pcap = "1.1.0" -rand = "0.8.4" -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" +strum = { version = "0.26.3", features = ["derive"] } sysinfo = "0.30.12" -thiserror = "1.0.64" -threadpool = "1.8.1" tokio = { workspace = true } tokio-retry = "0.3" tokio-stream = { workspace = true } tokio-util = "0.7.10" tracing = { workspace = true } +tracing-subscriber = { workspace = true } uuid = { workspace = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +async-std = { workspace = true } +chrono = "0.4.19" +libp2p = { workspace = true } +hyper = { version = "0.14.23", features = ["full", "http1"] } +jsonrpsee-core = { version = "0.21.0", features = ["client"] } +libc = "0.2.150" +libp2p-webrtc = { workspace = true, features = ["tokio"] } +multihash = { workspace = true } +num = "0.4.0" +num_cpus = "1.13.0" +pcap = "1.1.0" +rand = "0.8.4" +rand_chacha = "0.3" +rocksdb = { version = "0.21.0", features = ["snappy", "multi-threaded-cf"], optional = true } +thiserror = "1.0.64" +threadpool = "1.8.1" 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"] } -tracing-subscriber = { workspace = true } -[dev-dependencies] -hex-literal = "0.4.0" +[target.'cfg(target_arch = "wasm32")'.dependencies] +ed25519-compact = "2.1.1" +thiserror-no-std = "2.0.2" +rand = { version = "0.8.4", default-features = false } +libp2p = { workspace = true, features = ["wasm-bindgen"] } +libp2p-webrtc-websys = { workspace = true } +wasm-bindgen = "0.2.90" +wasm-timer = "0.2.5" +web-time = "1.1.0" +tokio_with_wasm = { version = "0.7.1", default-features = false, features = ["sync", "macros", "rt", "time"] } + +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +hex-literal = "0.4.1" proptest = "1.0.0" test-case = "3.2.1" diff --git a/core/src/api/v2/mod.rs b/core/src/api/v2/mod.rs index 9e2715b05..27c40df3a 100644 --- a/core/src/api/v2/mod.rs +++ b/core/src/api/v2/mod.rs @@ -258,8 +258,7 @@ mod tests { Database, IsSyncedKey, LatestHeaderKey, LatestSyncKey, MemoryDB, RpcNodeKey, VerifiedCellCountKey, VerifiedDataKey, VerifiedHeaderKey, VerifiedSyncDataKey, }, - network::rpc::Node, - types::BlockRange, + types::{BlockRange, Node}, }; use async_trait::async_trait; use avail_rust::{ diff --git a/core/src/finality.rs b/core/src/finality.rs index b601582e1..c28175b8a 100644 --- a/core/src/finality.rs +++ b/core/src/finality.rs @@ -1,16 +1,17 @@ use std::collections::HashMap; -use avail_rust::sp_core::{ - blake2_256, - 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}; use tracing::{info, warn}; -use crate::types::{GrandpaJustification, SignerMessage}; +use crate::{ + types::{GrandpaJustification, SignerMessage}, + utils::blake2_256, +}; use color_eyre::{eyre::eyre, Result}; #[derive(Clone, Debug, Serialize, Deserialize)] @@ -19,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, @@ -47,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 837e184e0..64bf8e59f 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,17 +1,25 @@ +#[cfg(not(target_arch = "wasm32"))] pub mod api; +#[cfg(not(target_arch = "wasm32"))] pub mod app_client; +#[cfg(not(target_arch = "wasm32"))] #[cfg(feature = "crawl")] pub mod crawl_client; pub mod data; +#[cfg(not(target_arch = "wasm32"))] pub mod fat_client; pub mod finality; pub mod light_client; +#[cfg(not(target_arch = "wasm32"))] pub mod maintenance; pub mod network; pub mod proof; pub mod shutdown; +#[cfg(not(target_arch = "wasm32"))] pub mod sync_client; +#[cfg(not(target_arch = "wasm32"))] pub mod sync_finality; +#[cfg(not(target_arch = "wasm32"))] pub mod telemetry; pub mod types; pub mod utils; diff --git a/core/src/light_client.rs b/core/src/light_client.rs index e09ee7186..37e4d87b1 100644 --- a/core/src/light_client.rs +++ b/core/src/light_client.rs @@ -19,14 +19,18 @@ use avail_rust::{ kate_recovery::{commitments, matrix::Dimensions}, - sp_core::blake2_256, AvailHeader, H256, }; 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}, @@ -36,7 +40,7 @@ use crate::{ }, shutdown::Controller, types::{self, BlockRange, ClientChannels, Delay}, - utils::{calculate_confidence, extract_kate}, + utils::{blake2_256, calculate_confidence, extract_kate}, }; pub enum OutputEvent { diff --git a/core/src/network.rs b/core/src/network.rs index 84b3aabb5..01514f9d9 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 dc4207d74..77f0fada8 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; @@ -172,10 +184,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, } @@ -276,8 +290,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); @@ -290,12 +308,26 @@ 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")] + { + swarm = tokio_swarm + .with_other_transport(|key| { + libp2p_webrtc_websys::Transport::new(libp2p_webrtc_websys::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) @@ -342,6 +374,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 d15d2ad0d..66bf01400 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, 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}; +#[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 23c88ea2e..e236beb50 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 50c909c0b..f08035d2b 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, interval_at, Instant, Interval}, +#[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, interval_at, Instant, Interval}; +#[cfg(target_arch = "wasm32")] +use tokio_with_wasm::alias as tokio; use tracing::{debug, error, info, trace, warn}; +#[cfg(target_arch = "wasm32")] +use wasm_timer::Interval; +#[cfg(target_arch = "wasm32")] +use web_time::{Duration, Instant}; use super::{ configuration::LibP2PConfig, Behaviour, BehaviourEvent, Command, OutputEvent, QueryChannel, @@ -36,6 +44,7 @@ use crate::{ network::p2p::{is_multiaddr_global, AgentVersion}, shutdown::Controller, types::TimeToLive, + utils, }; // RelayState keeps track of all things relay related @@ -59,7 +68,7 @@ impl RelayState { fn select_random(&mut self) { // choose relay by random - if let Some(relay) = self.nodes.choose(&mut rand::thread_rng()) { + if let Some(relay) = self.nodes.choose(&mut utils::rng()) { let (id, addr) = relay.clone(); // appoint this relay as our chosen one self.id = id; @@ -191,7 +200,13 @@ impl EventLoop { }, bootstrap: BootstrapState { is_startup_done: false, + #[cfg(not(target_arch = "wasm32"))] timer: interval_at(Instant::now() + bootstrap_interval, bootstrap_interval), + #[cfg(target_arch = "wasm32")] + timer: Interval::new_at( + wasm_timer::Instant::now() + bootstrap_interval, + bootstrap_interval, + ), }, shutdown, event_loop_config: EventLoopConfig { @@ -209,9 +224,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; @@ -239,6 +259,35 @@ 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; + }, + }, + _ = self.bootstrap.timer.next() => self.handle_periodic_bootstraps(), + _ = 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(); } @@ -455,6 +504,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) => { @@ -515,6 +565,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 74bfb8522..2a59e9402 100644 --- a/core/src/network/rpc.rs +++ b/core/src/network/rpc.rs @@ -11,7 +11,7 @@ use serde::{de, Deserialize}; use std::collections::HashSet; use tokio::{ sync::broadcast, - time::{self, timeout}, + time::{timeout, Duration}, }; use tracing::{debug, info}; @@ -217,7 +217,7 @@ pub async fn wait_for_finalized_header( mut rpc_events_receiver: broadcast::Receiver, timeout_seconds: u64, ) -> Result { - let timeout_seconds = time::Duration::from_secs(timeout_seconds); + let timeout_seconds = Duration::from_secs(timeout_seconds); match timeout(timeout_seconds, rpc_events_receiver.recv()).await { Ok(Ok(rpc::Event::HeaderUpdate { header, .. })) => Ok(header), Ok(Err(error)) => Err(eyre!("Failed to receive finalized header: {error}")), diff --git a/core/src/network/rpc/client.rs b/core/src/network/rpc/client.rs index 3af494515..5b3c5b61b 100644 --- a/core/src/network/rpc/client.rs +++ b/core/src/network/rpc/client.rs @@ -22,6 +22,10 @@ use std::{ sync::Arc, task::{Context, Poll}, }; +#[cfg(not(target_arch = "wasm32"))] +use thiserror::Error; +#[cfg(target_arch = "wasm32")] +use thiserror_no_std::Error; use tokio::sync::RwLock; use tokio_retry::Retry; use tokio_stream::StreamExt; @@ -34,7 +38,7 @@ use crate::{ types::{Base64, Node, DEV_FLAG_GENHASH}, }; -#[derive(Debug, thiserror::Error)] +#[derive(Debug, Error)] enum RetryError { #[error("No previously connected node found in database")] NoPreviousNode, @@ -44,7 +48,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), 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 65c9f3220..82f364b5e 100644 --- a/core/src/network/rpc/subscriptions.rs +++ b/core/src/network/rpc/subscriptions.rs @@ -1,17 +1,17 @@ use avail_rust::{ primitives::block::grandpa::AuthorityId, - sp_core::{ - blake2_256, - ed25519::{self, Public}, - }, + sp_core::ed25519::{self, Public}, AvailHeader, }; 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, Subscription}; use crate::{ @@ -21,7 +21,7 @@ use crate::{ }, finality::{check_finality, ValidatorSet}, types::{BlockRange, GrandpaJustification}, - utils::filter_auth_set_changes, + utils::{blake2_256, filter_auth_set_changes}, }; #[derive(Clone, Debug)] diff --git a/core/src/proof.rs b/core/src/proof.rs index 0fc78f5cb..b0727ed26 100644 --- a/core/src/proof.rs +++ b/core/src/proof.rs @@ -1,24 +1,29 @@ -//! Parallelized proof verification - use avail_rust::kate_recovery::{ data::Cell, matrix::{Dimensions, Position}, - proof, }; use color_eyre::eyre; use dusk_plonk::commitment_scheme::kzg10::PublicParameters; +use futures::future::join_all; use itertools::{Either, Itertools}; use std::sync::Arc; -use tokio::{task::JoinSet, time::Instant}; -use tracing::{debug, Instrument}; +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::Instant; +use tracing::debug; +#[cfg(target_arch = "wasm32")] +use web_time::Instant; + +mod core; + +use crate::utils::spawn_in_span; async fn verify_proof( public_parameters: Arc, dimensions: Dimensions, commitment: [u8; 48], cell: Cell, -) -> Result<(Position, bool), proof::Error> { - proof::verify(&public_parameters, dimensions, &commitment, &cell) +) -> Result<(Position, bool), core::Error> { + core::verify(&public_parameters, dimensions, &commitment, &cell) .map(|verified| (cell.position, verified)) } @@ -36,24 +41,24 @@ pub async fn verify( let start_time = Instant::now(); - let mut tasks = JoinSet::new(); - - for cell in cells { - tasks.spawn( - verify_proof( + let tasks = cells + .iter() + .map(|cell| { + spawn_in_span(verify_proof( public_parameters.clone(), dimensions, commitments[cell.position.row as usize], cell.clone(), - ) - .in_current_span(), - ); - } + )) + }) + .collect::>(); + + let join_results: Vec<_> = join_all(tasks) + .await + .into_iter() + .collect::>()?; - let mut results = Vec::with_capacity(cells.len()); - while let Some(result) = tasks.join_next().await { - results.push(result??) - } + let results: Vec<(Position, bool)> = join_results.into_iter().collect::>()?; debug!(block_num, duration = ?start_time.elapsed(), "Proof verification completed"); diff --git a/core/src/proof/core.rs b/core/src/proof/core.rs new file mode 100644 index 000000000..49b8b55ef --- /dev/null +++ b/core/src/proof/core.rs @@ -0,0 +1,73 @@ +#[cfg(target_arch = "wasm32")] +pub use wasm::{verify, Error}; + +#[cfg(not(target_arch = "wasm32"))] +pub use avail_rust::kate_recovery::proof::{verify, Error}; + +#[cfg(target_arch = "wasm32")] +mod wasm { + use avail_rust::{ + avail_core::kate::COMMITMENT_SIZE, + kate_recovery::{data::Cell, matrix::Dimensions}, + }; + use dusk_bytes::Serializable; + use dusk_plonk::{ + bls12_381::G1Affine, + commitment_scheme::kzg10::{commitment::Commitment, proof::Proof, PublicParameters}, + fft::EvaluationDomain, + prelude::BlsScalar, + }; + use thiserror_no_std::Error; + + impl std::error::Error for Error {} + + impl From for Error { + fn from(_: dusk_bytes::Error) -> Self { + Error::InvalidData + } + } + + #[derive(Error, Debug)] + pub enum Error { + #[error("Proof, data or commitment is not valid")] + InvalidData, + #[error("Evaluation domain is not valid for given dimensions")] + InvalidDomain, + #[error("Public parameters degree is to small for given dimensions")] + InvalidDegree, + #[error("Position isn't in domain")] + InvalidPositionInDomain, + } + + pub fn verify( + public_parameters: &PublicParameters, + dimensions: Dimensions, + commitment: &[u8; COMMITMENT_SIZE], + cell: &Cell, + ) -> Result { + let width: u16 = dimensions.cols().into(); + let commitment_to_witness = G1Affine::from_bytes(&cell.proof()).map(Commitment::from)?; + + let evaluated_point = BlsScalar::from_bytes(&cell.data())?; + + let commitment_to_polynomial = G1Affine::from_bytes(commitment).map(Commitment::from)?; + + let proof = Proof { + commitment_to_witness, + evaluated_point, + commitment_to_polynomial, + }; + + let cols: usize = usize::from(width); + let point = EvaluationDomain::new(cols) + .map_err(|_| Error::InvalidDomain)? + .elements() + .nth(cell.position.col.into()) + .ok_or(Error::InvalidPositionInDomain)?; + + public_parameters + .trim(cols) + .map(|(_, verifier_key)| verifier_key.check(point, proof)) + .map_err(|_| Error::InvalidDegree) + } +} diff --git a/core/src/shutdown.rs b/core/src/shutdown.rs index ace956417..600add1d6 100644 --- a/core/src/shutdown.rs +++ b/core/src/shutdown.rs @@ -9,6 +9,7 @@ use std::{ sync::{Arc, Mutex}, task::Waker, }; +#[cfg(not(target_arch = "wasm32"))] use utils::user_signal; mod completed; @@ -162,6 +163,7 @@ impl Controller { } } + #[cfg(not(target_arch = "wasm32"))] /// Triggers a shutdown when each of the default termination signals is received. /// /// On Unix-based systems, these signals are Ctrl-C (SIGINT) or SIGTERM, @@ -382,6 +384,8 @@ mod tests { runtime, time::{sleep, timeout}, }; + #[cfg(target_arch = "wasm32")] + use tokio_with_wasm::alias as tokio; use crate::shutdown::{Controller, ShutdownHasCompleted, ShutdownHasStarted}; diff --git a/core/src/shutdown/utils.rs b/core/src/shutdown/utils.rs index 4589d2ee6..504cff718 100644 --- a/core/src/shutdown/utils.rs +++ b/core/src/shutdown/utils.rs @@ -1,3 +1,4 @@ +#[cfg(not(target_arch = "wasm32"))] /// This utility function returns a [`Future`] that completes upon /// receiving each of the default termination signals. /// diff --git a/core/src/types.rs b/core/src/types.rs index 76d0acfbd..e7a8f05fa 100644 --- a/core/src/types.rs +++ b/core/src/types.rs @@ -1,19 +1,21 @@ //! Shared light client structs and enums. use crate::network::rpc::Event; -use crate::utils::{extract_app_lookup, extract_kate}; +use crate::utils::{blake2_256, extract_app_lookup, extract_kate}; use avail_rust::{ avail::runtime_types::bounded_collections::bounded_vec::BoundedVec, avail_core::DataLookup, kate_recovery::{commitments, matrix::Dimensions}, - sp_core::{ - crypto::{self, Ss58Codec}, - {blake2_256, bytes, ed25519, H256}, - }, + sp_core::{bytes, ed25519, H256}, + AvailHeader, +}; +#[cfg(not(target_arch = "wasm32"))] +use avail_rust::{ + sp_core::crypto::{self, Ss58Codec}, subxt_signer::{ bip39::{Language, Mnemonic}, SecretString, SecretUri, }, - AvailHeader, Keypair, + Keypair, }; use base64::{engine::general_purpose, DecodeError, Engine}; use codec::{Decode, Encode, Input}; @@ -23,9 +25,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; @@ -212,8 +220,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 @@ -235,8 +243,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 @@ -255,8 +263,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 @@ -349,8 +357,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); @@ -408,6 +421,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) @@ -418,6 +432,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 { @@ -452,6 +467,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<&String>) -> Result { let mut suri = SecretUri::from_str(&suri)?; diff --git a/core/src/utils.rs b/core/src/utils.rs index 04ccd08f4..a98529bed 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -18,10 +18,13 @@ use color_eyre::{ Result, }; use futures::Future; +use tokio::task::JoinHandle; +#[cfg(target_arch = "wasm32")] +use tokio_with_wasm::alias as tokio; use tracing::{error, Instrument, Level, Subscriber}; use tracing_subscriber::{fmt::format, EnvFilter, FmtSubscriber}; -pub fn spawn_in_span(future: F) -> tokio::task::JoinHandle +pub fn spawn_in_span(future: F) -> JoinHandle where F: Future + Send + 'static, F::Output: Send + 'static, @@ -155,3 +158,36 @@ pub fn default_subscriber(log_level: Level) -> impl Subscriber + Send + Sync { .with_span_events(format::FmtSpan::CLOSE) .finish() } + +#[cfg(target_arch = "wasm32")] +fn blake2(data: &[u8]) -> [u8; N] { + blake2b_simd::Params::new() + .hash_length(N) + .hash(data) + .as_bytes() + .try_into() + .expect("slice is always the necessary length") +} + +#[cfg(target_arch = "wasm32")] +pub fn blake2_256(data: &[u8]) -> [u8; 32] { + blake2(data) +} + +#[cfg(not(target_arch = "wasm32"))] +pub fn blake2_256(data: &[u8]) -> [u8; 32] { + avail_rust::sp_core::blake2_256(data) +} + +#[cfg(not(target_arch = "wasm32"))] +pub fn rng() -> rand::rngs::ThreadRng { + rand::thread_rng() +} + +#[cfg(target_arch = "wasm32")] +pub fn rng() -> rand::rngs::StdRng { + use rand::SeedableRng; + let mut seed = [0u8; 32]; + getrandom::getrandom(&mut seed).expect("Failed to get random seed"); + rand::rngs::StdRng::from_seed(seed) +}