Skip to content

Async Send Simple Hold #3957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lightning/src/blinded_path/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ pub enum AsyncPaymentsContext {
/// [`Offer`]: crate::offers::offer::Offer
payment_id: PaymentId,
},
/// Context contained within the reply [`BlindedMessagePath`] we put in outbound
/// [`HeldHtlcAvailable`] messages, provided back to us in corresponding [`ReleaseHeldHtlc`]
/// messages.
OutboundHTLC {
/// Incoming channel id of the HTLC that is being held.
chan_id: u64,
/// The HTLC id of the held HTLC on the incoming channel.
htlc_id: u64,
},
/// Context contained within the [`BlindedMessagePath`]s we put in static invoices, provided back
/// to us in corresponding [`HeldHtlcAvailable`] messages.
///
Expand Down Expand Up @@ -599,6 +608,10 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
(2, invoice_id, required),
(4, path_absolute_expiry, required),
},
(6, OutboundHTLC) => {
(0, chan_id, required),
(2, htlc_id, required),
},
);

/// Contains a simple nonce for use in a blinded path's context.
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,7 @@ fn update_add_msg(
onion_routing_packet,
skimmed_fee_msat: None,
blinding_point,
hold_htlc: None,
}
}

Expand Down
22 changes: 19 additions & 3 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ struct OutboundHTLCOutput {
blinding_point: Option<PublicKey>,
skimmed_fee_msat: Option<u64>,
send_timestamp: Option<Duration>,
hold_htlc: bool,
}

impl OutboundHTLCOutput {
Expand Down Expand Up @@ -459,6 +460,7 @@ enum HTLCUpdateAwaitingACK {
// The extra fee we're skimming off the top of this HTLC.
skimmed_fee_msat: Option<u64>,
blinding_point: Option<PublicKey>,
hold_htlc: bool,
},
ClaimHTLC {
payment_preimage: PaymentPreimage,
Expand Down Expand Up @@ -7231,6 +7233,7 @@ where
ref onion_routing_packet,
skimmed_fee_msat,
blinding_point,
hold_htlc,
..
} => {
match self.send_htlc(
Expand All @@ -7242,6 +7245,7 @@ where
false,
skimmed_fee_msat,
blinding_point,
hold_htlc,
fee_estimator,
logger,
) {
Expand Down Expand Up @@ -8362,6 +8366,7 @@ where
onion_routing_packet: (**onion_packet).clone(),
skimmed_fee_msat: htlc.skimmed_fee_msat,
blinding_point: htlc.blinding_point,
hold_htlc: htlc.hold_htlc.then(|| ()),
});
}
}
Expand Down Expand Up @@ -10586,7 +10591,8 @@ where
pub fn queue_add_htlc<F: Deref, L: Deref>(
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
hold_htlc: bool, blinding_point: Option<PublicKey>,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
) -> Result<(), (LocalHTLCFailureReason, String)>
where
F::Target: FeeEstimator,
Expand All @@ -10601,6 +10607,7 @@ where
true,
skimmed_fee_msat,
blinding_point,
hold_htlc,
fee_estimator,
logger,
)
Expand Down Expand Up @@ -10631,7 +10638,7 @@ where
fn send_htlc<F: Deref, L: Deref>(
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>, hold_htlc: bool,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
) -> Result<bool, (LocalHTLCFailureReason, String)>
where
Expand Down Expand Up @@ -10713,6 +10720,7 @@ where
onion_routing_packet,
skimmed_fee_msat,
blinding_point,
hold_htlc,
});
return Ok(false);
}
Expand All @@ -10734,6 +10742,7 @@ where
blinding_point,
skimmed_fee_msat,
send_timestamp,
hold_htlc,
});
self.context.next_holder_htlc_id += 1;

Expand Down Expand Up @@ -10977,7 +10986,7 @@ where
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
hold_htlc: bool, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
where
F::Target: FeeEstimator,
Expand All @@ -10992,6 +11001,7 @@ where
false,
skimmed_fee_msat,
None,
hold_htlc,
fee_estimator,
logger,
);
Expand Down Expand Up @@ -12629,6 +12639,7 @@ where
ref onion_routing_packet,
blinding_point,
skimmed_fee_msat,
..
} => {
0u8.write(writer)?;
amount_msat.write(writer)?;
Expand Down Expand Up @@ -13032,6 +13043,7 @@ where
skimmed_fee_msat: None,
blinding_point: None,
send_timestamp: None,
hold_htlc: false, // TODO: Persistence
});
}

Expand All @@ -13050,6 +13062,7 @@ where
onion_routing_packet: Readable::read(reader)?,
skimmed_fee_msat: None,
blinding_point: None,
hold_htlc: false, // TODO: Persistence
},
1 => HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: Readable::read(reader)?,
Expand Down Expand Up @@ -13944,6 +13957,7 @@ mod tests {
skimmed_fee_msat: None,
blinding_point: None,
send_timestamp: None,
hold_htlc: false,
});

// Make sure when Node A calculates their local commitment transaction, none of the HTLCs pass
Expand Down Expand Up @@ -14398,6 +14412,7 @@ mod tests {
skimmed_fee_msat: None,
blinding_point: None,
send_timestamp: None,
hold_htlc: false,
};
let mut pending_outbound_htlcs = vec![dummy_outbound_output.clone(); 10];
for (idx, htlc) in pending_outbound_htlcs.iter_mut().enumerate() {
Expand All @@ -14423,6 +14438,7 @@ mod tests {
},
skimmed_fee_msat: None,
blinding_point: None,
hold_htlc: false,
};
let dummy_holding_cell_claim_htlc = |attribution_data| HTLCUpdateAwaitingACK::ClaimHTLC {
payment_preimage: PaymentPreimage([42; 32]),
Expand Down
Loading
Loading