Skip to content

Commit

Permalink
Merge pull request #1267 from getlipa/fix/get-activity-deadlock
Browse files Browse the repository at this point in the history
Fix `activities().get()` deadlock
  • Loading branch information
danielgranhao authored Nov 20, 2024
2 parents d78a488 + 524d7b5 commit ed652c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 14 additions & 0 deletions examples/node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ pub(crate) fn poll_for_user_input(node: &LightningNode, log_file_path: &str) {
println!("{}", format!("{message:#}").red());
}
}
"getactivity" => {
if let Err(message) = get_activity(node, &mut words) {
println!("{}", format!("{message:#}").red());
}
}
"o" | "overview" => {
if let Err(message) = overview(node, &mut words) {
println!("{}", format!("{message:#}").red());
Expand Down Expand Up @@ -457,6 +462,7 @@ fn setup_editor(history_path: &Path) -> Editor<CommandHinter, DefaultHistory> {
"listactivities [number of activities = 2]",
"listactivities ",
));
hints.insert(CommandHint::new("getactivity <hash>", "getactivity "));
hints.insert(CommandHint::new("listrecipients", "listrecipients"));
hints.insert(CommandHint::new(
"registerlightningaddress",
Expand Down Expand Up @@ -556,6 +562,7 @@ fn help() {
println!();
println!(" o | overview [number of activities = 10] [fun mode = false]");
println!(" l | listactivities [number of activities = 2]");
println!(" getactivity <hash>");
println!(" listrecipients");
println!(" registerlightningaddress");
println!(" querylightningaddress");
Expand Down Expand Up @@ -1269,6 +1276,13 @@ fn list_activities(node: &LightningNode, words: &mut dyn Iterator<Item = &str>)
Ok(())
}

fn get_activity(node: &LightningNode, words: &mut dyn Iterator<Item = &str>) -> Result<()> {
let hash = words.next().ok_or(anyhow!("Payment hash is required"))?;

let activity = node.activities().get(hash.to_string())?;
print_activity(activity)
}

fn print_activity(activity: Activity) -> Result<()> {
match activity {
Activity::IncomingPayment {
Expand Down
12 changes: 7 additions & 5 deletions src/activities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ impl Activities {
)?
.map(|p| self.activity_from_breez_payment(p))
{
Ok(activity?)
} else if let Some(incoming_payment_info) = self
return activity;
}

let invoice = self
.support
.data_store
.lock_unwrap()
.retrieve_created_invoice_by_hash(&hash)?
.map(|i| self.payment_from_created_invoice(&i))
{
.retrieve_created_invoice_by_hash(&hash)?;
if let Some(invoice) = invoice {
let incoming_payment_info = self.payment_from_created_invoice(&invoice);
Ok(Activity::IncomingPayment {
incoming_payment_info: incoming_payment_info?,
})
Expand Down

0 comments on commit ed652c0

Please sign in to comment.