@@ -26,6 +26,7 @@ use bitcoin::secp256k1::{ecdsa::Signature, Secp256k1};
26
26
use bitcoin::secp256k1::{PublicKey, SecretKey};
27
27
use bitcoin::{secp256k1, sighash, FeeRate, Sequence, TxIn};
28
28
29
+ use crate::blinded_path::message::BlindedMessagePath;
29
30
use crate::chain::chaininterface::{
30
31
fee_for_weight, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
31
32
};
@@ -273,6 +274,24 @@ impl InboundHTLCState {
273
274
_ => None,
274
275
}
275
276
}
277
+
278
+ /// Whether we need to hold onto this HTLC until receipt of a corresponding [`ReleaseHeldHtlc`]
279
+ /// onion message.
280
+ ///
281
+ /// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
282
+ fn should_hold_htlc(&self) -> bool {
283
+ match self {
284
+ InboundHTLCState::RemoteAnnounced(res)
285
+ | InboundHTLCState::AwaitingRemoteRevokeToAnnounce(res)
286
+ | InboundHTLCState::AwaitingAnnouncedRemoteRevoke(res) => match res {
287
+ InboundHTLCResolution::Pending { update_add_htlc } => {
288
+ update_add_htlc.hold_htlc.is_some()
289
+ },
290
+ InboundHTLCResolution::Resolved { .. } => false,
291
+ },
292
+ InboundHTLCState::Committed | InboundHTLCState::LocalRemoved(_) => false,
293
+ }
294
+ }
276
295
}
277
296
278
297
struct InboundHTLCOutput {
@@ -1588,12 +1607,12 @@ where
1588
1607
}
1589
1608
1590
1609
#[rustfmt::skip]
1591
- pub fn signer_maybe_unblocked<L: Deref>(
1592
- &mut self, chain_hash: ChainHash, logger: &L,
1593
- ) -> Option<SignerResumeUpdates> where L::Target: Logger {
1610
+ pub fn signer_maybe_unblocked<L: Deref, CBP >(
1611
+ &mut self, chain_hash: ChainHash, logger: &L, path_for_release_htlc: CBP
1612
+ ) -> Option<SignerResumeUpdates> where L::Target: Logger, CBP: Fn(u64) -> BlindedMessagePath {
1594
1613
match &mut self.phase {
1595
1614
ChannelPhase::Undefined => unreachable!(),
1596
- ChannelPhase::Funded(chan) => Some(chan.signer_maybe_unblocked(logger)),
1615
+ ChannelPhase::Funded(chan) => Some(chan.signer_maybe_unblocked(logger, path_for_release_htlc )),
1597
1616
ChannelPhase::UnfundedOutboundV1(chan) => {
1598
1617
let (open_channel, funding_created) = chan.signer_maybe_unblocked(chain_hash, logger);
1599
1618
Some(SignerResumeUpdates {
@@ -8901,13 +8920,14 @@ where
8901
8920
/// successfully and we should restore normal operation. Returns messages which should be sent
8902
8921
/// to the remote side.
8903
8922
#[rustfmt::skip]
8904
- pub fn monitor_updating_restored<L: Deref, NS: Deref>(
8923
+ pub fn monitor_updating_restored<L: Deref, NS: Deref, CBP >(
8905
8924
&mut self, logger: &L, node_signer: &NS, chain_hash: ChainHash,
8906
- user_config: &UserConfig, best_block_height: u32
8925
+ user_config: &UserConfig, best_block_height: u32, path_for_release_htlc: CBP
8907
8926
) -> MonitorRestoreUpdates
8908
8927
where
8909
8928
L::Target: Logger,
8910
- NS::Target: NodeSigner
8929
+ NS::Target: NodeSigner,
8930
+ CBP: Fn(u64) -> BlindedMessagePath
8911
8931
{
8912
8932
assert!(self.context.channel_state.is_monitor_update_in_progress());
8913
8933
self.context.channel_state.clear_monitor_update_in_progress();
@@ -8976,7 +8996,7 @@ where
8976
8996
}
8977
8997
8978
8998
let mut raa = if self.context.monitor_pending_revoke_and_ack {
8979
- self.get_last_revoke_and_ack(logger)
8999
+ self.get_last_revoke_and_ack(path_for_release_htlc, logger)
8980
9000
} else { None };
8981
9001
let mut commitment_update = if self.context.monitor_pending_commitment_signed {
8982
9002
self.get_last_commitment_update_for_send(logger).ok()
@@ -9066,7 +9086,9 @@ where
9066
9086
/// Indicates that the signer may have some signatures for us, so we should retry if we're
9067
9087
/// blocked.
9068
9088
#[rustfmt::skip]
9069
- pub fn signer_maybe_unblocked<L: Deref>(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger {
9089
+ pub fn signer_maybe_unblocked<L: Deref, CBP>(
9090
+ &mut self, logger: &L, path_for_release_htlc: CBP
9091
+ ) -> SignerResumeUpdates where L::Target: Logger, CBP: Fn(u64) -> BlindedMessagePath {
9070
9092
if !self.holder_commitment_point.can_advance() {
9071
9093
log_trace!(logger, "Attempting to update holder per-commitment point...");
9072
9094
self.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger);
@@ -9094,7 +9116,7 @@ where
9094
9116
} else { None };
9095
9117
let mut revoke_and_ack = if self.context.signer_pending_revoke_and_ack {
9096
9118
log_trace!(logger, "Attempting to generate pending revoke and ack...");
9097
- self.get_last_revoke_and_ack(logger)
9119
+ self.get_last_revoke_and_ack(path_for_release_htlc, logger)
9098
9120
} else { None };
9099
9121
9100
9122
if self.context.resend_order == RAACommitmentOrder::CommitmentFirst
@@ -9165,9 +9187,12 @@ where
9165
9187
}
9166
9188
}
9167
9189
9168
- fn get_last_revoke_and_ack<L: Deref>(&mut self, logger: &L) -> Option<msgs::RevokeAndACK>
9190
+ fn get_last_revoke_and_ack<CBP, L: Deref>(
9191
+ &mut self, path_for_release_htlc: CBP, logger: &L,
9192
+ ) -> Option<msgs::RevokeAndACK>
9169
9193
where
9170
9194
L::Target: Logger,
9195
+ CBP: Fn(u64) -> BlindedMessagePath,
9171
9196
{
9172
9197
debug_assert!(
9173
9198
self.holder_commitment_point.next_transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2
@@ -9180,13 +9205,22 @@ where
9180
9205
.ok();
9181
9206
if let Some(per_commitment_secret) = per_commitment_secret {
9182
9207
if self.holder_commitment_point.can_advance() {
9208
+ let mut release_htlc_message_paths = Vec::new();
9209
+ for htlc in &self.context.pending_inbound_htlcs {
9210
+ if htlc.state.should_hold_htlc() {
9211
+ let path = path_for_release_htlc(htlc.htlc_id);
9212
+ release_htlc_message_paths.push((htlc.htlc_id, path));
9213
+ }
9214
+ }
9215
+
9183
9216
self.context.signer_pending_revoke_and_ack = false;
9184
9217
return Some(msgs::RevokeAndACK {
9185
9218
channel_id: self.context.channel_id,
9186
9219
per_commitment_secret,
9187
9220
next_per_commitment_point: self.holder_commitment_point.next_point(),
9188
9221
#[cfg(taproot)]
9189
9222
next_local_nonce: None,
9223
+ release_htlc_message_paths,
9190
9224
});
9191
9225
}
9192
9226
}
@@ -9234,6 +9268,7 @@ where
9234
9268
onion_routing_packet: (**onion_packet).clone(),
9235
9269
skimmed_fee_msat: htlc.skimmed_fee_msat,
9236
9270
blinding_point: htlc.blinding_point,
9271
+ hold_htlc: None, // Will be set by the async sender when support is added
9237
9272
});
9238
9273
}
9239
9274
}
@@ -9333,13 +9368,15 @@ where
9333
9368
/// May panic if some calls other than message-handling calls (which will all Err immediately)
9334
9369
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
9335
9370
#[rustfmt::skip]
9336
- pub fn channel_reestablish<L: Deref, NS: Deref>(
9371
+ pub fn channel_reestablish<L: Deref, NS: Deref, CBP >(
9337
9372
&mut self, msg: &msgs::ChannelReestablish, logger: &L, node_signer: &NS,
9338
- chain_hash: ChainHash, user_config: &UserConfig, best_block: &BestBlock
9373
+ chain_hash: ChainHash, user_config: &UserConfig, best_block: &BestBlock,
9374
+ path_for_release_htlc: CBP,
9339
9375
) -> Result<ReestablishResponses, ChannelError>
9340
9376
where
9341
9377
L::Target: Logger,
9342
- NS::Target: NodeSigner
9378
+ NS::Target: NodeSigner,
9379
+ CBP: Fn(u64) -> BlindedMessagePath
9343
9380
{
9344
9381
if !self.context.channel_state.is_peer_disconnected() {
9345
9382
// While BOLT 2 doesn't indicate explicitly we should error this channel here, it
@@ -9555,7 +9592,7 @@ where
9555
9592
self.context.monitor_pending_revoke_and_ack = true;
9556
9593
None
9557
9594
} else {
9558
- self.get_last_revoke_and_ack(logger)
9595
+ self.get_last_revoke_and_ack(path_for_release_htlc, logger)
9559
9596
}
9560
9597
} else {
9561
9598
debug_assert!(false, "All values should have been handled in the four cases above");
@@ -16782,6 +16819,7 @@ mod tests {
16782
16819
chain_hash,
16783
16820
&config,
16784
16821
0,
16822
+ |_| unreachable!()
16785
16823
);
16786
16824
16787
16825
// Receive funding_signed, but the channel will be configured to hold sending channel_ready and
@@ -16796,6 +16834,7 @@ mod tests {
16796
16834
chain_hash,
16797
16835
&config,
16798
16836
0,
16837
+ |_| unreachable!()
16799
16838
);
16800
16839
// Our channel_ready shouldn't be sent yet, even with trust_own_funding_0conf set,
16801
16840
// as the funding transaction depends on all channels in the batch becoming ready.
0 commit comments