Skip to content

Commit

Permalink
Convert SyncingEngine::run to use tokio::select! instead of polli…
Browse files Browse the repository at this point in the history
…ng (#2132)
  • Loading branch information
dmitry-markin authored Nov 3, 2023
1 parent 8dc41ba commit d512b3f
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 214 deletions.
1 change: 1 addition & 0 deletions substrate/client/network/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ schnellru = "0.2.1"
smallvec = "1.11.0"
thiserror = "1.0"
tokio-stream = "0.1.14"
tokio = { version = "1.32.0", features = ["time", "macros"] }
fork-tree = { path = "../../../utils/fork-tree" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus" }
sc-client-api = { path = "../../api" }
Expand Down
12 changes: 10 additions & 2 deletions substrate/client/network/sync/src/block_announce_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! `BlockAnnounceValidator` is responsible for async validation of block announcements.
//! [`BlockAnnounceValidator`] is responsible for async validation of block announcements.
//! [`Stream`] implemented by [`BlockAnnounceValidator`] never terminates.

use crate::futures_stream::FuturesStream;
use futures::{Future, FutureExt, Stream, StreamExt};
use futures::{stream::FusedStream, Future, FutureExt, Stream, StreamExt};
use libp2p::PeerId;
use log::{debug, error, trace, warn};
use sc_network_common::sync::message::BlockAnnounce;
Expand Down Expand Up @@ -300,6 +301,13 @@ impl<B: BlockT> Stream for BlockAnnounceValidator<B> {
}
}

// As [`BlockAnnounceValidator`] never terminates, we can easily implement [`FusedStream`] for it.
impl<B: BlockT> FusedStream for BlockAnnounceValidator<B> {
fn is_terminated(&self) -> bool {
false
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit d512b3f

Please sign in to comment.