Update smoldot to 0.12 (#1212)

* Update lightclient

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Fix typo

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Update cargo.toml

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Add tracing logs to improve debugging

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Add socket buffers module for `PlatformRef`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Update `SubxtPlatform`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cargo: Add lightclient dependencies

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo.lock of wasm tests

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Add constant for with-buffer module

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* lightclient: Replace rand crate with getrandom

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* example: Update cargo lock file

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* examples: Update deps

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Tadeo Hepperle <62739623+tadeohepperle@users.noreply.github.com>
This commit is contained in:
Alexandru Vasile
2023-11-03 15:14:54 +02:00
committed by GitHub
parent 40aca5ba65
commit b472fe5223
9 changed files with 1101 additions and 1091 deletions
Generated
+117 -149
View File
@@ -36,41 +36,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aead"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877"
dependencies = [
"generic-array 0.14.7",
]
[[package]]
name = "aes"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
"opaque-debug 0.3.0",
]
[[package]]
name = "aes-gcm"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6"
dependencies = [
"aead",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
]
[[package]]
name = "ahash"
version = "0.7.6"
@@ -103,6 +68,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "allocator-api2"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]]
name = "android-tzdata"
version = "0.1.1"
@@ -339,10 +310,10 @@ dependencies = [
]
[[package]]
name = "atomic"
version = "0.5.3"
name = "atomic-take"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba"
checksum = "a8ab6b55fe97976e46f91ddbed8d147d966475dc29b2032757ba47e02376fbc3"
[[package]]
name = "atomic-waker"
@@ -633,27 +604,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chacha20"
version = "0.8.2"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6"
checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
"zeroize",
]
[[package]]
name = "chacha20poly1305"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a18446b09be63d457bbec447509e85f662f32952b035ce892290396bc0b0cff5"
dependencies = [
"aead",
"chacha20",
"cipher",
"poly1305",
"zeroize",
]
[[package]]
@@ -697,11 +654,12 @@ dependencies = [
[[package]]
name = "cipher"
version = "0.3.0"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"generic-array 0.14.7",
"crypto-common",
"inout",
]
[[package]]
@@ -898,7 +856,7 @@ dependencies = [
"ciborium",
"clap 3.2.25",
"criterion-plot",
"itertools",
"itertools 0.10.5",
"lazy_static",
"num-traits",
"oorandom",
@@ -919,7 +877,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1"
dependencies = [
"cast",
"itertools",
"itertools 0.10.5",
]
[[package]]
@@ -1001,15 +959,6 @@ dependencies = [
"subtle",
]
[[package]]
name = "ctr"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea"
dependencies = [
"cipher",
]
[[package]]
name = "curve25519-dalek"
version = "2.1.3"
@@ -1045,6 +994,7 @@ dependencies = [
"cfg-if",
"cpufeatures",
"curve25519-dalek-derive",
"digest 0.10.7",
"fiat-crypto",
"platforms",
"rustc_version",
@@ -1244,7 +1194,16 @@ version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7"
dependencies = [
"signature",
"signature 1.6.4",
]
[[package]]
name = "ed25519"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53"
dependencies = [
"signature 2.1.0",
]
[[package]]
@@ -1254,7 +1213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d"
dependencies = [
"curve25519-dalek 3.2.0",
"ed25519",
"ed25519 1.5.3",
"sha2 0.9.9",
"zeroize",
]
@@ -1273,6 +1232,21 @@ dependencies = [
"zeroize",
]
[[package]]
name = "ed25519-zebra"
version = "4.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9"
dependencies = [
"curve25519-dalek 4.1.1",
"ed25519 2.2.3",
"hashbrown 0.14.1",
"hex",
"rand_core 0.6.4",
"sha2 0.10.8",
"zeroize",
]
[[package]]
name = "either"
version = "1.9.0"
@@ -1585,16 +1559,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "ghash"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99"
dependencies = [
"opaque-debug 0.3.0",
"polyval",
]
[[package]]
name = "gimli"
version = "0.27.3"
@@ -1734,6 +1698,8 @@ version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12"
dependencies = [
"ahash 0.8.3",
"allocator-api2",
"serde",
]
@@ -1988,6 +1954,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590"
[[package]]
name = "inout"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
dependencies = [
"generic-array 0.14.7",
]
[[package]]
name = "instant"
version = "0.1.12"
@@ -2035,12 +2010,6 @@ dependencies = [
"wabt",
]
[[package]]
name = "intx"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f38a50a899dc47a6d0ed5508e7f601a2e34c3a85303514b5d137f3c10a0c75"
[[package]]
name = "io-lifetimes"
version = "1.0.11"
@@ -2061,6 +2030,15 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.9"
@@ -2278,9 +2256,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "lru"
version = "0.10.1"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "718e8fae447df0c7e1ba7f5189829e63fd536945c8988d61444c19039f16b670"
checksum = "a4a83fb7698b3643a0e34f9ae6f2e8f0178c0fd42f8b59d493aa271ff3a5bf21"
[[package]]
name = "mach"
@@ -2751,27 +2729,15 @@ dependencies = [
[[package]]
name = "poly1305"
version = "0.7.2"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede"
checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
dependencies = [
"cpufeatures",
"opaque-debug 0.3.0",
"universal-hash",
]
[[package]]
name = "polyval"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1"
dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug 0.3.0",
"universal-hash",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@@ -3593,6 +3559,12 @@ version = "1.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c"
[[package]]
name = "signature"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500"
[[package]]
name = "siphasher"
version = "0.3.11"
@@ -3633,29 +3605,30 @@ dependencies = [
[[package]]
name = "smoldot"
version = "0.8.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cce5e2881b30bad7ef89f383a816ad0b22c45915911f28499026de4a76d20ee"
checksum = "4388a7690d9f76320dedc7f97f213160fbe4fb4a38a8b4cc8bb96e0fd05e0971"
dependencies = [
"arrayvec 0.7.4",
"async-lock",
"atomic",
"atomic-take",
"base64 0.21.4",
"bip39",
"blake2-rfc",
"bs58 0.5.0",
"chacha20",
"crossbeam-queue",
"derive_more",
"ed25519-zebra",
"ed25519-zebra 4.0.3",
"either",
"event-listener",
"fnv",
"futures-channel",
"futures-lite",
"futures-util",
"hashbrown 0.14.1",
"hex",
"hmac 0.12.1",
"itertools",
"itertools 0.11.0",
"libsecp256k1",
"merlin 3.0.0",
"no-std-net",
@@ -3665,6 +3638,7 @@ dependencies = [
"num-traits",
"pbkdf2 0.12.2",
"pin-project",
"poly1305",
"rand 0.8.5",
"rand_chacha 0.3.1",
"ruzstd",
@@ -3672,60 +3646,51 @@ dependencies = [
"serde",
"serde_json",
"sha2 0.10.8",
"sha3",
"siphasher",
"slab",
"smallvec",
"smol",
"snow",
"soketto",
"tiny-keccak",
"twox-hash",
"wasmi",
"x25519-dalek",
"zeroize",
]
[[package]]
name = "smoldot-light"
version = "0.6.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b2f7b4687b83ff244ef6137735ed5716ad37dcdf3ee16c4eb1a32fb9808fa47"
checksum = "bea3d21923cbdb1362205ff8b2adb5da67e6b81b34c4bba1baaef9b88cbd83b8"
dependencies = [
"async-channel",
"async-lock",
"base64 0.21.4",
"blake2-rfc",
"derive_more",
"either",
"event-listener",
"fnv",
"futures-channel",
"futures-lite",
"futures-util",
"hashbrown 0.14.1",
"hex",
"itertools",
"itertools 0.11.0",
"log",
"lru",
"no-std-net",
"parking_lot",
"pin-project",
"rand 0.8.5",
"rand_chacha 0.3.1",
"serde",
"serde_json",
"siphasher",
"slab",
"smol",
"smoldot",
]
[[package]]
name = "snow"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9d1425eb528a21de2755c75af4c9b5d57f50a0d4c3b7f1828a4cd03f8ba155"
dependencies = [
"aes-gcm",
"blake2",
"chacha20poly1305",
"curve25519-dalek 4.1.1",
"rand_core 0.6.4",
"rustc_version",
"sha2 0.10.8",
"subtle",
"zeroize",
]
[[package]]
@@ -3804,7 +3769,7 @@ dependencies = [
"bounded-collections",
"bs58 0.4.0",
"dyn-clonable",
"ed25519-zebra",
"ed25519-zebra 3.1.0",
"futures",
"hash-db",
"hash256-std-hasher",
@@ -3882,7 +3847,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d597e35a9628fe7454b08965b2442e3ec0f264b0a90d41328e87422cec02e99"
dependencies = [
"bytes",
"ed25519",
"ed25519 1.5.3",
"ed25519-dalek",
"futures",
"libsecp256k1",
@@ -4292,6 +4257,7 @@ dependencies = [
"getrandom 0.2.10",
"instant",
"js-sys",
"pin-project",
"send_wrapper 0.6.0",
"serde",
"serde_json",
@@ -4488,15 +4454,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "tiny-keccak"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
dependencies = [
"crunchy",
]
[[package]]
name = "tinytemplate"
version = "1.2.1"
@@ -4846,11 +4803,11 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "universal-hash"
version = "0.4.1"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
dependencies = [
"generic-array 0.14.7",
"crypto-common",
"subtle",
]
@@ -5017,11 +4974,10 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "wasmi"
version = "0.30.0"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51fb5c61993e71158abf5bb863df2674ca3ec39ed6471c64f07aeaf751d67b4"
checksum = "1f341edb80021141d4ae6468cbeefc50798716a347d4085c3811900049ea8945"
dependencies = [
"intx",
"smallvec",
"spin 0.9.8",
"wasmi_arena",
@@ -5037,9 +4993,9 @@ checksum = "401c1f35e413fac1846d4843745589d9ec678977ab35a384db8ae7830525d468"
[[package]]
name = "wasmi_core"
version = "0.12.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624e6333e861ef49095d2d678b76ebf30b06bf37effca845be7e5b87c90071b7"
checksum = "dcf1a7db34bff95b85c261002720c00c3a6168256dcb93041d3fa2054d19856a"
dependencies = [
"downcast-rs",
"libm",
@@ -5410,6 +5366,18 @@ dependencies = [
"tap",
]
[[package]]
name = "x25519-dalek"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb66477291e7e8d2b0ff1bcb900bf29489a9692816d79874bea351e7a8b6de96"
dependencies = [
"curve25519-dalek 4.1.1",
"rand_core 0.6.4",
"serde",
"zeroize",
]
[[package]]
name = "yansi"
version = "0.5.1"
+4 -2
View File
@@ -82,10 +82,12 @@ wasm-bindgen-test = "0.3.24"
which = "4.4.2"
# Light client support:
smoldot = { version = "0.8.0", default-features = false }
smoldot-light = { version = "0.6.0", default-features = false }
smoldot = { version = "0.12.0", default-features = false }
smoldot-light = { version = "0.10.0", default-features = false }
tokio-stream = "0.1.14"
futures-util = "0.3.28"
rand = "0.8.5"
pin-project = "1.1.3"
# Light client wasm:
web-sys = { version = "0.3.61", features = ["BinaryType", "CloseEvent", "MessageEvent", "WebSocket"] }
+132 -176
View File
@@ -27,41 +27,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aead"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877"
dependencies = [
"generic-array 0.14.7",
]
[[package]]
name = "aes"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
"opaque-debug 0.3.0",
]
[[package]]
name = "aes-gcm"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6"
dependencies = [
"aead",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
]
[[package]]
name = "ahash"
version = "0.7.6"
@@ -94,6 +59,12 @@ dependencies = [
"memchr",
]
[[package]]
name = "allocator-api2"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]]
name = "android-tzdata"
version = "0.1.1"
@@ -271,10 +242,10 @@ dependencies = [
]
[[package]]
name = "atomic"
version = "0.5.3"
name = "atomic-take"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba"
checksum = "a8ab6b55fe97976e46f91ddbed8d147d966475dc29b2032757ba47e02376fbc3"
[[package]]
name = "atomic-waker"
@@ -532,27 +503,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chacha20"
version = "0.8.2"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c80e5460aa66fe3b91d40bcbdab953a597b60053e34d684ac6903f863b680a6"
checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
"zeroize",
]
[[package]]
name = "chacha20poly1305"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a18446b09be63d457bbec447509e85f662f32952b035ce892290396bc0b0cff5"
dependencies = [
"aead",
"chacha20",
"cipher",
"poly1305",
"zeroize",
]
[[package]]
@@ -569,11 +526,12 @@ dependencies = [
[[package]]
name = "cipher"
version = "0.3.0"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"generic-array 0.14.7",
"crypto-common",
"inout",
]
[[package]]
@@ -710,15 +668,6 @@ dependencies = [
"subtle",
]
[[package]]
name = "ctr"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea"
dependencies = [
"cipher",
]
[[package]]
name = "curve25519-dalek"
version = "2.1.3"
@@ -747,18 +696,32 @@ dependencies = [
[[package]]
name = "curve25519-dalek"
version = "4.0.0-rc.1"
version = "4.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16"
checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c"
dependencies = [
"cfg-if",
"cpufeatures",
"curve25519-dalek-derive",
"digest 0.10.7",
"fiat-crypto",
"packed_simd_2",
"platforms",
"rustc_version",
"subtle",
"zeroize",
]
[[package]]
name = "curve25519-dalek-derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
]
[[package]]
name = "curve25519-dalek-ng"
version = "4.1.1"
@@ -934,7 +897,16 @@ version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7"
dependencies = [
"signature",
"signature 1.6.4",
]
[[package]]
name = "ed25519"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53"
dependencies = [
"signature 2.1.0",
]
[[package]]
@@ -944,7 +916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d"
dependencies = [
"curve25519-dalek 3.2.0",
"ed25519",
"ed25519 1.5.3",
"sha2 0.9.9",
"zeroize",
]
@@ -963,6 +935,21 @@ dependencies = [
"zeroize",
]
[[package]]
name = "ed25519-zebra"
version = "4.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9"
dependencies = [
"curve25519-dalek 4.1.1",
"ed25519 2.2.3",
"hashbrown 0.14.0",
"hex",
"rand_core 0.6.4",
"sha2 0.10.7",
"zeroize",
]
[[package]]
name = "either"
version = "1.9.0"
@@ -1031,9 +1018,9 @@ dependencies = [
[[package]]
name = "fiat-crypto"
version = "0.1.20"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77"
checksum = "a481586acf778f1b1455424c343f71124b048ffa5f4fc3f8f6ae9dc432dcb3c7"
[[package]]
name = "fixed-hash"
@@ -1243,16 +1230,6 @@ dependencies = [
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "ghash"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99"
dependencies = [
"opaque-debug 0.3.0",
"polyval",
]
[[package]]
name = "gimli"
version = "0.27.3"
@@ -1322,6 +1299,8 @@ version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
dependencies = [
"ahash 0.8.3",
"allocator-api2",
"serde",
]
@@ -1561,6 +1540,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590"
[[package]]
name = "inout"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
dependencies = [
"generic-array 0.14.7",
]
[[package]]
name = "instant"
version = "0.1.12"
@@ -1579,12 +1567,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "intx"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f38a50a899dc47a6d0ed5508e7f601a2e34c3a85303514b5d137f3c10a0c75"
[[package]]
name = "io-lifetimes"
version = "1.0.11"
@@ -1598,9 +1580,9 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.10.5"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
@@ -1729,12 +1711,6 @@ version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "libm"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a"
[[package]]
name = "libm"
version = "0.2.7"
@@ -1819,9 +1795,9 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "lru"
version = "0.10.1"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "718e8fae447df0c7e1ba7f5189829e63fd536945c8988d61444c19039f16b670"
checksum = "a4a83fb7698b3643a0e34f9ae6f2e8f0178c0fd42f8b59d493aa271ff3a5bf21"
[[package]]
name = "mach"
@@ -2050,16 +2026,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "packed_simd_2"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282"
dependencies = [
"cfg-if",
"libm 0.1.4",
]
[[package]]
name = "parachain-example"
version = "0.1.0"
@@ -2172,18 +2138,18 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "pin-project"
version = "1.1.0"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead"
checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.1.0"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07"
checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
dependencies = [
"proc-macro2",
"quote",
@@ -2226,27 +2192,15 @@ dependencies = [
[[package]]
name = "poly1305"
version = "0.7.2"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede"
checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
dependencies = [
"cpufeatures",
"opaque-debug 0.3.0",
"universal-hash",
]
[[package]]
name = "polyval"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1"
dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug 0.3.0",
"universal-hash",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
@@ -3084,6 +3038,12 @@ version = "1.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c"
[[package]]
name = "signature"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500"
[[package]]
name = "siphasher"
version = "0.3.10"
@@ -3101,9 +3061,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.10.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
[[package]]
name = "smol"
@@ -3124,24 +3084,25 @@ dependencies = [
[[package]]
name = "smoldot"
version = "0.8.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cce5e2881b30bad7ef89f383a816ad0b22c45915911f28499026de4a76d20ee"
checksum = "4388a7690d9f76320dedc7f97f213160fbe4fb4a38a8b4cc8bb96e0fd05e0971"
dependencies = [
"arrayvec 0.7.4",
"async-lock",
"atomic",
"atomic-take",
"base64 0.21.2",
"bip39",
"blake2-rfc",
"bs58 0.5.0",
"chacha20",
"crossbeam-queue",
"derive_more",
"ed25519-zebra",
"ed25519-zebra 4.0.3",
"either",
"event-listener",
"fnv",
"futures-channel",
"futures-lite",
"futures-util",
"hashbrown 0.14.0",
"hex",
@@ -3156,6 +3117,7 @@ dependencies = [
"num-traits",
"pbkdf2 0.12.2",
"pin-project",
"poly1305",
"rand 0.8.5",
"rand_chacha 0.3.1",
"ruzstd",
@@ -3163,60 +3125,51 @@ dependencies = [
"serde",
"serde_json",
"sha2 0.10.7",
"sha3",
"siphasher",
"slab",
"smallvec",
"smol",
"snow",
"soketto",
"tiny-keccak",
"twox-hash",
"wasmi",
"x25519-dalek",
"zeroize",
]
[[package]]
name = "smoldot-light"
version = "0.6.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b2f7b4687b83ff244ef6137735ed5716ad37dcdf3ee16c4eb1a32fb9808fa47"
checksum = "bea3d21923cbdb1362205ff8b2adb5da67e6b81b34c4bba1baaef9b88cbd83b8"
dependencies = [
"async-channel",
"async-lock",
"base64 0.21.2",
"blake2-rfc",
"derive_more",
"either",
"event-listener",
"fnv",
"futures-channel",
"futures-lite",
"futures-util",
"hashbrown 0.14.0",
"hex",
"itertools",
"log",
"lru",
"no-std-net",
"parking_lot",
"pin-project",
"rand 0.8.5",
"rand_chacha 0.3.1",
"serde",
"serde_json",
"siphasher",
"slab",
"smol",
"smoldot",
]
[[package]]
name = "snow"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ccba027ba85743e09d15c03296797cad56395089b832b48b5a5217880f57733"
dependencies = [
"aes-gcm",
"blake2",
"chacha20poly1305",
"curve25519-dalek 4.0.0-rc.1",
"rand_core 0.6.4",
"rustc_version",
"sha2 0.10.7",
"subtle",
"zeroize",
]
[[package]]
@@ -3295,7 +3248,7 @@ dependencies = [
"bounded-collections",
"bs58 0.4.0",
"dyn-clonable",
"ed25519-zebra",
"ed25519-zebra 3.1.0",
"futures",
"hash-db",
"hash256-std-hasher",
@@ -3373,7 +3326,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d597e35a9628fe7454b08965b2442e3ec0f264b0a90d41328e87422cec02e99"
dependencies = [
"bytes",
"ed25519",
"ed25519 1.5.3",
"ed25519-dalek",
"futures",
"libsecp256k1",
@@ -3720,6 +3673,7 @@ name = "subxt-macro"
version = "0.32.1"
dependencies = [
"darling 0.20.3",
"parity-scale-codec",
"proc-macro-error",
"subxt-codegen",
"syn 2.0.38",
@@ -3859,15 +3813,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "tiny-keccak"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
dependencies = [
"crunchy",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
@@ -4103,7 +4048,7 @@ checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
dependencies = [
"cfg-if",
"digest 0.10.7",
"rand 0.8.5",
"rand 0.7.3",
"static_assertions",
]
@@ -4154,11 +4099,11 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "universal-hash"
version = "0.4.1"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
dependencies = [
"generic-array 0.14.7",
"crypto-common",
"subtle",
]
@@ -4280,11 +4225,10 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "wasmi"
version = "0.30.0"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51fb5c61993e71158abf5bb863df2674ca3ec39ed6471c64f07aeaf751d67b4"
checksum = "1f341edb80021141d4ae6468cbeefc50798716a347d4085c3811900049ea8945"
dependencies = [
"intx",
"smallvec",
"spin 0.9.8",
"wasmi_arena",
@@ -4300,12 +4244,12 @@ checksum = "401c1f35e413fac1846d4843745589d9ec678977ab35a384db8ae7830525d468"
[[package]]
name = "wasmi_core"
version = "0.12.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624e6333e861ef49095d2d678b76ebf30b06bf37effca845be7e5b87c90071b7"
checksum = "dcf1a7db34bff95b85c261002720c00c3a6168256dcb93041d3fa2054d19856a"
dependencies = [
"downcast-rs",
"libm 0.2.7",
"libm",
"num-traits",
"paste",
]
@@ -4667,6 +4611,18 @@ dependencies = [
"tap",
]
[[package]]
name = "x25519-dalek"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb66477291e7e8d2b0ff1bcb900bf29489a9692816d79874bea351e7a8b6de96"
dependencies = [
"curve25519-dalek 4.1.1",
"rand_core 0.6.4",
"serde",
"zeroize",
]
[[package]]
name = "yap"
version = "0.11.0"
+2
View File
@@ -42,6 +42,7 @@ web = [
"wasm-bindgen-futures",
"futures-timer/wasm-bindgen",
"instant/wasm-bindgen",
"pin-project",
# For websocket.
"js-sys",
@@ -72,6 +73,7 @@ wasm-bindgen-futures = { workspace = true, optional = true }
futures-timer = { workspace = true, optional = true }
instant = { workspace = true, optional = true }
tokio-util = { workspace = true, optional = true }
pin-project = { workspace = true, optional = true }
# Included if "web" feature is enabled, to enable its js feature.
getrandom = { workspace = true, optional = true }
+10
View File
@@ -114,6 +114,8 @@ impl BackgroundTask {
self.requests.insert(id, sender);
tracing::trace!(target: LOG_TARGET, "Generated unique id={id} for request={request}");
let result = self.client.json_rpc_request(request, self.chain_id);
if let Err(err) = result {
tracing::warn!(
@@ -136,6 +138,8 @@ impl BackgroundTask {
"Cannot send RPC request error to id={id}",
);
}
} else {
tracing::trace!(target: LOG_TARGET, "Submitted to smoldot request with id={id}");
}
}
FromSubxt::Subscription {
@@ -154,6 +158,8 @@ impl BackgroundTask {
self.id_to_subscription.insert(id, (sub_id, sender));
tracing::trace!(target: LOG_TARGET, "Generated unique id={id} for subscription request={request}");
let result = self.client.json_rpc_request(request, self.chain_id);
if let Err(err) = result {
tracing::warn!(
@@ -176,6 +182,8 @@ impl BackgroundTask {
"Cannot send RPC request error to id={id}",
);
}
} else {
tracing::trace!(target: LOG_TARGET, "Submitted to smoldot subscription request with id={id}");
}
}
};
@@ -183,6 +191,8 @@ impl BackgroundTask {
/// Parse the response received from the light client and sent it to the appropriate user.
fn handle_rpc_response(&mut self, response: String) {
tracing::trace!(target: LOG_TARGET, "Received from smoldot response={:?}", response);
match RpcResponse::from_str(&response) {
Ok(RpcResponse::Error { id, error }) => {
let Ok(id) = id.parse::<usize>() else {
+372 -88
View File
@@ -5,20 +5,10 @@
//! Wasm implementation for the light client's platform using
//! custom websockets.
use core::time::Duration;
use futures_util::{future, FutureExt};
use smoldot::libp2p::multiaddr::ProtocolRef;
use smoldot_light::platform::{ConnectError, PlatformConnection};
use std::{
collections::VecDeque,
net::{IpAddr, SocketAddr},
};
use super::wasm_socket::WasmSocket;
pub fn spawn(task: future::BoxFuture<'static, ()>) {
wasm_bindgen_futures::spawn_local(task);
}
use core::time::Duration;
use futures_util::{future, FutureExt};
pub fn now_from_unix_epoch() -> Duration {
instant::SystemTime::now()
@@ -40,87 +30,381 @@ pub fn sleep(duration: Duration) -> Delay {
futures_timer::Delay::new(duration).boxed()
}
pub struct Stream {
pub socket: WasmSocket,
/// Read and write buffers of the connection, or `None` if the socket has been reset.
pub buffers: Option<(StreamReadBuffer, StreamWriteBuffer)>,
}
/// Implementation detail of a stream from the `SubxtPlatform`.
#[pin_project::pin_project]
pub struct Stream(#[pin] pub with_buffers::WithBuffers<WasmSocket>);
pub enum StreamReadBuffer {
Open {
buffer: Vec<u8>,
cursor: std::ops::Range<usize>,
},
Closed,
}
pub mod with_buffers {
use smoldot::libp2p::read_write;
pub enum StreamWriteBuffer {
Open {
buffer: VecDeque<u8>,
must_flush: bool,
must_close: bool,
},
Closed,
}
pub async fn connect<'a>(
proto1: ProtocolRef<'a>,
proto2: ProtocolRef<'a>,
proto3: Option<ProtocolRef<'a>>,
) -> Result<PlatformConnection<Stream, std::convert::Infallible>, ConnectError> {
// Ensure ahead of time that the multiaddress is supported.
let addr = match (&proto1, &proto2, &proto3) {
(ProtocolRef::Ip4(ip), ProtocolRef::Tcp(port), Some(ProtocolRef::Ws)) => {
let addr = SocketAddr::new(IpAddr::V4((*ip).into()), *port);
format!("ws://{}", addr.to_string())
}
(ProtocolRef::Ip6(ip), ProtocolRef::Tcp(port), Some(ProtocolRef::Ws)) => {
let addr = SocketAddr::new(IpAddr::V6((*ip).into()), *port);
format!("ws://{}", addr.to_string())
}
(
ProtocolRef::Dns(addr) | ProtocolRef::Dns4(addr) | ProtocolRef::Dns6(addr),
ProtocolRef::Tcp(port),
Some(ProtocolRef::Ws),
) => {
format!("ws://{}:{}", addr.to_string(), port)
}
(
ProtocolRef::Dns(addr) | ProtocolRef::Dns4(addr) | ProtocolRef::Dns6(addr),
ProtocolRef::Tcp(port),
Some(ProtocolRef::Wss),
) => {
format!("wss://{}:{}", addr.to_string(), port)
}
_ => {
return Err(ConnectError {
is_bad_addr: true,
message: "Unknown protocols combination".to_string(),
})
}
use core::{
fmt, future, mem, ops,
pin::{self, Pin},
task::Poll,
};
tracing::debug!("Connecting to addr={addr}");
use crate::platform::wasm_helpers::Instant;
use futures_util::{AsyncRead, AsyncWrite};
use std::io;
/// Holds an implementation of `AsyncRead` and `AsyncWrite`, alongside with a read buffer and a
/// write buffer.
#[pin_project::pin_project]
pub struct WithBuffers<T> {
/// Actual socket to read from/write to.
#[pin]
socket: T,
/// Error that has happened on the socket, if any.
error: Option<io::Error>,
/// Storage for data read from the socket. The first [`WithBuffers::read_buffer_valid`] bytes
/// contain actual socket data, while the rest contains garbage data.
/// The capacity of this buffer is at least equal to the amount of bytes requested by the
/// inner data consumer.
read_buffer: Vec<u8>,
/// Number of bytes of data in [`WithBuffers::read_buffer`] that contain actual data.
read_buffer_valid: usize,
read_buffer_reasonable_capacity: usize,
/// True if reading from the socket has returned `Ok(0)` earlier, in other words "end of
/// file".
read_closed: bool,
/// Storage for data to write to the socket.
write_buffers: Vec<Vec<u8>>,
/// True if the consumer has closed the writing side earlier.
write_closed: bool,
/// True if the consumer has closed the writing side earlier, and the socket still has to
/// be closed.
close_pending: bool,
/// True if data has been written on the socket and the socket needs to be flushed.
flush_pending: bool,
let socket = WasmSocket::new(addr.as_str()).map_err(|err| ConnectError {
is_bad_addr: false,
message: format!("Failed to reach peer: {err}"),
})?;
/// Value of [`read_write::ReadWrite::now`] that was fed by the latest call to
/// [`WithBuffers::read_write_access`].
read_write_now: Option<Instant>,
/// Value of [`read_write::ReadWrite::wake_up_after`] produced by the latest call
/// to [`WithBuffers::read_write_access`].
read_write_wake_up_after: Option<Instant>,
}
Ok(PlatformConnection::SingleStreamMultistreamSelectNoiseYamux(
Stream {
socket,
buffers: Some((
StreamReadBuffer::Open {
buffer: vec![0; 16384],
cursor: 0..0,
const BUFFER_CAPACITY: usize = 65536;
const WRITE_BYTES_QUEUEABLE: usize = 128 * 1024;
impl<T> WithBuffers<T> {
/// Initializes a new [`WithBuffers`] with the given socket.
///
/// The socket must still be open in both directions.
pub fn new(socket: T) -> Self {
WithBuffers {
socket,
error: None,
read_buffer: Vec::with_capacity(BUFFER_CAPACITY),
read_buffer_valid: 0,
read_buffer_reasonable_capacity: BUFFER_CAPACITY,
read_closed: false,
write_buffers: Vec::with_capacity(64),
write_closed: false,
close_pending: false,
flush_pending: false,
read_write_now: None,
read_write_wake_up_after: None,
}
}
/// Returns an object that implements `Deref<Target = ReadWrite>`. This object can be used
/// to push or pull data to/from the socket.
///
/// > **Note**: The parameter requires `Self` to be pinned for consistency with
/// > [`WithBuffers::wait_read_write_again`].
pub fn read_write_access(
self: Pin<&mut Self>,
now: Instant,
) -> Result<ReadWriteAccess, &io::Error> {
let this = self.project();
debug_assert!(this
.read_write_now
.as_ref()
.map_or(true, |old_now| *old_now <= now));
*this.read_write_wake_up_after = None;
*this.read_write_now = Some(now);
if let Some(error) = this.error.as_ref() {
return Err(error);
}
this.read_buffer.truncate(*this.read_buffer_valid);
let write_bytes_queued = this.write_buffers.iter().map(Vec::len).sum();
Ok(ReadWriteAccess {
read_buffer_len_before: this.read_buffer.len(),
write_buffers_len_before: this.write_buffers.len(),
read_write: read_write::ReadWrite {
now,
incoming_buffer: mem::take(this.read_buffer),
expected_incoming_bytes: if !*this.read_closed { Some(0) } else { None },
read_bytes: 0,
write_bytes_queued,
write_buffers: mem::take(this.write_buffers),
write_bytes_queueable: if !*this.write_closed {
// Limit outgoing buffer size to 128kiB.
Some(WRITE_BYTES_QUEUEABLE.saturating_sub(write_bytes_queued))
} else {
None
},
wake_up_after: this.read_write_wake_up_after.take(),
},
StreamWriteBuffer::Open {
buffer: VecDeque::with_capacity(16384),
must_close: false,
must_flush: false,
},
)),
},
))
read_buffer: this.read_buffer,
read_buffer_valid: this.read_buffer_valid,
read_buffer_reasonable_capacity: *this.read_buffer_reasonable_capacity,
write_buffers: this.write_buffers,
write_closed: this.write_closed,
close_pending: this.close_pending,
read_write_wake_up_after: this.read_write_wake_up_after,
})
}
}
impl<T> WithBuffers<T>
where
T: AsyncRead + AsyncWrite,
{
/// Waits until [`WithBuffers::read_write_access`] should be called again.
///
/// Returns if an error happens on the socket. If an error happened in the past on the socket,
/// the future never yields.
pub async fn wait_read_write_again<F>(
self: Pin<&mut Self>,
timer_builder: impl FnOnce(Instant) -> F,
) where
F: future::Future<Output = ()>,
{
let mut this = self.project();
// Return immediately if `wake_up_after <= now`.
match (&*this.read_write_wake_up_after, &*this.read_write_now) {
(Some(when_wake_up), Some(now)) if *when_wake_up <= *now => {
return;
}
_ => {}
}
let mut timer = pin::pin!({
let fut = this
.read_write_wake_up_after
.as_ref()
.map(|when| timer_builder(*when));
async {
if let Some(fut) = fut {
fut.await;
} else {
future::pending::<()>().await;
}
}
});
// Grow the read buffer in order to make space for potentially more data.
this.read_buffer.resize(this.read_buffer.capacity(), 0);
future::poll_fn(move |cx| {
if this.error.is_some() {
// Never return.
return Poll::Pending;
}
// If still `true` at the end of the function, `Poll::Pending` is returned.
let mut pending = true;
match future::Future::poll(Pin::new(&mut timer), cx) {
Poll::Pending => {}
Poll::Ready(()) => {
pending = false;
}
}
if !*this.read_closed {
let read_result = AsyncRead::poll_read(
this.socket.as_mut(),
cx,
&mut this.read_buffer[*this.read_buffer_valid..],
);
match read_result {
Poll::Pending => {}
Poll::Ready(Ok(0)) => {
*this.read_closed = true;
pending = false;
}
Poll::Ready(Ok(n)) => {
*this.read_buffer_valid += n;
// TODO: consider waking up only if the expected bytes of the consumer are exceeded
pending = false;
}
Poll::Ready(Err(err)) => {
*this.error = Some(err);
return Poll::Ready(());
}
};
}
loop {
if this.write_buffers.iter().any(|b| !b.is_empty()) {
let write_result = {
let buffers = this
.write_buffers
.iter()
.map(|buf| io::IoSlice::new(buf))
.collect::<Vec<_>>();
AsyncWrite::poll_write_vectored(this.socket.as_mut(), cx, &buffers)
};
match write_result {
Poll::Ready(Ok(0)) => {
// It is not legal for `poll_write` to return 0 bytes written.
unreachable!();
}
Poll::Ready(Ok(mut n)) => {
*this.flush_pending = true;
while n > 0 {
let first_buf = this.write_buffers.first_mut().unwrap();
if first_buf.len() <= n {
n -= first_buf.len();
this.write_buffers.remove(0);
} else {
// TODO: consider keeping the buffer as is but starting the next write at a later offset
first_buf.copy_within(n.., 0);
first_buf.truncate(first_buf.len() - n);
break;
}
}
// Wake up if the write buffers switch from non-empty to empty.
if this.write_buffers.is_empty() {
pending = false;
}
}
Poll::Ready(Err(err)) => {
*this.error = Some(err);
return Poll::Ready(());
}
Poll::Pending => break,
};
} else if *this.flush_pending {
match AsyncWrite::poll_flush(this.socket.as_mut(), cx) {
Poll::Ready(Ok(())) => {
*this.flush_pending = false;
}
Poll::Ready(Err(err)) => {
*this.error = Some(err);
return Poll::Ready(());
}
Poll::Pending => break,
}
} else if *this.close_pending {
match AsyncWrite::poll_close(this.socket.as_mut(), cx) {
Poll::Ready(Ok(())) => {
*this.close_pending = false;
pending = false;
break;
}
Poll::Ready(Err(err)) => {
*this.error = Some(err);
return Poll::Ready(());
}
Poll::Pending => break,
}
} else {
break;
}
}
if !pending {
Poll::Ready(())
} else {
Poll::Pending
}
})
.await;
}
}
impl<T: fmt::Debug> fmt::Debug for WithBuffers<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("WithBuffers").field(&self.socket).finish()
}
}
/// See [`WithBuffers::read_write_access`].
pub struct ReadWriteAccess<'a> {
read_write: read_write::ReadWrite<Instant>,
read_buffer_len_before: usize,
write_buffers_len_before: usize,
// Fields below as references from the content of the `WithBuffers`.
read_buffer: &'a mut Vec<u8>,
read_buffer_valid: &'a mut usize,
read_buffer_reasonable_capacity: usize,
write_buffers: &'a mut Vec<Vec<u8>>,
write_closed: &'a mut bool,
close_pending: &'a mut bool,
read_write_wake_up_after: &'a mut Option<Instant>,
}
impl<'a> ops::Deref for ReadWriteAccess<'a> {
type Target = read_write::ReadWrite<Instant>;
fn deref(&self) -> &Self::Target {
&self.read_write
}
}
impl<'a> ops::DerefMut for ReadWriteAccess<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.read_write
}
}
impl<'a> Drop for ReadWriteAccess<'a> {
fn drop(&mut self) {
*self.read_buffer = mem::take(&mut self.read_write.incoming_buffer);
*self.read_buffer_valid = self.read_buffer.len();
// Adjust `read_buffer` to the number of bytes requested by the consumer.
if let Some(expected_incoming_bytes) = self.read_write.expected_incoming_bytes {
if expected_incoming_bytes < self.read_buffer_reasonable_capacity
&& self.read_buffer.is_empty()
{
// We use `shrink_to(0)` then `reserve(cap)` rather than just `shrink_to(cap)`
// so that the `Vec` doesn't try to preserve the data in the read buffer.
self.read_buffer.shrink_to(0);
self.read_buffer
.reserve(self.read_buffer_reasonable_capacity);
} else if expected_incoming_bytes > self.read_buffer.len() {
self.read_buffer
.reserve(expected_incoming_bytes - self.read_buffer.len());
}
debug_assert!(self.read_buffer.capacity() >= expected_incoming_bytes);
}
*self.write_buffers = mem::take(&mut self.read_write.write_buffers);
if self.read_write.write_bytes_queueable.is_none() && !*self.write_closed {
*self.write_closed = true;
*self.close_pending = true;
}
*self.read_write_wake_up_after = self.read_write.wake_up_after.take();
// If the consumer has advanced its reading or writing sides, we make the next call to
// `read_write_access` return immediately by setting `wake_up_after`.
if (self.read_buffer_len_before != self.read_buffer.len()
&& self
.read_write
.expected_incoming_bytes
.map_or(false, |b| b <= self.read_buffer.len()))
|| (self.write_buffers_len_before != self.write_buffers.len()
&& !*self.write_closed)
{
*self.read_write_wake_up_after = Some(self.read_write.now);
}
}
}
}
+137 -259
View File
@@ -2,21 +2,22 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use super::wasm_socket::WasmSocket;
use core::time::Duration;
use futures::{prelude::*, task::Poll};
use smoldot::libp2p::multiaddr::Multiaddr;
use futures::prelude::*;
use smoldot_light::platform::{
ConnectError, PlatformConnection, PlatformRef, PlatformSubstreamDirection, ReadBuffer,
Address, ConnectError, ConnectionType, IpAddr, MultiStreamAddress, MultiStreamWebRtcConnection,
PlatformRef, SubstreamDirection,
};
use std::{io::IoSlice, pin::Pin};
use std::{io, net::SocketAddr, pin::Pin};
use super::wasm_helpers::{StreamReadBuffer, StreamWriteBuffer};
const LOG_TARGET: &str = "subxt-platform-wasm";
/// Subxt plaform implementation for wasm.
/// Subxt platform implementation for wasm.
///
/// This implementation is a conversion of the implementation from the smoldot:
/// https://github.com/smol-dot/smoldot/blob/f49ce4ea6a325c444ab6ad37d3ab5558edf0d541/light-base/src/platform/default.rs#L52.
/// https://github.com/smol-dot/smoldot/blob/6401d4df90569e23073d646b14a8fbf9f7e6bdd3/light-base/src/platform/default.rs#L83.
///
/// This platform will evolve over time and we'll need to keep this code in sync.
#[derive(Clone)]
@@ -30,17 +31,18 @@ impl SubxtPlatform {
impl PlatformRef for SubxtPlatform {
type Delay = super::wasm_helpers::Delay;
type Yield = future::Ready<()>;
type Instant = super::wasm_helpers::Instant;
type Connection = std::convert::Infallible;
type MultiStream = std::convert::Infallible;
type Stream = super::wasm_helpers::Stream;
type ConnectFuture = future::BoxFuture<
type StreamConnectFuture = future::BoxFuture<'static, Result<Self::Stream, ConnectError>>;
type MultiStreamConnectFuture = future::BoxFuture<
'static,
Result<PlatformConnection<Self::Stream, Self::Connection>, ConnectError>,
Result<MultiStreamWebRtcConnection<Self::MultiStream>, ConnectError>,
>;
type ReadWriteAccess<'a> = super::wasm_helpers::with_buffers::ReadWriteAccess<'a>;
type StreamUpdateFuture<'a> = future::BoxFuture<'a, ()>;
type NextSubstreamFuture<'a> =
future::Pending<Option<(Self::Stream, PlatformSubstreamDirection)>>;
type StreamErrorRef<'a> = &'a std::io::Error;
type NextSubstreamFuture<'a> = future::Pending<Option<(Self::Stream, SubstreamDirection)>>;
fn now_from_unix_epoch(&self) -> Duration {
super::wasm_helpers::now_from_unix_epoch()
@@ -50,6 +52,13 @@ impl PlatformRef for SubxtPlatform {
super::wasm_helpers::now()
}
fn fill_random_bytes(&self, buffer: &mut [u8]) {
// This could fail if the system does not have access to a good source of entropy.
// Note: `rand::RngCore::fill_bytes` also panics on errors and `rand::OsCore` calls
// identically into `getrandom::getrandom`.
getrandom::getrandom(buffer).expect("Cannot fill random bytes");
}
fn sleep(&self, duration: Duration) -> Self::Delay {
super::wasm_helpers::sleep(duration)
}
@@ -58,251 +67,12 @@ impl PlatformRef for SubxtPlatform {
self.sleep(when.saturating_duration_since(self.now()))
}
fn yield_after_cpu_intensive(&self) -> Self::Yield {
// No-op.
future::ready(())
}
fn connect(&self, multiaddr: &str) -> Self::ConnectFuture {
// We simply copy the address to own it. We could be more zero-cost here, but doing so
// would considerably complicate the implementation.
let multiaddr = multiaddr.to_owned();
tracing::debug!("Connecting to multiaddress={:?}", multiaddr);
Box::pin(async move {
let addr = multiaddr.parse::<Multiaddr>().map_err(|_| ConnectError {
is_bad_addr: true,
message: "Failed to parse address".to_string(),
})?;
let mut iter = addr.iter().fuse();
let proto1 = iter.next().ok_or(ConnectError {
is_bad_addr: true,
message: "Unknown protocols combination".to_string(),
})?;
let proto2 = iter.next().ok_or(ConnectError {
is_bad_addr: true,
message: "Unknown protocols combination".to_string(),
})?;
let proto3 = iter.next();
if iter.next().is_some() {
return Err(ConnectError {
is_bad_addr: true,
message: "Unknown protocols combination".to_string(),
});
}
super::wasm_helpers::connect(proto1, proto2, proto3).await
})
}
fn open_out_substream(&self, c: &mut Self::Connection) {
// This function can only be called with so-called "multi-stream" connections. We never
// open such connection.
match *c {}
}
fn next_substream<'a>(&self, c: &'a mut Self::Connection) -> Self::NextSubstreamFuture<'a> {
// This function can only be called with so-called "multi-stream" connections. We never
// open such connection.
match *c {}
}
fn update_stream<'a>(&self, stream: &'a mut Self::Stream) -> Self::StreamUpdateFuture<'a> {
Box::pin(future::poll_fn(|cx| {
// The `connect` is expected to be called before this method and would populate
// the buffers properly. When the buffers are empty, this future is shortly dropped.
let Some((read_buffer, write_buffer)) = stream.buffers.as_mut() else {
return Poll::Pending;
};
// Whether the future returned by `update_stream` should return `Ready` or `Pending`.
let mut update_stream_future_ready = false;
if let StreamReadBuffer::Open {
buffer: ref mut buf,
ref mut cursor,
} = read_buffer
{
// When reading data from the socket, `poll_read` might return "EOF". In that
// situation, we transition to the `Closed` state, which would discard the data
// currently in the buffer. For this reason, we only try to read if there is no
// data left in the buffer.
if cursor.start == cursor.end {
if let Poll::Ready(result) = Pin::new(&mut stream.socket).poll_read(cx, buf) {
update_stream_future_ready = true;
match result {
Err(_) => {
// End the stream.
stream.buffers = None;
return Poll::Ready(());
}
Ok(0) => {
// EOF.
*read_buffer = StreamReadBuffer::Closed;
}
Ok(bytes) => {
*cursor = 0..bytes;
}
}
}
}
}
if let StreamWriteBuffer::Open {
buffer: ref mut buf,
must_flush,
must_close,
} = write_buffer
{
while !buf.is_empty() {
let write_queue_slices = buf.as_slices();
if let Poll::Ready(result) = Pin::new(&mut stream.socket).poll_write_vectored(
cx,
&[
IoSlice::new(write_queue_slices.0),
IoSlice::new(write_queue_slices.1),
],
) {
if !*must_close {
// In the situation where the API user wants to close the writing
// side, simply sending the buffered data isn't enough to justify
// making the future ready.
update_stream_future_ready = true;
}
match result {
Err(_) => {
// End the stream.
stream.buffers = None;
return Poll::Ready(());
}
Ok(bytes) => {
*must_flush = true;
for _ in 0..bytes {
buf.pop_front();
}
}
}
} else {
break;
}
}
if buf.is_empty() && *must_close {
if let Poll::Ready(result) = Pin::new(&mut stream.socket).poll_close(cx) {
update_stream_future_ready = true;
match result {
Err(_) => {
// End the stream.
stream.buffers = None;
return Poll::Ready(());
}
Ok(()) => {
*write_buffer = StreamWriteBuffer::Closed;
}
}
}
} else if *must_flush {
if let Poll::Ready(result) = Pin::new(&mut stream.socket).poll_flush(cx) {
update_stream_future_ready = true;
match result {
Err(_) => {
// End the stream.
stream.buffers = None;
return Poll::Ready(());
}
Ok(()) => {
*must_flush = false;
}
}
}
}
}
if update_stream_future_ready {
Poll::Ready(())
} else {
// Progress cannot be made since poll_read, poll_write, poll_close, poll_flush
// are not ready yet. Smoldot drops this future and calls it again with the
// next processing iteration.
Poll::Pending
}
}))
}
fn read_buffer<'a>(&self, stream: &'a mut Self::Stream) -> ReadBuffer<'a> {
match stream.buffers.as_ref().map(|(r, _)| r) {
None => ReadBuffer::Reset,
Some(StreamReadBuffer::Closed) => ReadBuffer::Closed,
Some(StreamReadBuffer::Open { buffer, cursor }) => {
ReadBuffer::Open(&buffer[cursor.clone()])
}
}
}
fn advance_read_cursor(&self, stream: &mut Self::Stream, extra_bytes: usize) {
let Some(StreamReadBuffer::Open { ref mut cursor, .. }) =
stream.buffers.as_mut().map(|(r, _)| r)
else {
assert_eq!(extra_bytes, 0);
return;
};
assert!(cursor.start + extra_bytes <= cursor.end);
cursor.start += extra_bytes;
}
fn writable_bytes(&self, stream: &mut Self::Stream) -> usize {
let Some(StreamWriteBuffer::Open {
ref mut buffer,
must_close: false,
..
}) = stream.buffers.as_mut().map(|(_, w)| w)
else {
return 0;
};
buffer.capacity() - buffer.len()
}
fn send(&self, stream: &mut Self::Stream, data: &[u8]) {
debug_assert!(!data.is_empty());
// Because `writable_bytes` returns 0 if the writing side is closed, and because `data`
// must always have a size inferior or equal to `writable_bytes`, we know for sure that
// the writing side isn't closed.
let Some(StreamWriteBuffer::Open { ref mut buffer, .. }) =
stream.buffers.as_mut().map(|(_, w)| w)
else {
panic!()
};
buffer.reserve(data.len());
buffer.extend(data.iter().copied());
}
fn close_send(&self, stream: &mut Self::Stream) {
// It is not illegal to call this on an already-reset stream.
let Some((_, write_buffer)) = stream.buffers.as_mut() else {
return;
};
match write_buffer {
StreamWriteBuffer::Open {
must_close: must_close @ false,
..
} => *must_close = true,
_ => {
// However, it is illegal to call this on a stream that was already close
// attempted.
panic!()
}
}
}
fn spawn_task(&self, _: std::borrow::Cow<str>, task: future::BoxFuture<'static, ()>) {
super::wasm_helpers::spawn(task);
fn spawn_task(
&self,
_task_name: std::borrow::Cow<str>,
task: impl future::Future<Output = ()> + Send + 'static,
) {
wasm_bindgen_futures::spawn_local(task);
}
fn client_name(&self) -> std::borrow::Cow<str> {
@@ -312,4 +82,112 @@ impl PlatformRef for SubxtPlatform {
fn client_version(&self) -> std::borrow::Cow<str> {
env!("CARGO_PKG_VERSION").into()
}
fn supports_connection_type(&self, connection_type: ConnectionType) -> bool {
let result = matches!(
connection_type,
ConnectionType::WebSocketIpv4 { .. }
| ConnectionType::WebSocketIpv6 { .. }
| ConnectionType::WebSocketDns { .. }
);
tracing::trace!(
target: LOG_TARGET,
"Supports connection type={:?} result={}",
connection_type, result
);
result
}
fn connect_stream(&self, multiaddr: Address) -> Self::StreamConnectFuture {
tracing::trace!(target: LOG_TARGET, "Connect stream to multiaddr={:?}", multiaddr);
// `PlatformRef` trait guarantees that `connect_stream` is only called with addresses
// stated in `supports_connection_type`.
let addr = match multiaddr {
Address::WebSocketDns {
hostname,
port,
secure: true,
} => {
format!("wss://{}:{}", hostname, port)
}
Address::WebSocketDns {
hostname,
port,
secure: false,
} => {
format!("ws://{}:{}", hostname, port)
}
Address::WebSocketIp {
ip: IpAddr::V4(ip),
port,
} => {
let addr = SocketAddr::from((ip, port));
format!("ws://{}", addr.to_string())
}
Address::WebSocketIp {
ip: IpAddr::V6(ip),
port,
} => {
let addr = SocketAddr::from((ip, port));
format!("ws://{}", addr.to_string())
}
// The API user of the `PlatformRef` trait is never supposed to open connections of
// a type that isn't supported.
_ => {
unreachable!("Connecting to an address not supported. This code path indicates a bug in smoldot. Please raise an issue at https://github.com/smol-dot/smoldot/issues")
}
};
Box::pin(async move {
tracing::debug!(target: LOG_TARGET, "Connecting to addr={addr}");
let socket = WasmSocket::new(addr.as_str()).map_err(|err| ConnectError {
message: format!("Failed to reach peer: {err}"),
})?;
Ok(super::wasm_helpers::Stream(
super::wasm_helpers::with_buffers::WithBuffers::new(socket),
))
})
}
fn connect_multistream(&self, _address: MultiStreamAddress) -> Self::MultiStreamConnectFuture {
panic!("Multistreams are not currently supported. This code path indicates a bug in smoldot. Please raise an issue at https://github.com/smol-dot/smoldot/issues")
}
fn open_out_substream(&self, c: &mut Self::MultiStream) {
// This function can only be called with so-called "multi-stream" connections. We never
// open such connection.
match *c {}
}
fn next_substream(&self, c: &'_ mut Self::MultiStream) -> Self::NextSubstreamFuture<'_> {
// This function can only be called with so-called "multi-stream" connections. We never
// open such connection.
match *c {}
}
fn read_write_access<'a>(
&self,
stream: Pin<&'a mut Self::Stream>,
) -> Result<Self::ReadWriteAccess<'a>, &'a io::Error> {
let stream = stream.project();
stream.0.read_write_access(Self::Instant::now())
}
fn wait_read_write_again<'a>(
&self,
stream: Pin<&'a mut Self::Stream>,
) -> Self::StreamUpdateFuture<'a> {
let stream = stream.project();
Box::pin(stream.0.wait_read_write_again(|when| async move {
let now = super::wasm_helpers::now();
let duration = when.saturating_duration_since(now);
super::wasm_helpers::sleep(duration).await;
}))
}
}
+326 -416
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -19,7 +19,7 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
//
// ```bash
// # Polkadot does not accept by default WebSocket connections to the P2P network.
// # Ensure `--listen-addr` is provided with valid ws adddress endpoint.
// # Ensure `--listen-addr` is provided with valid ws address endpoint.
// # The `--node-key` provides a deterministic p2p address for the node.
// ./polkadot --dev --node-key 0000000000000000000000000000000000000000000000000000000000000001 --listen-addr /ip4/0.0.0.0/tcp/30333/ws
// ```