Skip to content

Commit 8f5d09c

Browse files
committed
apply fixes in TheBlueMatts and update_fee state tweak
1 parent decac48 commit 8f5d09c

File tree

3 files changed

+392
-188
lines changed

3 files changed

+392
-188
lines changed

src/ln/channel.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,6 @@ impl Channel {
760760
}
761761
}
762762

763-
764763
for ref htlc in self.pending_inbound_htlcs.iter() {
765764
let include = match htlc.state {
766765
InboundHTLCState::RemoteAnnounced => !generated_by_local,
@@ -1613,7 +1612,7 @@ impl Channel {
16131612

16141613
let mut htlcs_and_sigs = Vec::with_capacity(local_commitment_tx.1.len());
16151614
for (idx, ref htlc) in local_commitment_tx.1.iter().enumerate() {
1616-
let mut htlc_tx = self.build_htlc_transaction(&local_commitment_txid, htlc, true, &local_keys, self.feerate_per_kw);
1615+
let mut htlc_tx = self.build_htlc_transaction(&local_commitment_txid, htlc, true, &local_keys, feerate_per_kw);
16171616
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, &local_keys);
16181617
let htlc_sighash = Message::from_slice(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx.input[0], &htlc_redeemscript, htlc.amount_msat / 1000)[..]).unwrap();
16191618
secp_call!(self.secp_ctx.verify(&htlc_sighash, &msg.htlc_signatures[idx], &local_keys.b_htlc_key), "Invalid HTLC tx siganture from peer", self.channel_id());
@@ -1635,6 +1634,9 @@ impl Channel {
16351634
if !self.channel_outbound {
16361635
if let Some(fee_update) = self.pending_update_fee {
16371636
self.feerate_per_kw = fee_update;
1637+
// We later use the presence of pending_update_fee to indicate we should generate a
1638+
// commitment_signed upon receipt of revoke_and_ack, so we can only set it to None
1639+
// if we're not awaiting a revoke (ie will send a commitment_signed now).
16381640
if (self.channel_state & ChannelState::AwaitingRemoteRevoke as u32) == 0 {
16391641
need_our_commitment = true;
16401642
self.pending_update_fee = None;
@@ -1657,7 +1659,6 @@ impl Channel {
16571659
}
16581660
}
16591661

1660-
16611662
self.cur_local_commitment_transaction_number -= 1;
16621663
self.last_local_commitment_txn = new_local_commitment_txn;
16631664

@@ -1679,7 +1680,7 @@ impl Channel {
16791680
/// Used to fulfill holding_cell_htlcs when we get a remote ack (or implicitly get it by them
16801681
/// fulfilling or failing the last pending HTLC)
16811682
fn free_holding_cell_htlcs(&mut self) -> Result<Option<(msgs::CommitmentUpdate, ChannelMonitor)>, HandleError> {
1682-
if self.holding_cell_htlc_updates.len() != 0 {
1683+
if self.holding_cell_htlc_updates.len() != 0 || self.holding_cell_update_fee.is_some() {
16831684
let mut htlc_updates = Vec::new();
16841685
mem::swap(&mut htlc_updates, &mut self.holding_cell_htlc_updates);
16851686
let mut update_add_htlcs = Vec::with_capacity(htlc_updates.len());
@@ -1853,12 +1854,16 @@ impl Channel {
18531854
}
18541855
self.value_to_self_msat = (self.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
18551856

1856-
if let Some(feerate) = self.pending_update_fee.take() {
1857-
if self.channel_outbound {
1857+
if self.channel_outbound {
1858+
if let Some(feerate) = self.pending_update_fee.take() {
18581859
self.feerate_per_kw = feerate;
1859-
} else {
1860-
assert_eq!(feerate, self.feerate_per_kw);
1861-
require_commitment = true;
1860+
}
1861+
} else {
1862+
if let Some(feerate) = self.pending_update_fee {
1863+
if feerate == self.feerate_per_kw {
1864+
require_commitment = true;
1865+
self.pending_update_fee = None;
1866+
}
18621867
}
18631868
}
18641869

@@ -2828,7 +2833,9 @@ impl Channel {
28282833

28292834
let mut feerate_per_kw = self.feerate_per_kw;
28302835
if let Some(feerate) = self.pending_update_fee {
2831-
feerate_per_kw = feerate;
2836+
if self.channel_outbound {
2837+
feerate_per_kw = feerate;
2838+
}
28322839
}
28332840

28342841
let remote_keys = self.build_remote_transaction_keys()?;

0 commit comments

Comments
 (0)