Skip to content

Commit 466fea5

Browse files
authored
Merge pull request #275 from carlaKC/267-remove-async
simln-lib: remove unnecessary async in SimNode trait
2 parents 8dc3d4a + 0af677a commit 466fea5

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

simln-lib/src/sim_node.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ impl SimulatedChannel {
467467

468468
/// SimNetwork represents a high level network coordinator that is responsible for the task of actually propagating
469469
/// payments through the simulated network.
470-
#[async_trait]
471470
trait SimNetwork: Send + Sync {
472471
/// Sends payments over the route provided through the network, reporting the final payment outcome to the sender
473472
/// channel provided.
@@ -480,9 +479,9 @@ trait SimNetwork: Send + Sync {
480479
);
481480

482481
/// Looks up a node in the simulated network and a list of its channel capacities.
483-
async fn lookup_node(&self, node: &PublicKey) -> Result<(NodeInfo, Vec<u64>), LightningError>;
482+
fn lookup_node(&self, node: &PublicKey) -> Result<(NodeInfo, Vec<u64>), LightningError>;
484483
/// Lists all nodes in the simulated network.
485-
async fn list_nodes(&self) -> Result<Vec<NodeInfo>, LightningError>;
484+
fn list_nodes(&self) -> Result<Vec<NodeInfo>, LightningError>;
486485
}
487486

488487
/// A wrapper struct used to implement the LightningNode trait (can be thought of as "the" lightning node). Passes
@@ -671,21 +670,15 @@ impl<T: SimNetwork> LightningNode for SimNode<'_, T> {
671670
}
672671

673672
async fn get_node_info(&mut self, node_id: &PublicKey) -> Result<NodeInfo, LightningError> {
674-
Ok(self.network.lock().await.lookup_node(node_id).await?.0)
673+
Ok(self.network.lock().await.lookup_node(node_id)?.0)
675674
}
676675

677676
async fn list_channels(&mut self) -> Result<Vec<u64>, LightningError> {
678-
Ok(self
679-
.network
680-
.lock()
681-
.await
682-
.lookup_node(&self.info.pubkey)
683-
.await?
684-
.1)
677+
Ok(self.network.lock().await.lookup_node(&self.info.pubkey)?.1)
685678
}
686679

687680
async fn get_graph(&mut self) -> Result<Graph, LightningError> {
688-
let nodes = self.network.lock().await.list_nodes().await?;
681+
let nodes = self.network.lock().await.list_nodes()?;
689682

690683
let mut nodes_by_pk = HashMap::new();
691684

@@ -1066,7 +1059,6 @@ pub fn populate_network_graph<'a, C: Clock>(
10661059
Ok(graph)
10671060
}
10681061

1069-
#[async_trait]
10701062
impl SimNetwork for SimGraph {
10711063
/// dispatch_payment asynchronously propagates a payment through the simulated network, returning a tracking
10721064
/// channel that can be used to obtain the result of the payment. At present, MPP payments are not supported.
@@ -1109,7 +1101,7 @@ impl SimNetwork for SimGraph {
11091101
}
11101102

11111103
/// lookup_node fetches a node's information and channel capacities.
1112-
async fn lookup_node(&self, node: &PublicKey) -> Result<(NodeInfo, Vec<u64>), LightningError> {
1104+
fn lookup_node(&self, node: &PublicKey) -> Result<(NodeInfo, Vec<u64>), LightningError> {
11131105
self.nodes
11141106
.get(node)
11151107
.map(|channels| (node_info(*node), channels.clone()))
@@ -1118,7 +1110,7 @@ impl SimNetwork for SimGraph {
11181110
))
11191111
}
11201112

1121-
async fn list_nodes(&self) -> Result<Vec<NodeInfo>, LightningError> {
1113+
fn list_nodes(&self) -> Result<Vec<NodeInfo>, LightningError> {
11221114
let mut nodes = vec![];
11231115

11241116
for node in &self.nodes {
@@ -1846,7 +1838,6 @@ mod tests {
18461838
mock! {
18471839
Network{}
18481840

1849-
#[async_trait]
18501841
impl SimNetwork for Network{
18511842
fn dispatch_payment(
18521843
&mut self,
@@ -1856,8 +1847,8 @@ mod tests {
18561847
sender: Sender<Result<PaymentResult, LightningError>>,
18571848
);
18581849

1859-
async fn lookup_node(&self, node: &PublicKey) -> Result<(NodeInfo, Vec<u64>), LightningError>;
1860-
async fn list_nodes(&self) -> Result<Vec<NodeInfo>, LightningError>;
1850+
fn lookup_node(&self, node: &PublicKey) -> Result<(NodeInfo, Vec<u64>), LightningError>;
1851+
fn list_nodes(&self) -> Result<Vec<NodeInfo>, LightningError>;
18611852
}
18621853
}
18631854

0 commit comments

Comments
 (0)