Replace request-response incoming requests queue with async-channel (#14199)

This commit is contained in:
Dmitry Markin
2023-05-24 12:24:09 +03:00
committed by GitHub
parent 4766ec5531
commit db90f3b622
13 changed files with 53 additions and 53 deletions
@@ -20,10 +20,7 @@
use crate::schema::v1::{KeyValueStateEntry, StateEntry, StateRequest, StateResponse};
use codec::{Decode, Encode};
use futures::{
channel::{mpsc, oneshot},
stream::StreamExt,
};
use futures::{channel::oneshot, stream::StreamExt};
use libp2p::PeerId;
use log::{debug, trace};
use lru::LruCache;
@@ -114,7 +111,7 @@ enum SeenRequestsValue {
/// Handler for incoming block requests from a remote peer.
pub struct StateRequestHandler<B: BlockT, Client> {
client: Arc<Client>,
request_receiver: mpsc::Receiver<IncomingRequest>,
request_receiver: async_channel::Receiver<IncomingRequest>,
/// Maps from request to number of times we have seen this request.
///
/// This is used to check if a peer is spamming us with the same request.
@@ -135,7 +132,7 @@ where
) -> (Self, ProtocolConfig) {
// Reserve enough request slots for one request per peer when we are at the maximum
// number of peers.
let (tx, request_receiver) = mpsc::channel(num_peer_hint);
let (tx, request_receiver) = async_channel::bounded(num_peer_hint);
let mut protocol_config = generate_protocol_config(
protocol_id,