diff --git a/plugins/grpc-plugin-hold/src/hooks.rs b/plugins/grpc-plugin-hold/src/hooks.rs index 4f389372b144..a3e7a3e40c31 100644 --- a/plugins/grpc-plugin-hold/src/hooks.rs +++ b/plugins/grpc-plugin-hold/src/hooks.rs @@ -164,26 +164,12 @@ 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 { @@ -191,6 +177,23 @@ pub(crate) async fn htlc_handler( 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; + } } } diff --git a/plugins/grpc-plugin-hold/src/main.rs b/plugins/grpc-plugin-hold/src/main.rs index 1ae1527566ef..09097df0e498 100644 --- a/plugins/grpc-plugin-hold/src/main.rs +++ b/plugins/grpc-plugin-hold/src/main.rs @@ -32,6 +32,7 @@ pub struct HoldInvoice { pub hold_state: Holdstate, pub generation: u64, pub htlc_data: HashMap, + pub last_htlc_expiry: u32, pub invoice: ListinvoicesInvoices, }