mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 17:28:00 +00:00
Modular block request handler (#1524)
Submit the outstanding PRs from the old repos(these were already reviewed and approved before the repo rorg, but not yet submitted): Main PR: https://github.com/paritytech/substrate/pull/14014 Companion PRs: https://github.com/paritytech/polkadot/pull/7134, https://github.com/paritytech/cumulus/pull/2489 The changes in the PR: 1. ChainSync currently calls into the block request handler directly. Instead, move the block request handler behind a trait. This allows new protocols to be plugged into ChainSync. 2. BuildNetworkParams is changed so that custom relay protocol implementations can be (optionally) passed in during network creation time. If custom protocol is not specified, it defaults to the existing block handler 3. BlockServer and BlockDownloader traits are introduced for the protocol implementation. The existing block handler has been changed to implement these traits 4. Other changes: [X] Make TxHash serializable. This is needed for exchanging the serialized hash in the relay protocol messages [X] Clean up types no longer used(OpaqueBlockRequest, OpaqueBlockResponse) --------- Co-authored-by: Dmitry Markin <dmitry@markin.tech> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
c6df364157
commit
b35b28ca4b
@@ -16,15 +16,17 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
//! Contains a mock implementation of `ChainSync` that can be used
|
||||
//! for testing calls made to `ChainSync`.
|
||||
//! Contains mock implementations of `ChainSync` and 'BlockDownloader'.
|
||||
|
||||
use futures::task::Poll;
|
||||
use crate::block_relay_protocol::{BlockDownloader as BlockDownloaderT, BlockResponseError};
|
||||
|
||||
use futures::{channel::oneshot, task::Poll};
|
||||
use libp2p::PeerId;
|
||||
use sc_network::RequestFailure;
|
||||
use sc_network_common::sync::{
|
||||
message::{BlockAnnounce, BlockData, BlockRequest, BlockResponse},
|
||||
BadPeer, ChainSync as ChainSyncT, Metrics, OnBlockData, OnBlockJustification,
|
||||
OpaqueBlockResponse, PeerInfo, SyncStatus,
|
||||
BadPeer, ChainSync as ChainSyncT, Metrics, OnBlockData, OnBlockJustification, PeerInfo,
|
||||
SyncStatus,
|
||||
};
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor};
|
||||
|
||||
@@ -79,11 +81,6 @@ mockall::mock! {
|
||||
);
|
||||
fn peer_disconnected(&mut self, who: &PeerId);
|
||||
fn metrics(&self) -> Metrics;
|
||||
fn block_response_into_blocks(
|
||||
&self,
|
||||
request: &BlockRequest<Block>,
|
||||
response: OpaqueBlockResponse,
|
||||
) -> Result<Vec<BlockData<Block>>, String>;
|
||||
fn poll<'a>(
|
||||
&mut self,
|
||||
cx: &mut std::task::Context<'a>,
|
||||
@@ -95,3 +92,21 @@ mockall::mock! {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mockall::mock! {
|
||||
pub BlockDownloader<Block: BlockT> {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<Block: BlockT> BlockDownloaderT<Block> for BlockDownloader<Block> {
|
||||
async fn download_blocks(
|
||||
&self,
|
||||
who: PeerId,
|
||||
request: BlockRequest<Block>,
|
||||
) -> Result<Result<Vec<u8>, RequestFailure>, oneshot::Canceled>;
|
||||
fn block_response_into_blocks(
|
||||
&self,
|
||||
request: &BlockRequest<Block>,
|
||||
response: Vec<u8>,
|
||||
) -> Result<Vec<BlockData<Block>>, BlockResponseError>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user