Skip to content

Commit 0f06f82

Browse files
committed
Drop now-unused fields from MsgHandleErrInternal
1 parent 15e9a1a commit 0f06f82

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,8 @@ impl Into<u16> for FailureCode {
545545

546546
struct MsgHandleErrInternal {
547547
err: msgs::LightningError,
548-
chan_id: Option<(ChannelId, u128)>, // If Some a channel of ours has been closed
548+
closes_channel: bool,
549549
shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
550-
channel_capacity: Option<u64>,
551550
}
552551
impl MsgHandleErrInternal {
553552
#[inline]
@@ -562,17 +561,16 @@ impl MsgHandleErrInternal {
562561
},
563562
},
564563
},
565-
chan_id: None,
564+
closes_channel: false,
566565
shutdown_finish: None,
567-
channel_capacity: None,
568566
}
569567
}
570568
#[inline]
571569
fn from_no_close(err: msgs::LightningError) -> Self {
572-
Self { err, chan_id: None, shutdown_finish: None, channel_capacity: None }
570+
Self { err, closes_channel: false, shutdown_finish: None }
573571
}
574572
#[inline]
575-
fn from_finish_shutdown(err: String, channel_id: ChannelId, user_channel_id: u128, shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>, channel_capacity: u64) -> Self {
573+
fn from_finish_shutdown(err: String, channel_id: ChannelId, shutdown_res: ShutdownResult, channel_update: Option<msgs::ChannelUpdate>) -> Self {
576574
let err_msg = msgs::ErrorMessage { channel_id, data: err.clone() };
577575
let action = if shutdown_res.monitor_update.is_some() {
578576
// We have a closing `ChannelMonitorUpdate`, which means the channel was funded and we
@@ -584,9 +582,8 @@ impl MsgHandleErrInternal {
584582
};
585583
Self {
586584
err: LightningError { err, action },
587-
chan_id: Some((channel_id, user_channel_id)),
585+
closes_channel: true,
588586
shutdown_finish: Some((shutdown_res, channel_update)),
589-
channel_capacity: Some(channel_capacity)
590587
}
591588
}
592589
#[inline]
@@ -617,14 +614,13 @@ impl MsgHandleErrInternal {
617614
},
618615
},
619616
},
620-
chan_id: None,
617+
closes_channel: false,
621618
shutdown_finish: None,
622-
channel_capacity: None,
623619
}
624620
}
625621

626622
fn closes_channel(&self) -> bool {
627-
self.chan_id.is_some()
623+
self.closes_channel
628624
}
629625
}
630626

@@ -1956,22 +1952,27 @@ macro_rules! handle_error {
19561952

19571953
match $internal {
19581954
Ok(msg) => Ok(msg),
1959-
Err(MsgHandleErrInternal { err, chan_id, shutdown_finish, channel_capacity }) => {
1955+
Err(MsgHandleErrInternal { err, shutdown_finish, .. }) => {
19601956
let mut msg_events = Vec::with_capacity(2);
19611957

19621958
if let Some((shutdown_res, update_option)) = shutdown_finish {
1959+
let counterparty_node_id = shutdown_res.counterparty_node_id;
1960+
let channel_id = shutdown_res.channel_id;
1961+
let logger = WithContext::from(
1962+
&$self.logger, Some(counterparty_node_id), Some(channel_id),
1963+
);
1964+
log_error!(logger, "Force-closing channel: {}", err.err);
1965+
19631966
$self.finish_close_channel(shutdown_res);
19641967
if let Some(update) = update_option {
19651968
msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
19661969
msg: update
19671970
});
19681971
}
1972+
} else {
1973+
log_error!($self.logger, "Got non-closing error: {}", err.err);
19691974
}
19701975

1971-
let logger = WithContext::from(
1972-
&$self.logger, Some($counterparty_node_id), chan_id.map(|(chan_id, _)| chan_id)
1973-
);
1974-
log_error!(logger, "{}", err.err);
19751976
if let msgs::ErrorAction::IgnoreError = err.action {
19761977
} else {
19771978
msg_events.push(events::MessageSendEvent::HandleError {
@@ -2033,11 +2034,9 @@ macro_rules! convert_chan_phase_err {
20332034
update_maps_on_chan_removal!($self, $channel.context);
20342035
let reason = ClosureReason::ProcessingError { err: msg.clone() };
20352036
let shutdown_res = $channel.context.force_shutdown(true, reason);
2036-
let user_id = $channel.context.get_user_id();
2037-
let channel_capacity_satoshis = $channel.context.get_value_satoshis();
2038-
2039-
(true, MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, user_id,
2040-
shutdown_res, $channel_update, channel_capacity_satoshis))
2037+
let err =
2038+
MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, shutdown_res, $channel_update);
2039+
(true, err)
20412040
},
20422041
}
20432042
};
@@ -2834,7 +2833,8 @@ where
28342833
&self.logger, Some(shutdown_res.counterparty_node_id), Some(shutdown_res.channel_id),
28352834
);
28362835

2837-
log_debug!(logger, "Finishing closure of channel with {} HTLCs to fail", shutdown_res.dropped_outbound_htlcs.len());
2836+
log_debug!(logger, "Finishing closure of channel due to {} with {} HTLCs to fail",
2837+
shutdown_res.closure_reason, shutdown_res.dropped_outbound_htlcs.len());
28382838
for htlc_source in shutdown_res.dropped_outbound_htlcs.drain(..) {
28392839
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source;
28402840
let reason = HTLCFailReason::from_failure_code(0x4000 | 8);
@@ -3746,11 +3746,9 @@ where
37463746
let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger)
37473747
.map_err(|(mut chan, e)| if let ChannelError::Close(msg) = e {
37483748
let channel_id = chan.context.channel_id();
3749-
let user_id = chan.context.get_user_id();
37503749
let reason = ClosureReason::ProcessingError { err: msg.clone() };
37513750
let shutdown_res = chan.context.force_shutdown(false, reason);
3752-
let channel_capacity = chan.context.get_value_satoshis();
3753-
(chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, user_id, shutdown_res, None, channel_capacity))
3751+
(chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None))
37543752
} else { unreachable!(); });
37553753
match funding_res {
37563754
Ok(funding_msg) => (chan, funding_msg),

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ fn test_update_fee_that_funder_cannot_afford() {
768768
//check to see if the funder, who sent the update_fee request, can afford the new fee (funder_balance >= fee+channel_reserve)
769769
//Should produce and error.
770770
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &commit_signed_msg);
771-
nodes[1].logger.assert_log("lightning::ln::channelmanager", "Funding remote cannot afford proposed new fee".to_string(), 1);
771+
nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Funding remote cannot afford proposed new fee", 3);
772772
check_added_monitors!(nodes[1], 1);
773773
check_closed_broadcast!(nodes[1], true);
774774
check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError { err: String::from("Funding remote cannot afford proposed new fee") },
@@ -1617,7 +1617,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
16171617

16181618
nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &msg);
16191619
// Check that the payment failed and the channel is closed in response to the malicious UpdateAdd.
1620-
nodes[0].logger.assert_log("lightning::ln::channelmanager", "Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value".to_string(), 1);
1620+
nodes[0].logger.assert_log_contains("lightning::ln::channelmanager", "Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value", 3);
16211621
assert_eq!(nodes[0].node.list_channels().len(), 0);
16221622
let err_msg = check_closed_broadcast!(nodes[0], true).unwrap();
16231623
assert_eq!(err_msg.data, "Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value");
@@ -1796,7 +1796,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
17961796

17971797
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg);
17981798
// Check that the payment failed and the channel is closed in response to the malicious UpdateAdd.
1799-
nodes[1].logger.assert_log("lightning::ln::channelmanager", "Remote HTLC add would put them under remote reserve value".to_string(), 1);
1799+
nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Remote HTLC add would put them under remote reserve value", 3);
18001800
assert_eq!(nodes[1].node.list_channels().len(), 1);
18011801
let err_msg = check_closed_broadcast!(nodes[1], true).unwrap();
18021802
assert_eq!(err_msg.data, "Remote HTLC add would put them under remote reserve value");
@@ -6295,7 +6295,7 @@ fn test_update_add_htlc_bolt2_receiver_zero_value_msat() {
62956295
updates.update_add_htlcs[0].amount_msat = 0;
62966296

62976297
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
6298-
nodes[1].logger.assert_log("lightning::ln::channelmanager", "Remote side tried to send a 0-msat HTLC".to_string(), 1);
6298+
nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Remote side tried to send a 0-msat HTLC", 3);
62996299
check_closed_broadcast!(nodes[1], true).unwrap();
63006300
check_added_monitors!(nodes[1], 1);
63016301
check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError { err: "Remote side tried to send a 0-msat HTLC".to_string() },

0 commit comments

Comments
 (0)