Skip to content

Commit 6a85d6b

Browse files
author
Antoine Riard
committed
[TBS]
2 parents 2258d2b + 07895d0 commit 6a85d6b

File tree

4 files changed

+540
-44
lines changed

4 files changed

+540
-44
lines changed

src/ln/channel.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ const B_OUTPUT_PLUS_SPENDING_INPUT_WEIGHT: u64 = 104; // prevout: 40, nSequence:
363363
/// it's 2^24.
364364
pub const MAX_FUNDING_SATOSHIS: u64 = (1 << 24);
365365

366+
#[cfg(test)]
367+
pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 138; //Here we have a diff due to HTLC CLTV expiry being < 2^15 in test
368+
#[cfg(not(test))]
369+
pub const ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 139;
370+
pub const OFFERED_HTLC_SCRIPT_WEIGHT: usize = 133;
371+
366372
/// Used to return a simple Error back to ChannelManager. Will get converted to a
367373
/// msgs::ErrorAction::SendErrorMessage or msgs::ErrorAction::IgnoreError as appropriate with our
368374
/// channel_id in ChannelManager.
@@ -1572,7 +1578,7 @@ impl Channel {
15721578

15731579
/// Marks an outbound HTLC which we have received update_fail/fulfill/malformed
15741580
#[inline]
1575-
fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, check_preimage: Option<[u8; 32]>, fail_reason: Option<HTLCFailReason>) -> Result<&HTLCSource, ChannelError> {
1581+
fn mark_outbound_htlc_removed(&mut self, htlc_id: u64, check_preimage: Option<[u8; 32]>, fail_reason: Option<HTLCFailReason>) -> Result<(&HTLCSource, [u8;32]), ChannelError> {
15761582
for htlc in self.pending_outbound_htlcs.iter_mut() {
15771583
if htlc.htlc_id == htlc_id {
15781584
match check_preimage {
@@ -1592,13 +1598,13 @@ impl Channel {
15921598
OutboundHTLCState::AwaitingRemoteRevokeToRemove | OutboundHTLCState::AwaitingRemovedRemoteRevoke | OutboundHTLCState::RemoteRemoved =>
15931599
return Err(ChannelError::Close("Remote tried to fulfill/fail HTLC that they'd already fulfilled/failed")),
15941600
}
1595-
return Ok(&htlc.source);
1601+
return Ok((&htlc.source, htlc.payment_hash));
15961602
}
15971603
}
15981604
Err(ChannelError::Close("Remote tried to fulfill/fail an HTLC we couldn't find"))
15991605
}
16001606

1601-
pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<&HTLCSource, ChannelError> {
1607+
pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(&HTLCSource, [u8;32]), ChannelError> {
16021608
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
16031609
return Err(ChannelError::Close("Got fulfill HTLC message when channel was not in an operational state"));
16041610
}
@@ -1614,7 +1620,7 @@ impl Channel {
16141620
self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None)
16151621
}
16161622

1617-
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<&HTLCSource, ChannelError> {
1623+
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<(&HTLCSource, [u8;32]), ChannelError> {
16181624
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
16191625
return Err(ChannelError::Close("Got fail HTLC message when channel was not in an operational state"));
16201626
}
@@ -1625,7 +1631,7 @@ impl Channel {
16251631
self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason))
16261632
}
16271633

1628-
pub fn update_fail_malformed_htlc<'a>(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailReason) -> Result<&HTLCSource, ChannelError> {
1634+
pub fn update_fail_malformed_htlc<'a>(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailReason) -> Result<(&HTLCSource, [u8;32]), ChannelError> {
16291635
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
16301636
return Err(ChannelError::Close("Got fail malformed HTLC message when channel was not in an operational state"));
16311637
}

0 commit comments

Comments
 (0)