diff --git a/.github/dylints/blocking_in_actor_loop/.cargo/config.toml b/.github/dylints/blocking_in_actor_loop/.cargo/config.toml new file mode 100644 index 00000000000..d58627620a1 --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.'cfg(all())'] +rustflags = ["-C", "linker=dylint-link"] diff --git a/.github/dylints/blocking_in_actor_loop/.gitattributes b/.github/dylints/blocking_in_actor_loop/.gitattributes new file mode 100644 index 00000000000..5b01840729b --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/.gitattributes @@ -0,0 +1 @@ +ui/*.stderr whitespace=-blank-at-eof diff --git a/.github/dylints/blocking_in_actor_loop/Cargo.lock b/.github/dylints/blocking_in_actor_loop/Cargo.lock new file mode 100644 index 00000000000..7493ec67fd8 --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/Cargo.lock @@ -0,0 +1,1581 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + +[[package]] +name = "blocking_in_actor_loop" +version = "0.0.1" +dependencies = [ + "dylint_linting", + "dylint_testing", +] + +[[package]] +name = "camino" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48" +dependencies = [ + "serde_core", +] + +[[package]] +name = "cargo-platform" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0061da739915fae12ea00e16397555ed4371a6bb285431aab930f61b0aa4ba" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "cargo_metadata" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef987d17b0a113becdd19d3d0022d04d7ef41f9efe4f3fb63ac44ba61df3ade9" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror 2.0.18", +] + +[[package]] +name = "cc" +version = "1.2.62" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "compiletest_rs" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f150fe9105fcd2a57cad53f0c079a24de65195903ef670990f5909f695eac04c" +dependencies = [ + "diff", + "filetime", + "getopts", + "lazy_static", + "libc", + "log", + "miow", + "regex", + "rustfix", + "serde", + "serde_derive", + "serde_json", + "tester", + "windows-sys 0.59.0", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dylint" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b795f98802f87352aab60584eea87f942c53ab30edcafab4b31a6cbdd9e8a3ac" +dependencies = [ + "anstyle", + "anyhow", + "cargo_metadata", + "dylint_internal", + "log", + "once_cell", + "semver", + "serde", + "serde_json", + "tempfile", +] + +[[package]] +name = "dylint_internal" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a03ff51e671fceef87e50fef97ddc1569241af242d76e0b367dfcc812c860eb0" +dependencies = [ + "anstyle", + "anyhow", + "bitflags", + "cargo_metadata", + "git2", + "home", + "log", + "regex", + "serde", + "tar", + "thiserror 2.0.18", + "toml", +] + +[[package]] +name = "dylint_linting" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3efcb9b741bccdd6f1ce701c4b17b452112e8c0cd045c8b894a112584ff5d55" +dependencies = [ + "cargo_metadata", + "dylint_internal", + "paste", + "rustversion", + "serde", + "thiserror 2.0.18", + "toml", +] + +[[package]] +name = "dylint_testing" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eaa3ca6e1f740cd587630c321f61927b4cafdc2abf7c2fbacc3fca8635fcc48" +dependencies = [ + "anyhow", + "cargo_metadata", + "compiletest_rs", + "dylint", + "dylint_internal", + "env_logger", + "once_cell", + "regex", + "serde_json", + "tempfile", +] + +[[package]] +name = "env_filter" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e90c2accc4b07a8456ea0debdc2e7587bdd890680d71173a15d4ae604f6eef" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0621c04f2196ac3f488dd583365b9c09be011a4ab8b9f37248ffcc8f6198b56a" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "jiff", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + +[[package]] +name = "filetime" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759" +dependencies = [ + "cfg-if", + "libc", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getopts" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", +] + +[[package]] +name = "git2" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jiff" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00b5dbd620d61dfdcb6007c9c1f6054ebd75319f163d886a9055cec1155073d" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-static" +version = "0.2.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e000de030ff8022ea1da3f466fbb0f3a809f5e51ed31f6dd931c35181ad8e6d7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "libgit2-sys" +version = "0.18.4+1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b26f66f35e1871b22efcf7191564123d2a446ca0538cde63c23adfefa9b15b7" +dependencies = [ + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", +] + +[[package]] +name = "libredox" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" +dependencies = [ + "libc", +] + +[[package]] +name = "libssh2-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "libz-sys" +version = "1.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc3a226e576f50782b3305c5ccf458698f92798987f551c6a02efe8276721e22" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "miow" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "536bfad37a309d62069485248eeaba1e8d9853aaf951caaeaed0585a95346f08" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-sys" +version = "0.9.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28a22dc7140cda5f096e5e7724a6962ca81a7f8bfd2979f9b18c11af56318c4" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "portable-atomic-util" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom 0.2.17", + "libredox", + "thiserror 1.0.69", +] + +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "rustfix" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82fa69b198d894d84e23afde8e9ab2af4400b2cba20d6bf2b428a8b01c222c5a" +dependencies = [ + "serde", + "serde_json", + "thiserror 1.0.69", + "tracing", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tar" +version = "0.4.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.2", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + +[[package]] +name = "tester" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89e8bf7e0eb2dd7b4228cc1b6821fc5114cd6841ae59f652a85488c016091e5f" +dependencies = [ + "cfg-if", + "getopts", + "libc", + "num_cpus", + "term", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "toml" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.3+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +dependencies = [ + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "xattr" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" +dependencies = [ + "libc", + "rustix", +] + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/.github/dylints/blocking_in_actor_loop/Cargo.toml b/.github/dylints/blocking_in_actor_loop/Cargo.toml new file mode 100644 index 00000000000..669858ecf48 --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "blocking_in_actor_loop" +version = "0.0.1" +description = "Reject blocking awaits in actor event loops." +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[dependencies] +dylint_linting = "6.0.0" + +[dev-dependencies] +dylint_testing = "6.0.0" + +[package.metadata.rust-analyzer] +rustc_private = true diff --git a/.github/dylints/blocking_in_actor_loop/rust-toolchain b/.github/dylints/blocking_in_actor_loop/rust-toolchain new file mode 100644 index 00000000000..588e8755f3a --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/rust-toolchain @@ -0,0 +1,5 @@ +# Dylint discovers library toolchains from this directory, so the just/CI +# `cargo +nightly-... dylint` invocation does not pin the library build. +[toolchain] +channel = "nightly" +components = ["rustc-dev", "llvm-tools-preview"] diff --git a/.github/dylints/blocking_in_actor_loop/src/lib.rs b/.github/dylints/blocking_in_actor_loop/src/lib.rs new file mode 100644 index 00000000000..3cfe3a301d7 --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/src/lib.rs @@ -0,0 +1,243 @@ +#![feature(rustc_private)] +#![warn(unused_extern_crates)] + +extern crate rustc_errors; +extern crate rustc_hir; +extern crate rustc_span; + +use rustc_errors::DiagDecorator; +use rustc_hir::{ + intravisit::{walk_expr, Visitor}, + Body, Expr, ExprKind, MatchSource, +}; +use rustc_lint::{LateContext, LateLintPass, LintContext}; +use rustc_span::{Span, Symbol}; + +dylint_linting::declare_late_lint! { + /// ### What it does + /// + /// Detects blocking waits in actor event loops, such as awaiting an actor + /// mailbox request/reply method or an async handler callback inside + /// `select_loop!`. It also detects async mailbox request/reply helpers that + /// create a oneshot channel, enqueue a message with the sender, and then + /// await the receiver before returning. + /// + /// ### Why is this bad? + /// + /// Actor loops must keep polling their mailbox and other event sources. + /// Awaiting another actor or an application callback from a branch body can + /// starve the loop. Hiding the wait behind an async mailbox helper makes it + /// too easy for actor loops to block accidentally. Spawn or pool the work + /// and select on its completion instead. + /// + /// ### Example + /// + /// ```rust + /// select_loop! { + /// context, + /// message = mailbox.recv() => { + /// handler.process(message).await; + /// }, + /// } + /// ``` + /// + /// Use instead: + /// + /// ```rust + /// select_loop! { + /// context, + /// message = mailbox.recv() => { + /// pending.push(async move { + /// handler.process(message).await; + /// }); + /// }, + /// _ = pending.next_completed() => {}, + /// } + /// ``` + pub BLOCKING_IN_ACTOR_LOOP, + Deny, + "blocking await in actor loop" +} + +impl<'tcx> LateLintPass<'tcx> for BlockingInActorLoop { + fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) { + match actor_loop_kind(cx, body) { + Some(kind) => BlockingAwaitVisitor { cx, kind }.visit_expr(body.value), + None => {} + } + + if let Some(span) = request_reply_helper_wait(cx, body) { + cx.emit_span_lint( + BLOCKING_IN_ACTOR_LOOP, + span, + DiagDecorator(|diag| { + diag.primary_message("async mailbox request/reply helper hides an actor wait"); + diag.span_help( + span, + "return the oneshot receiver and let callers select or await explicitly", + ); + }), + ); + } + } +} + +struct BlockingAwaitVisitor<'a, 'tcx> { + cx: &'a LateContext<'tcx>, + kind: ActorLoopKind, +} + +#[derive(Clone, Copy)] +enum ActorLoopKind { + SelectLoop, + MailboxWhile, +} + +impl<'tcx> Visitor<'tcx> for BlockingAwaitVisitor<'_, 'tcx> { + fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { + if let Some(call) = awaited_call(expr) { + if call.blocks_actor_loop(self.cx, self.kind) { + self.cx.emit_span_lint( + BLOCKING_IN_ACTOR_LOOP, + expr.span, + DiagDecorator(|diag| { + diag.primary_message("blocking await in actor loop"); + diag.span_help( + call.span, + "queue this work and select on its completion instead of awaiting it in the actor loop", + ); + }), + ); + } + return; + } + + walk_expr(self, expr); + } +} + +struct AwaitedCall<'tcx> { + receiver: Option<&'tcx Expr<'tcx>>, + method: Symbol, + span: Span, +} + +impl AwaitedCall<'_> { + fn blocks_actor_loop(&self, cx: &LateContext<'_>, kind: ActorLoopKind) -> bool { + is_async_callback(self.method) + || self + .receiver + .is_some_and(|receiver| is_mailbox(cx, receiver)) + || matches!(kind, ActorLoopKind::MailboxWhile) + && is_io_wait(self.method) + && self + .receiver + .is_none_or(|receiver| !is_mailbox_loop_recv(cx, receiver)) + } +} + +fn actor_loop_kind(cx: &LateContext<'_>, body: &Body<'_>) -> Option { + let snippet = cx + .sess() + .source_map() + .span_to_snippet(body.value.span) + .ok()?; + + if snippet.contains("select_loop!") { + return Some(ActorLoopKind::SelectLoop); + } + if snippet.contains("mailbox.recv().await") { + return Some(ActorLoopKind::MailboxWhile); + } + None +} + +fn request_reply_helper_wait(cx: &LateContext<'_>, body: &Body<'_>) -> Option { + let snippet = cx + .sess() + .source_map() + .span_to_snippet(body.value.span) + .ok()?; + + if !snippet.contains("oneshot::channel") + || !snippet.contains(".enqueue(Message::") + || !snippet.contains(".await") + { + return None; + } + + AwaitVisitor::default().await_span(body.value) +} + +#[derive(Default)] +struct AwaitVisitor { + span: Option, +} + +impl AwaitVisitor { + fn await_span<'tcx>(mut self, expr: &'tcx Expr<'tcx>) -> Option { + self.visit_expr(expr); + self.span + } +} + +impl<'tcx> Visitor<'tcx> for AwaitVisitor { + fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) { + if self.span.is_some() { + return; + } + + if matches!(expr.kind, ExprKind::Match(_, _, MatchSource::AwaitDesugar)) { + self.span = Some(expr.span); + return; + } + + walk_expr(self, expr); + } +} + +fn awaited_call<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { + let ExprKind::Match(awaited, _, MatchSource::AwaitDesugar) = expr.kind else { + return None; + }; + + find_call(awaited) +} + +fn find_call<'tcx>(expr: &'tcx Expr<'tcx>) -> Option> { + match expr.kind { + ExprKind::MethodCall(segment, receiver, ..) => Some(AwaitedCall { + receiver: Some(receiver), + method: segment.ident.name, + span: expr.span, + }), + ExprKind::Call(_, args) => args.iter().find_map(find_call), + ExprKind::Block(block, _) => block.expr.and_then(find_call), + _ => None, + } +} + +fn is_async_callback(method: Symbol) -> bool { + matches!(method.as_str(), "process" | "collected") +} + +fn is_io_wait(method: Symbol) -> bool { + matches!(method.as_str(), "send" | "recv") +} + +fn is_mailbox(cx: &LateContext<'_>, receiver: &Expr<'_>) -> bool { + let ty = cx.typeck_results().expr_ty(receiver).peel_refs(); + format!("{ty:?}").contains("Mailbox") +} + +fn is_mailbox_loop_recv(cx: &LateContext<'_>, receiver: &Expr<'_>) -> bool { + cx.sess() + .source_map() + .span_to_snippet(receiver.span) + .is_ok_and(|snippet| snippet.ends_with("mailbox")) +} + +#[test] +fn ui() { + dylint_testing::ui_test(env!("CARGO_PKG_NAME"), "ui"); +} diff --git a/.github/dylints/blocking_in_actor_loop/ui/main.rs b/.github/dylints/blocking_in_actor_loop/ui/main.rs new file mode 100644 index 00000000000..30e8ee34b1a --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/ui/main.rs @@ -0,0 +1,135 @@ +// edition:2021 +#![allow(dead_code)] +#![warn(blocking_in_actor_loop)] + +struct Context; + +macro_rules! select_loop { + ($context:expr, $body:block) => {{ + let _ = $context; + loop { + $body + break; + } + }}; +} + +mod oneshot { + use std::{ + future::Future, + marker::PhantomData, + pin::Pin, + task::{Context, Poll}, + }; + + pub struct Sender(PhantomData); + + pub struct Receiver(PhantomData); + + pub fn channel() -> (Sender, Receiver) { + (Sender(PhantomData), Receiver(PhantomData)) + } + + impl Future for Receiver { + type Output = Result; + + fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + Poll::Pending + } + } +} + +trait Handler { + async fn process(&mut self); +} + +trait Monitor { + async fn collected(&mut self); +} + +struct Mailbox; + +impl Mailbox { + async fn dial(&self) {} +} + +struct Storage; + +impl Storage { + async fn put(&mut self) {} +} + +struct ActorReceiver; + +impl ActorReceiver { + async fn recv(&mut self) -> Option<()> { + None + } +} + +struct Stream; + +impl Stream { + async fn send(&mut self) {} + + async fn recv(&mut self) {} +} + +enum Message { + Ready { responder: oneshot::Sender<()> }, +} + +struct RequestReplyMailbox; + +impl RequestReplyMailbox { + fn enqueue(&self, _: Message) {} + + async fn ready(&self) -> Option<()> { + let (responder, receiver) = oneshot::channel(); + self.enqueue(Message::Ready { responder }); + receiver.await.ok() + } + + fn ready_receiver(&self) -> oneshot::Receiver<()> { + let (responder, receiver) = oneshot::channel(); + self.enqueue(Message::Ready { responder }); + receiver + } +} + +async fn bad_handler(mut handler: impl Handler) { + let context = Context; + select_loop!(context, { + handler.process().await; + }); +} + +async fn bad_monitor(mut monitor: impl Monitor) { + let context = Context; + select_loop!(context, { + monitor.collected().await; + }); +} + +async fn bad_mailbox(mailbox: Mailbox) { + let context = Context; + select_loop!(context, { + mailbox.dial().await; + }); +} + +async fn storage_write_is_allowed(mut storage: Storage) { + let context = Context; + select_loop!(context, { + storage.put().await; + }); +} + +async fn bad_while_mailbox(mut mailbox: ActorReceiver, mut stream: Stream) { + while let Some(()) = mailbox.recv().await { + stream.send().await; + stream.recv().await; + } +} + +fn main() {} diff --git a/.github/dylints/blocking_in_actor_loop/ui/main.stderr b/.github/dylints/blocking_in_actor_loop/ui/main.stderr new file mode 100644 index 00000000000..9af9bbe7eb6 --- /dev/null +++ b/.github/dylints/blocking_in_actor_loop/ui/main.stderr @@ -0,0 +1,79 @@ +warning: async mailbox request/reply helper hides an actor wait + --> $DIR/main.rs:90:9 + | +LL | receiver.await.ok() + | ^^^^^^^^^^^^^^ + | +help: return the oneshot receiver and let callers select or await explicitly + --> $DIR/main.rs:90:9 + | +LL | receiver.await.ok() + | ^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/main.rs:3:9 + | +LL | #![warn(blocking_in_actor_loop)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: blocking await in actor loop + --> $DIR/main.rs:103:9 + | +LL | handler.process().await; + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: queue this work and select on its completion instead of awaiting it in the actor loop + --> $DIR/main.rs:103:9 + | +LL | handler.process().await; + | ^^^^^^^^^^^^^^^^^ + +warning: blocking await in actor loop + --> $DIR/main.rs:110:9 + | +LL | monitor.collected().await; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: queue this work and select on its completion instead of awaiting it in the actor loop + --> $DIR/main.rs:110:9 + | +LL | monitor.collected().await; + | ^^^^^^^^^^^^^^^^^^^ + +warning: blocking await in actor loop + --> $DIR/main.rs:117:9 + | +LL | mailbox.dial().await; + | ^^^^^^^^^^^^^^^^^^^^ + | +help: queue this work and select on its completion instead of awaiting it in the actor loop + --> $DIR/main.rs:117:9 + | +LL | mailbox.dial().await; + | ^^^^^^^^^^^^^^ + +warning: blocking await in actor loop + --> $DIR/main.rs:130:9 + | +LL | stream.send().await; + | ^^^^^^^^^^^^^^^^^^^ + | +help: queue this work and select on its completion instead of awaiting it in the actor loop + --> $DIR/main.rs:130:9 + | +LL | stream.send().await; + | ^^^^^^^^^^^^^ + +warning: blocking await in actor loop + --> $DIR/main.rs:131:9 + | +LL | stream.recv().await; + | ^^^^^^^^^^^^^^^^^^^ + | +help: queue this work and select on its completion instead of awaiting it in the actor loop + --> $DIR/main.rs:131:9 + | +LL | stream.recv().await; + | ^^^^^^^^^^^^^ + +warning: 6 warnings emitted + diff --git a/Cargo.toml b/Cargo.toml index 7b8857288f7..2893ea9ce75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ members = [ ] exclude = [ ".github/dylints/borrowed_child_context", + ".github/dylints/blocking_in_actor_loop", ".github/dylints/child_attribute_name_conflict", ] resolver = "2" diff --git a/broadcast/src/buffered/engine.rs b/broadcast/src/buffered/engine.rs index 314a9fad403..968ae723523 100644 --- a/broadcast/src/buffered/engine.rs +++ b/broadcast/src/buffered/engine.rs @@ -158,7 +158,10 @@ where network.0, network.1, ); - let peer_set_subscription = &mut self.peer_provider.subscribe().await; + let Ok(mut peer_set_subscription) = self.peer_provider.subscribe().await else { + debug!("peer set subscription failed"); + return; + }; select_loop! { self.context, diff --git a/broadcast/src/buffered/ingress.rs b/broadcast/src/buffered/ingress.rs index e7373be96dd..598a2d9cde3 100644 --- a/broadcast/src/buffered/ingress.rs +++ b/broadcast/src/buffered/ingress.rs @@ -127,11 +127,11 @@ impl Mailbox { /// Get a message by digest. /// - /// If the engine has shut down, returns `None`. - pub async fn get(&self, digest: M::Digest) -> Option { + /// The returned receiver is closed if the engine has shut down. + pub fn get(&self, digest: M::Digest) -> oneshot::Receiver> { let (responder, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::Get { digest, responder }); - receiver.await.unwrap_or_default() + receiver } } diff --git a/broadcast/src/buffered/mod.rs b/broadcast/src/buffered/mod.rs index 86865aef7dc..e11528d661d 100644 --- a/broadcast/src/buffered/mod.rs +++ b/broadcast/src/buffered/mod.rs @@ -414,7 +414,7 @@ mod tests { for peer in peers.iter() { let mailbox = mailboxes.get(peer).unwrap().clone(); let digest = message.digest(); - let receiver = mailbox.get(digest).await; + let receiver = mailbox.get(digest).await.unwrap_or_default(); if let Some(receiver) = receiver { assert_eq!(receiver, message.clone()); found += 1; @@ -442,7 +442,7 @@ mod tests { let digest_m1 = m1.digest(); // Attempt immediate retrieval before broadcasting - let receiver_before = mailbox_a.get(digest_m1).await; + let receiver_before = mailbox_a.get(digest_m1).await.unwrap_or_default(); assert!(receiver_before.is_none()); // Attempt retrieval before broadcasting @@ -458,7 +458,7 @@ mod tests { assert_eq!(msg_before, m1); // Attempt immediate retrieval after broadcasting - let receiver_after = mailbox_a.get(digest_m1).await; + let receiver_after = mailbox_a.get(digest_m1).await.unwrap_or_default(); assert_eq!(receiver_after, Some(m1.clone())); // Perform a second retrieval after the broadcast @@ -721,7 +721,8 @@ mod tests { .unwrap() .clone() .get(msg.digest()) - .await; + .await + .unwrap_or_default(); assert_eq!(got_target, Some(msg.clone())); // Non-target peer should not retrieve the message. @@ -730,7 +731,8 @@ mod tests { .unwrap() .clone() .get(msg.digest()) - .await; + .await + .unwrap_or_default(); assert!(got_other.is_none()); }); } @@ -763,7 +765,7 @@ mod tests { context.sleep(NETWORK_SPEED_WITH_BUFFER).await; // observer must get it now - assert_eq!(obs.get(digest).await, Some(dup.clone())); + assert_eq!(obs.get(digest).await.unwrap_or_default(), Some(dup.clone())); // Evict from p0's deque only for i in 0..CACHE_SIZE { @@ -771,7 +773,7 @@ mod tests { assert!(mb0.broadcast(Recipients::All, spam).accepted()); } context.sleep(NETWORK_SPEED_WITH_BUFFER).await; - assert_eq!(obs.get(digest).await, Some(dup.clone())); + assert_eq!(obs.get(digest).await.unwrap_or_default(), Some(dup.clone())); // Evict from p1's deque as well for i in 0..CACHE_SIZE { @@ -779,7 +781,7 @@ mod tests { assert!(mb1.broadcast(Recipients::All, spam).accepted()); } context.sleep(NETWORK_SPEED_WITH_BUFFER).await; - assert!(obs.get(digest).await.is_none()); + assert!(obs.get(digest).await.unwrap_or_default().is_none()); }); } @@ -809,7 +811,7 @@ mod tests { let mut hasher = Sha256::default(); for msg in [&m1, &m2, &m3] { - if let Some(value) = mb1.get(msg.digest()).await { + if let Some(value) = mb1.get(msg.digest()).await.unwrap_or_default() { hasher.update(&value.content); } } @@ -1029,7 +1031,7 @@ mod tests { ); // Get should not panic - let result = mailbox.get(digest).await; + let result = mailbox.get(digest).await.unwrap_or_default(); assert!(result.is_none(), "get after shutdown should return None"); }); } @@ -1075,7 +1077,10 @@ mod tests { // Verify message received let peer_mailbox = mailboxes.get(&peers[1]).unwrap().clone(); - let received = peer_mailbox.get(message.digest()).await; + let received = peer_mailbox + .get(message.digest()) + .await + .unwrap_or_default(); assert_eq!(received, Some(message)); // Abort all engine handles @@ -1153,7 +1158,7 @@ mod tests { // Peer B should have cached the message (received from A). let mailbox_b = mailboxes.get(&peer_b).unwrap().clone(); assert_eq!( - mailbox_b.get(msg.digest()).await, + mailbox_b.get(msg.digest()).await.unwrap_or_default(), Some(msg.clone()), "peer B should have the message before eviction" ); @@ -1165,7 +1170,11 @@ mod tests { // Peer A's deque was evicted; the message should be gone. assert!( - mailbox_b.get(msg.digest()).await.is_none(), + mailbox_b + .get(msg.digest()) + .await + .unwrap_or_default() + .is_none(), "message should be evicted after peer A left the peer set" ); }); @@ -1264,7 +1273,7 @@ mod tests { let mailbox_b = mailboxes.get(&peer_b).unwrap().clone(); assert_eq!( - mailbox_b.get(msg.digest()).await, + mailbox_b.get(msg.digest()).await.unwrap_or_default(), Some(msg.clone()), "peer B should have the message before eviction" ); @@ -1280,7 +1289,11 @@ mod tests { context.sleep(A_JIFFY).await; assert!( - mailbox_b.get(msg.digest()).await.is_none(), + mailbox_b + .get(msg.digest()) + .await + .unwrap_or_default() + .is_none(), "message should be evicted: peer A is not in the latest peer set" ); @@ -1292,7 +1305,11 @@ mod tests { context.sleep(NETWORK_SPEED_WITH_BUFFER).await; assert!( - mailbox_b.get(fresh.digest()).await.is_none(), + mailbox_b + .get(fresh.digest()) + .await + .unwrap_or_default() + .is_none(), "message should not be rebuffered after peer A left latest.primary" ); }); @@ -1385,12 +1402,16 @@ mod tests { context.sleep(NETWORK_SPEED_WITH_BUFFER).await; assert_eq!( - mailbox_a.get(msg.digest()).await, + mailbox_a.get(msg.digest()).await.unwrap_or_default(), None, "sender not in latest.primary should not buffer, including own broadcasts" ); assert!( - mailbox_b.get(msg.digest()).await.is_none(), + mailbox_b + .get(msg.digest()) + .await + .unwrap_or_default() + .is_none(), "peer B should not cache messages from a sender excluded by the initial latest.primary set" ); }); @@ -1429,7 +1450,7 @@ mod tests { engine.start(network); assert_eq!( - mailbox.get(msg.digest()).await, + mailbox.get(msg.digest()).await.unwrap_or_default(), Some(msg), "sender is already in the initial latest.primary set, so its local broadcast should be cached" ); @@ -1513,12 +1534,16 @@ mod tests { context.sleep(NETWORK_SPEED_WITH_BUFFER).await; assert_eq!( - mailbox_a.get(before.digest()).await, + mailbox_a.get(before.digest()).await.unwrap_or_default(), None, "without latest.primary, local broadcasts are not buffered" ); assert!( - mailbox_b.get(before.digest()).await.is_none(), + mailbox_b + .get(before.digest()) + .await + .unwrap_or_default() + .is_none(), "without latest.primary, remote peers do not cache inbound messages" ); @@ -1534,7 +1559,10 @@ mod tests { .accepted()); context.sleep(NETWORK_SPEED_WITH_BUFFER).await; - assert_eq!(mailbox_b.get(after.digest()).await, Some(after)); + assert_eq!( + mailbox_b.get(after.digest()).await.unwrap_or_default(), + Some(after) + ); }); } @@ -1593,7 +1621,10 @@ mod tests { // B has the message in both A's and C's deques (ref count = 2). let mailbox_b = mailboxes.get(&peer_b).unwrap().clone(); - assert_eq!(mailbox_b.get(msg.digest()).await, Some(msg.clone())); + assert_eq!( + mailbox_b.get(msg.digest()).await.unwrap_or_default(), + Some(msg.clone()) + ); // Evict peer A only; C is still in the latest primary set. let remaining = commonware_utils::ordered::Set::from_iter_dedup(vec![peer_b, peer_c]); @@ -1602,7 +1633,7 @@ mod tests { // Message should still be available (C's deque still holds it). assert_eq!( - mailbox_b.get(msg.digest()).await, + mailbox_b.get(msg.digest()).await.unwrap_or_default(), Some(msg.clone()), "message should survive when another peer in the primary set still references it" ); diff --git a/collector/fuzz/fuzz_targets/collector.rs b/collector/fuzz/fuzz_targets/collector.rs index 3f5ab2d997c..59d07501d5d 100644 --- a/collector/fuzz/fuzz_targets/collector.rs +++ b/collector/fuzz/fuzz_targets/collector.rs @@ -151,7 +151,7 @@ impl Handler for FuzzHandler { type Request = FuzzRequest; type Response = FuzzResponse; - async fn process( + fn process( &mut self, _origin: Self::PublicKey, request: Self::Request, @@ -186,12 +186,7 @@ impl Monitor for FuzzMonitor { type PublicKey = PublicKey; type Response = FuzzResponse; - async fn collected( - &mut self, - _handler: Self::PublicKey, - _response: Self::Response, - _count: usize, - ) { + fn collected(&mut self, _handler: Self::PublicKey, _response: Self::Response, _count: usize) { self.collected_count += 1; } } @@ -379,9 +374,7 @@ fn fuzz(input: FuzzInput) { if let Some(handler) = handlers.get_mut(&handler_idx) { let (tx, rx) = oneshot::channel(); - handler - .process(peers[origin_idx].public_key(), request.clone(), tx) - .await; + handler.process(peers[origin_idx].public_key(), request.clone(), tx); if should_respond { if let Ok(response) = rx.await { @@ -400,9 +393,7 @@ fn fuzz(input: FuzzInput) { let handler_idx = (peer_idx as usize) % peers.len(); if let Some(monitor) = monitors.get_mut(&monitor_idx) { - monitor - .collected(peers[handler_idx].public_key(), response, count) - .await; + monitor.collected(peers[handler_idx].public_key(), response, count); } } diff --git a/collector/src/lib.rs b/collector/src/lib.rs index 4ebdb8dc4f3..d92628ad012 100644 --- a/collector/src/lib.rs +++ b/collector/src/lib.rs @@ -15,7 +15,6 @@ commonware_macros::stability_scope!(ALPHA { use commonware_cryptography::{Committable, Digestible, PublicKey}; use commonware_p2p::Recipients; use commonware_utils::channel::oneshot; - use std::future::Future; pub mod p2p; @@ -53,15 +52,17 @@ commonware_macros::stability_scope!(ALPHA { + Digestible::Digest> + Codec; - /// Processes a `request` from an [Originator] and (optionally) send a response. + /// Processes a `request` from an [Originator] and (optionally) sends a response. /// - /// If no response is needed, the `responder` should be dropped. + /// Implementations should return promptly. If processing requires async work, + /// enqueue it and use `response` to send the result later. If no response is + /// needed, the `response` should be dropped. fn process( &mut self, origin: Self::PublicKey, request: Self::Request, response: oneshot::Sender, - ) -> impl Future + Send; + ); } /// A [Monitor] collects responses from [Handler]s. @@ -75,12 +76,15 @@ commonware_macros::stability_scope!(ALPHA { /// Called for each response collected with the number of responses collected so far for /// the same commitment. /// + /// Implementations should return promptly. If observing a collection event + /// requires async work, enqueue it before returning. + /// /// [Monitor::collected] is only called once per `handler`. fn collected( &mut self, handler: Self::PublicKey, response: Self::Response, count: usize, - ) -> impl Future + Send; + ); } }); diff --git a/collector/src/p2p/engine.rs b/collector/src/p2p/engine.rs index e7cfe65cd02..95481fdf32e 100644 --- a/collector/src/p2p/engine.rs +++ b/collector/src/p2p/engine.rs @@ -123,7 +123,7 @@ where responses.1, ); - // Create futures pool + // Create futures pools let mut processed: Pool> = Pool::default(); select_loop! { self.context, @@ -184,8 +184,10 @@ where // Handle the request let (tx, rx) = oneshot::channel(); - self.handler.process(peer.clone(), msg, tx).await; - processed.push(async move { Ok((peer, rx.await?)) }); + self.handler.process(peer.clone(), msg, tx); + processed.push(async move { + Ok((peer, rx.await?)) + }); }, // Response from a handler @@ -222,7 +224,8 @@ where } // Send the response to the monitor - self.monitor.collected(peer, msg, responses.1.len()).await; + let count = responses.1.len(); + self.monitor.collected(peer, msg, count); }, } } diff --git a/collector/src/p2p/mocks/handler.rs b/collector/src/p2p/mocks/handler.rs index 3d76f24a0e2..cd73a28c2bf 100644 --- a/collector/src/p2p/mocks/handler.rs +++ b/collector/src/p2p/mocks/handler.rs @@ -58,7 +58,7 @@ impl crate::Handler for Handler { type Request = Request; type Response = Response; - async fn process( + fn process( &mut self, origin: Self::PublicKey, request: Self::Request, diff --git a/collector/src/p2p/mocks/monitor.rs b/collector/src/p2p/mocks/monitor.rs index 82785497625..24c8323aab6 100644 --- a/collector/src/p2p/mocks/monitor.rs +++ b/collector/src/p2p/mocks/monitor.rs @@ -34,7 +34,7 @@ impl crate::Monitor for Monitor { type PublicKey = PublicKey; type Response = Response; - async fn collected( + fn collected( &mut self, handler: Self::PublicKey, response: Self::Response, diff --git a/consensus/src/aggregation/mocks/reporter.rs b/consensus/src/aggregation/mocks/reporter.rs index b99805e4493..52af235de58 100644 --- a/consensus/src/aggregation/mocks/reporter.rs +++ b/consensus/src/aggregation/mocks/reporter.rs @@ -201,16 +201,16 @@ where S: Scheme, D: Digest, { - pub async fn get_tip(&mut self) -> Option<(Height, Epoch)> { + pub fn get_tip(&mut self) -> oneshot::Receiver> { let (sender, receiver) = oneshot::channel(); assert!( self.sender.enqueue(Message::GetTip(sender)).accepted(), "Failed to send get tip" ); - receiver.await.unwrap() + receiver } - pub async fn get_contiguous_tip(&mut self) -> Option { + pub fn get_contiguous_tip(&mut self) -> oneshot::Receiver> { let (sender, receiver) = oneshot::channel(); assert!( self.sender @@ -218,15 +218,15 @@ where .accepted(), "Failed to send get contiguous tip" ); - receiver.await.unwrap() + receiver } - pub async fn get(&mut self, height: Height) -> Option<(D, Epoch)> { + pub fn get(&mut self, height: Height) -> oneshot::Receiver> { let (sender, receiver) = oneshot::channel(); assert!( self.sender.enqueue(Message::Get(height, sender)).accepted(), "Failed to send get" ); - receiver.await.unwrap() + receiver } } diff --git a/consensus/src/aggregation/mod.rs b/consensus/src/aggregation/mod.rs index 4e35ad8e038..db05b41e7a9 100644 --- a/consensus/src/aggregation/mod.rs +++ b/consensus/src/aggregation/mod.rs @@ -289,7 +289,7 @@ mod tests { loop { let (height, epoch) = mailbox .get_tip() - .await + .await.ok().flatten() .unwrap_or((Height::zero(), Epoch::zero())); debug!( %height, @@ -518,7 +518,7 @@ mod tests { .spawn(move |context| async move { loop { if let Some(tip_height) = - reporter_mailbox.get_contiguous_tip().await + reporter_mailbox.get_contiguous_tip().await.ok().flatten() { if tip_height >= target_height { break; @@ -665,7 +665,7 @@ mod tests { // Wait for validators to reach target_height (past skip_height) loop { - if let Some((tip_height, _)) = reporter_mailbox.get_tip().await { + if let Some((tip_height, _)) = reporter_mailbox.get_tip().await.ok().flatten() { debug!(%tip_height, %skip_height, %target_height, "reporter status"); if tip_height >= skip_height.saturating_add(window).previous().unwrap() { // max we can proceed before item confirmed @@ -750,7 +750,7 @@ mod tests { // Wait for skip_height to be confirmed (should happen on replay) loop { - if let Some(tip_height) = reporter_mailbox.get_contiguous_tip().await { + if let Some(tip_height) = reporter_mailbox.get_contiguous_tip().await.ok().flatten() { debug!( %tip_height, %skip_height, %target_height, "reporter status on restart" @@ -1102,7 +1102,7 @@ mod tests { for (validator_pk, mut reporter_mailbox) in reporters { let (tip, _) = reporter_mailbox .get_tip() - .await + .await.ok().flatten() .unwrap_or((Height::zero(), Epoch::zero())); if !tip.is_zero() { any_consensus = true; diff --git a/consensus/src/marshal/application/validation.rs b/consensus/src/marshal/application/validation.rs index 82b2697da6c..1e18bfd4314 100644 --- a/consensus/src/marshal/application/validation.rs +++ b/consensus/src/marshal/application/validation.rs @@ -29,8 +29,8 @@ impl Stage { block: V::Block, ) -> bool { match self { - Self::Verified => marshal.verified(round, block).await, - Self::Certified => marshal.certified(round, block).await, + Self::Verified => marshal.verified(round, block).await.is_ok(), + Self::Certified => marshal.certified(round, block).await.is_ok(), } } } diff --git a/consensus/src/marshal/coding/marshaled.rs b/consensus/src/marshal/coding/marshaled.rs index ffad8c58c5e..209ee7c3e9e 100644 --- a/consensus/src/marshal/coding/marshaled.rs +++ b/consensus/src/marshal/coding/marshaled.rs @@ -530,7 +530,7 @@ where // Certifier holds a notarization for this block, so route // the write to the notarized cache. `certified` is // idempotent, so crash-recovery double-invocation is safe. - if !marshaled.marshal.certified(round, block).await { + if marshaled.marshal.certified(round, block).await.is_err() { debug!(?round, "marshal unable to accept block"); return; } @@ -700,7 +700,7 @@ where // parent and cannot be broadcast under the current header, so // drop the receiver and let the voter nullify the view via // timeout. - if let Some(block) = marshal.get_verified(consensus_context.round).await { + if let Some(block) = marshal.get_verified(consensus_context.round).await.ok().flatten() { let block_context = block.context(); if block_context != consensus_context { debug!( @@ -768,7 +768,7 @@ where if parent.height() == last_in_epoch { let commitment = parent.commitment(); let round = consensus_context.round; - if !marshal.verified(round, parent).await { + if marshal.verified(round, parent).await.is_err() { debug!( ?round, ?commitment, @@ -825,7 +825,7 @@ where let commitment = coded_block.commitment(); let round = consensus_context.round; - if !marshal.proposed(round, coded_block).await { + if marshal.proposed(round, coded_block).await.is_err() { debug!(?round, ?commitment, "marshal rejected proposed block"); return; } @@ -965,7 +965,7 @@ where // Valid re-proposal: notify the marshal and complete the // verification task for `certify`. - if !marshal.verified(round, block).await { + if marshal.verified(round, block).await.is_err() { debug!(?round, "marshal unable to accept block"); return; } diff --git a/consensus/src/marshal/coding/mod.rs b/consensus/src/marshal/coding/mod.rs index 9f65b54f0a3..ca762ed6154 100644 --- a/consensus/src/marshal/coding/mod.rs +++ b/consensus/src/marshal/coding/mod.rs @@ -1058,11 +1058,11 @@ mod tests { // Wait until the descendant is archived: that proves finalization processing // has completed, at which point the parent must already have been repaired // from the shard buffer. - while handle.mailbox.get_block(Height::new(2)).await.is_none() { + while handle.mailbox.get_block(Height::new(2)).await.ok().flatten().is_none() { context.sleep(Duration::from_millis(10)).await; } - let parent = handle.mailbox.get_block(Height::new(1)).await; + let parent = handle.mailbox.get_block(Height::new(1)).await.ok().flatten(); assert!( parent.is_some(), "parent must be archived from shard buffer before height-prune evicts it" @@ -2366,7 +2366,7 @@ mod tests { // Validator 1 proposes coded_block_b (same inner block, different coding). // This stores it in v1's shard engine and actor cache. - assert!(v1_mailbox.verified(round1, coded_block_b.clone()).await); + assert!(v1_mailbox.verified(round1, coded_block_b.clone()).await.is_ok()); context.sleep(Duration::from_millis(100)).await; // Create finalization referencing commitment_a (the "correct" commitment). @@ -2388,14 +2388,14 @@ mod tests { context.sleep(Duration::from_secs(5)).await; // The mismatched block must not be stored. - let stored = v0_mailbox.get_block(Height::new(1)).await; + let stored = v0_mailbox.get_block(Height::new(1)).await.ok().flatten(); assert!( stored.is_none(), "v0 should reject backfilled block with mismatched commitment" ); // Without the block, finalization should not be persisted by height yet. - let stored_finalization = v0_mailbox.get_finalization(Height::new(1)).await; + let stored_finalization = v0_mailbox.get_finalization(Height::new(1)).await.ok().flatten(); assert!( stored_finalization.is_none(), "finalization should not be archived until matching block is available" @@ -2644,7 +2644,7 @@ mod tests { .await; let marshal2 = setup2.mailbox; - let post_restart = marshal2.get_block(&child_digest).await; + let post_restart = marshal2.get_block(&child_digest).await.ok().flatten(); assert!( post_restart.is_some(), "certify resolved true ⟹ block must be durably persisted" @@ -2760,7 +2760,7 @@ mod tests { // The proposer must recover its own block after restart. Without // the broadcast-path persistence fix, the block lived only in the // shards engine's in-memory cache and is now gone. - let post_restart = marshal2.get_block(&block_digest).await; + let post_restart = marshal2.get_block(&block_digest).await.ok().flatten(); assert!( post_restart.is_some(), "proposer should recover its own block after restart" @@ -2824,7 +2824,7 @@ mod tests { let coded_a: CodedBlock<_, ReedSolomon, Sha256> = CodedBlock::new(block_a.clone(), coding_config, &Sequential); let commitment_a = coded_a.commitment(); - assert!(marshal.verified(round, coded_a).await); + assert!(marshal.verified(round, coded_a).await.is_ok()); // After restart, a fresh application would build a different // block for the same round. @@ -2915,7 +2915,7 @@ mod tests { let stale_block = make_coding_block(stale_ctx, genesis.digest(), Height::new(1), 100); let stale_coded: CodedBlock<_, ReedSolomon, Sha256> = CodedBlock::new(stale_block, coding_config, &Sequential); - assert!(marshal.verified(round, stale_coded).await); + assert!(marshal.verified(round, stale_coded).await.is_ok()); // Simulate a replay where parent selection now points to a // different parent commitment than the cached block was built for. diff --git a/consensus/src/marshal/coding/shards/engine.rs b/consensus/src/marshal/coding/shards/engine.rs index 171852d8e4d..935ff4c6a96 100644 --- a/consensus/src/marshal/coding/shards/engine.rs +++ b/consensus/src/marshal/coding/shards/engine.rs @@ -439,7 +439,10 @@ where ); // Keep the handle alive to prevent the background receiver from being aborted. let _receiver_handle = receiver_service.start(); - let mut peer_set_subscription = self.peer_provider.subscribe().await; + let Ok(mut peer_set_subscription) = self.peer_provider.subscribe().await else { + debug!("peer set subscription failed"); + return; + }; select_loop! { self.context, @@ -2074,8 +2077,7 @@ mod tests { let reconstructed = peer .mailbox .get(commitment) - .await - .expect("block should be reconstructed"); + .await.ok().flatten().expect("block should be reconstructed"); assert_eq!(reconstructed.commitment(), commitment); assert_eq!(reconstructed.height(), coded_block.height()); } @@ -2122,8 +2124,7 @@ mod tests { let reconstructed = peer .mailbox .get(commitment) - .await - .expect("block should be reconstructed"); + .await.ok().flatten().expect("block should be reconstructed"); assert_eq!(reconstructed.commitment(), commitment); assert_eq!(reconstructed.height(), coded_block.height()); } @@ -2334,15 +2335,15 @@ mod tests { // Verify all blocks are in the cache. assert!( - peer.mailbox.get(commitment1).await.is_some(), + peer.mailbox.get(commitment1).await.ok().flatten().is_some(), "block1 should be cached" ); assert!( - peer.mailbox.get(commitment2).await.is_some(), + peer.mailbox.get(commitment2).await.ok().flatten().is_some(), "block2 should be cached" ); assert!( - peer.mailbox.get(commitment3).await.is_some(), + peer.mailbox.get(commitment3).await.ok().flatten().is_some(), "block3 should be cached" ); @@ -2352,17 +2353,17 @@ mod tests { // Blocks at heights 1 and 2 should be pruned. assert!( - peer.mailbox.get(commitment1).await.is_none(), + peer.mailbox.get(commitment1).await.ok().flatten().is_none(), "block1 should be pruned" ); assert!( - peer.mailbox.get(commitment2).await.is_none(), + peer.mailbox.get(commitment2).await.ok().flatten().is_none(), "block2 should be pruned" ); // Block at height 3 should still be cached. assert!( - peer.mailbox.get(commitment3).await.is_some(), + peer.mailbox.get(commitment3).await.ok().flatten().is_some(), "block3 should still be cached" ); }); @@ -3028,8 +3029,7 @@ mod tests { let reconstructed = peers[2] .mailbox .get(commitment_b) - .await - .expect("block B should reconstruct"); + .await.ok().flatten().expect("block B should reconstruct"); assert_eq!(reconstructed.commitment(), commitment_b); // A state should be pruned (at/below reconstructed view). Sending the same @@ -3102,7 +3102,7 @@ mod tests { peers[2].mailbox.proposed(round_b, block_b); assert!( - peers[2].mailbox.get(commitment_b).await.is_some(), + peers[2].mailbox.get(commitment_b).await.ok().flatten().is_some(), "local proposal should be cached before pruning" ); peers[2].mailbox.prune(commitment_b); @@ -3184,7 +3184,7 @@ mod tests { context.sleep(config.link.latency * 2).await; // Block should not be reconstructed yet (no leader shard verified). - let block = peers[3].mailbox.get(commitment).await; + let block = peers[3].mailbox.get(commitment).await.ok().flatten(); assert!(block.is_none(), "block should not be reconstructed yet"); // Now the leader (peer 0) sends peer 3's own-index shard. @@ -3207,7 +3207,7 @@ mod tests { ); // Block should now be reconstructed (4 checked shards >= minimum_shards). - let block = peers[3].mailbox.get(commitment).await; + let block = peers[3].mailbox.get(commitment).await.ok().flatten(); assert!( block.is_some(), "block should be reconstructed after batch validation" @@ -3276,7 +3276,7 @@ mod tests { "shard subscription should not resolve before leader announcement" ); assert!( - peers[receiver_idx].mailbox.get(commitment).await.is_none(), + peers[receiver_idx].mailbox.get(commitment).await.ok().flatten().is_none(), "block should not reconstruct before leader announcement" ); @@ -3296,7 +3296,7 @@ mod tests { context.sleep(config.link.latency * 2).await; assert!( - peers[receiver_idx].mailbox.get(commitment).await.is_some(), + peers[receiver_idx].mailbox.get(commitment).await.ok().flatten().is_some(), "block should reconstruct after buffered shards are ingested" ); @@ -3344,7 +3344,7 @@ mod tests { context.sleep(config.link.latency * 2).await; assert!( - peers[receiver_idx].mailbox.get(commitment).await.is_none(), + peers[receiver_idx].mailbox.get(commitment).await.ok().flatten().is_none(), "block should not reconstruct before the commitment is notarized" ); @@ -3360,8 +3360,7 @@ mod tests { let reconstructed = peers[receiver_idx] .mailbox .get(commitment) - .await - .expect("block should reconstruct from buffered peer shards"); + .await.ok().flatten().expect("block should reconstruct from buffered peer shards"); assert_eq!(reconstructed.commitment(), commitment); let mut assigned = peers[receiver_idx] @@ -3509,8 +3508,7 @@ mod tests { let reconstructed = peers[receiver_idx] .mailbox .get(commitment) - .await - .expect("block should reconstruct from post-leader shards"); + .await.ok().flatten().expect("block should reconstruct from post-leader shards"); assert_eq!(reconstructed.commitment(), commitment); assert!( @@ -3839,7 +3837,7 @@ mod tests { ) .await; assert!( - peers[receiver_idx].mailbox.get(commitment1).await.is_none(), + peers[receiver_idx].mailbox.get(commitment1).await.ok().flatten().is_none(), "block should not reconstruct with only 3 checked shards" ); @@ -3857,8 +3855,7 @@ mod tests { let reconstructed = peers[receiver_idx] .mailbox .get(commitment1) - .await - .expect("block should reconstruct after additional valid shard"); + .await.ok().flatten().expect("block should reconstruct after additional valid shard"); assert_eq!(reconstructed.commitment(), commitment1); }, ); @@ -4211,7 +4208,7 @@ mod tests { context.sleep(DEFAULT_LINK.latency * 3).await; - let reconstructed = receiver_mailbox.get(commitment).await; + let reconstructed = receiver_mailbox.get(commitment).await.ok().flatten(); assert!( reconstructed.is_some(), "receiver should reconstruct after broadcaster validates and broadcasts shard" @@ -4302,8 +4299,7 @@ mod tests { peers[receiver_idx] .mailbox .get(fake_commitment) - .await - .is_none(), + .await.ok().flatten().is_none(), "block should not be available after DigestMismatch" ); @@ -4349,8 +4345,7 @@ mod tests { let reconstructed = peers[receiver_idx] .mailbox .get(real_commitment1) - .await - .expect("valid block should reconstruct after prior failure"); + .await.ok().flatten().expect("valid block should reconstruct after prior failure"); assert_eq!(reconstructed.commitment(), real_commitment1); }, ); @@ -4423,8 +4418,7 @@ mod tests { peers[receiver_idx] .mailbox .get(fake_commitment) - .await - .is_none(), + .await.ok().flatten().is_none(), "block should not be available after ContextMismatch" ); assert!( @@ -4462,8 +4456,7 @@ mod tests { let reconstructed = peers[receiver_idx] .mailbox .get(real_commitment) - .await - .expect("valid block should reconstruct after prior context mismatch"); + .await.ok().flatten().expect("valid block should reconstruct after prior context mismatch"); assert_eq!(reconstructed.commitment(), real_commitment); }, ); @@ -4545,8 +4538,7 @@ mod tests { let reconstructed_a = peers[receiver_idx] .mailbox .get(commitment_a) - .await - .expect("conflicting commitment should reconstruct first"); + .await.ok().flatten().expect("conflicting commitment should reconstruct first"); assert_eq!(reconstructed_a.commitment(), commitment_a); // Commitment B should still be recoverable after A reconstructed. @@ -4693,8 +4685,7 @@ mod tests { let reconstructed = peer .mailbox .get(commitment) - .await - .expect("block should be reconstructed"); + .await.ok().flatten().expect("block should be reconstructed"); assert_eq!(reconstructed.commitment(), commitment); } @@ -4816,8 +4807,7 @@ mod tests { let reconstructed = np .mailbox .get(commitment) - .await - .expect("non-participant should reconstruct block"); + .await.ok().flatten().expect("non-participant should reconstruct block"); assert_eq!(reconstructed.commitment(), commitment); } @@ -5007,7 +4997,7 @@ mod tests { "shard subscription should not resolve after evicted leader's buffer" ); assert!( - mailbox.get(commitment).await.is_none(), + mailbox.get(commitment).await.ok().flatten().is_none(), "block should not reconstruct from evicted buffers" ); }); @@ -5214,7 +5204,7 @@ mod tests { "old-epoch shard subscription should stay pending after cutover" ); assert!( - mailbox.get(commitment).await.is_none(), + mailbox.get(commitment).await.ok().flatten().is_none(), "old-epoch commitment should not reconstruct from overlap-only buffered shards" ); }); @@ -5395,7 +5385,7 @@ mod tests { } context.sleep(DEFAULT_LINK.latency * 2).await; - let block = mailbox.get(commitment).await; + let block = mailbox.get(commitment).await.ok().flatten(); assert!( block.is_some(), "evicted node should reconstruct from buffered shards sent by remaining latest.primary peers" diff --git a/consensus/src/marshal/coding/shards/mailbox.rs b/consensus/src/marshal/coding/shards/mailbox.rs index e427d5ac3c3..03df887b653 100644 --- a/consensus/src/marshal/coding/shards/mailbox.rs +++ b/consensus/src/marshal/coding/shards/mailbox.rs @@ -242,22 +242,25 @@ where } /// Request a reconstructed block by its [`Commitment`]. - pub async fn get(&self, commitment: Commitment) -> Option> { + pub fn get(&self, commitment: Commitment) -> oneshot::Receiver>> { let (response, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::GetByCommitment { commitment, response, }); - receiver.await.ok().flatten() + receiver } /// Request a reconstructed block by its digest. - pub async fn get_by_digest(&self, digest: B::Digest) -> Option> { + pub fn get_by_digest( + &self, + digest: B::Digest, + ) -> oneshot::Receiver>> { let (response, receiver) = oneshot::channel(); let _ = self .sender .enqueue(Message::GetByDigest { digest, response }); - receiver.await.ok().flatten() + receiver } /// Subscribe to assigned shard verification for a commitment. diff --git a/consensus/src/marshal/coding/variant.rs b/consensus/src/marshal/coding/variant.rs index 67f604cc2a6..1794d0945b3 100644 --- a/consensus/src/marshal/coding/variant.rs +++ b/consensus/src/marshal/coding/variant.rs @@ -85,11 +85,11 @@ where &self, digest: as Digestible>::Digest, ) -> Option> { - self.get_by_digest(digest).await + self.get_by_digest(digest).await.ok().flatten() } async fn find_by_commitment(&self, commitment: Commitment) -> Option> { - self.get(commitment).await + self.get(commitment).await.ok().flatten() } fn subscribe_by_digest( diff --git a/consensus/src/marshal/conformance.rs b/consensus/src/marshal/conformance.rs index 970feda0af3..68558dcb216 100644 --- a/consensus/src/marshal/conformance.rs +++ b/consensus/src/marshal/conformance.rs @@ -114,7 +114,7 @@ async fn wait_processed( height: Height, ) { loop { - if setup.mailbox.get_processed_height().await == Some(height) { + if setup.mailbox.get_processed_height().await.ok().flatten() == Some(height) { break; } context.sleep(Duration::from_millis(1)).await; diff --git a/consensus/src/marshal/core/mailbox.rs b/consensus/src/marshal/core/mailbox.rs index deb2ba26799..bb4ece52344 100644 --- a/consensus/src/marshal/core/mailbox.rs +++ b/consensus/src/marshal/core/mailbox.rs @@ -558,51 +558,54 @@ impl Mailbox { } /// Retrieve `(height, digest)` for a finalized block by height, digest, or latest. - pub async fn get_info( + pub fn get_info( &self, identifier: impl Into::Digest>>, - ) -> Option<(Height, ::Digest)> { + ) -> oneshot::Receiver::Digest)>> { let identifier = identifier.into(); let (response, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::GetInfo { identifier, response, }); - receiver.await.ok().flatten() + receiver } /// A best-effort attempt to retrieve a given block from local /// storage. It is not an indication to go fetch the block from the network. - pub async fn get_block( + pub fn get_block( &self, identifier: impl Into::Digest>>, - ) -> Option { + ) -> oneshot::Receiver> { let identifier = identifier.into(); let (response, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::GetBlock { identifier, response, }); - receiver.await.ok().flatten() + receiver } /// A best-effort attempt to retrieve a given [Finalization] from local /// storage. It is not an indication to go fetch the [Finalization] from the network. - pub async fn get_finalization(&self, height: Height) -> Option> { + pub fn get_finalization( + &self, + height: Height, + ) -> oneshot::Receiver>> { let (response, receiver) = oneshot::channel(); let _ = self .sender .enqueue(Message::GetFinalization { height, response }); - receiver.await.ok().flatten() + receiver } /// Retrieve the latest processed height. - pub async fn get_processed_height(&self) -> Option { + pub fn get_processed_height(&self) -> oneshot::Receiver> { let (response, receiver) = oneshot::channel(); let _ = self .sender .enqueue(Message::GetProcessedHeight { response }); - receiver.await.ok().flatten() + receiver } /// Hints that a finalized block may be available at the given height. @@ -720,54 +723,54 @@ impl Mailbox { } /// Returns the verified block previously persisted for `round`, if any. - pub async fn get_verified(&self, round: Round) -> Option { + pub fn get_verified(&self, round: Round) -> oneshot::Receiver> { let (response, receiver) = oneshot::channel(); let _ = self .sender .enqueue(Message::GetVerified { round, response }); - receiver.await.ok().flatten() + receiver } /// Notifies the actor that a block has been locally proposed. /// /// Returns after the block is durably persisted. #[must_use = "callers must consider block durability before proceeding"] - pub async fn proposed(&self, round: Round, block: V::Block) -> bool { + pub fn proposed(&self, round: Round, block: V::Block) -> oneshot::Receiver<()> { let (ack, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::Proposed { round, block, ack: Some(ack), }); - receiver.await.is_ok() + receiver } /// Notifies the actor that a block has been verified. /// /// Returns after the block is durably persisted. #[must_use = "callers must consider block durability before proceeding"] - pub async fn verified(&self, round: Round, block: V::Block) -> bool { + pub fn verified(&self, round: Round, block: V::Block) -> oneshot::Receiver<()> { let (ack, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::Verified { round, block, ack: Some(ack), }); - receiver.await.is_ok() + receiver } /// Notifies the actor that a block has been certified. /// /// Returns after the block is durably persisted. #[must_use = "callers must consider block durability before proceeding"] - pub async fn certified(&self, round: Round, block: V::Block) -> bool { + pub fn certified(&self, round: Round, block: V::Block) -> oneshot::Receiver<()> { let (ack, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::Certified { round, block, ack: Some(ack), }); - receiver.await.is_ok() + receiver } /// Attempts to set the sync starting point from a finalized commitment. diff --git a/consensus/src/marshal/mocks/harness.rs b/consensus/src/marshal/mocks/harness.rs index 4146ba8b3f8..d27f13225d5 100644 --- a/consensus/src/marshal/mocks/harness.rs +++ b/consensus/src/marshal/mocks/harness.rs @@ -395,8 +395,8 @@ async fn wait_for_validator_height( label: &str, ) { loop { - let block = validator.handle.mailbox.get_block(height).await; - let finalization = validator.handle.mailbox.get_finalization(height).await; + let block = validator.handle.mailbox.get_block(height).await.ok().flatten(); + let finalization = validator.handle.mailbox.get_finalization(height).await.ok().flatten(); if let (Some(block), Some(finalization)) = (block, finalization) { assert_eq!( block.digest(), @@ -474,7 +474,7 @@ async fn assert_validator_matches_canonical( .handle .mailbox .get_block(*height) - .await + .await.ok().flatten() .unwrap_or_else(|| { panic!( "{label}: missing finalized block at height {}", @@ -492,7 +492,7 @@ async fn assert_validator_matches_canonical( .handle .mailbox .get_finalization(*height) - .await + .await.ok().flatten() .unwrap_or_else(|| panic!("{label}: missing finalization at height {}", height.get())); assert_eq!( stored_finalization.round(), @@ -510,7 +510,7 @@ async fn assert_validator_matches_canonical( if let Some((height, digest, _)) = canonical.last() { assert_eq!( - validator.handle.mailbox.get_info(Identifier::Latest).await, + validator.handle.mailbox.get_info(Identifier::Latest).await.ok().flatten(), Some((*height, *digest)), "{label}: latest info should match the canonical tip", ); @@ -984,7 +984,7 @@ pub fn proposed_success_implies_recoverable_after_restart( restarted .mailbox .get_verified(round) - .await + .await.ok().flatten() .unwrap_or_else(|| { panic!( "marshal.proposed() returning true must imply \ @@ -999,7 +999,7 @@ pub fn proposed_success_implies_recoverable_after_restart( (seed={seed}, cycle={cycle})" ); assert!( - restarted.mailbox.get_block(&digest).await.is_some(), + restarted.mailbox.get_block(&digest).await.ok().flatten().is_some(), "get_block(&digest) must also recover the proposed block \ (seed={seed}, cycle={cycle})" ); @@ -1094,7 +1094,7 @@ pub fn verified_success_implies_recoverable_after_restart( restarted .mailbox .get_verified(round) - .await + .await.ok().flatten() .unwrap_or_else(|| { panic!( "marshal.verified() returning true must imply \ @@ -1109,7 +1109,7 @@ pub fn verified_success_implies_recoverable_after_restart( (seed={seed}, cycle={cycle})" ); assert!( - restarted.mailbox.get_block(&digest).await.is_some(), + restarted.mailbox.get_block(&digest).await.ok().flatten().is_some(), "get_block(&digest) must also recover the verified block \ (seed={seed}, cycle={cycle})" ); @@ -1211,7 +1211,7 @@ pub fn certified_success_implies_recoverable_after_restart( restarted .mailbox .get_block(&digest) - .await + .await.ok().flatten() .unwrap_or_else(|| { panic!( "marshal.certified() returning true must imply \ @@ -1316,7 +1316,7 @@ pub fn certify_at_later_view_survives_earlier_view_pruning() { // Verify `orphan` at its own distinct view V=2 (no certify). H::verify(&mut handle, v_orphan, &orphan, &mut peers).await; assert!( - handle.mailbox.get_block(&orphan_digest).await.is_some(), + handle.mailbox.get_block(&orphan_digest).await.ok().flatten().is_some(), "negative control assumes `orphan` is present before pruning; \ if it is not, the V=2 write was dropped and the post-prune \ assertion would pass vacuously" @@ -1361,13 +1361,13 @@ pub fn certify_at_later_view_survives_earlier_view_pruning() { // proves retention pruning actually evicted the early-view entries at // the expected floor. assert!( - handle.mailbox.get_block(&orphan_digest).await.is_none(), + handle.mailbox.get_block(&orphan_digest).await.ok().flatten().is_none(), "verify-only block at V=2 must be evicted by retention pruning" ); // The repeated block must still be retrievable: verified_blocks[V=1] // has been pruned, but notarized_blocks[V=25] still holds it. - let recovered = handle.mailbox.get_block(&repeated_digest).await; + let recovered = handle.mailbox.get_block(&repeated_digest).await.ok().flatten(); assert!( recovered.is_some(), "block certified at V=25 must survive retention pruning of V=1" @@ -1439,13 +1439,13 @@ pub fn certify_persists_equivocated_block() { "certified must ack" ); - let got_a = handle.mailbox.get_block(&digest_a).await; + let got_a = handle.mailbox.get_block(&digest_a).await.ok().flatten(); assert!( got_a.is_some(), "verified block A must be persisted in verified_blocks" ); assert_eq!(got_a.unwrap().digest(), digest_a); - let got_b = handle.mailbox.get_block(&digest_b).await; + let got_b = handle.mailbox.get_block(&digest_b).await.ok().flatten(); assert!( got_b.is_some(), "certified block B must be persisted despite a verify at the same round" @@ -1559,7 +1559,7 @@ pub fn delivery_visibility_implies_recoverable_after_restart( provider.clone(), ) .await; - let recovered = restarted.mailbox.get_block(Height::new(1)).await.expect( + let recovered = restarted.mailbox.get_block(Height::new(1)).await.ok().flatten().expect( "delivered finalized block must be recoverable after restart \ (seed={seed}, cycle={cycle})", ); @@ -1573,7 +1573,7 @@ pub fn delivery_visibility_implies_recoverable_after_restart( restarted .mailbox .get_finalization(Height::new(1)) - .await + .await.ok().flatten() .expect( "delivered finalization must be recoverable after restart \ (seed={seed}, cycle={cycle})", @@ -1800,7 +1800,7 @@ impl TestHarness for StandardHarness { } async fn propose(handle: &mut ValidatorHandle, round: Round, block: &B) { - assert!(handle.mailbox.proposed(round, block.clone()).await); + assert!(handle.mailbox.proposed(round, block.clone()).await.is_ok()); } async fn verify( @@ -1809,11 +1809,11 @@ impl TestHarness for StandardHarness { block: &B, _all_handles: &mut [ValidatorHandle], ) { - assert!(handle.mailbox.verified(round, block.clone()).await); + assert!(handle.mailbox.verified(round, block.clone()).await.is_ok()); } async fn certify(handle: &mut ValidatorHandle, round: Round, block: &B) -> bool { - handle.mailbox.certified(round, block.clone()).await + handle.mailbox.certified(round, block.clone()).await.is_ok() } fn make_finalization(proposal: Proposal, schemes: &[S], quorum: u32) -> Finalization { @@ -1961,7 +1961,7 @@ impl TestHarness for StandardHarness { } async fn verify_for_prune(handle: &mut ValidatorHandle, round: Round, block: &B) { - assert!(handle.mailbox.verified(round, block.clone()).await); + assert!(handle.mailbox.verified(round, block.clone()).await.is_ok()); } } @@ -2649,7 +2649,7 @@ impl TestHarness for CodingHarness { round: Round, block: &CodedBlock, Sha256>, ) { - assert!(handle.mailbox.proposed(round, block.clone()).await); + assert!(handle.mailbox.proposed(round, block.clone()).await.is_ok()); } async fn verify( @@ -2658,7 +2658,7 @@ impl TestHarness for CodingHarness { block: &CodedBlock, Sha256>, _all_handles: &mut [ValidatorHandle], ) { - assert!(handle.mailbox.verified(round, block.clone()).await); + assert!(handle.mailbox.verified(round, block.clone()).await.is_ok()); } async fn certify( @@ -2666,7 +2666,7 @@ impl TestHarness for CodingHarness { round: Round, block: &CodedBlock, Sha256>, ) -> bool { - handle.mailbox.certified(round, block.clone()).await + handle.mailbox.certified(round, block.clone()).await.is_ok() } fn make_finalization( @@ -2831,7 +2831,7 @@ impl TestHarness for CodingHarness { round: Round, block: &CodedBlock, Sha256>, ) { - assert!(handle.mailbox.verified(round, block.clone()).await); + assert!(handle.mailbox.verified(round, block.clone()).await.is_ok()); } } @@ -3208,11 +3208,11 @@ pub fn genesis_emitted_once() { ) .await; assert_eq!(setup.height, None); - assert_eq!(setup.mailbox.get_processed_height().await, None); + assert_eq!(setup.mailbox.get_processed_height().await.ok().flatten(), None); assert_eq!(setup.application.acknowledged().await, Height::zero()); context.sleep(Duration::from_millis(10)).await; assert_eq!( - setup.mailbox.get_processed_height().await, + setup.mailbox.get_processed_height().await.ok().flatten(), Some(Height::zero()) ); assert!(setup.application.blocks().contains_key(&Height::zero())); @@ -3377,12 +3377,12 @@ pub fn sync_height_floor() { let latest_finalization = second_handle .mailbox .get_finalization(Height::new(NUM_BLOCKS)) - .await + .await.ok().flatten() .unwrap(); let floor_finalization = second_handle .mailbox .get_finalization(Height::new(NEW_SYNC_FLOOR)) - .await + .await.ok().flatten() .unwrap(); mailbox.set_floor(floor_finalization); @@ -3409,7 +3409,7 @@ pub fn sync_height_floor() { for height in 1..=NUM_BLOCKS { let block = mailbox .get_block(Identifier::Height(Height::new(height))) - .await; + .await.ok().flatten(); if height < NEW_SYNC_FLOOR { assert!(block.is_none()); } else { @@ -3502,11 +3502,11 @@ pub fn prune_finalized_archives() { for i in 1..=20u64 { assert!( - mailbox.get_block(Height::new(i)).await.is_some(), + mailbox.get_block(Height::new(i)).await.ok().flatten().is_some(), "block {i} should exist before pruning" ); assert!( - mailbox.get_finalization(Height::new(i)).await.is_some(), + mailbox.get_finalization(Height::new(i)).await.ok().flatten().is_some(), "finalization {i} should exist before pruning" ); } @@ -3515,7 +3515,7 @@ pub fn prune_finalized_archives() { context.sleep(Duration::from_millis(50)).await; for i in 1..=20u64 { assert!( - mailbox.get_block(Height::new(i)).await.is_some(), + mailbox.get_block(Height::new(i)).await.ok().flatten().is_some(), "block {i} should still exist after pruning above floor" ); } @@ -3524,22 +3524,22 @@ pub fn prune_finalized_archives() { context.sleep(Duration::from_millis(100)).await; for i in 1..10u64 { assert!( - mailbox.get_block(Height::new(i)).await.is_none(), + mailbox.get_block(Height::new(i)).await.ok().flatten().is_none(), "block {i} should be pruned" ); assert!( - mailbox.get_finalization(Height::new(i)).await.is_none(), + mailbox.get_finalization(Height::new(i)).await.ok().flatten().is_none(), "finalization {i} should be pruned" ); } for i in 10..=20u64 { assert!( - mailbox.get_block(Height::new(i)).await.is_some(), + mailbox.get_block(Height::new(i)).await.ok().flatten().is_some(), "block {i} should still exist after pruning" ); assert!( - mailbox.get_finalization(Height::new(i)).await.is_some(), + mailbox.get_finalization(Height::new(i)).await.ok().flatten().is_some(), "finalization {i} should still exist after pruning" ); } @@ -3548,21 +3548,21 @@ pub fn prune_finalized_archives() { context.sleep(Duration::from_millis(100)).await; for i in 10..20u64 { assert!( - mailbox.get_block(Height::new(i)).await.is_none(), + mailbox.get_block(Height::new(i)).await.ok().flatten().is_none(), "block {i} should be pruned after second prune" ); assert!( - mailbox.get_finalization(Height::new(i)).await.is_none(), + mailbox.get_finalization(Height::new(i)).await.ok().flatten().is_none(), "finalization {i} should be pruned after second prune" ); } assert!( - mailbox.get_block(Height::new(20)).await.is_some(), + mailbox.get_block(Height::new(20)).await.ok().flatten().is_some(), "block 20 should still exist" ); assert!( - mailbox.get_finalization(Height::new(20)).await.is_some(), + mailbox.get_finalization(Height::new(20)).await.ok().flatten().is_some(), "finalization 20 should still exist" ); @@ -3572,21 +3572,21 @@ pub fn prune_finalized_archives() { for i in 1..20u64 { assert!( - mailbox.get_block(Height::new(i)).await.is_none(), + mailbox.get_block(Height::new(i)).await.ok().flatten().is_none(), "block {i} should still be pruned after restart" ); assert!( - mailbox.get_finalization(Height::new(i)).await.is_none(), + mailbox.get_finalization(Height::new(i)).await.ok().flatten().is_none(), "finalization {i} should still be pruned after restart" ); } assert!( - mailbox.get_block(Height::new(20)).await.is_some(), + mailbox.get_block(Height::new(20)).await.ok().flatten().is_some(), "block 20 should still exist after restart" ); assert!( - mailbox.get_finalization(Height::new(20)).await.is_some(), + mailbox.get_finalization(Height::new(20)).await.ok().flatten().is_some(), "finalization 20 should still exist after restart" ); }) @@ -3718,7 +3718,7 @@ pub fn reject_stale_block_delivery_after_floor_update() { .await; // Barrier: mailbox messages are FIFO, so this confirms `set_floor` // has been processed before we re-enable the delayed delivery path. - let _ = victim_mailbox.get_finalization(floor).await; + let _ = victim_mailbox.get_finalization(floor).await.ok().flatten(); // Restore attacker -> victim traffic so delayed resolver responses can arrive. oracle @@ -3737,13 +3737,13 @@ pub fn reject_stale_block_delivery_after_floor_update() { ); assert!( - victim_mailbox.get_block(stale_height).await.is_none(), + victim_mailbox.get_block(stale_height).await.ok().flatten().is_none(), "stale block below floor must not be persisted" ); assert!( victim_mailbox .get_finalization(stale_height) - .await + .await.ok().flatten() .is_none(), "stale finalization below floor must not be persisted" ); @@ -3834,7 +3834,7 @@ pub fn commitment_fetch_height_hint_mismatch_wakes_subscriber() let cached = victim_handle .mailbox .get_block(&received.digest()) - .await + .await.ok().flatten() .expect("height-hint-mismatched fetch should cache by decoded height"); assert_eq!(cached.height(), actual_height); }); @@ -4344,22 +4344,22 @@ pub fn get_info_basic_queries_present_and_missing() { }; // Initially, no latest - assert!(handle.mailbox.get_info(Identifier::Latest).await.is_none()); + assert!(handle.mailbox.get_info(Identifier::Latest).await.ok().flatten().is_none()); // The genesis anchor is stored as a finalized block without a finalization row. let genesis = H::genesis_block(participants.len() as u16); let genesis_digest = H::digest(&genesis); assert_eq!( - handle.mailbox.get_info(Height::zero()).await, + handle.mailbox.get_info(Height::zero()).await.ok().flatten(), Some((Height::zero(), genesis_digest)) ); assert_eq!( - handle.mailbox.get_info(&genesis_digest).await, + handle.mailbox.get_info(&genesis_digest).await.ok().flatten(), Some((Height::zero(), genesis_digest)) ); // Before finalization, specific height returns None - assert!(handle.mailbox.get_info(Height::new(1)).await.is_none()); + assert!(handle.mailbox.get_info(Height::new(1)).await.ok().flatten().is_none()); // Create and verify a block, then finalize it let parent = Sha256::hash(b""); @@ -4388,28 +4388,28 @@ pub fn get_info_basic_queries_present_and_missing() { // Latest should now be the finalized block assert_eq!( - handle.mailbox.get_info(Identifier::Latest).await, + handle.mailbox.get_info(Identifier::Latest).await.ok().flatten(), Some((Height::new(1), digest)) ); // Height 1 now present assert_eq!( - handle.mailbox.get_info(Height::new(1)).await, + handle.mailbox.get_info(Height::new(1)).await.ok().flatten(), Some((Height::new(1), digest)) ); // Commitment should map to its height assert_eq!( - handle.mailbox.get_info(&digest).await, + handle.mailbox.get_info(&digest).await.ok().flatten(), Some((Height::new(1), digest)) ); // Missing height - assert!(handle.mailbox.get_info(Height::new(2)).await.is_none()); + assert!(handle.mailbox.get_info(Height::new(2)).await.ok().flatten().is_none()); // Missing commitment let missing = Sha256::hash(b"missing"); - assert!(handle.mailbox.get_info(&missing).await.is_none()); + assert!(handle.mailbox.get_info(&missing).await.ok().flatten().is_none()); }) } @@ -4471,7 +4471,7 @@ pub fn get_info_latest_progression_multiple_finalizations() { // Latest should always point to most recently finalized assert_eq!( - handle.mailbox.get_info(Identifier::Latest).await, + handle.mailbox.get_info(Identifier::Latest).await.ok().flatten(), Some((Height::new(i), digest)) ); @@ -4484,7 +4484,7 @@ pub fn get_info_latest_progression_multiple_finalizations() { for (i, digest) in digests.iter().enumerate() { let height = Height::new(i as u64 + 1); assert_eq!( - handle.mailbox.get_info(height).await, + handle.mailbox.get_info(height).await.ok().flatten(), Some((height, *digest)) ); } @@ -4524,9 +4524,9 @@ pub fn get_block_by_height_and_latest() { assert!(handle .mailbox .get_block(Identifier::Height(Height::new(1))) - .await + .await.ok().flatten() .is_none()); - assert!(handle.mailbox.get_block(Identifier::Latest).await.is_none()); + assert!(handle.mailbox.get_block(Identifier::Latest).await.ok().flatten().is_none()); let mut parent = Sha256::hash(b""); let mut parent_commitment = H::genesis_parent_commitment(participants.len() as u16); @@ -4566,14 +4566,14 @@ pub fn get_block_by_height_and_latest() { let fetched = handle .mailbox .get_block(Identifier::Height(height)) - .await + .await.ok().flatten() .unwrap(); assert_eq!(fetched.digest(), *digest); assert_eq!(fetched.height(), height); } // Latest should be last block - let latest = handle.mailbox.get_block(Identifier::Latest).await.unwrap(); + let latest = handle.mailbox.get_block(Identifier::Latest).await.ok().flatten().unwrap(); assert_eq!(latest.digest(), blocks[2].0); assert_eq!(latest.height(), Height::new(3)); @@ -4581,7 +4581,7 @@ pub fn get_block_by_height_and_latest() { assert!(handle .mailbox .get_block(Identifier::Height(Height::new(10))) - .await + .await.ok().flatten() .is_none()); }) } @@ -4641,13 +4641,13 @@ pub fn get_block_by_commitment_from_sources_and_missing() { H::report_finalization(&mut handle.mailbox, finalization).await; // Get by commitment - let fetched = handle.mailbox.get_block(&digest).await.unwrap(); + let fetched = handle.mailbox.get_block(&digest).await.ok().flatten().unwrap(); assert_eq!(fetched.digest(), digest); assert_eq!(fetched.height(), Height::new(1)); // Missing commitment let missing = Sha256::hash(b"missing"); - assert!(handle.mailbox.get_block(&missing).await.is_none()); + assert!(handle.mailbox.get_block(&missing).await.ok().flatten().is_none()); }) } @@ -4684,7 +4684,7 @@ pub fn get_finalization_by_height() { assert!(handle .mailbox .get_finalization(Height::new(1)) - .await + .await.ok().flatten() .is_none()); let mut parent = Sha256::hash(b""); @@ -4717,7 +4717,7 @@ pub fn get_finalization_by_height() { let fin = handle .mailbox .get_finalization(Height::new(i)) - .await + .await.ok().flatten() .unwrap(); assert_eq!(fin.proposal.payload, commitment); assert_eq!(fin.round().view(), View::new(i)); @@ -4730,7 +4730,7 @@ pub fn get_finalization_by_height() { assert!(handle .mailbox .get_finalization(Height::new(10)) - .await + .await.ok().flatten() .is_none()); }) } @@ -4823,7 +4823,7 @@ pub fn hint_finalized_triggers_fetch() { assert!(handle1 .mailbox .get_finalization(Height::new(5)) - .await + .await.ok().flatten() .is_none()); // Validator 1: hint that block 5 is finalized, targeting validator 0 @@ -4835,7 +4835,7 @@ pub fn hint_finalized_triggers_fetch() { while handle1 .mailbox .get_finalization(Height::new(5)) - .await + .await.ok().flatten() .is_none() { context.sleep(Duration::from_millis(10)).await; @@ -4845,7 +4845,7 @@ pub fn hint_finalized_triggers_fetch() { let finalization = handle1 .mailbox .get_finalization(Height::new(5)) - .await + .await.ok().flatten() .expect("finalization should be fetched"); assert_eq!(finalization.proposal.round.view(), View::new(5)); }) @@ -4914,7 +4914,7 @@ where } // Stream from latest -> height 1 - let (_, commitment) = handle.mailbox.get_info(Identifier::Latest).await.unwrap(); + let (_, commitment) = handle.mailbox.get_info(Identifier::Latest).await.ok().flatten().unwrap(); let fetch_duration = Timed::new(context.histogram( "ancestor_fetch_duration", "Histogram of time taken to fetch a block via the ancestry stream, in seconds", @@ -5016,8 +5016,8 @@ pub fn finalize_same_height_different_views() { context.sleep(Duration::from_millis(100)).await; // Verify both validators stored the block correctly - let block0 = handles[0].mailbox.get_block(Height::new(1)).await.unwrap(); - let block1 = handles[1].mailbox.get_block(Height::new(1)).await.unwrap(); + let block0 = handles[0].mailbox.get_block(Height::new(1)).await.ok().flatten().unwrap(); + let block1 = handles[1].mailbox.get_block(Height::new(1)).await.ok().flatten().unwrap(); assert_eq!(block0.digest(), digest); assert_eq!(block1.digest(), digest); @@ -5025,12 +5025,12 @@ pub fn finalize_same_height_different_views() { let fin0 = handles[0] .mailbox .get_finalization(Height::new(1)) - .await + .await.ok().flatten() .unwrap(); let fin1 = handles[1] .mailbox .get_finalization(Height::new(1)) - .await + .await.ok().flatten() .unwrap(); // Verify the finalizations have the expected different views @@ -5041,11 +5041,11 @@ pub fn finalize_same_height_different_views() { // Both validators can retrieve block by height assert_eq!( - handles[0].mailbox.get_info(Height::new(1)).await, + handles[0].mailbox.get_info(Height::new(1)).await.ok().flatten(), Some((Height::new(1), digest)) ); assert_eq!( - handles[1].mailbox.get_info(Height::new(1)).await, + handles[1].mailbox.get_info(Height::new(1)).await.ok().flatten(), Some((Height::new(1), digest)) ); @@ -5058,7 +5058,7 @@ pub fn finalize_same_height_different_views() { let fin0_after = handles[0] .mailbox .get_finalization(Height::new(1)) - .await + .await.ok().flatten() .unwrap(); assert_eq!(fin0_after.round().view(), View::new(1)); @@ -5066,7 +5066,7 @@ pub fn finalize_same_height_different_views() { let fin1_after = handles[1] .mailbox .get_finalization(Height::new(1)) - .await + .await.ok().flatten() .unwrap(); assert_eq!(fin1_after.round().view(), View::new(2)); }) @@ -5213,7 +5213,7 @@ pub fn broadcast_caches_block() { handle .mailbox .get_block(&digest) - .await + .await.ok().flatten() .expect("block should be cached after broadcast"); // Restart marshal, removing any in-memory cache @@ -5248,7 +5248,7 @@ pub fn broadcast_caches_block() { handle2 .mailbox .get_block(&digest) - .await + .await.ok().flatten() .expect("block should be cached after broadcast"); }) } diff --git a/consensus/src/marshal/standard/deferred.rs b/consensus/src/marshal/standard/deferred.rs index 5edc0caf69c..48848048804 100644 --- a/consensus/src/marshal/standard/deferred.rs +++ b/consensus/src/marshal/standard/deferred.rs @@ -348,7 +348,7 @@ where // Certifier holds a notarization for this block, so route // the write to the notarized cache. `certified` is // idempotent, so crash-recovery double-invocation is safe. - if !marshaled.marshal.certified(round, block).await { + if marshaled.marshal.certified(round, block).await.is_err() { debug!(?round, "marshal unable to accept block"); return; } @@ -483,7 +483,7 @@ where // cached block was built against a different parent and cannot be // broadcast under the current header, so drop the receiver // and let the voter nullify the view via timeout. - if let Some(block) = marshal.get_verified(consensus_context.round).await { + if let Some(block) = marshal.get_verified(consensus_context.round).await.ok().flatten() { let block_context = block.context(); if block_context != consensus_context { debug!( @@ -549,7 +549,11 @@ where .expect("current epoch should exist"); if parent.height() == last_in_epoch { let digest = parent.digest(); - if !marshal.verified(consensus_context.round, parent).await { + if marshal + .verified(consensus_context.round, parent) + .await + .is_err() + { debug!( round = ?consensus_context.round, ?digest, @@ -601,7 +605,11 @@ where build_timer.observe(&runtime_context); let digest = built_block.digest(); - if !marshal.proposed(consensus_context.round, built_block).await { + if marshal + .proposed(consensus_context.round, built_block) + .await + .is_err() + { debug!( round = ?consensus_context.round, ?digest, @@ -860,7 +868,7 @@ mod tests { assert!( marshal .verified(Round::new(Epoch::new(0), View::new(1)), parent.clone()) - .await + .await.is_ok() ); // Block A at view 5 (height 2) @@ -872,7 +880,7 @@ mod tests { }; let block_a = B::new::(context_a.clone(), parent_digest, Height::new(2), 200); let commitment_a = StandardHarness::commitment(&block_a); - assert!(marshal.verified(round_a, block_a.clone()).await); + assert!(marshal.verified(round_a, block_a.clone()).await.is_ok()); // Block B at view 10 (height 2, different block same height) let round_b = Round::new(Epoch::new(0), View::new(10)); @@ -883,7 +891,7 @@ mod tests { }; let block_b = B::new::(context_b.clone(), parent_digest, Height::new(2), 300); let commitment_b = StandardHarness::commitment(&block_b); - assert!(marshal.verified(round_b, block_b.clone()).await); + assert!(marshal.verified(round_b, block_b.clone()).await.is_ok()); context.sleep(Duration::from_millis(10)).await; @@ -1001,7 +1009,7 @@ mod tests { marshal .clone() .verified(Round::new(Epoch::zero(), View::new(19)), parent.clone()) - .await + .await.is_ok() ); // Create a block at height 20 (first block in epoch 1, which is NOT supported) @@ -1022,7 +1030,7 @@ mod tests { marshal .clone() .verified(unsupported_round, block.clone()) - .await + .await.is_ok() ); context.sleep(Duration::from_millis(10)).await; @@ -1097,7 +1105,7 @@ mod tests { marshal .clone() .verified(Round::new(Epoch::zero(), View::new(1)), parent.clone()) - .await + .await.is_ok() ); // Build a block with context A (embedded in the block). @@ -1109,7 +1117,7 @@ mod tests { }; let block_a = B::new::(context_a, parent.digest(), Height::new(2), 200); let commitment_a = StandardHarness::commitment(&block_a); - assert!(marshal.verified(round_a, block_a).await); + assert!(marshal.verified(round_a, block_a).await.is_ok()); context.sleep(Duration::from_millis(10)).await; @@ -1191,7 +1199,7 @@ mod tests { // block subscription is still pending. context.sleep(Duration::from_millis(10)).await; - assert!(marshal.proposed(round, block).await); + assert!(marshal.proposed(round, block).await.is_ok()); let certify_rx = marshaled.certify(round, digest).await; select! { result = certify_rx => { @@ -1360,7 +1368,7 @@ mod tests { }; let block_a = B::new::(ctx.clone(), genesis.digest(), Height::new(1), 100); let digest_a = block_a.digest(); - assert!(marshal.verified(round, block_a.clone()).await); + assert!(marshal.verified(round, block_a.clone()).await.is_ok()); let block_b = B::new::(ctx.clone(), genesis.digest(), Height::new(1), 200); let digest_b = block_b.digest(); @@ -1428,7 +1436,7 @@ mod tests { parent: (View::zero(), genesis.digest()), }; let stale_block = B::new::(stale_ctx, genesis.digest(), Height::new(1), 100); - assert!(marshal.verified(round, stale_block).await); + assert!(marshal.verified(round, stale_block).await.is_ok()); // Simulate a replay where parent selection now points to a // different parent view than the cached block was built for. diff --git a/consensus/src/marshal/standard/inline.rs b/consensus/src/marshal/standard/inline.rs index b2bcc9ad655..1e8b9269abc 100644 --- a/consensus/src/marshal/standard/inline.rs +++ b/consensus/src/marshal/standard/inline.rs @@ -262,6 +262,8 @@ where if marshal .get_verified(consensus_context.round) .await + .ok() + .flatten() .is_some() { debug!( @@ -313,7 +315,11 @@ where .expect("current epoch should exist"); if parent.height() == last_in_epoch { let digest = parent.digest(); - if !marshal.verified(consensus_context.round, parent).await { + if marshal + .verified(consensus_context.round, parent) + .await + .is_err() + { debug!( round = ?consensus_context.round, ?digest, @@ -365,7 +371,11 @@ where build_timer.observe(&runtime_context); let digest = built_block.digest(); - if !marshal.proposed(consensus_context.round, built_block).await { + if marshal + .proposed(consensus_context.round, built_block) + .await + .is_err() + { debug!( round = ?consensus_context.round, ?digest, @@ -529,7 +539,7 @@ where // block through marshal before signaling success. The caller // holds a notarization for this block, so route it into the // notarized cache directly rather than the verified cache. - if marshal.certified(round, block).await { + if marshal.certified(round, block).await.is_ok() { tx.send_lossy(true); } }); @@ -674,7 +684,7 @@ mod tests { }; let parent = B::new::(parent_ctx, genesis.digest(), Height::new(1), 100); let parent_digest = parent.digest(); - assert!(marshal.verified(parent_round, parent).await); + assert!(marshal.verified(parent_round, parent).await.is_ok()); let round = Round::new(Epoch::zero(), View::new(2)); let verify_context = Ctx { @@ -685,7 +695,7 @@ mod tests { let block = B::new::(verify_context.clone(), parent_digest, Height::new(2), 200); let digest = block.digest(); - assert!(marshal.verified(round, block).await); + assert!(marshal.verified(round, block).await.is_ok()); // Complete verify first so the block is already available locally. let verify_rx = inline.verify(verify_context, digest).await; @@ -755,7 +765,7 @@ mod tests { }; let parent = B::new::(parent_ctx, genesis.digest(), Height::new(1), 100); let parent_digest = parent.digest(); - assert!(marshal.verified(parent_round, parent).await); + assert!(marshal.verified(parent_round, parent).await.is_ok()); let round = Round::new(Epoch::zero(), View::new(2)); let verify_context = Ctx { @@ -766,7 +776,7 @@ mod tests { let block = B::new::(verify_context.clone(), parent_digest, Height::new(2), 200); let digest = block.digest(); - assert!(marshal.verified(round, block).await); + assert!(marshal.verified(round, block).await.is_ok()); // Certify should still resolve by waiting on marshal block availability directly. let certify_rx = inline.certify(round, digest).await; @@ -830,7 +840,7 @@ mod tests { 1900, ); let boundary_digest = boundary_block.digest(); - assert!(marshal.verified(boundary_round, boundary_block).await); + assert!(marshal.verified(boundary_round, boundary_block).await.is_ok()); let reproposal_round = Round::new(Epoch::zero(), View::new(boundary_height.get() + 1)); let reproposal_context = Ctx { @@ -982,7 +992,7 @@ mod tests { .await; let marshal2 = setup2.mailbox; - let post_restart = marshal2.get_block(&child_digest).await; + let post_restart = marshal2.get_block(&child_digest).await.ok().flatten(); assert!( post_restart.is_some(), "verify resolved true so block must be durably persisted (seed={seed})" @@ -1091,7 +1101,7 @@ mod tests { .await; let marshal2 = setup2.mailbox; - let post_restart = marshal2.get_block(&child_digest).await; + let post_restart = marshal2.get_block(&child_digest).await.ok().flatten(); assert!( post_restart.is_some(), "certify resolved true so block must be durably persisted (seed={seed})" @@ -1214,7 +1224,7 @@ mod tests { .await; let marshal2 = setup2.mailbox; - let post_restart = marshal2.get_block(&child_digest).await; + let post_restart = marshal2.get_block(&child_digest).await.ok().flatten(); assert!( post_restart.is_none(), "failed marshal.verified ack must not leave a durably recoverable block" @@ -1272,7 +1282,7 @@ mod tests { let pre_application = pre_setup.application; let stale_block = B::new::(ctx.clone(), genesis.digest(), Height::new(1), 100); - assert!(pre_marshal.verified(round, stale_block).await); + assert!(pre_marshal.verified(round, stale_block).await.is_ok()); // Simulate a crash: abort the actor and drop every handle so the // storage partition is fully released before reopening. diff --git a/consensus/src/marshal/standard/mod.rs b/consensus/src/marshal/standard/mod.rs index 53bcf3c88b8..7fb76bb1a3d 100644 --- a/consensus/src/marshal/standard/mod.rs +++ b/consensus/src/marshal/standard/mod.rs @@ -566,12 +566,12 @@ mod tests { assert!( peer_mailbox .verified(Round::new(Epoch::zero(), View::new(1)), block_one.clone()) - .await + .await.is_ok() ); assert!( peer_mailbox .verified(Round::new(Epoch::zero(), View::new(2)), block_two.clone()) - .await + .await.is_ok() ); StandardHarness::report_finalization(&mut peer_mailbox, finalization_two.clone()).await; context.sleep(Duration::from_millis(200)).await; @@ -667,17 +667,17 @@ mod tests { assert!( peer_mailbox .verified(Round::new(Epoch::zero(), View::new(1)), block_one.clone()) - .await + .await.is_ok() ); assert!( peer_mailbox .verified(Round::new(Epoch::zero(), View::new(2)), block_two.clone()) - .await + .await.is_ok() ); assert!( peer_mailbox .verified(Round::new(Epoch::zero(), View::new(3)), block_three.clone()) - .await + .await.is_ok() ); StandardHarness::report_finalization(&mut peer_mailbox, finalization_two.clone()).await; StandardHarness::report_finalization(&mut peer_mailbox, finalization_three.clone()) @@ -780,17 +780,17 @@ mod tests { // The tip tracks the highest finalization, not the highest block. assert_eq!( - recovering.mailbox.get_info(Identifier::Latest).await, + recovering.mailbox.get_info(Identifier::Latest).await.ok().flatten(), Some((Height::new(1), block_one.digest())), "latest tip should be derived from the highest stored finalization" ); assert_eq!( - recovering.mailbox.get_block(Height::new(2)).await, + recovering.mailbox.get_block(Height::new(2)).await.ok().flatten(), Some(block_two.clone()), "block without a finalization row should still be queryable by height" ); assert_eq!( - recovering.mailbox.get_info(Height::new(2)).await, + recovering.mailbox.get_info(Height::new(2)).await.ok().flatten(), Some((Height::new(2), block_two.digest())), "block info should fall back to the finalized-block archive" ); @@ -879,7 +879,7 @@ mod tests { Round::new(Epoch::zero(), View::new(block.height().get())), (*block).clone(), ) - .await + .await.is_ok() ); StandardHarness::report_finalization(&mut peer_mailbox, finalizations[i].clone()) .await; @@ -982,7 +982,7 @@ mod tests { Round::new(Epoch::zero(), View::new(block.height().get())), block.clone(), ) - .await + .await.is_ok() ); } context.sleep(Duration::from_millis(200)).await; @@ -1030,7 +1030,7 @@ mod tests { let block = recovering .mailbox .get_block(Height::new(height)) - .await + .await.ok().flatten() .unwrap_or_else(|| panic!("block {height} should be recoverable")); assert_eq!(block.digest(), blocks[(height - 1) as usize].digest()); } @@ -1410,7 +1410,7 @@ mod tests { let block = B::new::(block_context.clone(), genesis.digest(), Height::new(1), 100); let digest = block.digest(); - assert!(marshal.verified(round, block).await); + assert!(marshal.verified(round, block).await.is_ok()); context.sleep(Duration::from_millis(10)).await; @@ -1810,7 +1810,7 @@ mod tests { let child = B::new::(child_context.clone(), parent_digest, Height::new(3), 200); let child_digest = child.digest(); - assert!(marshal.verified(child_round, child).await); + assert!(marshal.verified(child_round, child).await.is_ok()); let verify = wrapper.verify(child_context, child_digest).await; wait_until( @@ -1845,7 +1845,7 @@ mod tests { "{kind:?}: malicious child height must not drive parent fetches" ); - assert!(marshal.verified(parent_round, parent).await); + assert!(marshal.verified(parent_round, parent).await.is_ok()); let verify_result = verify.await.expect("verify result missing"); if kind == WrapperKind::Inline { assert!( @@ -1930,10 +1930,10 @@ mod tests { let parent_proposal = Proposal::new(parent_round, View::zero(), parent_digest); let parent_notarization = StandardHarness::make_notarization(parent_proposal, &schemes, QUORUM); - assert!(honest_mailbox.verified(parent_round, parent.clone()).await); + assert!(honest_mailbox.verified(parent_round, parent.clone()).await.is_ok()); StandardHarness::report_notarization(&mut honest_mailbox, parent_notarization) .await; - assert!(honest_mailbox.get_block(&parent_digest).await.is_some()); + assert!(honest_mailbox.get_block(&parent_digest).await.ok().flatten().is_some()); let malicious_backfill = oracle .control(malicious.clone()) @@ -1972,7 +1972,7 @@ mod tests { let child = B::new::(child_context.clone(), parent_digest, Height::new(2), 200); let child_digest = child.digest(); - assert!(victim_mailbox.verified(child_round, child).await); + assert!(victim_mailbox.verified(child_round, child).await.is_ok()); let mock_app: MockVerifyingApp = MockVerifyingApp::new(); let mut wrapper = Wrapper::new( @@ -2117,7 +2117,7 @@ mod tests { marshal .clone() .verified(boundary_round, boundary_block.clone()) - .await + .await.is_ok() ); context.sleep(Duration::from_millis(10)).await; @@ -2190,7 +2190,7 @@ mod tests { marshal .clone() .verified(boundary_round, boundary_block) - .await + .await.is_ok() ); context.sleep(Duration::from_millis(10)).await; @@ -2229,7 +2229,7 @@ mod tests { marshal .clone() .verified(non_boundary_round, non_boundary_block) - .await + .await.is_ok() ); context.sleep(Duration::from_millis(10)).await; @@ -2335,7 +2335,7 @@ mod tests { marshal .clone() .verified(malformed_round, malformed_block) - .await + .await.is_ok() ); context.sleep(Duration::from_millis(10)).await; @@ -2374,7 +2374,7 @@ mod tests { let parent = B::new::(parent_context, genesis.digest(), Height::new(1), 300); let parent_digest = parent.digest(); - assert!(marshal.verified(parent_round, parent).await); + assert!(marshal.verified(parent_round, parent).await.is_ok()); let mismatch_round = Round::new(Epoch::zero(), View::new(3)); let mismatched_context = Ctx { @@ -2393,7 +2393,7 @@ mod tests { marshal .clone() .verified(mismatch_round, mismatched_block) - .await + .await.is_ok() ); context.sleep(Duration::from_millis(10)).await; @@ -2466,7 +2466,7 @@ mod tests { }; let parent = B::new::(parent_context, genesis.digest(), Height::new(1), 100); let parent_digest = parent.digest(); - assert!(marshal.verified(parent_round, parent).await); + assert!(marshal.verified(parent_round, parent).await.is_ok()); // 2) Publish a valid child; only application-level verification should fail. let round = Round::new(Epoch::zero(), View::new(2)); @@ -2477,7 +2477,7 @@ mod tests { }; let block = B::new::(verify_context.clone(), parent_digest, Height::new(2), 200); let digest = block.digest(); - assert!(marshal.verified(round, block).await); + assert!(marshal.verified(round, block).await.is_ok()); context.sleep(Duration::from_millis(10)).await; @@ -2981,14 +2981,14 @@ mod tests { let stored_genesis = mailbox .get_block(Identifier::Height(Height::zero())) - .await + .await.ok().flatten() .expect("genesis should be available without a buffer"); assert_eq!(stored_genesis.digest(), genesis.digest()); let round = Round::new(Epoch::zero(), View::new(1)); let block = make_raw_block(genesis.digest(), Height::new(1), 100); let digest = block.digest(); - assert!(mailbox.verified(round, block).await); + assert!(mailbox.verified(round, block).await.is_ok()); mailbox.forward( round, digest, @@ -2996,7 +2996,7 @@ mod tests { ); let verified = mailbox .get_verified(round) - .await + .await.ok().flatten() .expect("verified block should remain available without a buffer"); assert_eq!(verified.digest(), digest); }); @@ -3123,7 +3123,7 @@ mod tests { let served = make_raw_block(Sha256::hash(b"served-parent"), Height::new(1), 100); let served_round = Round::new(Epoch::zero(), View::new(1)); - assert!(mailbox.verified(served_round, served.clone()).await); + assert!(mailbox.verified(served_round, served.clone()).await.is_ok()); let (response, response_rx) = oneshot::channel(); resolver.enqueue(handler::Message::Produce { key: handler::Key::Block(StandardHarness::commitment(&served)), @@ -3133,7 +3133,7 @@ mod tests { let next = make_raw_block(floor_block.digest(), Height::new(6), 600); let next_round = Round::new(Epoch::zero(), View::new(6)); - assert!(mailbox.verified(next_round, next.clone()).await); + assert!(mailbox.verified(next_round, next.clone()).await.is_ok()); let next_finalization = StandardHarness::make_finalization( Proposal::new(next_round, View::new(5), StandardHarness::commitment(&next)), &schemes, @@ -3144,7 +3144,7 @@ mod tests { context.sleep(Duration::from_millis(100)).await; assert!(matches!(started_rx.try_recv(), Err(TryRecvError::Empty))); - assert!(mailbox.verified(floor_round, floor_block).await); + assert!(mailbox.verified(floor_round, floor_block).await.is_ok()); assert_eq!(started_rx.await.unwrap(), Height::new(5)); }); } @@ -3195,13 +3195,13 @@ mod tests { "local startup floor anchor must not be fetched" ); assert_eq!( - mailbox.get_block(Height::new(5)).await.unwrap().digest(), + mailbox.get_block(Height::new(5)).await.ok().flatten().unwrap().digest(), floor_block.digest() ); let next = make_raw_block(floor_block.digest(), Height::new(6), 600); let next_round = Round::new(Epoch::zero(), View::new(6)); - assert!(mailbox.verified(next_round, next.clone()).await); + assert!(mailbox.verified(next_round, next.clone()).await.is_ok()); let next_finalization = StandardHarness::make_finalization( Proposal::new(next_round, View::new(5), StandardHarness::commitment(&next)), &schemes, @@ -3320,7 +3320,7 @@ mod tests { let next = make_raw_block(floor_block.digest(), Height::new(6), 600); let next_round = Round::new(Epoch::zero(), View::new(6)); - assert!(mailbox.verified(next_round, next.clone()).await); + assert!(mailbox.verified(next_round, next.clone()).await.is_ok()); let next_finalization = StandardHarness::make_finalization( Proposal::new(next_round, View::new(5), StandardHarness::commitment(&next)), &schemes, @@ -3392,7 +3392,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block1_round, block1.clone()).await); + assert!(mailbox.verified(block1_round, block1.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block1_finalization).await; wait_until( &context, @@ -3433,11 +3433,11 @@ mod tests { ) .await; - assert!(mailbox.verified(floor_round, floor_block.clone()).await); + assert!(mailbox.verified(floor_round, floor_block.clone()).await.is_ok()); assert_eq!( mailbox .get_block(Height::new(5)) - .await + .await.ok().flatten() .expect("floor block missing") .digest(), floor_block.digest() @@ -3455,7 +3455,7 @@ mod tests { height: Height::new(2), }, ); - let _ = mailbox.get_block(Height::new(5)).await; + let _ = mailbox.get_block(Height::new(5)).await.ok().flatten(); assert_eq!( resolver.fetches().len(), fetches_after_floor, @@ -3496,7 +3496,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block1_round, block1).await); + assert!(mailbox.verified(block1_round, block1).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block1_finalization).await; wait_until( &context, @@ -3526,7 +3526,7 @@ mod tests { assert_eq!( mailbox .get_block(Height::new(5)) - .await + .await.ok().flatten() .expect("floor block missing") .digest(), floor_block.digest() @@ -3548,7 +3548,7 @@ mod tests { height: Height::new(2), }, ); - let _ = mailbox.get_block(Height::new(5)).await; + let _ = mailbox.get_block(Height::new(5)).await.ok().flatten(); assert_eq!( resolver.fetches().len(), fetches_after_floor, @@ -3607,7 +3607,7 @@ mod tests { let missing = make_raw_block(floor_block.digest(), Height::new(6), 600); let later = make_raw_block(missing.digest(), Height::new(7), 700); let later_round = Round::new(Epoch::zero(), View::new(7)); - assert!(mailbox.verified(later_round, later.clone()).await); + assert!(mailbox.verified(later_round, later.clone()).await.is_ok()); let later_finalization = StandardHarness::make_finalization( Proposal::new( later_round, @@ -3618,7 +3618,7 @@ mod tests { QUORUM, ); StandardHarness::report_finalization(&mut mailbox, later_finalization).await; - assert!(mailbox.get_finalization(Height::new(7)).await.is_some()); + assert!(mailbox.get_finalization(Height::new(7)).await.ok().flatten().is_some()); assert!( resolver.fetches().iter().all(|fetch| { !matches!( @@ -3632,7 +3632,7 @@ mod tests { "gap repair must wait until the floor anchor is resolved" ); - assert!(mailbox.verified(floor_round, floor_block).await); + assert!(mailbox.verified(floor_round, floor_block).await.is_ok()); wait_until( &context, Duration::from_secs(5), @@ -3722,7 +3722,7 @@ mod tests { ) .await; - assert!(mailbox.verified(floor_round, floor_block).await); + assert!(mailbox.verified(floor_round, floor_block).await.is_ok()); wait_until( &context, Duration::from_secs(5), @@ -3820,7 +3820,7 @@ mod tests { let old_next_round = Round::new(Epoch::zero(), View::new(6)); let old_next = make_raw_block(old_floor_block.digest(), Height::new(6), 600); - assert!(mailbox.verified(old_next_round, old_next.clone()).await); + assert!(mailbox.verified(old_next_round, old_next.clone()).await.is_ok()); let old_next_finalization = StandardHarness::make_finalization( Proposal::new( old_next_round, @@ -3831,11 +3831,11 @@ mod tests { QUORUM, ); StandardHarness::report_finalization(&mut mailbox, old_next_finalization).await; - assert!(mailbox.get_finalization(Height::new(6)).await.is_some()); + assert!(mailbox.get_finalization(Height::new(6)).await.ok().flatten().is_some()); let new_next_round = Round::new(Epoch::zero(), View::new(8)); let new_next = make_raw_block(new_floor_block.digest(), Height::new(8), 800); - assert!(mailbox.verified(new_next_round, new_next.clone()).await); + assert!(mailbox.verified(new_next_round, new_next.clone()).await.is_ok()); let new_next_finalization = StandardHarness::make_finalization( Proposal::new( new_next_round, @@ -3846,7 +3846,7 @@ mod tests { QUORUM, ); StandardHarness::report_finalization(&mut mailbox, new_next_finalization).await; - assert!(mailbox.get_finalization(Height::new(8)).await.is_some()); + assert!(mailbox.get_finalization(Height::new(8)).await.ok().flatten().is_some()); let old_floor_fetch = resolver .fetches() @@ -3959,7 +3959,7 @@ mod tests { let next = make_raw_block(floor_block.digest(), Height::new(6), 600); let next_round = Round::new(Epoch::zero(), View::new(6)); - assert!(mailbox.verified(next_round, next.clone()).await); + assert!(mailbox.verified(next_round, next.clone()).await.is_ok()); let next_finalization = StandardHarness::make_finalization( Proposal::new(next_round, View::new(5), StandardHarness::commitment(&next)), &schemes, @@ -4008,7 +4008,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block1_round, block1.clone()).await); + assert!(mailbox.verified(block1_round, block1.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block1_finalization).await; wait_until( &context, @@ -4062,9 +4062,9 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block2_round, block2).await); + assert!(mailbox.verified(block2_round, block2).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block2_finalization).await; - assert!(mailbox.get_finalization(Height::new(2)).await.is_some()); + assert!(mailbox.get_finalization(Height::new(2)).await.ok().flatten().is_some()); context.sleep(Duration::from_millis(100)).await; assert_eq!(application.pending_ack_heights(), vec![Height::new(1)]); @@ -4075,7 +4075,7 @@ mod tests { // Once the anchor arrives, dispatch restarts at the floor // successor instead of treating the stale ack as progress. - assert!(mailbox.verified(floor_round, floor_block).await); + assert!(mailbox.verified(floor_round, floor_block).await.is_ok()); select! { height = application.acknowledged() => { assert_eq!( @@ -4124,7 +4124,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block1_round, block1).await); + assert!(mailbox.verified(block1_round, block1).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block1_finalization).await; wait_until( &context, @@ -4148,7 +4148,7 @@ mod tests { // The genesis anchor is already local and below the in-flight // height 1 ack, so applying it must not touch pending acks. mailbox.set_floor(floor_finalization); - assert!(mailbox.get_block(Height::zero()).await.is_some()); + assert!(mailbox.get_block(Height::zero()).await.ok().flatten().is_some()); assert_eq!( application.pending_ack_heights(), @@ -4201,7 +4201,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block1_round, block1.clone()).await); + assert!(mailbox.verified(block1_round, block1.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block1_finalization).await; wait_until( &context, @@ -4232,7 +4232,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block2_round, block2).await); + assert!(mailbox.verified(block2_round, block2).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block2_finalization).await; wait_until( &context, @@ -4280,7 +4280,7 @@ mod tests { // This lower local anchor is already behind processed height. It // may advance the round floor, but must leave height 2 in flight. mailbox.set_floor(stale_floor_finalization); - assert!(mailbox.get_block(Height::zero()).await.is_some()); + assert!(mailbox.get_block(Height::zero()).await.ok().flatten().is_some()); assert_eq!( application.pending_ack_heights(), @@ -4335,7 +4335,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block1_round, block1.clone()).await); + assert!(mailbox.verified(block1_round, block1.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block1_finalization).await; wait_until( &context, @@ -4366,7 +4366,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block2_round, block2).await); + assert!(mailbox.verified(block2_round, block2).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, block2_finalization).await; wait_until( &context, @@ -4387,7 +4387,7 @@ mod tests { QUORUM, ); mailbox.set_floor(same_height_finalization); - assert!(mailbox.get_block(Height::new(1)).await.is_some()); + assert!(mailbox.get_block(Height::new(1)).await.ok().flatten().is_some()); assert_eq!( application.pending_ack_heights(), @@ -4428,7 +4428,7 @@ mod tests { &schemes, QUORUM, ); - assert!(mailbox.verified(block_round, block.clone()).await); + assert!(mailbox.verified(block_round, block.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, finalization).await; assert_eq!(application.acknowledged().await, Height::new(1)); @@ -4484,7 +4484,7 @@ mod tests { assert!( mailbox .verified(Round::new(Epoch::zero(), View::new(2)), barrier) - .await + .await.is_ok() ); assert_eq!( resolver.fetches().len(), @@ -4565,11 +4565,11 @@ mod tests { ); assert!( - mailbox.get_block(Height::new(2)).await.is_some(), + mailbox.get_block(Height::new(2)).await.ok().flatten().is_some(), "standard floor anchor should be archived using its parent digest" ); assert!( - mailbox.get_finalization(Height::new(2)).await.is_some(), + mailbox.get_finalization(Height::new(2)).await.ok().flatten().is_some(), "standard floor finalization should be archived by height" ); }); @@ -4673,7 +4673,7 @@ mod tests { assert_eq!(application.acknowledged().await, Height::zero()); assert!( - mailbox.verified(round, block.clone()).await, + mailbox.verified(round, block.clone()).await.is_ok(), "verified block should persist before finalization" ); StandardHarness::report_finalization(&mut mailbox, finalization).await; @@ -4703,7 +4703,7 @@ mod tests { assert!( mailbox .verified(Round::new(Epoch::zero(), View::new(2)), barrier) - .await, + .await.is_ok(), "barrier verification should be processed" ); assert_eq!( @@ -4752,7 +4752,7 @@ mod tests { let mut mailbox = mailbox; assert_eq!(application.acknowledged().await, Height::zero()); - assert!(mailbox.verified(round, block.clone()).await); + assert!(mailbox.verified(round, block.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, finalization).await; let retain_floor = resolver.retain_count() + 2; @@ -4781,7 +4781,7 @@ mod tests { assert!( mailbox .verified(Round::new(Epoch::zero(), View::new(2)), barrier) - .await + .await.is_ok() ); assert_eq!( resolver.fetches().len(), @@ -4816,7 +4816,7 @@ mod tests { ) .await; assert_eq!( - mailbox.get_block(Height::zero()).await.unwrap().digest(), + mailbox.get_block(Height::zero()).await.ok().flatten().unwrap().digest(), original_genesis.digest() ); @@ -4870,7 +4870,7 @@ mod tests { let mut mailbox = mailbox; assert_eq!(application.acknowledged().await, Height::zero()); - assert!(mailbox.verified(round, block.clone()).await); + assert!(mailbox.verified(round, block.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, finalization).await; let retain_floor = resolver.retain_count() + 2; @@ -4883,7 +4883,7 @@ mod tests { ) .await; assert_eq!( - mailbox.get_info(Identifier::Latest).await, + mailbox.get_info(Identifier::Latest).await.ok().flatten(), Some((Height::new(1), block.digest())) ); @@ -4914,7 +4914,7 @@ mod tests { assert!( mailbox .verified(Round::new(Epoch::zero(), View::new(2)), barrier) - .await + .await.is_ok() ); assert_eq!( resolver.fetches().len(), @@ -5055,7 +5055,7 @@ mod tests { ) .await; - assert!(mailbox.verified(floor_round, floor_block.clone()).await); + assert!(mailbox.verified(floor_round, floor_block.clone()).await.is_ok()); mailbox.set_floor(floor_finalization); select! { height = started => { @@ -5097,7 +5097,7 @@ mod tests { assert!( mailbox .verified(Round::new(Epoch::zero(), View::new(6)), barrier) - .await, + .await.is_ok(), "barrier verification should be processed" ); wait_until( @@ -5161,7 +5161,7 @@ mod tests { .await; mailbox.set_floor(finalization.clone()); - assert!(mailbox.verified(round, block.clone()).await); + assert!(mailbox.verified(round, block.clone()).await.is_ok()); wait_until( &context, Duration::from_secs(5), @@ -5186,7 +5186,7 @@ mod tests { assert!( mailbox .verified(Round::new(Epoch::zero(), View::new(2)), barrier) - .await + .await.is_ok() ); assert_eq!( resolver.fetches().len(), @@ -5382,7 +5382,7 @@ mod tests { .await; assert!( - mailbox.verified(round, block.clone()).await, + mailbox.verified(round, block.clone()).await.is_ok(), "verified block should persist to the cache" ); StandardHarness::report_finalization(&mut mailbox, finalization.clone()).await; @@ -5420,7 +5420,7 @@ mod tests { let recovered = mailbox .get_block(Height::new(1)) - .await + .await.ok().flatten() .expect("finalized block must be durable before delivery"); assert_eq!( recovered.digest(), @@ -5430,7 +5430,7 @@ mod tests { assert_eq!( mailbox .get_finalization(Height::new(1)) - .await + .await.ok().flatten() .expect("finalization must be durable before delivery") .round(), round, @@ -5658,7 +5658,7 @@ mod tests { .await; let buffer = buffer.expect("buffer was provided"); - assert!(mailbox.proposed(round, block.clone()).await); + assert!(mailbox.proposed(round, block.clone()).await.is_ok()); let targets = vec![participants[1].clone()]; mailbox.forward(round, digest, Recipients::Some(targets.clone())); @@ -5714,7 +5714,7 @@ mod tests { .await; let buffer = buffer.expect("buffer was provided"); - assert!(mailbox.verified(round, block.clone()).await); + assert!(mailbox.verified(round, block.clone()).await.is_ok()); let targets = vec![participants[1].clone(), participants[2].clone()]; mailbox.forward(round, digest, Recipients::Some(targets.clone())); @@ -5777,7 +5777,7 @@ mod tests { QUORUM, ); mailbox.set_floor(finalization); - assert!(mailbox.verified(floor_round, floor_anchor).await); + assert!(mailbox.verified(floor_round, floor_anchor).await.is_ok()); context.sleep(Duration::from_millis(50)).await; mailbox.hint_finalized(Height::new(5), NonEmptyVec::new(participants[1].clone())); @@ -5821,11 +5821,11 @@ mod tests { ) .await; - assert!(mailbox.verified(round, block.clone()).await); + assert!(mailbox.verified(round, block.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, finalization).await; // Wait until marshal has durably stored the finalization. - while mailbox.get_finalization(Height::new(1)).await.is_none() { + while mailbox.get_finalization(Height::new(1)).await.ok().flatten().is_none() { context.sleep(Duration::from_millis(10)).await; } @@ -5912,10 +5912,10 @@ mod tests { ) .await; - assert!(mailbox.verified(round, block.clone()).await); + assert!(mailbox.verified(round, block.clone()).await.is_ok()); StandardHarness::report_finalization(&mut mailbox, finalization).await; - while mailbox.get_finalization(Height::new(1)).await.is_none() { + while mailbox.get_finalization(Height::new(1)).await.ok().flatten().is_none() { context.sleep(Duration::from_millis(10)).await; } @@ -5924,8 +5924,8 @@ mod tests { context.sleep(Duration::from_millis(50)).await; // The finalized block and its finalization must still be retrievable. - assert!(mailbox.get_block(Height::new(1)).await.is_some()); - assert!(mailbox.get_finalization(Height::new(1)).await.is_some()); + assert!(mailbox.get_block(Height::new(1)).await.ok().flatten().is_some()); + assert!(mailbox.get_finalization(Height::new(1)).await.ok().flatten().is_some()); }); } } diff --git a/consensus/src/marshal/standard/validation.rs b/consensus/src/marshal/standard/validation.rs index 4561eae7303..e747034202e 100644 --- a/consensus/src/marshal/standard/validation.rs +++ b/consensus/src/marshal/standard/validation.rs @@ -99,7 +99,7 @@ where return Some(Decision::Complete(false)); } - if !marshal.verified(context.round, block).await { + if marshal.verified(context.round, block).await.is_err() { return None; } return Some(Decision::Complete(true)); diff --git a/consensus/src/marshal/standard/variant.rs b/consensus/src/marshal/standard/variant.rs index 09d19e51909..c59a0354d23 100644 --- a/consensus/src/marshal/standard/variant.rs +++ b/consensus/src/marshal/standard/variant.rs @@ -68,7 +68,7 @@ where type PublicKey = K; async fn find_by_digest(&self, digest: B::Digest) -> Option { - self.get(digest).await + self.get(digest).await.unwrap_or_default() } async fn find_by_commitment(&self, commitment: B::Digest) -> Option { diff --git a/consensus/src/ordered_broadcast/mocks/reporter.rs b/consensus/src/ordered_broadcast/mocks/reporter.rs index d46583ca92d..5e4a99a6db2 100644 --- a/consensus/src/ordered_broadcast/mocks/reporter.rs +++ b/consensus/src/ordered_broadcast/mocks/reporter.rs @@ -218,7 +218,7 @@ impl crate::Reporter for Mailbox { } impl Mailbox { - pub async fn get_tip(&mut self, sequencer: C) -> Option<(Height, Epoch)> { + pub fn get_tip(&mut self, sequencer: C) -> oneshot::Receiver> { let (sender, receiver) = oneshot::channel(); assert!( self.sender @@ -226,10 +226,10 @@ impl Mailbox { .accepted(), "Failed to send get tip" ); - receiver.await.unwrap() + receiver } - pub async fn get_contiguous_tip(&mut self, sequencer: C) -> Option { + pub fn get_contiguous_tip(&mut self, sequencer: C) -> oneshot::Receiver> { let (sender, receiver) = oneshot::channel(); assert!( self.sender @@ -237,10 +237,10 @@ impl Mailbox { .accepted(), "Failed to send get contiguous tip" ); - receiver.await.unwrap() + receiver } - pub async fn get(&mut self, sequencer: C, height: Height) -> Option<(D, Epoch)> { + pub fn get(&mut self, sequencer: C, height: Height) -> oneshot::Receiver> { let (sender, receiver) = oneshot::channel(); assert!( self.sender @@ -248,6 +248,6 @@ impl Mailbox { .accepted(), "Failed to send get" ); - receiver.await.unwrap() + receiver } } diff --git a/consensus/src/ordered_broadcast/mod.rs b/consensus/src/ordered_broadcast/mod.rs index f73b23b9d7e..7429d0fcab4 100644 --- a/consensus/src/ordered_broadcast/mod.rs +++ b/consensus/src/ordered_broadcast/mod.rs @@ -303,12 +303,12 @@ mod tests { loop { let (height, epoch) = mailbox .get_tip(sequencer.clone()) - .await + .await.ok().flatten() .unwrap_or((Height::zero(), Epoch::zero())); debug!(height = %height, epoch = %epoch, ?sequencer, ?reporter, "reporter"); let contiguous_height = mailbox .get_contiguous_tip(sequencer.clone()) - .await + .await.ok().flatten() .unwrap_or(Height::zero()); if height >= threshold_height && epoch >= threshold_epoch @@ -341,7 +341,7 @@ mod tests { for (sequencer, mailbox) in reporters.iter_mut() { let (height, _) = mailbox .get_tip(sequencer.clone()) - .await + .await.ok().flatten() .unwrap_or((Height::zero(), Epoch::zero())); if height > max_height { max_height = height; diff --git a/examples/bridge/src/application/actor.rs b/examples/bridge/src/application/actor.rs index c57cb34d973..64e8e5b833a 100644 --- a/examples/bridge/src/application/actor.rs +++ b/examples/bridge/src/application/actor.rs @@ -20,6 +20,7 @@ use commonware_cryptography::{ use commonware_parallel::Sequential; use commonware_runtime::{Metrics, Sink, Spawner, Stream}; use commonware_stream::encrypted::{Receiver, Sender}; +use commonware_utils::channel::mpsc; use rand::Rng; use rand_core::CryptoRngCore; use tracing::{debug, info}; @@ -56,22 +57,57 @@ impl } /// Run the application actor. - pub async fn run(mut self) { - let (mut indexer_sender, mut indexer_receiver) = self.indexer; - while let Some(message) = self.mailbox.recv().await { + pub async fn run(self) { + let Self { + context, + indexer, + this_network, + other_network, + hasher, + mut mailbox, + } = self; + let (worker_sender, worker_receiver) = mpsc::unbounded_channel(); + let worker = context.child("indexer_worker").spawn(move |context| { + Self::run_indexer( + context, + indexer, + this_network, + other_network, + hasher, + worker_receiver, + ) + }); + + while let Some(message) = mailbox.recv().await { + if worker_sender.send(message).is_err() { + break; + } + } + worker.abort(); + } + + async fn run_indexer( + mut context: R, + (mut indexer_sender, mut indexer_receiver): (Sender, Receiver), + this_network: ::Public, + other_network: Scheme, + mut hasher: H, + mut messages: mpsc::UnboundedReceiver>, + ) { + while let Some(message) = messages.recv().await { match message { Message::Propose { round, response } => { // Either propose a random message (prefix=0) or include a consensus certificate (prefix=1) - let block = match self.context.gen_bool(0.5) { + let block = match context.gen_bool(0.5) { true => { // Generate a random message - BlockFormat::::Random(self.context.gen()) + BlockFormat::::Random(context.gen()) } false => { // Fetch a certificate from the indexer for the other network let msg = Inbound::GetFinalization::(inbound::GetFinalization { - network: *self.other_network.identity(), + network: *other_network.identity(), }) .encode(); indexer_sender @@ -95,11 +131,7 @@ impl // Verify certificate assert!( - finalization.verify( - &mut self.context, - &self.other_network, - &Sequential - ), + finalization.verify(&mut context, &other_network, &Sequential), "indexer is corrupt" ); @@ -109,13 +141,13 @@ impl }; // Hash the message - self.hasher.update(&block.encode()); - let digest = self.hasher.finalize(); + hasher.update(&block.encode()); + let digest = hasher.finalize(); info!(?block, payload = ?digest, "proposed"); // Publish to indexer let msg = Inbound::PutBlock::(inbound::PutBlock { - network: self.this_network, + network: this_network, block, }) .encode(); @@ -143,7 +175,7 @@ impl Message::Verify { payload, response } => { // Fetch payload from indexer let msg = Inbound::GetBlock(inbound::GetBlock { - network: self.this_network, + network: this_network, digest: payload, }) .encode(); @@ -172,11 +204,8 @@ impl let _ = response.send(true); } BlockFormat::Bridge(finalization) => { - let result = finalization.verify( - &mut self.context, - &self.other_network, - &Sequential, - ); + let result = + finalization.verify(&mut context, &other_network, &Sequential); let _ = response.send(result); } } @@ -193,7 +222,7 @@ impl // Post finalization let msg = Inbound::PutFinalization::(inbound::PutFinalization { - network: self.this_network, + network: this_network, finalization, }) .encode(); diff --git a/examples/bridge/src/bin/indexer.rs b/examples/bridge/src/bin/indexer.rs index 69157648e49..27ca6da0deb 100644 --- a/examples/bridge/src/bin/indexer.rs +++ b/examples/bridge/src/bin/indexer.rs @@ -255,10 +255,7 @@ fn main() { let (peer, mut sender, mut receiver) = match listen( context.child("listener"), - |peer| { - let out = validators.position(&peer).is_some(); - async move { out } - }, + |peer| validators.position(&peer).is_some(), config.clone(), stream, sink, diff --git a/examples/reshare/src/application/core.rs b/examples/reshare/src/application/core.rs index d6510003890..a47ca22864e 100644 --- a/examples/reshare/src/application/core.rs +++ b/examples/reshare/src/application/core.rs @@ -80,7 +80,7 @@ where // This approach does allow duplicate commitments to be proposed, but // the arbiter handles this by choosing the first commitment it sees // from any given dealer. - let reshare = self.dkg.act().await; + let reshare = self.dkg.act().await.ok().flatten(); // Create a new block with the consensus context Some(Block::new( diff --git a/examples/reshare/src/dkg/actor.rs b/examples/reshare/src/dkg/actor.rs index e903917b2fd..69f921cd71e 100644 --- a/examples/reshare/src/dkg/actor.rs +++ b/examples/reshare/src/dkg/actor.rs @@ -654,7 +654,10 @@ mod tests { use commonware_math::algebra::Random; use commonware_p2p::{utils::mocks::inert_channel, PeerSetSubscription, Provider}; use commonware_runtime::{deterministic, Runner, Supervisor as _}; - use commonware_utils::{channel::mpsc, N3f1, NZUsize, TryCollect, NZU32}; + use commonware_utils::{ + channel::{mpsc, oneshot}, + N3f1, NZUsize, TryCollect, NZU32, + }; use core::marker::PhantomData; use std::collections::BTreeMap; @@ -670,13 +673,17 @@ mod tests { impl Provider for NoopManager

{ type PublicKey = P; - async fn peer_set(&mut self, _: u64) -> Option> { - None + fn peer_set(&mut self, _: u64) -> oneshot::Receiver>> { + let (sender, receiver) = oneshot::channel(); + let _ = sender.send(None); + receiver } - async fn subscribe(&mut self) -> PeerSetSubscription { + fn subscribe(&mut self) -> oneshot::Receiver> { let (_, rx) = mpsc::unbounded_channel(); - rx + let (sender, receiver) = oneshot::channel(); + let _ = sender.send(rx); + receiver } } diff --git a/examples/reshare/src/dkg/ingress.rs b/examples/reshare/src/dkg/ingress.rs index 21064e7bb71..a697538d532 100644 --- a/examples/reshare/src/dkg/ingress.rs +++ b/examples/reshare/src/dkg/ingress.rs @@ -81,7 +81,7 @@ where /// Request the [Actor]'s next payload for inclusion within a block. /// /// [Actor]: super::Actor - pub async fn act(&mut self) -> Option> { + pub fn act(&mut self) -> oneshot::Receiver>> { let (response_tx, response_rx) = oneshot::channel(); if !self .sender @@ -91,16 +91,9 @@ where .accepted() { error!("failed to send act message"); - return None; } - match response_rx.await { - Ok(outcome) => outcome, - Err(err) => { - error!(?err, "failed to receive act response"); - None - } - } + response_rx } } diff --git a/examples/reshare/src/orchestrator/actor.rs b/examples/reshare/src/orchestrator/actor.rs index abf95e7a6a6..6dbf570d959 100644 --- a/examples/reshare/src/orchestrator/actor.rs +++ b/examples/reshare/src/orchestrator/actor.rs @@ -2,7 +2,10 @@ use crate::{ application::{genesis, Block, EpochProvider, Provider}, - orchestrator::{ingress::Message, Mailbox}, + orchestrator::{ + ingress::{EpochTransition, Message}, + Mailbox, + }, BLOCKS_PER_EPOCH, }; use commonware_actor::mailbox; @@ -27,9 +30,14 @@ use commonware_runtime::{ telemetry::metrics::{Gauge, GaugeExt, MetricsExt as _}, BufferPooler, Clock, ContextCell, Handle, Metrics, Network, Spawner, Storage, }; -use commonware_utils::{vec::NonEmptyVec, NZUsize, NZU16}; +use commonware_utils::{futures::Pool, vec::NonEmptyVec, NZUsize, NZU16}; use rand_core::CryptoRngCore; -use std::{collections::BTreeMap, marker::PhantomData, num::NonZeroUsize, time::Duration}; +use std::{ + collections::{BTreeMap, BTreeSet}, + marker::PhantomData, + num::NonZeroUsize, + time::Duration, +}; use tracing::{debug, info, warn}; /// Configuration for the orchestrator. @@ -197,6 +205,11 @@ where // Wait for instructions to transition epochs. let epocher = FixedEpocher::new(BLOCKS_PER_EPOCH); let mut engines: BTreeMap> = BTreeMap::new(); + let mut pending_epochs = BTreeSet::new(); + let mut pending_floors: Pool<( + EpochTransition, + Result, + )> = Pool::default(); select_loop! { self.context, @@ -240,50 +253,37 @@ where break; } => match transition { Message::Enter(transition) => { - // If the epoch is already in the map, ignore. - if engines.contains_key(&transition.epoch) { + if engines.contains_key(&transition.epoch) + || !pending_epochs.insert(transition.epoch) + { warn!(epoch = %transition.epoch, "entered existing epoch"); continue; } // DKG state does not persist the consensus floor; derive it from marshal's // finalized boundary block when entering each epoch. - let floor = match Self::floor_boundary(&epocher, transition.epoch) { - Some(boundary_height) => self - .marshal - .get_block(boundary_height) - .await - .unwrap_or_else(|| { - panic!( - "missing finalized boundary block at height {} for epoch {}", - boundary_height, transition.epoch - ) - }) - .digest(), - None => genesis::().digest(), - }; - - // Register the new signing scheme with the scheme provider. - let scheme = self.provider.scheme_for_epoch(&transition); - assert!(self.provider.register(transition.epoch, scheme.clone())); - - // Enter the new epoch. - let handle = self - .enter_epoch( - transition.epoch, - floor, - scheme, - &mut vote_mux, - &mut certificate_mux, - &mut resolver_mux, - ) - .await; - engines.insert(transition.epoch, handle); - let _ = self.latest_epoch.try_set(transition.epoch.get()); - - info!(epoch = %transition.epoch, "entered epoch"); + let boundary = Self::floor_boundary(&epocher, transition.epoch); + let marshal = self.marshal.clone(); + pending_floors.push(async move { + let floor = match boundary { + Some(boundary_height) => marshal + .get_block(boundary_height) + .await + .ok() + .flatten() + .map(|block| block.digest()) + .ok_or(boundary_height), + None => Ok(genesis::().digest()), + }; + (transition, floor) + }); } Message::Exit(epoch) => { + if pending_epochs.remove(&epoch) { + info!(%epoch, "exited pending epoch"); + continue; + } + // Remove the engine and abort it. let Some(handle) = engines.remove(&epoch) else { warn!(%epoch, "exited non-existent epoch"); @@ -297,6 +297,43 @@ where info!(%epoch, "exited epoch"); } }, + (transition, floor) = pending_floors.next_completed() => { + if !pending_epochs.remove(&transition.epoch) { + debug!(epoch = %transition.epoch, "ignoring canceled epoch"); + continue; + } + + if engines.contains_key(&transition.epoch) { + warn!(epoch = %transition.epoch, "entered existing epoch"); + continue; + } + let floor = floor.unwrap_or_else(|boundary_height| { + panic!( + "missing finalized boundary block at height {} for epoch {}", + boundary_height, transition.epoch + ) + }); + + // Register the new signing scheme with the scheme provider. + let scheme = self.provider.scheme_for_epoch(&transition); + assert!(self.provider.register(transition.epoch, scheme.clone())); + + // Enter the new epoch. + let handle = self + .enter_epoch( + transition.epoch, + floor, + scheme, + &mut vote_mux, + &mut certificate_mux, + &mut resolver_mux, + ) + .await; + engines.insert(transition.epoch, handle); + let _ = self.latest_epoch.try_set(transition.epoch.get()); + + info!(epoch = %transition.epoch, "entered epoch"); + }, } } diff --git a/p2p/src/authenticated/discovery/actors/dialer.rs b/p2p/src/authenticated/discovery/actors/dialer.rs index c2fbf0ae86b..cf9250cc18c 100644 --- a/p2p/src/authenticated/discovery/actors/dialer.rs +++ b/p2p/src/authenticated/discovery/actors/dialer.rs @@ -1,6 +1,7 @@ //! Actor responsible for dialing peers and establishing connections. use crate::authenticated::{ + dialing::Dialable, discovery::{ actors::{ spawner, @@ -10,7 +11,7 @@ use crate::authenticated::{ }, Mailbox, }; -use commonware_cryptography::Signer; +use commonware_cryptography::{PublicKey, Signer}; use commonware_macros::select_loop; use commonware_runtime::{ spawn_cell, @@ -19,15 +20,36 @@ use commonware_runtime::{ StreamOf, }; use commonware_stream::encrypted::{dial, Config as StreamConfig}; +use commonware_utils::channel::oneshot; +use futures::future::{self, Either}; use rand::seq::SliceRandom; use rand_core::CryptoRngCore; -use std::time::Duration; +use std::time::{Duration, SystemTime}; use tracing::debug; // Mailbox for the spawner actor. type SupervisorMailbox = Mailbox, StreamOf, ::PublicKey>>; +enum TrackerQuery { + Dialable(oneshot::Receiver>), + Dial(oneshot::Receiver>>), +} + +enum TrackerReply { + Dialable(Dialable), + Dial(Option>), +} + +impl TrackerQuery { + async fn recv(&mut self) -> TrackerReply { + match self { + Self::Dialable(receiver) => TrackerReply::Dialable(receiver.await.unwrap_or_default()), + Self::Dial(receiver) => TrackerReply::Dial(receiver.await.ok().flatten()), + } + } +} + /// Configuration for the dialer actor. pub struct Config { /// Configuration for the stream. @@ -140,6 +162,16 @@ impl< }); } + fn empty_queue_deadline( + &self, + now: SystemTime, + next_query_at: Option, + ) -> SystemTime { + let min = now + self.dial_frequency; + let max = (now + self.peer_connection_cooldown).max(min); + next_query_at.unwrap_or(max).clamp(min, max) + } + /// Start the dialer actor. pub fn start( mut self, @@ -155,36 +187,58 @@ impl< mut supervisor: SupervisorMailbox, ) { let mut dial_deadline = self.context.current(); + let mut query: Option> = None; select_loop! { self.context, + on_start => { + let wait_for_deadline = if query.is_some() { + Either::Left(future::pending()) + } else { + Either::Right(self.context.sleep_until(dial_deadline)) + }; + let wait_for_query = match &mut query { + Some(query) => Either::Left(query.recv()), + None => Either::Right(future::pending()), + }; + }, on_stopped => { debug!("context shutdown, stopping dialer"); }, - _ = self.context.sleep_until(dial_deadline) => { - // Refill the queue if empty. + _ = wait_for_deadline => { let now = self.context.current(); - let mut next_query_at = None; if self.queue.is_empty() { - let dialable = tracker.dialable().await; - self.queue = dialable.peers; - self.queue.shuffle(self.context.as_mut()); - next_query_at = dialable.next_query_at; + query = Some(TrackerQuery::Dialable(tracker.dialable())); + continue; } - // Set next deadline. - dial_deadline = if self.queue.is_empty() { - let min = now + self.dial_frequency; - let max = (now + self.peer_connection_cooldown).max(min); - next_query_at.unwrap_or(max).clamp(min, max) + if let Some(peer) = self.queue.pop() { + query = Some(TrackerQuery::Dial(tracker.dial(peer))); } else { - now + self.dial_frequency - }; - - // Pop through peers until we can reserve and dial one. - while let Some(peer) = self.queue.pop() { - if let Some(reservation) = tracker.dial(peer).await { - self.dial_peer(reservation, &mut supervisor); - break; + dial_deadline = self.empty_queue_deadline(now, None); + } + }, + reply = wait_for_query => { + query = None; + let now = self.context.current(); + match reply { + TrackerReply::Dialable(dialable) => { + self.queue = dialable.peers; + self.queue.shuffle(self.context.as_mut()); + dial_deadline = if self.queue.is_empty() { + self.empty_queue_deadline(now, dialable.next_query_at) + } else { + now + }; + } + TrackerReply::Dial(result) => { + if let Some(reservation) = result { + self.dial_peer(reservation, &mut supervisor); + dial_deadline = now + self.dial_frequency; + } else if self.queue.is_empty() { + dial_deadline = now + self.dial_frequency; + } else { + dial_deadline = now; + } } } }, diff --git a/p2p/src/authenticated/discovery/actors/listener.rs b/p2p/src/authenticated/discovery/actors/listener.rs index 57cebe1ce16..99336d1a4bd 100644 --- a/p2p/src/authenticated/discovery/actors/listener.rs +++ b/p2p/src/authenticated/discovery/actors/listener.rs @@ -95,9 +95,10 @@ impl, mut supervisor: Mailbox, StreamOf, C::PublicKey>>, ) { + // The tracker owns acceptance and reservation so the handshake callback stays synchronous. let (peer, send, recv) = match listen( context, - |peer| tracker.acceptable(peer), + |_| true, stream_cfg, stream, sink, @@ -113,7 +114,7 @@ impl { - let _ = responder.send(true); - } tracker::Message::Listen { reservation, .. } => { let _ = reservation.send(None); } @@ -436,9 +434,6 @@ mod tests { let tracker_task = context.child("tracker").spawn(|_| async move { while let Some(message) = tracker_rx.recv().await { match message { - tracker::Message::Acceptable { responder, .. } => { - let _ = responder.send(true); - } tracker::Message::Listen { reservation, .. } => { let _ = reservation.send(None); } diff --git a/p2p/src/authenticated/discovery/actors/peer/actor.rs b/p2p/src/authenticated/discovery/actors/peer/actor.rs index 594d553ff1f..67635874aa0 100644 --- a/p2p/src/authenticated/discovery/actors/peer/actor.rs +++ b/p2p/src/authenticated/discovery/actors/peer/actor.rs @@ -493,7 +493,7 @@ mod tests { move |ctx| async move { commonware_stream::encrypted::listen( ctx, - |_| async { true }, + |_| true, remote_config, remote_stream, remote_sink, @@ -594,7 +594,7 @@ mod tests { move |ctx| async move { commonware_stream::encrypted::listen( ctx, - |_| async { true }, + |_| true, remote_config, remote_stream, remote_sink, @@ -701,7 +701,7 @@ mod tests { move |ctx| async move { commonware_stream::encrypted::listen( ctx, - |_| async { true }, + |_| true, remote_config, remote_stream, remote_sink, @@ -806,7 +806,7 @@ mod tests { move |ctx| async move { commonware_stream::encrypted::listen( ctx, - |_| async { true }, + |_| true, remote_config, remote_stream, remote_sink, diff --git a/p2p/src/authenticated/discovery/actors/router/ingress.rs b/p2p/src/authenticated/discovery/actors/router/ingress.rs index ba218a7af7b..c6e128c0fef 100644 --- a/p2p/src/authenticated/discovery/actors/router/ingress.rs +++ b/p2p/src/authenticated/discovery/actors/router/ingress.rs @@ -76,15 +76,15 @@ impl Mailbox

{ /// Notify the router that a peer is ready to communicate. /// - /// Returns `None` if the router has shut down. - pub async fn ready(&self, peer: P, relay: Relay) -> Option> { + /// The returned receiver is closed if the router has shut down. + pub fn ready(&self, peer: P, relay: Relay) -> oneshot::Receiver> { let (channels, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Ready { peer, relay, channels, }); - receiver.await.ok() + receiver } /// Notify the router that a peer is no longer available. diff --git a/p2p/src/authenticated/discovery/actors/spawner/actor.rs b/p2p/src/authenticated/discovery/actors/spawner/actor.rs index 6c7f3772ae0..3b03028a726 100644 --- a/p2p/src/authenticated/discovery/actors/spawner/actor.rs +++ b/p2p/src/authenticated/discovery/actors/spawner/actor.rs @@ -107,7 +107,8 @@ impl< let info_verifier = self.info_verifier.clone(); move |context| async move { // Get greeting from tracker (returns None if not eligible) - let Some(greeting) = tracker.connect(peer.clone(), is_dialer).await + let Some(greeting) = + tracker.connect(peer.clone(), is_dialer).await.ok() else { debug!(?peer, "peer not eligible"); drop(reservation); @@ -132,7 +133,8 @@ impl< ); // Register peer with the router (may fail during shutdown) - let Some(channels) = router.ready(peer.clone(), messenger).await + let Some(channels) = + router.ready(peer.clone(), messenger).await.ok() else { debug!(?peer, "router shut down during peer setup"); return; diff --git a/p2p/src/authenticated/discovery/actors/spawner/ingress.rs b/p2p/src/authenticated/discovery/actors/spawner/ingress.rs index 344121dad92..a35d846a84b 100644 --- a/p2p/src/authenticated/discovery/actors/spawner/ingress.rs +++ b/p2p/src/authenticated/discovery/actors/spawner/ingress.rs @@ -99,7 +99,7 @@ mod tests { move |context| async move { listen( context, - |_| async { true }, + |_| true, stream_config(remote_key), remote_stream, remote_sink, diff --git a/p2p/src/authenticated/discovery/actors/tracker/actor.rs b/p2p/src/authenticated/discovery/actors/tracker/actor.rs index d1228e3e4ef..e71f80ce694 100644 --- a/p2p/src/authenticated/discovery/actors/tracker/actor.rs +++ b/p2p/src/authenticated/discovery/actors/tracker/actor.rs @@ -249,6 +249,7 @@ impl Actor { } => { let _ = reservation.send(self.directory.dial(&public_key)); } + #[cfg(test)] Message::Acceptable { public_key, responder, @@ -368,9 +369,11 @@ mod tests { let res = mailbox .listen(peer.clone()) .await + .ok() + .flatten() .expect("reservation failed"); let dialer = false; - let greeting = mailbox.connect(peer.clone(), dialer).await; + let greeting = mailbox.connect(peer.clone(), dialer).await.ok(); assert!( greeting.is_some(), "expected greeting info for authorized peer" @@ -428,7 +431,7 @@ mod tests { .unwrap(); oracle.track(0, too_many_peers); // Ensure the message is processed causing the panic - let _ = mailbox.dialable().await; + let _ = mailbox.dialable().await.unwrap_or_default(); }); } @@ -453,7 +456,7 @@ mod tests { .unwrap(); let primary: Set = Set::default(); oracle.track(0, TrackedPeers::new(primary, large_secondary)); - let _ = mailbox.dialable().await; + let _ = mailbox.dialable().await.unwrap_or_default(); }); } @@ -467,14 +470,14 @@ mod tests { let (_unauth_signer, unauth_pk) = new_signer_and_pk(1); // Connect as listener - should return None for unauthorized peer - let result = mailbox.connect(unauth_pk.clone(), false).await; + let result = mailbox.connect(unauth_pk.clone(), false).await.ok(); assert!( result.is_none(), "Unauthorized peer should get None on Connect" ); // Connect as dialer - should return None for unauthorized peer - let result = mailbox.connect(unauth_pk, true).await; + let result = mailbox.connect(unauth_pk, true).await.ok(); assert!( result.is_none(), "Unauthorized peer should get None on Connect" @@ -503,7 +506,7 @@ mod tests { ); context.sleep(Duration::from_millis(10)).await; - let _res = mailbox.listen(auth_pk.clone()).await.unwrap(); + let _res = mailbox.listen(auth_pk.clone()).await.ok().flatten().unwrap(); let tracker_info = mailbox .connect(auth_pk.clone(), false) .await @@ -610,7 +613,7 @@ mod tests { Some(peer::Message::Kill) )); - let dialable_peers = mailbox.dialable().await; + let dialable_peers = mailbox.dialable().await.unwrap_or_default(); assert!(!dialable_peers.peers.iter().any(|peer| peer == &pk1)); }); } @@ -822,9 +825,9 @@ mod tests { } = setup_actor(context.child("actor"), cfg_initial); // None listenable because not registered - assert!(!mailbox.acceptable(peer_pk.clone()).await); - assert!(!mailbox.acceptable(peer_pk2.clone()).await); - assert!(!mailbox.acceptable(peer_pk3.clone()).await); + assert!(!mailbox.acceptable(peer_pk.clone()).await.unwrap_or(false)); + assert!(!mailbox.acceptable(peer_pk2.clone()).await.unwrap_or(false)); + assert!(!mailbox.acceptable(peer_pk3.clone()).await.unwrap_or(false)); oracle.track( 0, @@ -833,11 +836,11 @@ mod tests { context.sleep(Duration::from_millis(10)).await; // Not listenable because self - assert!(!mailbox.acceptable(peer_pk).await); + assert!(!mailbox.acceptable(peer_pk).await.unwrap_or(false)); // Listenable because registered - assert!(mailbox.acceptable(peer_pk2).await); + assert!(mailbox.acceptable(peer_pk2).await.unwrap_or(false)); // Not listenable because not registered - assert!(!mailbox.acceptable(peer_pk3).await); + assert!(!mailbox.acceptable(peer_pk3).await.unwrap_or(false)); }); } @@ -854,26 +857,26 @@ mod tests { let (_peer_signer, peer_pk) = new_signer_and_pk(1); - let reservation = mailbox.listen(peer_pk.clone()).await; + let reservation = mailbox.listen(peer_pk.clone()).await.ok().flatten(); assert!(reservation.is_none()); oracle.track(0, Set::try_from([peer_pk.clone()]).unwrap()); context.sleep(Duration::from_millis(10)).await; // Allow register to process - assert!(mailbox.acceptable(peer_pk.clone()).await); + assert!(mailbox.acceptable(peer_pk.clone()).await.unwrap_or(false)); - let reservation = mailbox.listen(peer_pk.clone()).await; + let reservation = mailbox.listen(peer_pk.clone()).await.ok().flatten(); assert!(reservation.is_some()); - assert!(!mailbox.acceptable(peer_pk.clone()).await); + assert!(!mailbox.acceptable(peer_pk.clone()).await.unwrap_or(false)); - let failed_reservation = mailbox.listen(peer_pk.clone()).await; + let failed_reservation = mailbox.listen(peer_pk.clone()).await.ok().flatten(); assert!(failed_reservation.is_none()); drop(reservation.unwrap()); context.sleep(Duration::from_millis(1_010)).await; // Allow release and rate limit to pass - let reservation_after_release = mailbox.listen(peer_pk.clone()).await; + let reservation_after_release = mailbox.listen(peer_pk.clone()).await.ok().flatten(); assert!(reservation_after_release.is_some()); }); } @@ -890,7 +893,7 @@ mod tests { ); let TestHarness { mailbox, .. } = setup_actor(context.child("actor"), cfg_initial); - let dialable_peers = mailbox.dialable().await; + let dialable_peers = mailbox.dialable().await.unwrap_or_default(); assert_eq!(dialable_peers.peers.len(), 1); assert_eq!(dialable_peers.peers[0], boot_pk); }); @@ -908,7 +911,7 @@ mod tests { .. } = setup_actor(context.child("actor"), cfg); - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); let (_primary_signer, primary_pk) = new_signer_and_pk(1); let (mut secondary_signer, secondary_pk) = new_signer_and_pk(2); @@ -934,7 +937,7 @@ mod tests { update.all.secondary, Set::try_from([secondary_pk.clone()]).unwrap() ); - assert!(mailbox.acceptable(secondary_pk.clone()).await); + assert!(mailbox.acceptable(secondary_pk.clone()).await.unwrap_or(false)); let secondary_info = new_peer_info( &mut secondary_signer, @@ -947,7 +950,7 @@ mod tests { mailbox.peers(vec![secondary_info]); context.sleep(Duration::from_millis(10)).await; - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert!(!dialable.peers.iter().any(|peer| peer == &secondary_pk)); }); } @@ -964,7 +967,7 @@ mod tests { .. } = setup_actor(context.child("actor"), cfg); - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); let (_signer, pk) = new_signer_and_pk(1); oracle.track( @@ -988,7 +991,7 @@ mod tests { update.all.secondary.is_empty(), "aggregate secondary excludes keys that are primary" ); - assert!(mailbox.acceptable(pk).await); + assert!(mailbox.acceptable(pk).await.unwrap_or(false)); }); } @@ -1005,7 +1008,7 @@ mod tests { let TestHarness { mailbox, .. } = setup_actor(context.child("actor"), cfg_initial); - let reservation = mailbox.dial(boot_pk.clone()).await; + let reservation = mailbox.dial(boot_pk.clone()).await.ok().flatten(); assert!(reservation.is_some()); if let Some(res) = reservation { match res.metadata() { @@ -1021,7 +1024,7 @@ mod tests { } let (_unknown_signer, unknown_pk) = new_signer_and_pk(100); - let no_reservation = mailbox.dial(unknown_pk).await; + let no_reservation = mailbox.dial(unknown_pk).await.ok().flatten(); assert!(no_reservation.is_none()); }); } diff --git a/p2p/src/authenticated/discovery/actors/tracker/directory.rs b/p2p/src/authenticated/discovery/actors/tracker/directory.rs index db9c5bfd8be..8f2484a49bb 100644 --- a/p2p/src/authenticated/discovery/actors/tracker/directory.rs +++ b/p2p/src/authenticated/discovery/actors/tracker/directory.rs @@ -318,6 +318,9 @@ impl Directory { /// /// Returns `Some` on success, `None` otherwise. pub fn listen(&mut self, peer: &C) -> Option> { + if !self.acceptable(peer) { + return None; + } self.reserve(Metadata::Listener(peer.clone())) } diff --git a/p2p/src/authenticated/discovery/actors/tracker/ingress.rs b/p2p/src/authenticated/discovery/actors/tracker/ingress.rs index ed34fa24da3..8b3389f9849 100644 --- a/p2p/src/authenticated/discovery/actors/tracker/ingress.rs +++ b/p2p/src/authenticated/discovery/actors/tracker/ingress.rs @@ -14,7 +14,7 @@ use commonware_actor::{ Feedback, }; use commonware_cryptography::PublicKey; -use commonware_utils::channel::{mpsc, oneshot}; +use commonware_utils::channel::oneshot; use std::collections::VecDeque; /// Messages that can be sent to the tracker actor. @@ -105,23 +105,14 @@ pub enum Message { /// The public key of the peer to reserve. public_key: C, - /// sender to respond with the reservation. + /// Sender to respond with the reservation. reservation: oneshot::Sender>>, }, // ---------- Used by listener ---------- - /// Check if a peer is acceptable (can accept an incoming connection from them). - Acceptable { - /// The public key of the peer to check. - public_key: C, - - /// The sender to respond with whether the peer is acceptable. - responder: oneshot::Sender, - }, - /// Request a reservation for a particular peer. /// - /// The tracker will respond with an [`Option>`], which will be `None` if the + /// The tracker will respond with an [`Option>`], which will be `None` if the /// reservation cannot be granted (e.g., if the peer is already connected, blocked or already /// has an active reservation). Listen { @@ -132,6 +123,17 @@ pub enum Message { reservation: oneshot::Sender>>, }, + // ---------- Used by tests ---------- + /// Check if a peer is acceptable (can accept an incoming connection from them). + #[cfg(test)] + Acceptable { + /// The public key of the peer to check. + public_key: C, + + /// The sender to respond with whether the peer is acceptable. + responder: oneshot::Sender, + }, + // ---------- Used by reservation ---------- /// Release a reservation. Release { @@ -159,16 +161,19 @@ impl Mailbox { /// Send a `Connect` message to the tracker and receive the greeting info. /// - /// Returns `Some(info)` if the peer is eligible, `None` if the channel was - /// dropped (peer not eligible or tracker shut down). - pub(crate) async fn connect(&self, public_key: C, dialer: bool) -> Option> { + /// The returned receiver is closed if the peer is not eligible or the tracker is shut down. + pub(crate) fn connect( + &self, + public_key: C, + dialer: bool, + ) -> oneshot::Receiver> { let (responder, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Connect { public_key, dialer, responder, }); - receiver.await.ok() + receiver } /// Send a `Construct` message to the tracker. @@ -188,47 +193,48 @@ impl Mailbox { /// Request dialable peers from the tracker. /// - /// Returns an empty response if the tracker is shut down. - pub(crate) async fn dialable(&self) -> Dialable { + /// The returned receiver is closed if the tracker is shut down. + pub(crate) fn dialable(&self) -> oneshot::Receiver> { let (responder, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Dialable { responder }); - receiver.await.unwrap_or_default() + receiver } /// Send a `Dial` message to the tracker. /// - /// Returns `None` if the tracker is shut down. - pub(crate) async fn dial(&self, public_key: C) -> Option> { + /// The returned receiver is closed if the tracker is shut down. + pub(crate) fn dial(&self, public_key: C) -> oneshot::Receiver>> { let (reservation, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Dial { public_key, reservation, }); - receiver.await.ok().flatten() + receiver } /// Send an `Acceptable` message to the tracker. /// - /// Returns `false` if the tracker is shut down. - pub(crate) async fn acceptable(&self, public_key: C) -> bool { + /// The returned receiver is closed if the tracker is shut down. + #[cfg(test)] + pub(crate) fn acceptable(&self, public_key: C) -> oneshot::Receiver { let (responder, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Acceptable { public_key, responder, }); - receiver.await.unwrap_or(false) + receiver } /// Send a `Listen` message to the tracker. /// - /// Returns `None` if the tracker is shut down. - pub(crate) async fn listen(&self, public_key: C) -> Option> { + /// The returned receiver is closed if the tracker is shut down. + pub(crate) fn listen(&self, public_key: C) -> oneshot::Receiver>> { let (reservation, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Listen { public_key, reservation, }); - receiver.await.ok().flatten() + receiver } } @@ -268,22 +274,19 @@ impl Oracle { impl crate::Provider for Oracle { type PublicKey = C; - async fn peer_set(&mut self, id: u64) -> Option> { + fn peer_set(&mut self, id: u64) -> oneshot::Receiver>> { let (responder, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::PeerSet { index: id, responder, }); - receiver.await.ok().flatten() + receiver } - async fn subscribe(&mut self) -> PeerSetSubscription { + fn subscribe(&mut self) -> oneshot::Receiver> { let (responder, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::Subscribe { responder }); - receiver.await.unwrap_or_else(|_| { - let (_, rx) = mpsc::unbounded_channel(); - rx - }) + receiver } } diff --git a/p2p/src/authenticated/discovery/mod.rs b/p2p/src/authenticated/discovery/mod.rs index e9bc6cf332e..57634e11040 100644 --- a/p2p/src/authenticated/discovery/mod.rs +++ b/p2p/src/authenticated/discovery/mod.rs @@ -784,7 +784,7 @@ mod tests { network.start(); // Subscribe to peer sets - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); // Register initial peer set let set10: Set<_> = peers_and_sks @@ -992,7 +992,7 @@ mod tests { network.start(); // Subscribe to peer sets - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); // Register a peer set that does NOT include self let peer_set: Set<_> = [other_pk.clone()].try_into().unwrap(); @@ -2306,7 +2306,7 @@ mod tests { // Oracle operations should not panic even after shutdown oracle.track(1, peers.clone()); - let _ = oracle.peer_set(0).await; + let _ = oracle.peer_set(0).await.ok().flatten(); let _ = oracle.subscribe().await; crate::block_peer(&mut oracle, address.clone()); @@ -2395,7 +2395,7 @@ mod tests { let (slow_relay, _slow_receivers) = Relay::new(context.child("slow_relay"), NZUsize!(10)); assert!( - mailbox.ready(slow_peer.clone(), slow_relay).await.is_some(), + mailbox.ready(slow_peer.clone(), slow_relay).await.ok().is_some(), "Failed to register slow peer" ); @@ -2404,7 +2404,7 @@ mod tests { let (fast_relay, mut fast_receivers) = Relay::new(context.child("fast_relay"), NZUsize!(100)); assert!( - mailbox.ready(fast_peer.clone(), fast_relay).await.is_some(), + mailbox.ready(fast_peer.clone(), fast_relay).await.ok().is_some(), "Failed to register fast peer" ); diff --git a/p2p/src/authenticated/lookup/actors/dialer.rs b/p2p/src/authenticated/lookup/actors/dialer.rs index 9f2044405b9..c21ea4982d8 100644 --- a/p2p/src/authenticated/lookup/actors/dialer.rs +++ b/p2p/src/authenticated/lookup/actors/dialer.rs @@ -2,6 +2,7 @@ use crate::{ authenticated::{ + dialing::Dialable, lookup::{ actors::{ spawner, @@ -13,7 +14,7 @@ use crate::{ }, Ingress, }; -use commonware_cryptography::Signer; +use commonware_cryptography::{PublicKey, Signer}; use commonware_macros::select_loop; use commonware_runtime::{ spawn_cell, @@ -22,15 +23,36 @@ use commonware_runtime::{ StreamOf, }; use commonware_stream::encrypted::{dial, Config as StreamConfig}; +use commonware_utils::channel::oneshot; +use futures::future::{self, Either}; use rand::seq::SliceRandom; use rand_core::CryptoRngCore; -use std::time::Duration; +use std::time::{Duration, SystemTime}; use tracing::debug; // Mailbox for the spawner actor. type SupervisorMailbox = Mailbox, StreamOf, ::PublicKey>>; +enum TrackerQuery { + Dialable(oneshot::Receiver>), + Dial(oneshot::Receiver, Ingress)>>), +} + +enum TrackerReply { + Dialable(Dialable), + Dial(Option<(Reservation, Ingress)>), +} + +impl TrackerQuery { + async fn recv(&mut self) -> TrackerReply { + match self { + Self::Dialable(receiver) => TrackerReply::Dialable(receiver.await.unwrap_or_default()), + Self::Dial(receiver) => TrackerReply::Dial(receiver.await.ok().flatten()), + } + } +} + /// Configuration for the dialer actor. pub struct Config { /// Configuration for the stream. @@ -144,6 +166,16 @@ impl< }); } + fn empty_queue_deadline( + &self, + now: SystemTime, + next_query_at: Option, + ) -> SystemTime { + let min = now + self.dial_frequency; + let max = (now + self.peer_connection_cooldown).max(min); + next_query_at.unwrap_or(max).clamp(min, max) + } + /// Start the dialer actor. pub fn start( mut self, @@ -159,36 +191,58 @@ impl< mut supervisor: SupervisorMailbox, ) { let mut dial_deadline = self.context.current(); + let mut query: Option> = None; select_loop! { self.context, + on_start => { + let wait_for_deadline = if query.is_some() { + Either::Left(future::pending()) + } else { + Either::Right(self.context.sleep_until(dial_deadline)) + }; + let wait_for_query = match &mut query { + Some(query) => Either::Left(query.recv()), + None => Either::Right(future::pending()), + }; + }, on_stopped => { debug!("context shutdown, stopping dialer"); }, - _ = self.context.sleep_until(dial_deadline) => { - // Refill the queue if empty. + _ = wait_for_deadline => { let now = self.context.current(); - let mut next_query_at = None; if self.queue.is_empty() { - let dialable = tracker.dialable().await; - self.queue = dialable.peers; - self.queue.shuffle(self.context.as_mut()); - next_query_at = dialable.next_query_at; + query = Some(TrackerQuery::Dialable(tracker.dialable())); + continue; } - // Set next deadline. - dial_deadline = if self.queue.is_empty() { - let min = now + self.dial_frequency; - let max = (now + self.peer_connection_cooldown).max(min); - next_query_at.unwrap_or(max).clamp(min, max) + if let Some(peer) = self.queue.pop() { + query = Some(TrackerQuery::Dial(tracker.dial(peer))); } else { - now + self.dial_frequency - }; - - // Pop through peers until we can reserve and dial one. - while let Some(peer) = self.queue.pop() { - if let Some((reservation, ingress)) = tracker.dial(peer).await { - self.dial_peer(reservation, ingress, &mut supervisor); - break; + dial_deadline = self.empty_queue_deadline(now, None); + } + }, + reply = wait_for_query => { + query = None; + let now = self.context.current(); + match reply { + TrackerReply::Dialable(dialable) => { + self.queue = dialable.peers; + self.queue.shuffle(self.context.as_mut()); + dial_deadline = if self.queue.is_empty() { + self.empty_queue_deadline(now, dialable.next_query_at) + } else { + now + }; + } + TrackerReply::Dial(result) => { + if let Some((reservation, ingress)) = result { + self.dial_peer(reservation, ingress, &mut supervisor); + dial_deadline = now + self.dial_frequency; + } else if self.queue.is_empty() { + dial_deadline = now + self.dial_frequency; + } else { + dial_deadline = now; + } } } }, diff --git a/p2p/src/authenticated/lookup/actors/listener.rs b/p2p/src/authenticated/lookup/actors/listener.rs index 2d3098b4739..af111aeb8e9 100644 --- a/p2p/src/authenticated/lookup/actors/listener.rs +++ b/p2p/src/authenticated/lookup/actors/listener.rs @@ -136,11 +136,11 @@ impl, mut supervisor: SpawnerMailbox, StreamOf, C::PublicKey>>, ) { - // Perform handshake let source_ip = address.ip(); + // The tracker owns acceptance and reservation so the handshake callback stays synchronous. let (peer, send, recv) = match listen( context, - |peer| tracker.acceptable(peer, source_ip), + |_| true, stream_cfg, stream, sink, @@ -156,7 +156,7 @@ impl { - let _ = responder.send(true); - } tracker::Message::Listen { reservation, .. } => { let _ = reservation.send(None); } @@ -536,9 +533,6 @@ mod tests { let tracker_task = context.child("tracker").spawn(|_| async move { while let Some(message) = tracker_rx.recv().await { match message { - tracker::Message::Acceptable { responder, .. } => { - let _ = responder.send(true); - } tracker::Message::Listen { reservation, .. } => { let _ = reservation.send(None); } @@ -621,9 +615,6 @@ mod tests { let tracker_task = context.child("tracker").spawn(|_| async move { while let Some(message) = tracker_rx.recv().await { match message { - tracker::Message::Acceptable { responder, .. } => { - let _ = responder.send(true); - } tracker::Message::Listen { reservation, .. } => { let _ = reservation.send(None); } @@ -711,9 +702,6 @@ mod tests { let tracker_task = context.child("tracker").spawn(|_| async move { while let Some(message) = tracker_rx.recv().await { match message { - tracker::Message::Acceptable { responder, .. } => { - let _ = responder.send(true); - } tracker::Message::Listen { reservation, .. } => { let _ = reservation.send(None); } diff --git a/p2p/src/authenticated/lookup/actors/peer/actor.rs b/p2p/src/authenticated/lookup/actors/peer/actor.rs index 3bf05dda3df..02f1ef62ea3 100644 --- a/p2p/src/authenticated/lookup/actors/peer/actor.rs +++ b/p2p/src/authenticated/lookup/actors/peer/actor.rs @@ -439,7 +439,7 @@ mod tests { move |ctx| async move { commonware_stream::encrypted::listen( ctx, - |_| async { true }, + |_| true, remote_config, remote_stream, remote_sink, @@ -548,7 +548,7 @@ mod tests { move |ctx| async move { commonware_stream::encrypted::listen( ctx, - |_| async { true }, + |_| true, remote_config, remote_stream, CountingSink::new(remote_sink, sends), diff --git a/p2p/src/authenticated/lookup/actors/router/ingress.rs b/p2p/src/authenticated/lookup/actors/router/ingress.rs index 74674119d25..1bbd79efa95 100644 --- a/p2p/src/authenticated/lookup/actors/router/ingress.rs +++ b/p2p/src/authenticated/lookup/actors/router/ingress.rs @@ -76,15 +76,15 @@ impl Mailbox

{ /// Notify the router that a peer is ready to communicate. /// - /// Returns `None` if the router has shut down. - pub async fn ready(&self, peer: P, relay: Relay) -> Option> { + /// The returned receiver is closed if the router has shut down. + pub fn ready(&self, peer: P, relay: Relay) -> oneshot::Receiver> { let (channels, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Ready { peer, relay, channels, }); - receiver.await.ok() + receiver } /// Notify the router that a peer is no longer available. diff --git a/p2p/src/authenticated/lookup/actors/spawner/actor.rs b/p2p/src/authenticated/lookup/actors/spawner/actor.rs index 72fbf331029..20b26d1751b 100644 --- a/p2p/src/authenticated/lookup/actors/spawner/actor.rs +++ b/p2p/src/authenticated/lookup/actors/spawner/actor.rs @@ -109,7 +109,8 @@ impl< ); // Register peer with the router (may fail during shutdown) - let Some(channels) = router.ready(peer.clone(), messenger).await else { + let Some(channels) = router.ready(peer.clone(), messenger).await.ok() + else { debug!(?peer, "router shut down during peer setup"); return; }; diff --git a/p2p/src/authenticated/lookup/actors/spawner/ingress.rs b/p2p/src/authenticated/lookup/actors/spawner/ingress.rs index e17b72b29f0..22268b580ad 100644 --- a/p2p/src/authenticated/lookup/actors/spawner/ingress.rs +++ b/p2p/src/authenticated/lookup/actors/spawner/ingress.rs @@ -99,7 +99,7 @@ mod tests { move |context| async move { listen( context, - |_| async { true }, + |_| true, stream_config(remote_key), remote_stream, remote_sink, diff --git a/p2p/src/authenticated/lookup/actors/tracker/actor.rs b/p2p/src/authenticated/lookup/actors/tracker/actor.rs index 1098f12d349..4cf59d3ad27 100644 --- a/p2p/src/authenticated/lookup/actors/tracker/actor.rs +++ b/p2p/src/authenticated/lookup/actors/tracker/actor.rs @@ -194,6 +194,7 @@ impl Actor { } => { let _ = reservation.send(self.directory.dial(&public_key)); } + #[cfg(test)] Message::Acceptable { public_key, source_ip, @@ -203,9 +204,10 @@ impl Actor { } Message::Listen { public_key, + source_ip, reservation, } => { - let _ = reservation.send(self.directory.listen(&public_key)); + let _ = reservation.send(self.directory.listen(&public_key, source_ip)); } Message::Block { public_key } => { // Block the peer @@ -336,13 +338,13 @@ mod tests { ); context.sleep(Duration::from_millis(10)).await; - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert!(dialable.peers.iter().any(|peer| peer == &pk)); crate::block_peer(&mut oracle, pk.clone()); context.sleep(Duration::from_millis(10)).await; - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert!(!dialable.peers.iter().any(|peer| peer == &pk)); }); } @@ -369,13 +371,13 @@ mod tests { crate::block_peer(&mut oracle, pk1.clone()); context.sleep(Duration::from_millis(10)).await; - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert!(!dialable.peers.iter().any(|peer| peer == &pk1)); crate::block_peer(&mut oracle, pk1.clone()); context.sleep(Duration::from_millis(10)).await; - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert!(!dialable.peers.iter().any(|peer| peer == &pk1)); }); } @@ -412,9 +414,9 @@ mod tests { } = setup_actor(context.child("actor"), cfg_initial); // None acceptable because not registered - assert!(!mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await); - assert!(!mailbox.acceptable(peer_pk2.clone(), peer_addr2.ip()).await); - assert!(!mailbox.acceptable(peer_pk3.clone(), peer_addr3.ip()).await); + assert!(!mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await.unwrap_or(false)); + assert!(!mailbox.acceptable(peer_pk2.clone(), peer_addr2.ip()).await.unwrap_or(false)); + assert!(!mailbox.acceptable(peer_pk3.clone(), peer_addr3.ip()).await.unwrap_or(false)); oracle.track( 0, @@ -427,13 +429,13 @@ mod tests { context.sleep(Duration::from_millis(10)).await; // Not acceptable because self - assert!(!mailbox.acceptable(peer_pk, peer_addr.ip()).await); + assert!(!mailbox.acceptable(peer_pk, peer_addr.ip()).await.unwrap_or(false)); // Acceptable because registered with correct IP - assert!(mailbox.acceptable(peer_pk2.clone(), peer_addr2.ip()).await); + assert!(mailbox.acceptable(peer_pk2.clone(), peer_addr2.ip()).await.unwrap_or(false)); // Not acceptable with wrong IP - assert!(!mailbox.acceptable(peer_pk2, peer_addr.ip()).await); + assert!(!mailbox.acceptable(peer_pk2, peer_addr.ip()).await.unwrap_or(false)); // Not acceptable because not registered - assert!(!mailbox.acceptable(peer_pk3, peer_addr3.ip()).await); + assert!(!mailbox.acceptable(peer_pk3, peer_addr3.ip()).await.unwrap_or(false)); }); } @@ -458,7 +460,7 @@ mod tests { // Unknown peer is NOT acceptable (bypass_ip_check only skips IP check) assert!( - !mailbox.acceptable(peer_pk3.clone(), peer_addr3.ip()).await, + !mailbox.acceptable(peer_pk3.clone(), peer_addr3.ip()).await.unwrap_or(false), "Unknown peer should not be acceptable" ); @@ -474,13 +476,13 @@ mod tests { // With bypass_ip_check=true, tracked peer with wrong IP is acceptable assert!( - mailbox.acceptable(peer_pk2.clone(), peer_addr.ip()).await, + mailbox.acceptable(peer_pk2.clone(), peer_addr.ip()).await.unwrap_or(false), "Registered peer with wrong IP should be acceptable with bypass_ip_check=true" ); // Self is still not acceptable assert!( - !mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await, + !mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await.unwrap_or(false), "Self should not be acceptable" ); @@ -489,7 +491,7 @@ mod tests { context.sleep(Duration::from_millis(10)).await; assert!( - !mailbox.acceptable(peer_pk2.clone(), peer_addr2.ip()).await, + !mailbox.acceptable(peer_pk2.clone(), peer_addr2.ip()).await.unwrap_or(false), "Blocked peer should not be acceptable" ); }); @@ -509,7 +511,11 @@ mod tests { let (_peer_signer, peer_pk) = new_signer_and_pk(1); let peer_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 8080); - let reservation = mailbox.listen(peer_pk.clone()).await; + let reservation = mailbox + .listen(peer_pk.clone(), peer_addr.ip()) + .await + .ok() + .flatten(); assert!(reservation.is_none()); oracle.track( @@ -518,20 +524,32 @@ mod tests { ); context.sleep(Duration::from_millis(10)).await; // Allow register to process - assert!(mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await); + assert!(mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await.unwrap_or(false)); - let reservation = mailbox.listen(peer_pk.clone()).await; + let reservation = mailbox + .listen(peer_pk.clone(), peer_addr.ip()) + .await + .ok() + .flatten(); assert!(reservation.is_some()); - assert!(!mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await); + assert!(!mailbox.acceptable(peer_pk.clone(), peer_addr.ip()).await.unwrap_or(false)); - let failed_reservation = mailbox.listen(peer_pk.clone()).await; + let failed_reservation = mailbox + .listen(peer_pk.clone(), peer_addr.ip()) + .await + .ok() + .flatten(); assert!(failed_reservation.is_none()); drop(reservation.unwrap()); context.sleep(Duration::from_millis(1_010)).await; // Allow release and rate limit to pass - let reservation_after_release = mailbox.listen(peer_pk.clone()).await; + let reservation_after_release = mailbox + .listen(peer_pk.clone(), peer_addr.ip()) + .await + .ok() + .flatten(); assert!(reservation_after_release.is_some()); }); } @@ -553,7 +571,7 @@ mod tests { Map::<_, crate::Address>::try_from([(boot_pk.clone(), boot_addr.into())]).unwrap(), ); - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert_eq!(dialable.peers.len(), 1); assert_eq!(dialable.peers[0], boot_pk); }); @@ -578,7 +596,7 @@ mod tests { Map::<_, crate::Address>::try_from([(boot_pk.clone(), boot_addr.into())]).unwrap(), ); - let result = mailbox.dial(boot_pk.clone()).await; + let result = mailbox.dial(boot_pk.clone()).await.ok().flatten(); assert!(result.is_some()); if let Some((res, ingress)) = result { match res.metadata() { @@ -591,7 +609,7 @@ mod tests { } let (_unknown_signer, unknown_pk) = new_signer_and_pk(100); - let no_reservation = mailbox.dial(unknown_pk).await; + let no_reservation = mailbox.dial(unknown_pk).await.ok().flatten(); assert!(no_reservation.is_none()); }); } @@ -607,7 +625,7 @@ mod tests { .. } = setup_actor(context.child("actor"), cfg); - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); let (_primary_signer, primary_pk) = new_signer_and_pk(1); let primary_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 9001); @@ -642,11 +660,18 @@ mod tests { Set::try_from([secondary_pk.clone()]).unwrap() ); - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert!(dialable.peers.iter().any(|peer| peer == &primary_pk)); assert!(!dialable.peers.iter().any(|peer| peer == &secondary_pk)); - assert!(mailbox.dial(secondary_pk.clone()).await.is_none()); - assert!(mailbox.acceptable(secondary_pk, secondary_addr.ip()).await); + assert!( + mailbox + .dial(secondary_pk.clone()) + .await + .ok() + .flatten() + .is_none() + ); + assert!(mailbox.acceptable(secondary_pk, secondary_addr.ip()).await.unwrap_or(false)); }); } @@ -662,7 +687,7 @@ mod tests { .. } = setup_actor(context.child("actor"), cfg); - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); let (_signer, pk) = new_signer_and_pk(1); let addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 9001); @@ -688,9 +713,9 @@ mod tests { "aggregate secondary excludes keys that are primary" ); - let dialable = mailbox.dialable().await; + let dialable = mailbox.dialable().await.unwrap_or_default(); assert!(dialable.peers.iter().any(|peer| peer == &pk)); - assert!(mailbox.acceptable(pk, addr.ip()).await); + assert!(mailbox.acceptable(pk, addr.ip()).await.unwrap_or(false)); }); } @@ -716,7 +741,11 @@ mod tests { // let the register take effect context.sleep(Duration::from_millis(10)).await; - let reservation = mailbox.listen(peer_pk.clone()).await; + let reservation = mailbox + .listen(peer_pk.clone(), peer_addr.ip()) + .await + .ok() + .flatten(); assert!(reservation.is_some()); let (peer_mailbox, mut peer_rx) = peer::Mailbox::new(NZUsize!(1)); @@ -783,7 +812,11 @@ mod tests { assert!(!registered_ips.contains(&addr_2.ip())); // Mark peer as connected - let reservation = mailbox.listen(pk_1.clone()).await; + let reservation = mailbox + .listen(pk_1.clone(), addr_1.ip()) + .await + .ok() + .flatten(); assert!(reservation.is_some()); let (peer_mailbox, mut peer_rx) = peer::Mailbox::new(NZUsize!(1)); @@ -863,7 +896,7 @@ mod tests { ); context.sleep(Duration::from_millis(10)).await; - let result = mailbox.dial(pk.clone()).await; + let result = mailbox.dial(pk.clone()).await.ok().flatten(); assert!(result.is_some()); let (_, ingress) = result.unwrap(); assert_eq!(ingress, Ingress::Socket(addr_1)); @@ -872,7 +905,7 @@ mod tests { context.sleep(Duration::from_millis(1010)).await; - let result = mailbox.dial(pk.clone()).await; + let result = mailbox.dial(pk.clone()).await.ok().flatten(); assert!(result.is_some()); let (_, ingress) = result.unwrap(); assert_eq!(ingress, Ingress::Socket(addr_2)); @@ -953,13 +986,13 @@ mod tests { ); context.sleep(Duration::from_millis(10)).await; - assert!(mailbox.acceptable(pk_1.clone(), addr_1.ip()).await); - assert!(!mailbox.acceptable(pk_1.clone(), addr_2.ip()).await); + assert!(mailbox.acceptable(pk_1.clone(), addr_1.ip()).await.unwrap_or(false)); + assert!(!mailbox.acceptable(pk_1.clone(), addr_2.ip()).await.unwrap_or(false)); oracle.overwrite([(pk_1.clone(), addr_2.into())].try_into().unwrap()); - assert!(!mailbox.acceptable(pk_1.clone(), addr_1.ip()).await); - assert!(mailbox.acceptable(pk_1.clone(), addr_2.ip()).await); + assert!(!mailbox.acceptable(pk_1.clone(), addr_1.ip()).await.unwrap_or(false)); + assert!(mailbox.acceptable(pk_1.clone(), addr_2.ip()).await.unwrap_or(false)); }); } @@ -985,7 +1018,7 @@ mod tests { context.sleep(Duration::from_millis(10)).await; // Establish connection - let reservation = mailbox.listen(pk.clone()).await; + let reservation = mailbox.listen(pk.clone(), addr_1.ip()).await.ok().flatten(); assert!(reservation.is_some()); let (peer_mailbox, mut peer_rx) = peer::Mailbox::new(NZUsize!(1)); @@ -1023,7 +1056,7 @@ mod tests { assert!(registered_ips.contains(&addr_a.ip())); // Establish connection to peer - let reservation = mailbox.listen(pk.clone()).await; + let reservation = mailbox.listen(pk.clone(), addr_a.ip()).await.ok().flatten(); assert!(reservation.is_some()); let (peer_mailbox, mut peer_rx) = peer::Mailbox::new(NZUsize!(1)); @@ -1076,13 +1109,21 @@ mod tests { let _ = listener_receiver.next().await.unwrap(); // Establish connection to pk_tracked - let reservation = mailbox.listen(pk_tracked.clone()).await; + let reservation = mailbox + .listen(pk_tracked.clone(), addr_1.ip()) + .await + .ok() + .flatten(); assert!(reservation.is_some()); let (tracked_mailbox, mut tracked_rx) = peer::Mailbox::new(NZUsize!(1)); mailbox.connect(pk_tracked.clone(), tracked_mailbox); // Establish connection to pk_unchanged - let reservation = mailbox.listen(pk_unchanged.clone()).await; + let reservation = mailbox + .listen(pk_unchanged.clone(), addr_unchanged.ip()) + .await + .ok() + .flatten(); assert!(reservation.is_some()); let (unchanged_mailbox, mut unchanged_rx) = peer::Mailbox::new(NZUsize!(1)); mailbox.connect(pk_unchanged.clone(), unchanged_mailbox); diff --git a/p2p/src/authenticated/lookup/actors/tracker/directory.rs b/p2p/src/authenticated/lookup/actors/tracker/directory.rs index b91dd2900c6..893bbbd93b5 100644 --- a/p2p/src/authenticated/lookup/actors/tracker/directory.rs +++ b/p2p/src/authenticated/lookup/actors/tracker/directory.rs @@ -304,7 +304,10 @@ impl Directory { /// Attempt to reserve a peer for the listener. /// /// Returns `Some` on success, `None` otherwise. - pub fn listen(&mut self, peer: &C) -> Option> { + pub fn listen(&mut self, peer: &C, source_ip: IpAddr) -> Option> { + if !self.acceptable(peer, source_ip) { + return None; + } self.reserve(Metadata::Listener(peer.clone())) } @@ -1187,7 +1190,9 @@ mod tests { ) .unwrap(); - let _reservation = directory.listen(&pk_1).expect("peer should reserve"); + let _reservation = directory + .listen(&pk_1, addr_1.ip()) + .expect("peer should reserve"); let connected_at: i64 = context.current().epoch_millis().try_into().unwrap(); directory.connect(&pk_1); diff --git a/p2p/src/authenticated/lookup/actors/tracker/ingress.rs b/p2p/src/authenticated/lookup/actors/tracker/ingress.rs index 16b29b66972..5b25dfe2be9 100644 --- a/p2p/src/authenticated/lookup/actors/tracker/ingress.rs +++ b/p2p/src/authenticated/lookup/actors/tracker/ingress.rs @@ -12,10 +12,7 @@ use commonware_actor::{ Feedback, }; use commonware_cryptography::PublicKey; -use commonware_utils::{ - channel::{mpsc, oneshot}, - ordered::Map, -}; +use commonware_utils::{channel::oneshot, ordered::Map}; use std::{collections::VecDeque, net::IpAddr}; /// Messages that can be sent to the tracker actor. @@ -81,31 +78,36 @@ pub enum Message { }, // ---------- Used by listener ---------- - /// Check if a peer is acceptable (can accept an incoming connection from them). - Acceptable { - /// The public key of the peer to check. - public_key: C, - - /// The IP address the peer connected from. - source_ip: IpAddr, - - /// The sender to respond with whether the peer is acceptable. - responder: oneshot::Sender, - }, - /// Request a reservation for a particular peer. /// - /// The tracker will respond with an [`Option>`], which will be `None` if the + /// The tracker will respond with an [`Option>`], which will be `None` if the /// reservation cannot be granted (e.g., if the peer is already connected, blocked or already /// has an active reservation). Listen { /// The public key of the peer to reserve. public_key: C, + /// The IP address the peer connected from. + source_ip: IpAddr, + /// The sender to respond with the reservation. reservation: oneshot::Sender>>, }, + // ---------- Used by tests ---------- + /// Check if a peer is acceptable (can accept an incoming connection from them). + #[cfg(test)] + Acceptable { + /// The public key of the peer to check. + public_key: C, + + /// The IP address the peer connected from. + source_ip: IpAddr, + + /// The sender to respond with whether the peer is acceptable. + responder: oneshot::Sender, + }, + // ---------- Used by reservation ---------- /// Release a reservation. Release { @@ -138,48 +140,57 @@ impl Mailbox { /// Request dialable peers from the tracker. /// - /// Returns an empty response if the tracker is shut down. - pub(crate) async fn dialable(&self) -> Dialable { + /// The returned receiver is closed if the tracker is shut down. + pub(crate) fn dialable(&self) -> oneshot::Receiver> { let (responder, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Dialable { responder }); - receiver.await.unwrap_or_default() + receiver } /// Send a `Dial` message to the tracker. /// - /// Returns `None` if the tracker is shut down. - pub(crate) async fn dial(&self, public_key: C) -> Option<(Reservation, Ingress)> { + /// The returned receiver is closed if the tracker is shut down. + pub(crate) fn dial( + &self, + public_key: C, + ) -> oneshot::Receiver, Ingress)>> { let (reservation, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Dial { public_key, reservation, }); - receiver.await.ok().flatten() + receiver } /// Send an `Acceptable` message to the tracker. /// - /// Returns `false` if the tracker is shut down. - pub(crate) async fn acceptable(&self, public_key: C, source_ip: IpAddr) -> bool { + /// The returned receiver is closed if the tracker is shut down. + #[cfg(test)] + pub(crate) fn acceptable(&self, public_key: C, source_ip: IpAddr) -> oneshot::Receiver { let (responder, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Acceptable { public_key, source_ip, responder, }); - receiver.await.unwrap_or(false) + receiver } /// Send a `Listen` message to the tracker. /// - /// Returns `None` if the tracker is shut down. - pub(crate) async fn listen(&self, public_key: C) -> Option> { + /// The returned receiver is closed if the tracker is shut down. + pub(crate) fn listen( + &self, + public_key: C, + source_ip: IpAddr, + ) -> oneshot::Receiver>> { let (reservation, receiver) = oneshot::channel(); let _ = self.0.enqueue(Message::Listen { public_key, + source_ip, reservation, }); - receiver.await.ok().flatten() + receiver } } @@ -219,22 +230,19 @@ impl Oracle { impl crate::Provider for Oracle { type PublicKey = C; - async fn peer_set(&mut self, id: u64) -> Option> { + fn peer_set(&mut self, id: u64) -> oneshot::Receiver>> { let (responder, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::PeerSet { index: id, responder, }); - receiver.await.ok().flatten() + receiver } - async fn subscribe(&mut self) -> PeerSetSubscription { + fn subscribe(&mut self) -> oneshot::Receiver> { let (responder, receiver) = oneshot::channel(); let _ = self.sender.enqueue(Message::Subscribe { responder }); - receiver.await.unwrap_or_else(|_| { - let (_, rx) = mpsc::unbounded_channel(); - rx - }) + receiver } } diff --git a/p2p/src/authenticated/lookup/mod.rs b/p2p/src/authenticated/lookup/mod.rs index 158ac1aa04c..befc919bfbd 100644 --- a/p2p/src/authenticated/lookup/mod.rs +++ b/p2p/src/authenticated/lookup/mod.rs @@ -723,7 +723,7 @@ mod tests { network.start(); // Subscribe to peer sets - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); // Register initial peer set let set10: Map<_, _> = peers_and_sks @@ -926,7 +926,7 @@ mod tests { network.start(); // Subscribe to peer sets - let mut subscription = oracle.subscribe().await; + let mut subscription = oracle.subscribe().await.unwrap(); // Register a peer set that does NOT include self let peer_set: Map<_, _> = [(other_pk.clone(), other_addr.into())].try_into().unwrap(); @@ -1868,7 +1868,7 @@ mod tests { // Oracle operations should not panic even after shutdown oracle.track(1, peers.clone()); - let _ = oracle.peer_set(0).await; + let _ = oracle.peer_set(0).await.ok().flatten(); let _ = oracle.subscribe().await; crate::block_peer(&mut oracle, address.clone()); @@ -2130,7 +2130,7 @@ mod tests { let (slow_relay, _slow_receivers) = Relay::new(context.child("slow_relay"), NZUsize!(10)); assert!( - mailbox.ready(slow_peer, slow_relay).await.is_some(), + mailbox.ready(slow_peer, slow_relay).await.ok().is_some(), "Failed to register slow peer" ); @@ -2138,7 +2138,7 @@ mod tests { let (fast_relay, mut fast_receivers) = Relay::new(context.child("fast_relay"), NZUsize!(100)); assert!( - mailbox.ready(fast_peer, fast_relay).await.is_some(), + mailbox.ready(fast_peer, fast_relay).await.ok().is_some(), "Failed to register fast peer" ); diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs index 71569321572..c80449d9f9d 100644 --- a/p2p/src/lib.rs +++ b/p2p/src/lib.rs @@ -18,7 +18,7 @@ stability_scope!(BETA { use commonware_cryptography::PublicKey; use commonware_runtime::{IoBuf, IoBufs}; use commonware_utils::{ - channel::mpsc, + channel::{mpsc, oneshot}, ordered::{Map, Set}, }; use std::{error::Error as StdError, fmt::Debug, future::Future, time::SystemTime}; @@ -271,10 +271,12 @@ stability_scope!(BETA { type PublicKey: PublicKey; /// Fetch the primary and secondary peers tracked at the given ID. + /// + /// The returned receiver is closed if the provider is shut down. fn peer_set( &mut self, id: u64, - ) -> impl Future>> + Send; + ) -> oneshot::Receiver>>; /// Subscribe to notifications when new peer sets are added. /// @@ -282,9 +284,9 @@ stability_scope!(BETA { /// `latest` reflects how [`Manager::track`] stored the set: a peer listed in /// both roles appears only under `latest.primary`. The `all` field aggregates /// across tracked sets with the same rule (secondary excludes keys present as primary). - fn subscribe( - &mut self, - ) -> impl Future> + Send; + /// + /// The returned receiver is closed if the provider is shut down. + fn subscribe(&mut self) -> oneshot::Receiver>; } /// Interface for managing peer set membership (where peer addresses are not known). diff --git a/p2p/src/simulated/ingress.rs b/p2p/src/simulated/ingress.rs index e8ceb47c305..fca688e913d 100644 --- a/p2p/src/simulated/ingress.rs +++ b/p2p/src/simulated/ingress.rs @@ -277,23 +277,17 @@ impl Oracle { } /// Get the primary and secondary peers for a given ID. - async fn peer_set(&self, id: u64) -> Option> { - request(&self.sender, move |response| Message::PeerSet { - id, - response, - }) - .await - .flatten() + fn peer_set(&self, id: u64) -> oneshot::Receiver>> { + let (response, receiver) = oneshot::channel(); + let _ = self.sender.send_lossy(Message::PeerSet { id, response }); + receiver } /// Subscribe to notifications when new peer sets are added. - async fn subscribe(&self) -> PeerSetSubscription

{ - request(&self.sender, |response| Message::Subscribe { response }) - .await - .unwrap_or_else(|| { - let (_, rx) = mpsc::unbounded_channel(); - rx - }) + fn subscribe(&self) -> oneshot::Receiver> { + let (response, receiver) = oneshot::channel(); + let _ = self.sender.send_lossy(Message::Subscribe { response }); + receiver } } @@ -322,12 +316,12 @@ impl Clone for Manager { impl crate::Provider for Manager { type PublicKey = P; - async fn peer_set(&mut self, id: u64) -> Option> { - self.oracle.peer_set(id).await + fn peer_set(&mut self, id: u64) -> oneshot::Receiver>> { + self.oracle.peer_set(id) } - async fn subscribe(&mut self) -> PeerSetSubscription { - self.oracle.subscribe().await + fn subscribe(&mut self) -> oneshot::Receiver> { + self.oracle.subscribe() } } @@ -371,12 +365,12 @@ impl Clone for SocketManager { impl crate::Provider for SocketManager { type PublicKey = P; - async fn peer_set(&mut self, id: u64) -> Option> { - self.oracle.peer_set(id).await + fn peer_set(&mut self, id: u64) -> oneshot::Receiver>> { + self.oracle.peer_set(id) } - async fn subscribe(&mut self) -> PeerSetSubscription

{ - self.oracle.subscribe().await + fn subscribe(&mut self) -> oneshot::Receiver> { + self.oracle.subscribe() } } diff --git a/p2p/src/simulated/mod.rs b/p2p/src/simulated/mod.rs index ca849990a4c..5723b604865 100644 --- a/p2p/src/simulated/mod.rs +++ b/p2p/src/simulated/mod.rs @@ -218,7 +218,7 @@ mod tests { { let mut manager = oracle.manager(); manager.track(0, Set::from_iter_dedup(peers)); - assert!(manager.peer_set(0).await.is_some()); + assert!(manager.peer_set(0).await.ok().flatten().is_some()); } async fn wait_for_task_count( @@ -2359,14 +2359,14 @@ mod tests { network.start(); let mut manager = oracle.manager(); - assert_eq!(manager.peer_set(0).await, None); + assert_eq!(manager.peer_set(0).await.ok().flatten(), None); let pk1 = PrivateKey::from_seed(1).public_key(); let pk2 = PrivateKey::from_seed(2).public_key(); manager.track(0xFF, Set::try_from([pk1.clone(), pk2.clone()]).unwrap()); assert_eq!( - manager.peer_set(0xFF).await.unwrap(), + manager.peer_set(0xFF).await.ok().flatten().unwrap(), TrackedPeers::primary(Set::try_from([pk1, pk2]).unwrap()) ); }); @@ -2401,11 +2401,11 @@ mod tests { .unwrap(), ); - let peer_set = manager.peer_set(1).await.expect("peer set missing"); + let peer_set = manager.peer_set(1).await.ok().flatten().expect("peer set missing"); let keys: Vec<_> = Vec::from(peer_set.primary.clone()); assert_eq!(keys, vec![pk1.clone(), pk2.clone()]); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); let update = subscription.recv().await.unwrap(); assert_eq!(update.index, 1); let latest_keys: Vec<_> = Vec::from(update.latest.primary.clone()); @@ -2458,7 +2458,7 @@ mod tests { ); assert_eq!( - manager.peer_set(7).await.unwrap(), + manager.peer_set(7).await.ok().flatten().unwrap(), TrackedPeers::new( Set::try_from([pk1]).unwrap(), Set::try_from([PrivateKey::from_seed(2).public_key()]).unwrap(), @@ -2497,14 +2497,14 @@ mod tests { ); assert_eq!( - manager.peer_set(9).await.unwrap(), + manager.peer_set(9).await.ok().flatten().unwrap(), TrackedPeers::new( Set::try_from([pk1.clone(), pk2.clone()]).unwrap(), Set::try_from([pk3.clone()]).unwrap(), ) ); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); let update = subscription.recv().await.unwrap(); assert_eq!(update.index, 9); assert!(update.latest.primary.position(&pk2).is_some()); @@ -2544,7 +2544,7 @@ mod tests { ); assert_eq!( - manager.peer_set(7).await.unwrap(), + manager.peer_set(7).await.ok().flatten().unwrap(), TrackedPeers::new( Set::try_from([pk1]).unwrap(), Set::try_from([PrivateKey::from_seed(2).public_key()]).unwrap(), @@ -2572,7 +2572,7 @@ mod tests { let addr_primary: Address = SocketAddr::from(([127, 0, 0, 1], 4000)).into(); let addr_secondary: Address = SocketAddr::from(([127, 0, 0, 1], 5000)).into(); let mut manager = oracle.socket_manager(); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); manager.track( 11, @@ -2628,12 +2628,12 @@ mod tests { ); // Verify peer set contains expected keys (addresses are ignored by simulated network) - let peer_set = manager.peer_set(1).await.expect("peer set missing"); + let peer_set = manager.peer_set(1).await.ok().flatten().expect("peer set missing"); let keys: Vec<_> = Vec::from(peer_set.primary); assert_eq!(keys, vec![pk1.clone(), pk2.clone()]); // Verify subscription works - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); let update = subscription.recv().await.unwrap(); assert_eq!(update.index, 1); let latest_keys: Vec<_> = Vec::from(update.latest.primary); @@ -2715,7 +2715,7 @@ mod tests { // Register second peer set with pk2 and pk3 manager.track(2, Set::try_from(vec![pk2.clone(), pk3.clone()]).unwrap()); - assert!(manager.peer_set(2).await.is_some()); + assert!(manager.peer_set(2).await.ok().flatten().is_some()); // Now pk3 is in a peer set and pk1 can broadcast to it. let recipients = sender1.check(Recipients::All).unwrap().recipients(); @@ -2723,7 +2723,7 @@ mod tests { // Register third peer set with pk3 and pk4 (this will evict peer set 1) manager.track(3, Set::try_from(vec![pk3.clone(), pk4.clone()]).unwrap()); - assert!(manager.peer_set(3).await.is_some()); + assert!(manager.peer_set(3).await.ok().flatten().is_some()); // pk1 should now be removed from all peer sets. let recipients = sender2.check(Recipients::All).unwrap().recipients(); @@ -2737,16 +2737,16 @@ mod tests { assert!(recipients.contains(&pk4)); // Verify peer set contents - let peer_set_2 = manager.peer_set(2).await.unwrap(); + let peer_set_2 = manager.peer_set(2).await.ok().flatten().unwrap(); assert!(peer_set_2.primary.position(&pk2).is_some()); assert!(peer_set_2.primary.position(&pk3).is_some()); - let peer_set_3 = manager.peer_set(3).await.unwrap(); + let peer_set_3 = manager.peer_set(3).await.ok().flatten().unwrap(); assert!(peer_set_3.primary.position(&pk3).is_some()); assert!(peer_set_3.primary.position(&pk4).is_some()); // Peer set 1 should no longer exist - assert!(manager.peer_set(1).await.is_none()); + assert!(manager.peer_set(1).await.ok().flatten().is_none()); }); } @@ -2780,7 +2780,7 @@ mod tests { let mut manager = oracle.manager(); manager.track(1, Set::try_from([pk1, pk2.clone()]).unwrap()); - assert!(manager.peer_set(1).await.is_some()); + assert!(manager.peer_set(1).await.ok().flatten().is_some()); assert_eq!( sender.check(Recipients::All).unwrap().recipients(), @@ -2804,7 +2804,7 @@ mod tests { ); network.start(); let mut manager = oracle.manager(); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); // Register a peer set let sender_pk = PrivateKey::from_seed(1).public_key(); @@ -2917,7 +2917,7 @@ mod tests { // Subscribe to peer set updates let mut manager = oracle.manager(); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); // Create peers let pk1 = PrivateKey::from_seed(1).public_key(); @@ -3014,9 +3014,9 @@ mod tests { // Create multiple subscriptions let mut manager = oracle.manager(); - let mut subscription1 = manager.subscribe().await; - let mut subscription2 = manager.subscribe().await; - let mut subscription3 = manager.subscribe().await; + let mut subscription1 = manager.subscribe().await.unwrap(); + let mut subscription2 = manager.subscribe().await.unwrap(); + let mut subscription3 = manager.subscribe().await.unwrap(); // Create peers let pk1 = PrivateKey::from_seed(1).public_key(); @@ -3076,7 +3076,7 @@ mod tests { // Subscribe to peer set updates let mut manager = oracle.manager(); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); // Register a peer set that does NOT include self manager.track(1, Set::try_from(vec![other_pk.clone()]).unwrap()); @@ -3260,7 +3260,7 @@ mod tests { // Manager operations should not panic manager.track(1, Set::try_from([pk1.clone()]).unwrap()); - let _ = manager.peer_set(0).await; + let _ = manager.peer_set(0).await.ok().flatten(); let _ = manager.subscribe().await; // Oracle operations should not panic @@ -3420,7 +3420,7 @@ mod tests { // Subscribe after tracking. The current peer set should be // available immediately on the subscription channel. - let mut subscription = Provider::subscribe(&mut manager).await; + let mut subscription = Provider::subscribe(&mut manager).await.unwrap(); let update = subscription .try_recv() .expect("current peer set should be available immediately after subscribe"); diff --git a/p2p/src/simulated/network.rs b/p2p/src/simulated/network.rs index 9b669c36438..3c9b74743af 100644 --- a/p2p/src/simulated/network.rs +++ b/p2p/src/simulated/network.rs @@ -1564,14 +1564,14 @@ mod tests { network.start(); let mut manager = oracle.manager(); - let peer_set = manager.peer_set(0).await.unwrap(); + let peer_set = manager.peer_set(0).await.ok().flatten().unwrap(); assert_eq!(peer_set.primary, Set::try_from([primary.clone()]).unwrap()); assert_eq!( peer_set.secondary, Set::try_from([secondary.clone()]).unwrap() ); - let mut updates = manager.subscribe().await; + let mut updates = manager.subscribe().await.unwrap(); let update = updates.recv().await.unwrap(); assert_eq!(update.index, 0); assert_eq!( @@ -1866,7 +1866,7 @@ mod tests { // Subscribe to peer sets let mut manager = oracle.manager(); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); // Register initial peer set manager.track(10, Set::try_from([pk1.clone(), pk2.clone()]).unwrap()); @@ -1915,7 +1915,7 @@ mod tests { let pk_sec = ed25519::PrivateKey::from_seed(24).public_key(); let mut manager = oracle.manager(); - let mut subscription = manager.subscribe().await; + let mut subscription = manager.subscribe().await.unwrap(); manager.track( 10, @@ -2194,7 +2194,7 @@ mod tests { ), ); - let mut updates = manager.subscribe().await; + let mut updates = manager.subscribe().await.unwrap(); let update = updates.recv().await.unwrap(); assert_eq!(update.index, 0); assert!(update.latest.primary.position(&pk2).is_some()); @@ -2276,7 +2276,7 @@ mod tests { let pk_y = ed25519::PrivateKey::from_seed(2).public_key(); let mut manager = oracle.manager(); - let mut sub = manager.subscribe().await; + let mut sub = manager.subscribe().await.unwrap(); // Index 0: X is primary, Y is secondary. manager.track( diff --git a/p2p/src/utils/mod.rs b/p2p/src/utils/mod.rs index 0555c874208..acb296dbc3a 100644 --- a/p2p/src/utils/mod.rs +++ b/p2p/src/utils/mod.rs @@ -6,6 +6,7 @@ use commonware_utils::{ channel::{ fallible::FallibleExt, mpsc::{self, UnboundedReceiver, UnboundedSender}, + oneshot, }, ordered::Set, }; @@ -47,12 +48,14 @@ impl StaticProvider

{ impl Provider for StaticProvider

{ type PublicKey = P; - async fn peer_set(&mut self, id: u64) -> Option> { + fn peer_set(&mut self, id: u64) -> oneshot::Receiver>> { assert_eq!(id, self.id); - Some(TrackedPeers::primary(self.peers.clone())) + let (sender, receiver) = oneshot::channel(); + let _ = sender.send(Some(TrackedPeers::primary(self.peers.clone()))); + receiver } - async fn subscribe(&mut self) -> UnboundedReceiver> { + fn subscribe(&mut self) -> oneshot::Receiver>> { let (sender, receiver) = mpsc::unbounded_channel(); sender.send_lossy(PeerSetUpdate { index: self.id, @@ -60,6 +63,8 @@ impl Provider for StaticProvider

{ all: TrackedPeers::new(self.peers.clone(), Set::default()), }); self.senders.push(sender); // prevent the receiver from closing - receiver + let (response, result) = oneshot::channel(); + let _ = response.send(receiver); + result } } diff --git a/p2p/src/utils/mux.rs b/p2p/src/utils/mux.rs index 026991a0cd2..732580b1fc3 100644 --- a/p2p/src/utils/mux.rs +++ b/p2p/src/utils/mux.rs @@ -547,7 +547,7 @@ mod tests { b: PublicKey, ) { let mut manager = oracle.manager(); - let peers = manager.peer_set(0).await.unwrap_or_default(); + let peers = manager.peer_set(0).await.ok().flatten().unwrap_or_default(); manager.track( 0, Set::from_iter_dedup(peers.primary.iter().cloned().chain([a.clone(), b.clone()])), diff --git a/resolver/src/p2p/engine.rs b/resolver/src/p2p/engine.rs index 03d70b42e1a..d24e24932f3 100644 --- a/resolver/src/p2p/engine.rs +++ b/resolver/src/p2p/engine.rs @@ -164,7 +164,10 @@ where network.0, network.1, ); - let peer_set_subscription = &mut self.peer_provider.subscribe().await; + let Ok(mut peer_set_subscription) = self.peer_provider.subscribe().await else { + debug!("peer set subscription failed"); + return; + }; select_loop! { self.context, diff --git a/stream/fuzz/fuzz_targets/connection.rs b/stream/fuzz/fuzz_targets/connection.rs index 5cba8e2d166..9ca789e9e67 100644 --- a/stream/fuzz/fuzz_targets/connection.rs +++ b/stream/fuzz/fuzz_targets/connection.rs @@ -114,7 +114,7 @@ fn fuzz(input: FuzzInput) { move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, diff --git a/stream/fuzz/fuzz_targets/e2e.rs b/stream/fuzz/fuzz_targets/e2e.rs index 91028a16bdb..62a6a425a9b 100644 --- a/stream/fuzz/fuzz_targets/e2e.rs +++ b/stream/fuzz/fuzz_targets/e2e.rs @@ -131,7 +131,7 @@ fn fuzz(input: FuzzInput) { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, diff --git a/stream/fuzz/fuzz_targets/lazy_transport.rs b/stream/fuzz/fuzz_targets/lazy_transport.rs index e782ea5f6ba..b234e7b1d90 100644 --- a/stream/fuzz/fuzz_targets/lazy_transport.rs +++ b/stream/fuzz/fuzz_targets/lazy_transport.rs @@ -48,7 +48,7 @@ thread_local! { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, diff --git a/stream/fuzz/fuzz_targets/transport.rs b/stream/fuzz/fuzz_targets/transport.rs index dfb62e16f04..2a2fce06002 100644 --- a/stream/fuzz/fuzz_targets/transport.rs +++ b/stream/fuzz/fuzz_targets/transport.rs @@ -39,7 +39,7 @@ fn fuzz(data: &[u8]) { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, diff --git a/stream/src/encrypted.rs b/stream/src/encrypted.rs index 0ece6ea62f1..1bcc49752b9 100644 --- a/stream/src/encrypted.rs +++ b/stream/src/encrypted.rs @@ -73,7 +73,7 @@ use commonware_runtime::{ }; use commonware_utils::SystemTimeExt; use rand_core::CryptoRngCore; -use std::{future::Future, ops::Range, time::Duration}; +use std::{ops::Range, time::Duration}; use thiserror::Error; const TAG_SIZE: u32 = { @@ -243,13 +243,13 @@ pub async fn dial, - F: FnOnce(S::PublicKey) -> Fut, + F: FnOnce(S::PublicKey) -> bool, >( ctx: R, bouncer: F, @@ -261,7 +261,7 @@ pub async fn listen< let timeout = ctx.sleep(config.handshake_timeout); let inner_routine = async move { let peer = recv_handshake_frame::(&mut stream).await?; - if !bouncer(peer.clone()).await { + if !bouncer(peer.clone()) { return Err(Error::PeerRejected(peer.encode().to_vec())); } @@ -594,7 +594,7 @@ mod test { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, @@ -645,7 +645,7 @@ mod test { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, @@ -720,7 +720,7 @@ mod test { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, @@ -791,7 +791,7 @@ mod test { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, @@ -850,7 +850,7 @@ mod test { let listener_handle = context.child("listener").spawn(move |context| async move { listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink, @@ -921,7 +921,7 @@ mod test { let result = listen( context, - |_| async { true }, + |_| true, listener_config, listener_stream, listener_sink,