Skip to content

Commit

Permalink
multi: include Send in LightningNode trait as supertrait
Browse files Browse the repository at this point in the history
  • Loading branch information
carlaKC committed Jan 24, 2024
1 parent f4a8779 commit a0f0e28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions sim-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ async fn main() -> anyhow::Result<()> {
serde_json::from_str(&std::fs::read_to_string(sim_path)?)
.map_err(|e| anyhow!("Could not deserialize node connection data or activity description from simulation file (line {}, col {}).", e.line(), e.column()))?;

let mut clients: HashMap<PublicKey, Arc<Mutex<dyn LightningNode + Send>>> = HashMap::new();
let mut clients: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>> = HashMap::new();
let mut pk_node_map = HashMap::new();
let mut alias_node_map = HashMap::new();

for connection in nodes {
// TODO: Feels like there should be a better way of doing this without having to Arc<Mutex<T>>> it at this time.
// Box sort of works, but we won't know the size of the dyn LightningNode at compile time so the compiler will
// scream at us when trying to create the Arc<Mutex>> later on while adding the node to the clients map
let node: Arc<Mutex<dyn LightningNode + Send>> = match connection {
let node: Arc<Mutex<dyn LightningNode>> = match connection {
NodeConnection::LND(c) => Arc::new(Mutex::new(LndNode::new(c).await?)),
NodeConnection::CLN(c) => Arc::new(Mutex::new(ClnNode::new(c).await?)),
};
Expand Down
12 changes: 6 additions & 6 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Display for NodeInfo {

/// LightningNode represents the functionality that is required to execute events on a lightning node.
#[async_trait]
pub trait LightningNode {
pub trait LightningNode: Send {
/// Get information about the node.
fn get_info(&self) -> &NodeInfo;
/// Get the network this node is running at
Expand Down Expand Up @@ -325,7 +325,7 @@ enum SimulationOutput {
#[derive(Clone)]
pub struct Simulation {
// The lightning node that is being simulated.
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode + Send>>>,
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
// The activity that are to be executed on the node.
activity: Vec<ActivityDefinition>,
// High level triggers used to manage simulation tasks and shutdown.
Expand Down Expand Up @@ -362,7 +362,7 @@ struct ExecutorKit {

impl Simulation {
pub fn new(
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode + Send>>>,
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
activity: Vec<ActivityDefinition>,
total_time: Option<u32>,
expected_payment_msat: u64,
Expand Down Expand Up @@ -727,7 +727,7 @@ impl Simulation {
// expect the senders corresponding to our receiver to be dropped, which will cause the receiver to error out and
// exit.
async fn consume_events(
node: Arc<Mutex<dyn LightningNode + Send>>,
node: Arc<Mutex<dyn LightningNode>>,
mut receiver: Receiver<SimulationEvent>,
sender: Sender<SimulationOutput>,
shutdown: Trigger,
Expand Down Expand Up @@ -989,7 +989,7 @@ async fn run_results_logger(
/// out. In the multiple-producer case, a single producer shutting down does not drop *all* sending channels so the
/// consumer will not exit and a trigger is required.
async fn produce_simulation_results(
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode + Send>>>,
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
mut output_receiver: Receiver<SimulationOutput>,
results: Sender<(Payment, PaymentResult)>,
shutdown: Listener,
Expand Down Expand Up @@ -1037,7 +1037,7 @@ async fn produce_simulation_results(
}

async fn track_payment_result(
node: Arc<Mutex<dyn LightningNode + Send>>,
node: Arc<Mutex<dyn LightningNode>>,
results: Sender<(Payment, PaymentResult)>,
payment: Payment,
shutdown: Listener,
Expand Down

0 comments on commit a0f0e28

Please sign in to comment.