diff --git a/Cargo.lock b/Cargo.lock index 1002d1c894e16..6433b434409e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,7 +31,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -219,37 +219,110 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7deb0a829ca7bcfaf5da70b073a8d128619259a7be8216a355e23f00763059e5" [[package]] -name = "async-channel" +name = "async-attributes" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee81ba99bee79f3c8ae114ae4baa7eaa326f63447cf2ec65e4393618b63f8770" +checksum = "efd3d156917d94862e779f356c5acae312b08fd3121e792c857d7928c8088423" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "async-channel" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21279cfaa4f47df10b1816007e738ca3747ef2ee53ffc51cdbf57a8bb266fee3" dependencies = [ "concurrent-queue", "event-listener", "futures-core", ] +[[package]] +name = "async-executor" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d373d78ded7d0b3fa8039375718cde0aace493f2e34fb60f51cbf567562ca801" +dependencies = [ + "async-task 4.0.0", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell 1.4.1", + "vec-arena", +] + +[[package]] +name = "async-global-executor" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffd4f132a18f3fe7329c7b907047684f1b06174a900c559b661b2da8bb9cad5f" +dependencies = [ + "async-executor", + "async-io", + "futures-lite", + "num_cpus", + "once_cell 1.4.1", +] + +[[package]] +name = "async-io" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38628c78a34f111c5a6b98fc87dfc056cd1590b61afe748b145be4623c56d194" +dependencies = [ + "cfg-if", + "concurrent-queue", + "fastrand", + "futures-lite", + "libc", + "log", + "once_cell 1.4.1", + "parking", + "polling", + "socket2", + "vec-arena", + "waker-fn", + "wepoll-sys-stjepang", + "winapi 0.3.9", +] + +[[package]] +name = "async-mutex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66941c2577c4fa351e4ce5fdde8f86c69b88d623f3b955be1bc7362a23434632" +dependencies = [ + "event-listener", +] + [[package]] name = "async-std" -version = "1.6.2" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00d68a33ebc8b57800847d00787307f84a562224a14db069b0acefe4c2abbf5d" +checksum = "3c92085acfce8b32e5b261d0b59b8f3309aee69fea421ea3f271f8b93225754f" dependencies = [ - "async-task", + "async-attributes", + "async-global-executor", + "async-io", + "async-mutex", + "async-task 3.0.0", + "blocking", "crossbeam-utils", "futures-channel", "futures-core", "futures-io", - "futures-timer 3.0.2", + "futures-lite", + "gloo-timers", "kv-log-macro", "log", "memchr", "num_cpus", - "once_cell 1.4.0", + "once_cell 1.4.1", "pin-project-lite", "pin-utils", "slab", - "smol", "wasm-bindgen-futures", ] @@ -259,6 +332,12 @@ version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3" +[[package]] +name = "async-task" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c37ba09c1b5185eb9897a5cef32770031f58fa92d9a5f79eb50cae5030b39c1" + [[package]] name = "async-tls" version = "0.8.0" @@ -331,6 +410,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base-x" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b20b618342cf9891c292c4f5ac2cde7287cc5c87e87e9c769d617793607dec1" + [[package]] name = "base58" version = "0.1.0" @@ -471,7 +556,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ - "block-padding", + "block-padding 0.1.5", "byte-tools", "byteorder 1.3.4", "generic-array 0.12.3", @@ -483,7 +568,8 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.3", + "block-padding 0.2.1", + "generic-array 0.14.4", ] [[package]] @@ -492,7 +578,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa136449e765dc7faa244561ccae839c394048667929af599b5d931ebe7b7f10" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -504,17 +590,23 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + [[package]] name = "blocking" -version = "0.4.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2468ff7bf85066b4a3678fede6fe66db31846d753ff0adfbfab2c6a6e81612b" +checksum = "2640778f8053e72c11f621b0a5175a0560a269282aa98ed85107773ab8e2a556" dependencies = [ "async-channel", "atomic-waker", + "fastrand", "futures-lite", - "once_cell 1.4.0", - "parking", + "once_cell 1.4.1", "waker-fn", ] @@ -744,9 +836,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "1.1.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83c06aff61f2d899eb87c379df3cbf7876f14471dcab474e0b6dc90ab96c080" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" dependencies = [ "cache-padded", ] @@ -1026,7 +1118,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", "subtle 2.2.3", ] @@ -1100,6 +1192,28 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72aa14c04dfae8dd7d8a2b1cb7ca2152618cd01336dbfe704b8dcbf8d41dbd69" +[[package]] +name = "data-encoding-macro" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de6489dde5128f5ab2f71f88f8807a237cecf08d96dc7ca4be64e0730dc7d961" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", + "proc-macro-hack", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d2d6daefd5f1d4b74a891a5d2ab7dccba028d423107c074232a0c5dc0d40a9e" +dependencies = [ + "data-encoding", + "proc-macro-hack", + "syn", +] + [[package]] name = "derive_more" version = "0.99.9" @@ -1132,7 +1246,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -1332,9 +1446,9 @@ dependencies = [ [[package]] name = "event-listener" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "699d84875f1b72b4da017e6b0f77dfa88c0137f089958a88974d15938cbc2976" +checksum = "e1cd41440ae7e4734bbd42302f63eaba892afc93a3912dad84006247f0dedb0e" [[package]] name = "evm" @@ -1348,7 +1462,7 @@ dependencies = [ "primitive-types", "rlp", "serde", - "sha3", + "sha3 0.8.2", ] [[package]] @@ -1379,7 +1493,7 @@ checksum = "7410f5677a52203d3fca02b0eb8f96f9799f3a45cff82946a8ed28379e6b1b04" dependencies = [ "evm-core", "primitive-types", - "sha3", + "sha3 0.8.2", ] [[package]] @@ -1427,9 +1541,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "1.3.3" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36a9cb09840f81cd211e435d00a4e487edd263dc3c8ff815c32dd76ad668ebed" +checksum = "5c85295147490b8fcf2ea3d104080a105a8b2c63f9c319e82c02d8e952388919" [[package]] name = "fdlimit" @@ -1585,7 +1699,7 @@ dependencies = [ "frame-system", "impl-trait-for-tuples", "log", - "once_cell 1.4.0", + "once_cell 1.4.1", "parity-scale-codec", "parity-util-mem", "paste", @@ -1839,9 +1953,9 @@ checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" [[package]] name = "futures-lite" -version = "0.1.8" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180d8fc9819eb48a0c976672fbeea13a73e10999e812bdc9e14644c25ad51d60" +checksum = "5b77e08e656f472d8ea84c472fa8b0a7a917883048e1cf2d4e34a323cd0aaf63" dependencies = [ "fastrand", "futures-core", @@ -1876,7 +1990,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" dependencies = [ - "once_cell 1.4.0", + "once_cell 1.4.1", ] [[package]] @@ -1957,9 +2071,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.3" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", "version_check", @@ -2735,9 +2849,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.73" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" +checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" [[package]] name = "libloading" @@ -2794,6 +2908,25 @@ dependencies = [ "wasm-timer", ] +[[package]] +name = "libp2p-bitswap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65d2ad2d7d2a1818954192636f6e5a056299480132c6d3bd8f9b6ef863d60b5a" +dependencies = [ + "async-std", + "fnv", + "futures 0.3.5", + "libp2p", + "log", + "prost", + "prost-build", + "thiserror", + "tiny-cid", + "tiny-multihash", + "unsigned-varint 0.5.1", +] + [[package]] name = "libp2p-core" version = "0.22.1" @@ -3050,7 +3183,7 @@ dependencies = [ "pin-project", "rand 0.7.3", "salsa20", - "sha3", + "sha3 0.8.2", ] [[package]] @@ -3521,6 +3654,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" +[[package]] +name = "multibase" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b78c60039650ff12e140ae867ef5299a58e19dded4d334c849dc7177083667e2" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + [[package]] name = "multihash" version = "0.11.2" @@ -3530,9 +3674,9 @@ dependencies = [ "blake2b_simd", "blake2s_simd", "digest 0.8.1", - "sha-1", + "sha-1 0.8.2", "sha2 0.8.2", - "sha3", + "sha3 0.8.2", "unsigned-varint 0.3.3", ] @@ -4139,11 +4283,11 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" dependencies = [ - "parking_lot 0.10.2", + "parking_lot 0.11.0", ] [[package]] @@ -4472,7 +4616,7 @@ dependencies = [ "ripemd160", "rlp", "serde", - "sha3", + "sha3 0.8.2", "sp-core", "sp-io", "sp-runtime", @@ -5191,16 +5335,16 @@ dependencies = [ "mio", "mio-extras", "rand 0.7.3", - "sha-1", + "sha-1 0.8.2", "slab", "url 2.1.1", ] [[package]] name = "parking" -version = "1.0.5" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d4a6da31f8144a32532fe38fe8fb439a6842e0ec633f0037f0144c14e7f907" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" [[package]] name = "parking_lot" @@ -5421,6 +5565,19 @@ dependencies = [ "web-sys", ] +[[package]] +name = "polling" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0720e0b9ea9d52451cf29d3413ba8a9303f8815d9d9653ef70e03ff73e65566" +dependencies = [ + "cfg-if", + "libc", + "log", + "wepoll-sys-stjepang", + "winapi 0.3.9", +] + [[package]] name = "poly1305" version = "0.6.0" @@ -5508,9 +5665,9 @@ dependencies = [ [[package]] name = "proc-macro-error" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc175e9777c3116627248584e8f8b3e2987405cabe1c0adf7d1dd28f09dc7880" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", @@ -5521,14 +5678,12 @@ dependencies = [ [[package]] name = "proc-macro-error-attr" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc9795ca17eb581285ec44936da7fc2335a3f34f2ddd13118b6f4d515435c50" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "syn", - "syn-mid", "version_check", ] @@ -6029,7 +6184,7 @@ checksum = "952cd6b98c85bbc30efa1ba5783b8abf12fec8b3287ffa52605b9432313e34e4" dependencies = [ "cc", "libc", - "once_cell 1.4.0", + "once_cell 1.4.1", "spin", "untrusted", "web-sys", @@ -6899,6 +7054,7 @@ dependencies = [ "hex", "ip_network", "libp2p", + "libp2p-bitswap", "linked-hash-map", "linked_hash_set", "log", @@ -6933,6 +7089,7 @@ dependencies = [ "substrate-test-runtime-client", "tempfile", "thiserror", + "tiny-cid", "unsigned-varint 0.4.0", "void", "wasm-timer", @@ -7552,6 +7709,19 @@ dependencies = [ "opaque-debug 0.2.3", ] +[[package]] +name = "sha-1" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpuid-bool", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + [[package]] name = "sha2" version = "0.8.2" @@ -7590,6 +7760,18 @@ dependencies = [ "opaque-debug 0.2.3", ] +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "keccak", + "opaque-debug 0.3.0", +] + [[package]] name = "sharded-slab" version = "0.0.9" @@ -7686,27 +7868,6 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" -[[package]] -name = "smol" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "620cbb3c6e34da57d3a248cda0cd01cd5848164dc062e764e65d06fe3ea7aed5" -dependencies = [ - "async-task", - "blocking", - "concurrent-queue", - "fastrand", - "futures-io", - "futures-util", - "libc", - "once_cell 1.4.0", - "scoped-tls", - "slab", - "socket2", - "wepoll-sys-stjepang", - "winapi 0.3.9", -] - [[package]] name = "snow" version = "0.7.1" @@ -7750,7 +7911,7 @@ dependencies = [ "httparse", "log", "rand 0.7.3", - "sha-1", + "sha-1 0.8.2", ] [[package]] @@ -8525,7 +8686,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09f8ed9974042b8c3672ff3030a69fcc03b74c47c3d1ecb7755e8a3626011e88" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", ] [[package]] @@ -8537,6 +8698,18 @@ dependencies = [ "bytes 0.4.12", ] +[[package]] +name = "strobe-rs" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9baee171ea889cfe5333700f0948777b483db8dc805c5c519ffe92e7714783" +dependencies = [ + "bitflags", + "byteorder 1.3.4", + "subtle 2.2.3", + "tiny-keccak", +] + [[package]] name = "strsim" version = "0.8.0" @@ -8878,26 +9051,15 @@ checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" [[package]] name = "syn" -version = "1.0.35" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" +checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "synstructure" version = "0.12.4" @@ -9023,7 +9185,7 @@ checksum = "b0165e045cc2ae1660270ca65e1676dbaab60feb0f91b10f7d0665e9b47e31f2" dependencies = [ "failure", "hmac", - "once_cell 1.4.0", + "once_cell 1.4.1", "pbkdf2", "rand 0.7.3", "rustc-hash", @@ -9031,6 +9193,17 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "tiny-cid" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8db0f10795d9047653976779741a9f5b763a87aadc7bf0c80be5a2361ecc7a9" +dependencies = [ + "multibase", + "tiny-multihash", + "unsigned-varint 0.5.1", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -9040,6 +9213,38 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tiny-multihash" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632824c586db700f0fab27c2cca5b6bd7bf8e49b1f8ddce77f736c9fbe9401f2" +dependencies = [ + "blake2b_simd", + "blake2s_simd", + "digest 0.9.0", + "generic-array 0.14.4", + "sha-1 0.9.1", + "sha2 0.9.1", + "sha3 0.9.1", + "strobe-rs", + "tiny-multihash-derive", + "unsigned-varint 0.5.1", +] + +[[package]] +name = "tiny-multihash-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfcc7989e2269ece9a93256298139f1f28b5d2cc483cd033b60c0c76f36d9377" +dependencies = [ + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "tinytemplate" version = "1.1.0" @@ -9594,7 +9799,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" dependencies = [ - "generic-array 0.14.3", + "generic-array 0.14.4", "subtle 2.2.3", ] @@ -9660,6 +9865,12 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +[[package]] +name = "vec-arena" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" + [[package]] name = "vec_map" version = "0.8.2" diff --git a/client/network-gossip/src/bridge.rs b/client/network-gossip/src/bridge.rs index 70c2942597aa5..40839f6ab5ee1 100644 --- a/client/network-gossip/src/bridge.rs +++ b/client/network-gossip/src/bridge.rs @@ -210,7 +210,8 @@ impl Future for GossipEngine { this.forwarding_state = ForwardingState::Busy(to_forward.into()); }, - Event::Dht(_) => {} + Event::Dht(_) => {}, + Event::Bitswap(_) => {}, } // The network event stream closed. Do the same for [`GossipValidator`]. Poll::Ready(None) => return Poll::Ready(()), diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index c220728a4e4b4..2ecbec75ec1c3 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -32,6 +32,7 @@ futures-timer = "3.0.2" futures_codec = "0.4.0" hex = "0.4.0" ip_network = "0.3.4" +libp2p-bitswap = "0.7.0" linked-hash-map = "0.5.2" linked_hash_set = "0.1.3" log = "0.4.8" @@ -57,6 +58,7 @@ sp-core = { version = "2.0.0-rc6", path = "../../primitives/core" } sp-runtime = { version = "2.0.0-rc6", path = "../../primitives/runtime" } sp-utils = { version = "2.0.0-rc6", path = "../../primitives/utils" } thiserror = "1" +tiny-cid = "0.2.5" unsigned-varint = { version = "0.4.0", features = ["futures", "futures-codec"] } void = "1.0.2" wasm-timer = "0.2" diff --git a/client/network/src/behaviour.rs b/client/network/src/behaviour.rs index 6b3cfac38ae99..becc127b550da 100644 --- a/client/network/src/behaviour.rs +++ b/client/network/src/behaviour.rs @@ -54,6 +54,8 @@ pub struct Behaviour { peer_info: peer_info::PeerInfoBehaviour, /// Discovers nodes of the network. discovery: DiscoveryBehaviour, + /// Exchanges blocks of data with other nodes. + bitswap: libp2p_bitswap::Bitswap, /// Generic request-reponse protocols. request_responses: request_responses::RequestResponsesBehaviour, /// Block request handling. @@ -172,6 +174,23 @@ pub enum BehaviourOut { /// Events generated by a DHT as a response to get_value or put_value requests as well as the /// request duration. Dht(DhtEvent, Duration), + + /// Event generated by bitswap. + Bitswap(BitswapEvent) +} + +/// An event generated by bitswap. +#[derive(Clone, Debug)] +pub enum BitswapEvent { + /// A block has been received. + /// + /// There are no guarantees about the recieved block: + /// * The CID and block contents might not match. + /// * We might have receieved a block without having sent out a want request first. + /// * It is possible to receieve this message multiple times with the same block. + ReceivedBlock(PeerId, tiny_cid::Cid, Box<[u8]>), + /// A peer wants the block with the hash of `cid`, and with a given priority. + ReceivedWant(PeerId, tiny_cid::Cid, libp2p_bitswap::Priority), } impl Behaviour { @@ -197,6 +216,7 @@ impl Behaviour { finality_proof_requests, light_client_handler, events: VecDeque::new(), + bitswap: libp2p_bitswap::Bitswap::new(), role, }) } @@ -300,6 +320,37 @@ impl Behaviour { pub fn light_client_request(&mut self, r: light_client_handler::Request) -> Result<(), light_client_handler::Error> { self.light_client_handler.request(r) } + + /// Count the number of connected peers who want the bitswap block with the hash of `cid`. + pub fn bitswap_num_peers_want(&self, cid: &tiny_cid::Cid) -> usize { + self.bitswap.peers_want(cid).count() + } + + /// Determine whether a specific peer wants a bitswap block with the hash of `cid`. + pub fn bitswap_peer_wants_cid(&self, peer_id: &PeerId, cid: &tiny_cid::Cid) -> bool { + self.bitswap.peers_want(cid).find(|id| **id == *peer_id).is_some() + } + + /// Send a bitswap block to a specific peer, regardless of whether they want it or not. + pub fn bitswap_send_block(&mut self, peer_id: &PeerId, cid: tiny_cid::Cid, block: Box<[u8]>) { + self.bitswap.send_block(peer_id, cid, block) + } + + /// Send a bitswap block to all connected peers who want it. + pub fn bitswap_send_block_all(&mut self, cid: &tiny_cid::Cid, block: &[u8]) { + self.bitswap.send_block_all(cid, block) + } + + /// Send out a bitswap message telling connected peers that we want the block with the hash of + /// `cid`. We can also say how this block should be prioritised. + pub fn bitswap_want_block(&mut self, cid: tiny_cid::Cid, priority: libp2p_bitswap::Priority) { + self.bitswap.want_block(cid, priority) + } + + /// Send out a bitswap message cancelling a previously wanted block with the hash of `cid`. + pub fn bitswap_cancel_block(&mut self, cid: &tiny_cid::Cid) { + self.bitswap.cancel_block(cid) + } } fn reported_roles_to_observed_role(local_role: &Role, remote: &PeerId, roles: Roles) -> ObservedRole { @@ -537,6 +588,25 @@ impl NetworkBehaviourEventProcess } } +impl NetworkBehaviourEventProcess + for Behaviour { + fn inject_event(&mut self, event: libp2p_bitswap::BitswapEvent) { + match event { + libp2p_bitswap::BitswapEvent::ReceivedBlock(peer_id, cid, data) => { + self.events.push_back( + BehaviourOut::Bitswap(BitswapEvent::ReceivedBlock(peer_id, cid, data)) + ); + }, + libp2p_bitswap::BitswapEvent::ReceivedWant(peer_id, cid, priority) => { + self.events.push_back( + BehaviourOut::Bitswap(BitswapEvent::ReceivedWant(peer_id, cid, priority)) + ); + } + libp2p_bitswap::BitswapEvent::ReceivedCancel(..) => {}, + } + } +} + impl Behaviour { fn poll(&mut self, _: &mut Context, _: &mut impl PollParameters) -> Poll>> { if let Some(event) = self.events.pop_front() { diff --git a/client/network/src/lib.rs b/client/network/src/lib.rs index 3fd01c33dcf5f..04b9f134f7f1b 100644 --- a/client/network/src/lib.rs +++ b/client/network/src/lib.rs @@ -266,6 +266,7 @@ pub mod network_state; #[doc(inline)] pub use libp2p::{multiaddr, Multiaddr, PeerId}; +pub use behaviour::BitswapEvent; pub use protocol::{event::{DhtEvent, Event, ObservedRole}, sync::SyncState, PeerInfo}; pub use service::{ NetworkService, NetworkWorker, RequestFailure, OutboundFailure, NotificationSender, diff --git a/client/network/src/protocol/event.rs b/client/network/src/protocol/event.rs index 637bf805b5024..3bc52207530ae 100644 --- a/client/network/src/protocol/event.rs +++ b/client/network/src/protocol/event.rs @@ -22,6 +22,8 @@ use libp2p::core::PeerId; use libp2p::kad::record::Key; use sp_runtime::ConsensusEngineId; +pub use crate::behaviour::BitswapEvent; + /// Events generated by DHT as a response to get_value and put_value requests. #[derive(Debug, Clone)] #[must_use] @@ -45,6 +47,8 @@ pub enum DhtEvent { pub enum Event { /// Event generated by a DHT. Dht(DhtEvent), + /// Event generated by Bitswap. + Bitswap(BitswapEvent), /// Opened a substream with the given node with the given notifications protocol. /// diff --git a/client/network/src/service.rs b/client/network/src/service.rs index 59f55f01a45d1..64d9526707d03 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -597,6 +597,16 @@ impl NetworkWorker { pub fn add_reserved_peer(&self, peer: String) -> Result<(), String> { self.service.add_reserved_peer(peer) } + + /// Count the number of connected peers who want the bitswap block with the hash of `cid`. + pub fn bitswap_num_peers_want(&self, cid: &tiny_cid::Cid) -> usize { + self.network_service.bitswap_num_peers_want(cid) + } + + /// Determine whether a specific peer wants a bitswap block with the hash of `cid`. + pub fn bitswap_peer_wants_cid(&self, peer_id: &PeerId, cid: &tiny_cid::Cid) -> bool { + self.network_service.bitswap_peer_wants_cid(peer_id, cid) + } } impl NetworkService { @@ -1027,6 +1037,35 @@ impl NetworkService { .to_worker .unbounded_send(ServiceToWorkerMsg::OwnBlockImported(hash, number)); } + + /// Send a bitswap block to a specific peer, regardless of whether they want it or not. + pub fn bitswap_send_block(&self, peer_id: PeerId, cid: tiny_cid::Cid, data: Box<[u8]>) { + let _ = self + .to_worker + .unbounded_send(ServiceToWorkerMsg::BitswapSendBlock(peer_id, cid, data)); + } + + /// Send a bitswap block to all connected peers who want it. + pub fn bitswap_send_block_all(&self, cid: tiny_cid::Cid, data: Box<[u8]>) { + let _ = self + .to_worker + .unbounded_send(ServiceToWorkerMsg::BitswapSendBlockAll(cid, data)); + } + + /// Send out a bitswap message telling connected peers that we want the block with the hash of + /// `cid`. We can also say how this block should be prioritised. + pub fn bitswap_want_block(&self, cid: tiny_cid::Cid, priority: libp2p_bitswap::Priority) { + let _ = self + .to_worker + .unbounded_send(ServiceToWorkerMsg::BitswapWantBlock(cid, priority)); + } + + /// Send out a bitswap message cancelling a previously wanted block with the hash of `cid`. + pub fn bitswap_cancel_block(&self, cid: tiny_cid::Cid) { + let _ = self + .to_worker + .unbounded_send(ServiceToWorkerMsg::BitswapCancelBlock(cid)); + } } impl sp_consensus::SyncOracle @@ -1159,6 +1198,10 @@ enum ServiceToWorkerMsg { DisconnectPeer(PeerId), UpdateChain, OwnBlockImported(B::Hash, NumberFor), + BitswapSendBlock(PeerId, tiny_cid::Cid, Box<[u8]>), + BitswapSendBlockAll(tiny_cid::Cid, Box<[u8]>), + BitswapWantBlock(tiny_cid::Cid, libp2p_bitswap::Priority), + BitswapCancelBlock(tiny_cid::Cid), } /// Main network worker. Must be polled in order for the network to advance. @@ -1301,6 +1344,14 @@ impl Future for NetworkWorker { this.network_service.user_protocol_mut().update_chain(), ServiceToWorkerMsg::OwnBlockImported(hash, number) => this.network_service.user_protocol_mut().own_block_imported(hash, number), + ServiceToWorkerMsg::BitswapSendBlock(peer_id, cid, block) => + this.network_service.bitswap_send_block(&peer_id, cid, block), + ServiceToWorkerMsg::BitswapSendBlockAll(cid, block) => + this.network_service.bitswap_send_block_all(&cid, &block), + ServiceToWorkerMsg::BitswapWantBlock(cid, priority) => + this.network_service.bitswap_want_block(cid, priority), + ServiceToWorkerMsg::BitswapCancelBlock(cid) => + this.network_service.bitswap_cancel_block(&cid), } } @@ -1506,6 +1557,9 @@ impl Future for NetworkWorker { this.event_streams.send(Event::Dht(event)); }, + Poll::Ready(SwarmEvent::Behaviour(BehaviourOut::Bitswap(ev))) => { + this.event_streams.send(Event::Bitswap(ev)); + }, Poll::Ready(SwarmEvent::ConnectionEstablished { peer_id, endpoint, num_established }) => { trace!(target: "sub-libp2p", "Libp2p => Connected({:?})", peer_id); @@ -1531,14 +1585,14 @@ impl Future for NetworkWorker { let reason = match cause { Some(ConnectionError::IO(_)) => "transport-error", Some(ConnectionError::Handler(NodeHandlerWrapperError::Handler(EitherError::A(EitherError::A( - EitherError::A(EitherError::A(EitherError::A(EitherError::B( - EitherError::A(PingFailure::Timeout)))))))))) => "ping-timeout", + EitherError::A(EitherError::A(EitherError::A(EitherError::A(EitherError::B( + EitherError::A(PingFailure::Timeout))))))))))) => "ping-timeout", Some(ConnectionError::Handler(NodeHandlerWrapperError::Handler(EitherError::A(EitherError::A( - EitherError::A(EitherError::A(EitherError::A(EitherError::A( - NotifsHandlerError::Legacy(LegacyConnectionKillError)))))))))) => "force-closed", + EitherError::A(EitherError::A(EitherError::A(EitherError::A(EitherError::A( + NotifsHandlerError::Legacy(LegacyConnectionKillError))))))))))) => "force-closed", Some(ConnectionError::Handler(NodeHandlerWrapperError::Handler(EitherError::A(EitherError::A( - EitherError::A(EitherError::A(EitherError::A(EitherError::A( - NotifsHandlerError::SyncNotificationsClogged))))))))) => "sync-notifications-clogged", + EitherError::A(EitherError::A(EitherError::A(EitherError::A(EitherError::A( + NotifsHandlerError::SyncNotificationsClogged)))))))))) => "sync-notifications-clogged", Some(ConnectionError::Handler(NodeHandlerWrapperError::Handler(_))) => "protocol-error", Some(ConnectionError::Handler(NodeHandlerWrapperError::KeepAliveTimeout)) => "keep-alive-timeout", None => "actively-closed", diff --git a/client/network/src/service/out_events.rs b/client/network/src/service/out_events.rs index 1b86a5fa4317d..2eb13d2cc93f2 100644 --- a/client/network/src/service/out_events.rs +++ b/client/network/src/service/out_events.rs @@ -227,6 +227,11 @@ impl Metrics { self.events_total .with_label_values(&["dht", "sent", name]) .inc_by(num); + }, + Event::Bitswap(_) => { + self.events_total + .with_label_values(&["bitswap", "sent", name]) + .inc_by(num); } Event::NotificationStreamOpened { engine_id, .. } => { self.events_total @@ -258,6 +263,11 @@ impl Metrics { .with_label_values(&["dht", "received", name]) .inc(); } + Event::Bitswap(_) => { + self.events_total + .with_label_values(&["bitswap", "received", name]) + .inc(); + } Event::NotificationStreamOpened { engine_id, .. } => { self.events_total .with_label_values(&[&format!("notif-open-{:?}", engine_id), "received", name]) diff --git a/client/network/src/service/tests.rs b/client/network/src/service/tests.rs index 4b6f9dd156482..98ed7b2e2c6f2 100644 --- a/client/network/src/service/tests.rs +++ b/client/network/src/service/tests.rs @@ -271,6 +271,8 @@ fn notifications_state_consistent() { // Add new events here. future::Either::Left(Event::Dht(_)) => {} future::Either::Right(Event::Dht(_)) => {} + future::Either::Left(Event::Bitswap(_)) => {} + future::Either::Right(Event::Bitswap(_)) => {} }; } });