-
Notifications
You must be signed in to change notification settings - Fork 37
simln-lib/feature: Optional name for activity descriptions #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a3f4495
b99ac02
6f8d5c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,8 @@ pub type Interval = ValueOrRange<u16>; | |
/// This is constructed during activity validation and passed along to the [Simulation]. | ||
#[derive(Debug, Clone)] | ||
pub struct ActivityDefinition { | ||
/// Optional identifier for this activity. | ||
pub name: Option<String>, | ||
/// The source of the payment. | ||
pub source: NodeInfo, | ||
/// The destination of the payment. | ||
|
@@ -500,6 +502,7 @@ pub struct WriteResults { | |
/// ExecutorKit contains the components required to spin up an activity configured by the user, to be used to | ||
/// spin up the appropriate producers and consumers for the activity. | ||
struct ExecutorKit { | ||
name: Option<String>, | ||
source_info: NodeInfo, | ||
/// We use an arc mutex here because some implementations of the trait will be very expensive to clone. | ||
/// See [NetworkGraphView] for details. | ||
|
@@ -806,6 +809,10 @@ impl Simulation { | |
if !self.activity.is_empty() { | ||
for description in self.activity.iter() { | ||
let activity_generator = DefinedPaymentActivity::new( | ||
description | ||
.name | ||
.clone() | ||
.expect("Defined activity name is required"), | ||
description.destination.clone(), | ||
description | ||
.start_secs | ||
|
@@ -816,6 +823,7 @@ impl Simulation { | |
); | ||
|
||
generators.push(ExecutorKit { | ||
name: description.name.clone(), | ||
source_info: description.source.clone(), | ||
// Defined activities have very simple generators, so the traits required are implemented on | ||
// a single struct which we just cheaply clone. | ||
|
@@ -874,6 +882,7 @@ impl Simulation { | |
|
||
for (node_info, capacity) in active_nodes.values() { | ||
generators.push(ExecutorKit { | ||
name: None, | ||
source_info: node_info.clone(), | ||
network_generator: network_generator.clone(), | ||
payment_generator: Box::new( | ||
|
@@ -958,9 +967,11 @@ impl Simulation { | |
let pe_sender = sender.clone(); | ||
tasks.spawn(async move { | ||
let source = executor.source_info.clone(); | ||
let name = executor.name.as_deref().unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having something be an If somebody were using sim-ln as a library, this would make their code panic if they didn't provide a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the |
||
|
||
log::info!( | ||
"Starting activity producer for {}: {}.", | ||
"[{}] Starting activity producer for {}: {}.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: log name elsewhere as well? |
||
name, | ||
source, | ||
executor.payment_generator | ||
); | ||
|
@@ -1544,7 +1555,7 @@ mod tests { | |
let result = simulation.validate_activity().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("At least two nodes required"))); | ||
} | ||
|
||
|
@@ -1559,7 +1570,7 @@ mod tests { | |
let result = simulation.validate_activity().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("must support keysend"))); | ||
} | ||
|
||
|
@@ -1571,13 +1582,14 @@ mod tests { | |
let missing_nodes = test_utils::create_nodes(1, 100_000); | ||
let missing_node = missing_nodes.first().unwrap().0.clone(); | ||
let dest_node = nodes[0].clone(); | ||
let activity_name = None; | ||
|
||
let activity = test_utils::create_activity(missing_node, dest_node, 1000); | ||
let activity = test_utils::create_activity(activity_name, missing_node, dest_node, 1000); | ||
let simulation = test_utils::create_simulation(clients, vec![activity]); | ||
let result = simulation.validate_activity().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("Source node not found"))); | ||
} | ||
|
||
|
@@ -1588,13 +1600,15 @@ mod tests { | |
let (nodes, clients) = LightningTestNodeBuilder::new(1).build_full(); | ||
let dest_nodes = test_utils::create_nodes(1, 100_000); | ||
let dest_node = dest_nodes.first().unwrap().0.clone(); | ||
let activity_name = None; | ||
|
||
let activity = test_utils::create_activity(nodes[0].clone(), dest_node, 1000); | ||
let activity = | ||
test_utils::create_activity(activity_name, nodes[0].clone(), dest_node, 1000); | ||
let simulation = test_utils::create_simulation(clients, vec![activity]); | ||
let result = simulation.validate_activity().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("does not support keysend"))); | ||
} | ||
|
||
|
@@ -1605,9 +1619,11 @@ mod tests { | |
let (nodes, clients) = LightningTestNodeBuilder::new(1).build_full(); | ||
let dest_nodes = test_utils::create_nodes(1, 100_000); | ||
let mut dest_node = dest_nodes.first().unwrap().0.clone(); | ||
let activity_name = None; | ||
dest_node.features.set_keysend_optional(); | ||
|
||
let activity = test_utils::create_activity(nodes[0].clone(), dest_node, 1000); | ||
let activity = | ||
test_utils::create_activity(activity_name, nodes[0].clone(), dest_node, 1000); | ||
let simulation = test_utils::create_simulation(clients, vec![activity]); | ||
let result = simulation.validate_activity().await; | ||
|
||
|
@@ -1619,13 +1635,15 @@ mod tests { | |
#[tokio::test] | ||
async fn test_validate_zero_amount_no_valid() { | ||
let (nodes, clients) = LightningTestNodeBuilder::new(2).build_full(); | ||
let activity_name = None; | ||
|
||
let activity = test_utils::create_activity(nodes[0].clone(), nodes[1].clone(), 0); | ||
let activity = | ||
test_utils::create_activity(activity_name, nodes[0].clone(), nodes[1].clone(), 0); | ||
let simulation = test_utils::create_simulation(clients, vec![activity]); | ||
let result = simulation.validate_activity().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("zero values"))); | ||
} | ||
|
||
|
@@ -1639,7 +1657,7 @@ mod tests { | |
let result = simulation.validate_node_network().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("we don't control any nodes"))); | ||
} | ||
|
||
|
@@ -1655,7 +1673,7 @@ mod tests { | |
let result = simulation.validate_node_network().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("mainnet is not supported"))); | ||
} | ||
|
||
|
@@ -1671,7 +1689,7 @@ mod tests { | |
let result = simulation.validate_node_network().await; | ||
|
||
assert!(result.is_err()); | ||
assert!(matches!(result, | ||
assert!(matches!(result, | ||
Err(LightningError::ValidationError(msg)) if msg.contains("nodes are not on the same network"))); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,11 +207,13 @@ pub fn create_simulation( | |
) | ||
} | ||
pub fn create_activity( | ||
name: Option<String>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unclear to me what value this commit is adding? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the question, This commit is required because without the
This change ensures the |
||
source: NodeInfo, | ||
destination: NodeInfo, | ||
amount_msat: u64, | ||
) -> ActivityDefinition { | ||
ActivityDefinition { | ||
name, | ||
source, | ||
destination, | ||
start_secs: None, | ||
|
Uh oh!
There was an error while loading. Please reload this page.