Skip to content

Commit 2c82903

Browse files
carlaKCTheBlueMatt
andcommitted
ln: do not send and reject receive of update_fee for zero fee commits
Co-authored-by: Matt Corallo <git@bluematt.me>
1 parent caf0ea1 commit 2c82903

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

lightning/src/chain/package.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ pub(crate) fn verify_channel_type_features(channel_type_features: &Option<Channe
9999
supported_feature_set.set_scid_privacy_required();
100100
supported_feature_set.set_zero_conf_required();
101101

102+
#[cfg(test)]
103+
supported_feature_set.set_anchor_zero_fee_commitments_required();
104+
102105
// allow the passing of an additional necessary permitted flag
103106
if let Some(additional_permitted_features) = additional_permitted_features {
104107
supported_feature_set |= additional_permitted_features;

lightning/src/ln/channel.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,6 +4209,10 @@ where
42094209
F::Target: FeeEstimator,
42104210
L::Target: Logger,
42114211
{
4212+
if funding.get_channel_type().supports_anchor_zero_fee_commitments() {
4213+
return false;
4214+
}
4215+
42124216
// Before proposing a feerate update, check that we can actually afford the new fee.
42134217
let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(
42144218
&fee_estimator, funding.get_channel_type(),
@@ -7457,6 +7461,9 @@ where
74577461
if self.context.channel_state.is_remote_stfu_sent() || self.context.channel_state.is_quiescent() {
74587462
return Err(ChannelError::WarnAndDisconnect("Got fee update message while quiescent".to_owned()));
74597463
}
7464+
if self.funding.get_channel_type().supports_anchor_zero_fee_commitments() {
7465+
return Err(ChannelError::WarnAndDisconnect("Update fee message received for zero fee commitment channel".to_owned()));
7466+
}
74607467

74617468
core::iter::once(&self.funding)
74627469
.chain(self.pending_funding.iter())

lightning/src/ln/update_fee_tests.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,3 +1193,59 @@ pub fn do_cannot_afford_on_holding_cell_release(
11931193
nodes[0].logger.assert_log("lightning::ln::channel", err, 1);
11941194
}
11951195
}
1196+
1197+
#[test]
1198+
pub fn test_zero_fee_commiments_no_update_fee() {
1199+
// Tests that option_zero_fee_commitment channels do not sent update_fee messages, and that
1200+
// they'll disconnect and warn if they receive them.
1201+
let mut cfg = test_default_channel_config();
1202+
cfg.channel_handshake_config.negotiate_anchor_zero_fee_commitments = true;
1203+
cfg.manually_accept_inbound_channels = true;
1204+
1205+
let chanmon_cfgs = create_chanmon_cfgs(2);
1206+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1207+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(cfg.clone()), Some(cfg)]);
1208+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1209+
1210+
let channel = create_chan_between_nodes(&nodes[0], &nodes[1]);
1211+
1212+
let assert_zero_fee = || {
1213+
for node in nodes.iter() {
1214+
let channels = node.node.list_channels();
1215+
assert_eq!(channels.len(), 1);
1216+
assert!(channels[0]
1217+
.channel_type
1218+
.as_ref()
1219+
.unwrap()
1220+
.supports_anchor_zero_fee_commitments());
1221+
assert_eq!(channels[0].feerate_sat_per_1000_weight.unwrap(), 0);
1222+
}
1223+
};
1224+
assert_zero_fee();
1225+
1226+
// Sender should not queue an update_fee message.
1227+
nodes[0].node.timer_tick_occurred();
1228+
let events_0 = nodes[0].node.get_and_clear_pending_msg_events();
1229+
assert_eq!(events_0.len(), 0);
1230+
1231+
// Receiver should ignore and warn if sent update_fee.
1232+
let channel_id = channel.3;
1233+
let update_fee_msg = msgs::UpdateFee { channel_id, feerate_per_kw: 5000 };
1234+
nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &update_fee_msg);
1235+
1236+
let events_1 = nodes[1].node.get_and_clear_pending_msg_events();
1237+
assert_eq!(events_1.len(), 1);
1238+
match events_1[0] {
1239+
MessageSendEvent::HandleError { ref action, .. } => match action {
1240+
ErrorAction::DisconnectPeerWithWarning { ref msg, .. } => {
1241+
assert_eq!(msg.channel_id, channel_id);
1242+
assert!(msg
1243+
.data
1244+
.contains("Update fee message received for zero fee commitment channel"));
1245+
},
1246+
_ => panic!("Expected DisconnectPeerWithWarning, got {:?}", action),
1247+
},
1248+
_ => panic!("Expected HandleError event, got {:?}", events_1[0]),
1249+
}
1250+
assert_zero_fee();
1251+
}

0 commit comments

Comments
 (0)