@@ -28,6 +28,7 @@ use bitcoin::{secp256k1, sighash, TxIn};
28
28
#[cfg(splicing)]
29
29
use bitcoin::{FeeRate, Sequence};
30
30
31
+ use crate::blinded_path::message::BlindedMessagePath;
31
32
use crate::chain::chaininterface::{
32
33
fee_for_weight, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
33
34
};
@@ -283,6 +284,24 @@ impl InboundHTLCState {
283
284
_ => None,
284
285
}
285
286
}
287
+
288
+ /// Whether we need to hold onto this HTLC until receipt of a corresponding [`ReleaseHeldHtlc`]
289
+ /// onion message.
290
+ ///
291
+ /// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
292
+ fn should_hold_htlc(&self) -> bool {
293
+ match self {
294
+ InboundHTLCState::RemoteAnnounced(res)
295
+ | InboundHTLCState::AwaitingRemoteRevokeToAnnounce(res)
296
+ | InboundHTLCState::AwaitingAnnouncedRemoteRevoke(res) => match res {
297
+ InboundHTLCResolution::Pending { update_add_htlc } => {
298
+ update_add_htlc.hold_htlc.is_some()
299
+ },
300
+ InboundHTLCResolution::Resolved { .. } => false,
301
+ },
302
+ InboundHTLCState::Committed | InboundHTLCState::LocalRemoved(_) => false,
303
+ }
304
+ }
286
305
}
287
306
288
307
struct InboundHTLCOutput {
@@ -1606,12 +1625,12 @@ where
1606
1625
}
1607
1626
1608
1627
#[rustfmt::skip]
1609
- pub fn signer_maybe_unblocked<L: Deref>(
1610
- &mut self, chain_hash: ChainHash, logger: &L,
1611
- ) -> Option<SignerResumeUpdates> where L::Target: Logger {
1628
+ pub fn signer_maybe_unblocked<L: Deref, CBP >(
1629
+ &mut self, chain_hash: ChainHash, logger: &L, path_for_release_htlc: CBP
1630
+ ) -> Option<SignerResumeUpdates> where L::Target: Logger, CBP: Fn(u64) -> BlindedMessagePath {
1612
1631
match &mut self.phase {
1613
1632
ChannelPhase::Undefined => unreachable!(),
1614
- ChannelPhase::Funded(chan) => Some(chan.signer_maybe_unblocked(logger)),
1633
+ ChannelPhase::Funded(chan) => Some(chan.signer_maybe_unblocked(logger, path_for_release_htlc )),
1615
1634
ChannelPhase::UnfundedOutboundV1(chan) => {
1616
1635
let (open_channel, funding_created) = chan.signer_maybe_unblocked(chain_hash, logger);
1617
1636
Some(SignerResumeUpdates {
@@ -8712,13 +8731,14 @@ where
8712
8731
/// successfully and we should restore normal operation. Returns messages which should be sent
8713
8732
/// to the remote side.
8714
8733
#[rustfmt::skip]
8715
- pub fn monitor_updating_restored<L: Deref, NS: Deref>(
8734
+ pub fn monitor_updating_restored<L: Deref, NS: Deref, CBP >(
8716
8735
&mut self, logger: &L, node_signer: &NS, chain_hash: ChainHash,
8717
- user_config: &UserConfig, best_block_height: u32
8736
+ user_config: &UserConfig, best_block_height: u32, path_for_release_htlc: CBP
8718
8737
) -> MonitorRestoreUpdates
8719
8738
where
8720
8739
L::Target: Logger,
8721
- NS::Target: NodeSigner
8740
+ NS::Target: NodeSigner,
8741
+ CBP: Fn(u64) -> BlindedMessagePath
8722
8742
{
8723
8743
assert!(self.context.channel_state.is_monitor_update_in_progress());
8724
8744
self.context.channel_state.clear_monitor_update_in_progress();
@@ -8787,7 +8807,7 @@ where
8787
8807
}
8788
8808
8789
8809
let mut raa = if self.context.monitor_pending_revoke_and_ack {
8790
- self.get_last_revoke_and_ack(logger)
8810
+ self.get_last_revoke_and_ack(path_for_release_htlc, logger)
8791
8811
} else { None };
8792
8812
let mut commitment_update = if self.context.monitor_pending_commitment_signed {
8793
8813
self.get_last_commitment_update_for_send(logger).ok()
@@ -8877,7 +8897,9 @@ where
8877
8897
/// Indicates that the signer may have some signatures for us, so we should retry if we're
8878
8898
/// blocked.
8879
8899
#[rustfmt::skip]
8880
- pub fn signer_maybe_unblocked<L: Deref>(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger {
8900
+ pub fn signer_maybe_unblocked<L: Deref, CBP>(
8901
+ &mut self, logger: &L, path_for_release_htlc: CBP
8902
+ ) -> SignerResumeUpdates where L::Target: Logger, CBP: Fn(u64) -> BlindedMessagePath {
8881
8903
if !self.holder_commitment_point.can_advance() {
8882
8904
log_trace!(logger, "Attempting to update holder per-commitment point...");
8883
8905
self.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger);
@@ -8905,7 +8927,7 @@ where
8905
8927
} else { None };
8906
8928
let mut revoke_and_ack = if self.context.signer_pending_revoke_and_ack {
8907
8929
log_trace!(logger, "Attempting to generate pending revoke and ack...");
8908
- self.get_last_revoke_and_ack(logger)
8930
+ self.get_last_revoke_and_ack(path_for_release_htlc, logger)
8909
8931
} else { None };
8910
8932
8911
8933
if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
@@ -8976,9 +8998,12 @@ where
8976
8998
}
8977
8999
}
8978
9000
8979
- fn get_last_revoke_and_ack<L: Deref>(&mut self, logger: &L) -> Option<msgs::RevokeAndACK>
9001
+ fn get_last_revoke_and_ack<CBP, L: Deref>(
9002
+ &mut self, path_for_release_htlc: CBP, logger: &L,
9003
+ ) -> Option<msgs::RevokeAndACK>
8980
9004
where
8981
9005
L::Target: Logger,
9006
+ CBP: Fn(u64) -> BlindedMessagePath,
8982
9007
{
8983
9008
debug_assert!(
8984
9009
self.holder_commitment_point.next_transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2
@@ -8991,14 +9016,22 @@ where
8991
9016
.ok();
8992
9017
if let Some(per_commitment_secret) = per_commitment_secret {
8993
9018
if self.holder_commitment_point.can_advance() {
9019
+ let mut release_htlc_message_paths = Vec::new();
9020
+ for htlc in &self.context.pending_inbound_htlcs {
9021
+ if htlc.state.should_hold_htlc() {
9022
+ let path = path_for_release_htlc(htlc.htlc_id);
9023
+ release_htlc_message_paths.push((htlc.htlc_id, path));
9024
+ }
9025
+ }
9026
+
8994
9027
self.context.signer_pending_revoke_and_ack = false;
8995
9028
return Some(msgs::RevokeAndACK {
8996
9029
channel_id: self.context.channel_id,
8997
9030
per_commitment_secret,
8998
9031
next_per_commitment_point: self.holder_commitment_point.next_point(),
8999
9032
#[cfg(taproot)]
9000
9033
next_local_nonce: None,
9001
- release_htlc_message_paths: Vec::new() ,
9034
+ release_htlc_message_paths,
9002
9035
});
9003
9036
}
9004
9037
}
@@ -9146,13 +9179,15 @@ where
9146
9179
/// May panic if some calls other than message-handling calls (which will all Err immediately)
9147
9180
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
9148
9181
#[rustfmt::skip]
9149
- pub fn channel_reestablish<L: Deref, NS: Deref>(
9182
+ pub fn channel_reestablish<L: Deref, NS: Deref, CBP >(
9150
9183
&mut self, msg: &msgs::ChannelReestablish, logger: &L, node_signer: &NS,
9151
- chain_hash: ChainHash, user_config: &UserConfig, best_block: &BestBlock
9184
+ chain_hash: ChainHash, user_config: &UserConfig, best_block: &BestBlock,
9185
+ path_for_release_htlc: CBP,
9152
9186
) -> Result<ReestablishResponses, ChannelError>
9153
9187
where
9154
9188
L::Target: Logger,
9155
- NS::Target: NodeSigner
9189
+ NS::Target: NodeSigner,
9190
+ CBP: Fn(u64) -> BlindedMessagePath
9156
9191
{
9157
9192
if !self.context.channel_state.is_peer_disconnected() {
9158
9193
// While BOLT 2 doesn't indicate explicitly we should error this channel here, it
@@ -9371,7 +9406,7 @@ where
9371
9406
self.context.monitor_pending_revoke_and_ack = true;
9372
9407
None
9373
9408
} else {
9374
- self.get_last_revoke_and_ack(logger)
9409
+ self.get_last_revoke_and_ack(path_for_release_htlc, logger)
9375
9410
}
9376
9411
} else {
9377
9412
debug_assert!(false, "All values should have been handled in the four cases above");
@@ -16635,6 +16670,7 @@ mod tests {
16635
16670
chain_hash,
16636
16671
&config,
16637
16672
0,
16673
+ |_| unreachable!()
16638
16674
);
16639
16675
16640
16676
// Receive funding_signed, but the channel will be configured to hold sending channel_ready and
@@ -16649,6 +16685,7 @@ mod tests {
16649
16685
chain_hash,
16650
16686
&config,
16651
16687
0,
16688
+ |_| unreachable!()
16652
16689
);
16653
16690
// Our channel_ready shouldn't be sent yet, even with trust_own_funding_0conf set,
16654
16691
// as the funding transaction depends on all channels in the batch becoming ready.
0 commit comments