Skip to content

Commit

Permalink
save earliest htlc expiry from all htlcs of an invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 committed Jun 21, 2023
1 parent 276b662 commit 2fb6721
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
33 changes: 18 additions & 15 deletions plugins/grpc-plugin-hold/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,36 @@ pub(crate) async fn htlc_handler(
hold_state,
generation,
htlc_data,
last_htlc_expiry: cltv_expiry,
invoice: invoice.clone(),
},
);
} else {
let holdinvoice = states.get_mut(&pay_hash.to_string()).unwrap();
if cltv_expiry
< holdinvoice
.htlc_data
.values()
.map(|htlc| htlc.cltv_expiry)
.min()
.unwrap()
{
datastore_htlc_expiry(
&rpc_path,
pay_hash.to_string(),
cltv_expiry.to_string(),
)
.await?;
}
holdinvoice.htlc_data.insert(
global_htlc_ident.clone(),
HoldHtlc {
amount_msat,
cltv_expiry,
},
);

let earliest_htlc_expiry = holdinvoice
.htlc_data
.values()
.map(|htlc| htlc.cltv_expiry)
.min()
.unwrap();

if holdinvoice.last_htlc_expiry != earliest_htlc_expiry {
datastore_htlc_expiry(
&rpc_path,
pay_hash.to_string(),
earliest_htlc_expiry.to_string(),
)
.await?;
holdinvoice.last_htlc_expiry = earliest_htlc_expiry;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions plugins/grpc-plugin-hold/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct HoldInvoice {
pub hold_state: Holdstate,
pub generation: u64,
pub htlc_data: HashMap<HtlcIdentifier, HoldHtlc>,
pub last_htlc_expiry: u32,
pub invoice: ListinvoicesInvoices,
}

Expand Down

0 comments on commit 2fb6721

Please sign in to comment.