Add Event::DiscardFunding generation#1098
Conversation
|
We shouldn't generate a More generally, you may want to consider this here as well #1086 (comment). No pressure if you don't want to rewrite the PR to do so, but refactoring the event generation on close into a common function would make lots of code more readable (including the new code here). |
My bad, I missed the check for the channel state. Will add a check similar to If I'm not wrong then I should refactor the code that issues the Also, with regard to the order of event dispatch. I'm assuming we would want to discard the funding before closing the channel. |
Yep, sounds great!
I don't think it matters - the |
|
I made an assumption that we would want to discard the funding only when the other party doesn't send in their Based on that for every time we attempted to close a channel, it runs a check for that condition before issuing the event to discard funding. |
Codecov Report
@@ Coverage Diff @@
## main #1098 +/- ##
==========================================
- Coverage 90.73% 90.66% -0.07%
==========================================
Files 65 65
Lines 34318 34559 +241
==========================================
+ Hits 31137 31332 +195
- Misses 3181 3227 +46
Continue to review full report at Codecov.
|
lightning/src/util/events.rs
Outdated
| /// The channel_id of the channel which has been closed. | ||
| channel_id: [u8; 32], | ||
| /// The full transaction received from the user | ||
| transaction: Option<Transaction> |
There was a problem hiding this comment.
I'm not sure why this needs to be an option - is_funding_pending is gated on funding_transaction.is_some(), so we could combine it and funding_transaction into one function that checks the channel_state is as expected, and then returns the transaction if there is one, otherwise returns None.
There was a problem hiding this comment.
The initial idea was that funding transaction must be added if it exists, but now given that we are checking for it via funding_transaction.is_some() I will update the same to be Transaction
|
Tagged for 0.0.102 since we had a user request for exactly this. |
valentinewallace
left a comment
There was a problem hiding this comment.
Thanks, very nice cleanup as well!
|
Can you address the two pending comments and then squash the changes here to cleanup the git history prior to merge? |
|
@TheBlueMatt @valentinewallace Will address the pending comments and squash the changes. Thank you for all the pointers! |
During the event of a channel close, if the funding transaction is yet to be broadcasted then a DiscardFunding event is issued along with the ChannelClose event.
bfe1f39 to
1955008
Compare
TheBlueMatt
left a comment
There was a problem hiding this comment.
Diff from my/Val's last review:
$ git diff-tree -U1 bfe1f39e1 1955008d6
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 062319e64..936bbab7c 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -1904,5 +1904,4 @@ impl<Signer: Sign> Channel<Signer> {
/// Returns transaction if there is pending funding transaction that is yet to broadcast
- pub fn has_funding_pending(&self) -> Option<Transaction> {
- if self.funding_transaction.is_some() &&
- self.channel_state & (ChannelState::FundingCreated as u32) != 0 {
+ pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
+ if self.channel_state & (ChannelState::FundingCreated as u32) != 0 {
self.funding_transaction.clone()
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 800486fcc..5e43158b1 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -1331,3 +1331,3 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
let mut pending_events_lock = self.pending_events.lock().unwrap();
- match channel.has_funding_pending() {
+ match channel.unbroadcasted_funding() {
Some(transaction) => {
$
Fixes #953
Generates a newEvent::DiscardFundingwhen we issue anEvent::ChannelClosedas a result of the following Closure reasons:OutdatedChannelManagerProcessingErrorHolderForcedOutdatedChannelManagerClosedCounterpartyForceClosedDisconnectedPeerDuring the event of a channel close, if the channel is in a state of
FundingCreatedthen anEvent::DiscardFundingis issued along with the event for the channel close.