mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 07:27:55 +00:00
Make NetworkService callable for ChainSync (#12542)
Introduce a middleware called `NetworkServiceProvider` which the `ChainSync` can use to communicate with `NetworkService`. `ChainSync` is given a `NetworkServiceHandle` which it uses to call `NetworkServiceProvider` which then dispatches the calls to `NetworkService` on behalf of `ChainSync`. This change will allow `ChainSync` to disconnect and report peers and in the future it'll be possible to send requests and notifications through the `NetworkServiceProvider`. `NetworkServiceProvider` is needed only until the `ChainSync` object has been removed from `Protocol`. After that, a normal `NetworkService` handle can be passed onto `ChainSync` and these changes can be deprecated. Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{ChainSync, ForkTarget};
|
||||
use crate::{service::network::NetworkServiceProvider, ChainSync, ForkTarget};
|
||||
|
||||
use libp2p::PeerId;
|
||||
use sc_network_common::{service::NetworkSyncForkRequest, sync::ChainSync as ChainSyncT};
|
||||
@@ -29,12 +29,14 @@ use substrate_test_runtime_client::{TestClientBuilder, TestClientBuilderExt as _
|
||||
// poll `ChainSync` and verify that a new sync fork request has been registered
|
||||
#[async_std::test]
|
||||
async fn delegate_to_chainsync() {
|
||||
let (_chain_sync_network_provider, chain_sync_network_handle) = NetworkServiceProvider::new();
|
||||
let (mut chain_sync, chain_sync_service) = ChainSync::new(
|
||||
sc_network_common::sync::SyncMode::Full,
|
||||
Arc::new(TestClientBuilder::with_default_backend().build_with_longest_chain().0),
|
||||
Box::new(DefaultBlockAnnounceValidator),
|
||||
1u32,
|
||||
None,
|
||||
chain_sync_network_handle,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user