Skip to content

Commit

Permalink
Fix client code to match new NetworkService interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-markin committed Feb 11, 2023
1 parent 913e21c commit 8e1db2c
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
4 changes: 4 additions & 0 deletions client/authority-discovery/src/worker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ impl NetworkStateInfo for TestNetwork {
fn external_addresses(&self) -> Vec<Multiaddr> {
self.external_addresses.clone()
}

fn listen_addresses(&self) -> Vec<Multiaddr> {
self.external_addresses.clone()
}
}

struct TestSigner<'a> {
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/communication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const TELEMETRY_VOTERS_LIMIT: usize = 10;
/// well as the ability to set a fork sync request for a particular block.
pub trait Network<Block: BlockT>:
NetworkSyncForkRequest<Block::Hash, NumberFor<Block>>
+ NetworkBlock<Block::Hash, NumberFor<Block>>
+ NetworkBlock<Block::Hash, NumberFor<Block>, Block::Header>
+ GossipNetwork<Block>
+ Clone
+ Send
Expand All @@ -179,7 +179,7 @@ impl<Block, T> Network<Block> for T
where
Block: BlockT,
T: NetworkSyncForkRequest<Block::Hash, NumberFor<Block>>
+ NetworkBlock<Block::Hash, NumberFor<Block>>
+ NetworkBlock<Block::Hash, NumberFor<Block>, Block::Header>
+ GossipNetwork<Block>
+ Clone
+ Send
Expand Down
8 changes: 6 additions & 2 deletions client/finality-grandpa/src/communication/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sc_network_common::{
},
};
use sc_network_gossip::Validator;
use sc_network_test::{Block, Hash};
use sc_network_test::{Block, Hash, Header};
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use sp_finality_grandpa::AuthorityList;
use sp_keyring::Ed25519Keyring;
Expand Down Expand Up @@ -155,14 +155,18 @@ impl NetworkNotification for TestNetwork {
}
}

impl NetworkBlock<Hash, NumberFor<Block>> for TestNetwork {
impl NetworkBlock<Hash, NumberFor<Block>, Header> for TestNetwork {
fn announce_block(&self, hash: Hash, _data: Option<Vec<u8>>) {
let _ = self.sender.unbounded_send(Event::Announce(hash));
}

fn new_best_block_imported(&self, _hash: Hash, _number: NumberFor<Block>) {
unimplemented!();
}

fn on_block_finalized(&self, _hash: Hash, _header: Header) {
unimplemented!();
}
}

impl NetworkSyncForkRequest<Hash, NumberFor<Block>> for TestNetwork {
Expand Down
12 changes: 11 additions & 1 deletion client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ mod tests {
}
}

impl NetworkBlock<<Block as BlockT>::Hash, NumberFor<Block>> for TestNetwork {
impl NetworkBlock<<Block as BlockT>::Hash, NumberFor<Block>, <Block as BlockT>::Header>
for TestNetwork
{
fn announce_block(&self, _hash: <Block as BlockT>::Hash, _data: Option<Vec<u8>>) {
unimplemented!();
}
Expand All @@ -447,6 +449,14 @@ mod tests {
) {
unimplemented!();
}

fn on_block_finalized(
&self,
_hash: <Block as BlockT>::Hash,
_header: <Block as BlockT>::Header,
) {
unimplemented!();
}
}

struct AllowAll;
Expand Down
7 changes: 5 additions & 2 deletions client/network-gossip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ mod validator;

/// Abstraction over a network.
pub trait Network<B: BlockT>:
NetworkPeers + NetworkEventStream + NetworkNotification + NetworkBlock<B::Hash, NumberFor<B>>
NetworkPeers
+ NetworkEventStream
+ NetworkNotification
+ NetworkBlock<B::Hash, NumberFor<B>, B::Header>
{
fn add_set_reserved(&self, who: PeerId, protocol: ProtocolName) {
let addr =
Expand All @@ -97,6 +100,6 @@ impl<T, B: BlockT> Network<B> for T where
T: NetworkPeers
+ NetworkEventStream
+ NetworkNotification
+ NetworkBlock<B::Hash, NumberFor<B>>
+ NetworkBlock<B::Hash, NumberFor<B>, B::Header>
{
}
12 changes: 11 additions & 1 deletion client/network-gossip/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ mod tests {
}
}

impl NetworkBlock<<Block as BlockT>::Hash, NumberFor<Block>> for NoOpNetwork {
impl NetworkBlock<<Block as BlockT>::Hash, NumberFor<Block>, <Block as BlockT>::Header>
for NoOpNetwork
{
fn announce_block(&self, _hash: <Block as BlockT>::Hash, _data: Option<Vec<u8>>) {
unimplemented!();
}
Expand All @@ -689,6 +691,14 @@ mod tests {
) {
unimplemented!();
}

fn on_block_finalized(
&self,
_hash: <Block as BlockT>::Hash,
_header: <Block as BlockT>::Header,
) {
unimplemented!();
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use sp_runtime::{
};
use substrate_test_runtime_client::AccountKeyring;
pub use substrate_test_runtime_client::{
runtime::{Block, Extrinsic, Hash, Transfer},
runtime::{Block, Extrinsic, Hash, Header, Transfer},
TestClient, TestClientBuilder, TestClientBuilderExt,
};
use tokio::time::timeout;
Expand Down
4 changes: 4 additions & 0 deletions client/offchain/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ mod tests {
fn local_peer_id(&self) -> PeerId {
PeerId::random()
}

fn listen_addresses(&self) -> Vec<Multiaddr> {
Vec::new()
}
}

fn offchain_api() -> (Api, AsyncApi) {
Expand Down
4 changes: 4 additions & 0 deletions client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ mod tests {
fn local_peer_id(&self) -> PeerId {
PeerId::random()
}

fn listen_addresses(&self) -> Vec<Multiaddr> {
Vec::new()
}
}

impl NetworkPeers for TestNetwork {
Expand Down

0 comments on commit 8e1db2c

Please sign in to comment.