-
Notifications
You must be signed in to change notification settings - Fork 418
Replay lost MonitorEvent
s in some cases for closed channels
#4004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
12622df
5740ce2
ac49603
5d398a1
a16fe15
9430561
fba2f2d
c32ff14
6cd8b79
c355b63
6074cf5
9c7adaa
69b281b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15739,7 +15739,7 @@ where | |
log_error!(logger, " The ChannelMonitor for channel {} is at counterparty commitment transaction number {} but the ChannelManager is at counterparty commitment transaction number {}.", | ||
&channel.context.channel_id(), monitor.get_cur_counterparty_commitment_number(), channel.get_cur_counterparty_commitment_transaction_number()); | ||
} | ||
let mut shutdown_result = | ||
let shutdown_result = | ||
channel.force_shutdown(ClosureReason::OutdatedChannelManager); | ||
if shutdown_result.unbroadcasted_batch_funding_txid.is_some() { | ||
return Err(DecodeError::InvalidValue); | ||
|
@@ -15771,7 +15771,10 @@ where | |
}, | ||
); | ||
} | ||
failed_htlcs.append(&mut shutdown_result.dropped_outbound_htlcs); | ||
for (source, hash, cp_id, chan_id) in shutdown_result.dropped_outbound_htlcs { | ||
let reason = LocalHTLCFailureReason::ChannelClosed; | ||
failed_htlcs.push((source, hash, cp_id, chan_id, reason)); | ||
} | ||
channel_closures.push_back(( | ||
events::Event::ChannelClosed { | ||
channel_id: channel.context.channel_id(), | ||
|
@@ -15813,6 +15816,7 @@ where | |
*payment_hash, | ||
channel.context.get_counterparty_node_id(), | ||
channel.context.channel_id(), | ||
LocalHTLCFailureReason::ChannelClosed, | ||
)); | ||
} | ||
} | ||
|
@@ -16386,6 +16390,10 @@ where | |
// payments which are still in-flight via their on-chain state. | ||
// We only rebuild the pending payments map if we were most recently serialized by | ||
// 0.0.102+ | ||
// | ||
// First we rebuild the pending payments, and only once we do so we go through and | ||
// re-claim and re-fail pending payments. This avoids edge-cases around MPP payments | ||
// resulting in redundant actions. | ||
TheBlueMatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (channel_id, monitor) in args.channel_monitors.iter() { | ||
let mut is_channel_closed = false; | ||
let counterparty_node_id = monitor.get_counterparty_node_id(); | ||
|
@@ -16424,6 +16432,18 @@ where | |
); | ||
} | ||
} | ||
} | ||
} | ||
for (channel_id, monitor) in args.channel_monitors.iter() { | ||
let mut is_channel_closed = false; | ||
let counterparty_node_id = monitor.get_counterparty_node_id(); | ||
if let Some(peer_state_mtx) = per_peer_state.get(&counterparty_node_id) { | ||
let mut peer_state_lock = peer_state_mtx.lock().unwrap(); | ||
let peer_state = &mut *peer_state_lock; | ||
is_channel_closed = !peer_state.channel_by_id.contains_key(channel_id); | ||
} | ||
Comment on lines
+16437
to
+16444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not seeing the bug that this is fixing -- if a payment is failed after being fulfilled in Context from the commit message: "... we could get both a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets say we send an MPP payment along two different channels. One is claimed and the other failed (who knows why, the recipient just decided they don't like money for whatever reason). Going through the single loop we may first find the failed-htlc channel - we'll add the pending payment in
Comment on lines
+16437
to
+16444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would appreciate some more context on this part of the commit message: "this can lead to a pending payment getting re-added and re-claimed multiple times" (phrased as bad). It looks like in the prior code and this new code, we'll call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rewrote the commit message. |
||
|
||
if is_channel_closed { | ||
for (htlc_source, (htlc, preimage_opt)) in | ||
monitor.get_all_current_outbound_htlcs() | ||
{ | ||
|
@@ -16521,6 +16541,20 @@ where | |
}, | ||
} | ||
} | ||
for (htlc_source, payment_hash) in monitor.get_onchain_failed_outbound_htlcs() { | ||
log_info!( | ||
args.logger, | ||
"Failing HTLC with payment hash {} as it was resolved on-chain.", | ||
payment_hash | ||
); | ||
failed_htlcs.push(( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we generate a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fixed in #3984 :) |
||
htlc_source, | ||
payment_hash, | ||
monitor.get_counterparty_node_id(), | ||
monitor.channel_id(), | ||
LocalHTLCFailureReason::OnChainTimeout, | ||
)); | ||
} | ||
} | ||
|
||
// Whether the downstream channel was closed or not, try to re-apply any payment | ||
|
@@ -17201,13 +17235,10 @@ where | |
} | ||
} | ||
|
||
for htlc_source in failed_htlcs.drain(..) { | ||
let (source, payment_hash, counterparty_node_id, channel_id) = htlc_source; | ||
let failure_reason = LocalHTLCFailureReason::ChannelClosed; | ||
let receiver = HTLCHandlingFailureType::Forward { | ||
node_id: Some(counterparty_node_id), | ||
channel_id, | ||
}; | ||
for htlc_source in failed_htlcs { | ||
let (source, payment_hash, counterparty_id, channel_id, failure_reason) = htlc_source; | ||
let receiver = | ||
HTLCHandlingFailureType::Forward { node_id: Some(counterparty_id), channel_id }; | ||
let reason = HTLCFailReason::from_failure_code(failure_reason); | ||
channel_manager.fail_htlc_backwards_internal(&source, &payment_hash, &reason, receiver); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.