mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
Replace request-response incoming requests queue with async-channel (#14199)
This commit is contained in:
@@ -17,10 +17,7 @@
|
||||
//! Helper for handling (i.e. answering) grandpa warp sync requests from a remote peer.
|
||||
|
||||
use codec::Decode;
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
stream::StreamExt,
|
||||
};
|
||||
use futures::{channel::oneshot, stream::StreamExt};
|
||||
use log::debug;
|
||||
|
||||
use sc_network::{
|
||||
@@ -36,6 +33,9 @@ use std::{sync::Arc, time::Duration};
|
||||
|
||||
const MAX_RESPONSE_SIZE: u64 = 16 * 1024 * 1024;
|
||||
|
||||
/// Incoming warp requests bounded queue size.
|
||||
const MAX_WARP_REQUEST_QUEUE: usize = 20;
|
||||
|
||||
/// Generates a [`RequestResponseConfig`] for the grandpa warp sync request protocol, refusing
|
||||
/// incoming requests.
|
||||
pub fn generate_request_response_config<Hash: AsRef<[u8]>>(
|
||||
@@ -72,7 +72,7 @@ fn generate_legacy_protocol_name(protocol_id: ProtocolId) -> String {
|
||||
/// Handler for incoming grandpa warp sync requests from a remote peer.
|
||||
pub struct RequestHandler<TBlock: BlockT> {
|
||||
backend: Arc<dyn WarpSyncProvider<TBlock>>,
|
||||
request_receiver: mpsc::Receiver<IncomingRequest>,
|
||||
request_receiver: async_channel::Receiver<IncomingRequest>,
|
||||
}
|
||||
|
||||
impl<TBlock: BlockT> RequestHandler<TBlock> {
|
||||
@@ -83,7 +83,7 @@ impl<TBlock: BlockT> RequestHandler<TBlock> {
|
||||
fork_id: Option<&str>,
|
||||
backend: Arc<dyn WarpSyncProvider<TBlock>>,
|
||||
) -> (Self, RequestResponseConfig) {
|
||||
let (tx, request_receiver) = mpsc::channel(20);
|
||||
let (tx, request_receiver) = async_channel::bounded(MAX_WARP_REQUEST_QUEUE);
|
||||
|
||||
let mut request_response_config =
|
||||
generate_request_response_config(protocol_id, genesis_hash, fork_id);
|
||||
|
||||
Reference in New Issue
Block a user