Skip to content

Commit b7fed85

Browse files
f fix fee spike buffer + update to latest features API
1 parent d1bf6a1 commit b7fed85

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,20 +1768,22 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
17681768
if self.channel_outbound {
17691769
// Check that they won't violate our channel reserve by adding this HTLC.
17701770

1771-
// One of the +1's is for the HTLC that is currently being added to the commitment tx
1772-
// and the other is a fee spike buffer we're keeping for the remote (this deviates
1773-
// from the spec but should help protect us from stuck channels).
1774-
// TODO: is the reason this added HTLC's amount can't count toward's the receiver's
1775-
// fee spike buffer because that doesn't work with existing HTLC output spend scripts?
1776-
let local_fee_cost_msat = self.commit_tx_fee_msat(self.htlc_count_next_local_commit_tx() + 1 + 1);
1771+
// +1 for this HTLC
1772+
let local_fee_cost_msat = self.commit_tx_fee_msat(self.htlc_count_next_local_commit_tx() + 1);
17771773
if self.value_to_self_msat < self.their_channel_reserve_satoshis * 1000 + local_fee_cost_msat {
1774+
// TODO: finish this snippet so failing here doesn't cause channel close
1775+
// pending_forward_state = PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC{
1776+
// channel_id: msg.channel_id,
1777+
// htlc_id:
1778+
// }));
17781779
return Err(ChannelError::Ignore("Cannot receive value that would put us over their reserve value"));
17791780
}
17801781
}
17811782

1782-
// The +1 is for the HTLC that is currently being added to the commitment tx.
17831783
let remote_fee_cost_msat = if self.channel_outbound { 0 } else {
1784-
self.commit_tx_fee_msat(self.htlc_count_next_remote_commit_tx() + 1)
1784+
// +1 for this HTLC, +1 fee spike buffer we keep for the remote (this deviates from the spec but
1785+
// should protect us from stuck channels).
1786+
self.commit_tx_fee_msat(self.htlc_count_next_remote_commit_tx() + 1 + 1)
17851787
};
17861788
if htlc_inbound_value_msat + msg.amount_msat + self.value_to_self_msat + remote_fee_cost_msat
17871789
> (self.channel_value_satoshis - Channel::<ChanSigner>::get_our_channel_reserve_satoshis(self.channel_value_satoshis)) * 1000 + removed_outbound_total_msat {
@@ -3625,10 +3627,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
36253627

36263628
let their_balance = self.channel_value_satoshis * 1000 - self.value_to_self_msat;
36273629
let chan_reserve_we_require_msat = Channel::<ChanSigner>::get_our_channel_reserve_satoshis(self.channel_value_satoshis);
3628-
// +1 for this HTLC, +2 for their fee spike buffer
3629-
// TODO: is the reason this added HTLC's amount can't count toward's the receiver's
3630-
// fee spike buffer because that doesn't work with existing HTLC output spend scripts?
3631-
let remote_commit_tx_fee_msat = self.commit_tx_fee_msat(self.htlc_count_next_remote_commit_tx() + 1 + 2);
3630+
// +1 for this HTLC
3631+
let remote_commit_tx_fee_msat = self.commit_tx_fee_msat(self.htlc_count_next_remote_commit_tx() + 1);
36323632
if their_balance < chan_reserve_we_require_msat + remote_commit_tx_fee_msat {
36333633
return Err(ChannelError::Ignore("Cannot send value that would put them over our reserve value"));
36343634
}

lightning/src/ln/functional_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ fn test_basic_channel_reserve() {
15061506
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
15071507
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
15081508
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1509-
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported());
1509+
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known());
15101510

15111511
let chan_stat = get_channel_value_stat!(nodes[0], chan.2);
15121512
let their_channel_reserve = chan_stat.channel_reserve_msat;
@@ -1538,8 +1538,8 @@ fn test_channel_reserve_violation_close_pending_htlc() {
15381538
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
15391539
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
15401540
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
1541-
let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported());
1542-
let _ = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported());
1541+
let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known());
1542+
let _ = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 100000, 95000000, InitFeatures::known(), InitFeatures::known());
15431543

15441544
macro_rules! get_route_and_payment_hash {
15451545
($recv_value: expr) => {{
@@ -5859,7 +5859,7 @@ fn test_holding_cell_htlc_with_pending_fee_update() {
58595859
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
58605860
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
58615861
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
5862-
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported());
5862+
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known());
58635863

58645864
// First nodes[0] generates an update_fee, setting the channel's
58655865
// pending_update_fee.
@@ -6193,7 +6193,7 @@ fn test_update_add_htlc_bolt2_receiver_check_cltv_expiry() {
61936193
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
61946194
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
61956195
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known());
6196-
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 3999999, TEST_FINAL_CLTV).unwrap();
6196+
let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 399999, TEST_FINAL_CLTV).unwrap();
61976197
let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]);
61986198
nodes[0].node.send_payment(&route, our_payment_hash, &None).unwrap();
61996199
check_added_monitors!(nodes[0], 1);

0 commit comments

Comments
 (0)