mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 01:07:57 +00:00
Remove NetworkSpecialization (#4665)
* remove networkspecialization * Fix most of the fallout * get all tests compiling Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e8000e7429
commit
0090fe979b
@@ -52,17 +52,14 @@ use sc_network::config::{NetworkConfiguration, TransportConfig, BoxFinalityProof
|
||||
use libp2p::PeerId;
|
||||
use parking_lot::Mutex;
|
||||
use sp_core::H256;
|
||||
use sc_network::config::ProtocolConfig;
|
||||
use sc_network::config::{ProtocolConfig, TransactionPool};
|
||||
use sp_runtime::generic::{BlockId, OpaqueDigestItemId};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use sp_runtime::Justification;
|
||||
use sc_network::config::TransactionPool;
|
||||
use sc_network::specialization::NetworkSpecialization;
|
||||
use substrate_test_runtime_client::{self, AccountKeyring};
|
||||
|
||||
pub use substrate_test_runtime_client::runtime::{Block, Extrinsic, Hash, Transfer};
|
||||
pub use substrate_test_runtime_client::{TestClient, TestClientBuilder, TestClientBuilderExt};
|
||||
pub use sc_network::specialization::DummySpecialization;
|
||||
|
||||
type AuthorityId = sp_consensus_babe::AuthorityId;
|
||||
|
||||
@@ -178,7 +175,7 @@ impl PeersClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Peer<D, S: NetworkSpecialization<Block>> {
|
||||
pub struct Peer<D> {
|
||||
pub data: D,
|
||||
client: PeersClient,
|
||||
/// We keep a copy of the verifier so that we can invoke it for locally-generated blocks,
|
||||
@@ -189,12 +186,12 @@ pub struct Peer<D, S: NetworkSpecialization<Block>> {
|
||||
block_import: BlockImportAdapter<()>,
|
||||
select_chain: Option<LongestChain<substrate_test_runtime_client::Backend, Block>>,
|
||||
backend: Option<Arc<substrate_test_runtime_client::Backend>>,
|
||||
network: NetworkWorker<Block, S, <Block as BlockT>::Hash>,
|
||||
network: NetworkWorker<Block, <Block as BlockT>::Hash>,
|
||||
imported_blocks_stream: Box<dyn Stream<Item = BlockImportNotification<Block>, Error = ()> + Send>,
|
||||
finality_notification_stream: Box<dyn Stream<Item = FinalityNotification<Block>, Error = ()> + Send>,
|
||||
}
|
||||
|
||||
impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
impl<D> Peer<D> {
|
||||
/// Get this peer ID.
|
||||
pub fn id(&self) -> PeerId {
|
||||
self.network.service().local_peer_id()
|
||||
@@ -283,7 +280,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
Default::default()
|
||||
};
|
||||
self.block_import.import_block(import_block, cache).expect("block_import failed");
|
||||
self.network.on_block_imported(hash, header, Vec::new(), true);
|
||||
self.network.on_block_imported(header, Vec::new(), true);
|
||||
at = hash;
|
||||
}
|
||||
|
||||
@@ -336,7 +333,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
}
|
||||
|
||||
/// Get a reference to the network service.
|
||||
pub fn network_service(&self) -> &Arc<NetworkService<Block, S, <Block as BlockT>::Hash>> {
|
||||
pub fn network_service(&self) -> &Arc<NetworkService<Block, <Block as BlockT>::Hash>> {
|
||||
&self.network.service()
|
||||
}
|
||||
|
||||
@@ -392,16 +389,6 @@ impl TransactionPool<Hash, Block> for EmptyTransactionPool {
|
||||
fn transaction(&self, _h: &Hash) -> Option<Extrinsic> { None }
|
||||
}
|
||||
|
||||
pub trait SpecializationFactory {
|
||||
fn create() -> Self;
|
||||
}
|
||||
|
||||
impl SpecializationFactory for DummySpecialization {
|
||||
fn create() -> DummySpecialization {
|
||||
DummySpecialization
|
||||
}
|
||||
}
|
||||
|
||||
/// Implements `BlockImport` for any `Transaction`. Internally the transaction is
|
||||
/// "converted", aka the field is set to `None`.
|
||||
///
|
||||
@@ -522,7 +509,6 @@ impl<B: BlockT> VerifierAdapter<B> {
|
||||
}
|
||||
|
||||
pub trait TestNetFactory: Sized {
|
||||
type Specialization: NetworkSpecialization<Block> + SpecializationFactory;
|
||||
type Verifier: 'static + Verifier<Block>;
|
||||
type PeerData: Default;
|
||||
|
||||
@@ -536,9 +522,9 @@ pub trait TestNetFactory: Sized {
|
||||
) -> Self::Verifier;
|
||||
|
||||
/// Get reference to peer.
|
||||
fn peer(&mut self, i: usize) -> &mut Peer<Self::PeerData, Self::Specialization>;
|
||||
fn peers(&self) -> &Vec<Peer<Self::PeerData, Self::Specialization>>;
|
||||
fn mut_peers<F: FnOnce(&mut Vec<Peer<Self::PeerData, Self::Specialization>>)>(
|
||||
fn peer(&mut self, i: usize) -> &mut Peer<Self::PeerData>;
|
||||
fn peers(&self) -> &Vec<Peer<Self::PeerData>>;
|
||||
fn mut_peers<F: FnOnce(&mut Vec<Peer<Self::PeerData>>)>(
|
||||
&mut self,
|
||||
closure: F,
|
||||
);
|
||||
@@ -636,7 +622,6 @@ pub trait TestNetFactory: Sized {
|
||||
transaction_pool: Arc::new(EmptyTransactionPool),
|
||||
protocol_id: ProtocolId::from(&b"test-protocol-name"[..]),
|
||||
import_queue,
|
||||
specialization: self::SpecializationFactory::create(),
|
||||
block_announce_validator: Box::new(DefaultBlockAnnounceValidator::new(client.clone()))
|
||||
}).unwrap();
|
||||
|
||||
@@ -712,7 +697,6 @@ pub trait TestNetFactory: Sized {
|
||||
transaction_pool: Arc::new(EmptyTransactionPool),
|
||||
protocol_id: ProtocolId::from(&b"test-protocol-name"[..]),
|
||||
import_queue,
|
||||
specialization: self::SpecializationFactory::create(),
|
||||
block_announce_validator: Box::new(DefaultBlockAnnounceValidator::new(client.clone()))
|
||||
}).unwrap();
|
||||
|
||||
@@ -784,7 +768,6 @@ pub trait TestNetFactory: Sized {
|
||||
// We poll `imported_blocks_stream`.
|
||||
while let Ok(Async::Ready(Some(notification))) = peer.imported_blocks_stream.poll() {
|
||||
peer.network.on_block_imported(
|
||||
notification.hash,
|
||||
notification.header,
|
||||
Vec::new(),
|
||||
true,
|
||||
@@ -805,11 +788,10 @@ pub trait TestNetFactory: Sized {
|
||||
}
|
||||
|
||||
pub struct TestNet {
|
||||
peers: Vec<Peer<(), DummySpecialization>>,
|
||||
peers: Vec<Peer<()>>,
|
||||
}
|
||||
|
||||
impl TestNetFactory for TestNet {
|
||||
type Specialization = DummySpecialization;
|
||||
type Verifier = PassThroughVerifier;
|
||||
type PeerData = ();
|
||||
|
||||
@@ -826,15 +808,15 @@ impl TestNetFactory for TestNet {
|
||||
PassThroughVerifier(false)
|
||||
}
|
||||
|
||||
fn peer(&mut self, i: usize) -> &mut Peer<(), Self::Specialization> {
|
||||
fn peer(&mut self, i: usize) -> &mut Peer<()> {
|
||||
&mut self.peers[i]
|
||||
}
|
||||
|
||||
fn peers(&self) -> &Vec<Peer<(), Self::Specialization>> {
|
||||
fn peers(&self) -> &Vec<Peer<()>> {
|
||||
&self.peers
|
||||
}
|
||||
|
||||
fn mut_peers<F: FnOnce(&mut Vec<Peer<(), Self::Specialization>>)>(&mut self, closure: F) {
|
||||
fn mut_peers<F: FnOnce(&mut Vec<Peer<()>>)>(&mut self, closure: F) {
|
||||
closure(&mut self.peers);
|
||||
}
|
||||
}
|
||||
@@ -858,7 +840,6 @@ impl JustificationImport<Block> for ForceFinalized {
|
||||
pub struct JustificationTestNet(TestNet);
|
||||
|
||||
impl TestNetFactory for JustificationTestNet {
|
||||
type Specialization = DummySpecialization;
|
||||
type Verifier = PassThroughVerifier;
|
||||
type PeerData = ();
|
||||
|
||||
@@ -870,17 +851,16 @@ impl TestNetFactory for JustificationTestNet {
|
||||
self.0.make_verifier(client, config, peer_data)
|
||||
}
|
||||
|
||||
fn peer(&mut self, i: usize) -> &mut Peer<Self::PeerData, Self::Specialization> {
|
||||
fn peer(&mut self, i: usize) -> &mut Peer<Self::PeerData> {
|
||||
self.0.peer(i)
|
||||
}
|
||||
|
||||
fn peers(&self) -> &Vec<Peer<Self::PeerData, Self::Specialization>> {
|
||||
fn peers(&self) -> &Vec<Peer<Self::PeerData>> {
|
||||
self.0.peers()
|
||||
}
|
||||
|
||||
fn mut_peers<F: FnOnce(
|
||||
&mut Vec<Peer<Self::PeerData,
|
||||
Self::Specialization>>,
|
||||
&mut Vec<Peer<Self::PeerData>>,
|
||||
)>(&mut self, closure: F) {
|
||||
self.0.mut_peers(closure)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user