Skip to content
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

Add ChannelReady event #1743

Merged
merged 3 commits into from
Nov 3, 2022

Conversation

tnull
Copy link
Contributor

@tnull tnull commented Sep 26, 2022

Closes #1394.

This adds a ChannelReady event that will be emitted as soon as a new
channel becomes usable, i.e., after both sides have sent channel_ready.

@tnull tnull marked this pull request as draft September 26, 2022 12:17
@tnull
Copy link
Contributor Author

tnull commented Sep 26, 2022

Draft for now, since tests are still failing.

lightning/src/util/events.rs Outdated Show resolved Hide resolved
@tnull tnull changed the title Add ChannelEstablished event Add ChannelEstablished event Sep 26, 2022
@tnull tnull changed the title Add ChannelEstablished event Add ChannelOpened event Sep 28, 2022
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@TheBlueMatt TheBlueMatt added this to the 0.0.113 milestone Oct 21, 2022
@tnull tnull changed the title Add ChannelOpened event Add ChannelReady event Oct 26, 2022
@tnull tnull marked this pull request as ready for review October 26, 2022 12:31
@tnull
Copy link
Contributor Author

tnull commented Oct 26, 2022

Rebased on main and reworked the approach: a bool is now bubbled up from Channel::check_get_channel_ready along side the msgs::ChannelReady and used in ChannelManager to decide whether to emit_channel_ready!.

In the second commit I included the discussed renaming of ChannelState::ChannelFunded to ChannelState::ChannelReady, and since all three align nicely then, I now reconsidered and named the event Event::ChannelReady after all.

Finally, the third commit includes a minor fix for unused import warnings.

Tests currently still failing, looking into it.

@tnull tnull force-pushed the 2022-09-channel-events branch 2 times, most recently from b7135dd to 2526975 Compare October 26, 2022 13:15
@tnull tnull force-pushed the 2022-09-channel-events branch 2 times, most recently from f7d8c41 to dabe755 Compare October 28, 2022 10:52
@tnull
Copy link
Contributor Author

tnull commented Oct 28, 2022

Fixed tests and rebased on main.

@tnull tnull force-pushed the 2022-09-channel-events branch 4 times, most recently from 7fde0f7 to f969b45 Compare October 28, 2022 11:54
@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2022

Codecov Report

Base: 90.73% // Head: 90.78% // Increases project coverage by 0.04% 🎉

Coverage data is based on head (2ce2b15) compared to base (ad7ff0b).
Patch coverage: 81.19% of modified lines in pull request are covered.

❗ Current head 2ce2b15 differs from pull request most recent head 2f10adf. Consider uploading reports for the commit 2f10adf to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1743       /-   ##
==========================================
  Coverage   90.73%   90.78%    0.04%     
==========================================
  Files          87       87              
  Lines       47336    47608      272     
  Branches    47336    47608      272     
==========================================
  Hits        42950    43219      269     
- Misses       4386     4389        3     
Impacted Files Coverage Δ
lightning/src/ln/peer_handler.rs 55.82% <ø> (ø)
lightning/src/util/events.rs 37.93% <34.78%> (-0.20%) ⬇️
lightning-background-processor/src/lib.rs 95.96% <71.42%> (-0.28%) ⬇️
lightning/src/ln/functional_tests.rs 97.04% <80.00%> ( 0.09%) ⬆️
lightning/src/ln/channelmanager.rs 85.20% <91.66%> ( 0.01%) ⬆️
lightning/src/ln/functional_test_utils.rs 93.43% <92.85%> (-0.01%) ⬇️
lightning-invoice/src/utils.rs 95.20% <100.00%> ( 0.02%) ⬆️
lightning/src/ln/chanmon_update_fail_tests.rs 97.67% <100.00%> ( <0.01%) ⬆️
lightning/src/ln/channel.rs 88.70% <100.00%> ( 0.02%) ⬆️
lightning/src/ln/payment_tests.rs 98.81% <100.00%> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tnull tnull force-pushed the 2022-09-channel-events branch 5 times, most recently from 75861b2 to 735fa78 Compare October 28, 2022 13:43
@tnull tnull force-pushed the 2022-09-channel-events branch 3 times, most recently from ae803b8 to 85ee73a Compare October 28, 2022 15:32
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to squash.

lightning/src/util/events.rs Outdated Show resolved Hide resolved
lightning/src/util/events.rs Outdated Show resolved Hide resolved
lightning/src/util/events.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
@tnull tnull force-pushed the 2022-09-channel-events branch 2 times, most recently from 43e5538 to 71a999b Compare November 1, 2022 09:06
@tnull
Copy link
Contributor Author

tnull commented Nov 1, 2022

I now reverted the 'bubble-up' approach after all since all required checks are conducted in the should_emit_channel_ready_event and send_channel_ready!, which makes this much less intrusive.

Squashed changes.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just noticed we use "0conf" and "0-conf" in comments throughout the project. The hyphenated one looks "more correct". No biggie.

lightning-background-processor/src/lib.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Show resolved Hide resolved
@tnull tnull force-pushed the 2022-09-channel-events branch 2 times, most recently from 9033c30 to f3c23a8 Compare November 1, 2022 09:25
lightning-invoice/src/utils.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/functional_test_utils.rs Outdated Show resolved Hide resolved
lightning/src/ln/functional_tests.rs Outdated Show resolved Hide resolved
@@ -499,7 500,6 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let bs_htlc_claim_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
assert_eq!(bs_htlc_claim_txn.len(), 1);
check_spends!(bs_htlc_claim_txn[0], as_commitment_tx);
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], None, false, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why we have to move this up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we want to move this because the PaymentForwarded event is emitted by the handle_update_fulfill_htlc already and then the expect_channel_ready_event call in create_announced_chan_between_nodes fails due to 2 events being queued.

lightning/src/util/events.rs Outdated Show resolved Hide resolved
lightning/src/ln/peer_handler.rs Outdated Show resolved Hide resolved
@TheBlueMatt
Copy link
Collaborator

I think this is good - can you squash the fixups into the appropriate commits? Its somewhat hard to re-review when the fixups are all at the end rather than with the commit they'll eventually get squashed into.

@tnull
Copy link
Contributor Author

tnull commented Nov 2, 2022

I think this is good - can you squash the fixups into the appropriate commits? Its somewhat hard to re-review when the fixups are all at the end rather than with the commit they'll eventually get squashed into.

Think all fixups belonged to the first commit => Done.

@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Nov 2, 2022

Is it worth having a release notes entry for this that says that "no ChannelReady events will be generated for existing channels, including those which become ready on 0.0.113"? I don't think its worth having complicated logic for whether we default channel_ready_event_emitted to true or false based on state, but I also think it may be worth calling out.

@TheBlueMatt
Copy link
Collaborator

Either way, current code LGTM, probably fine to squash given the reviewers currently. You can leave a diff-tree of the fixups if you want.

This adds a `ChannelReady` event that is emitted as soon as a new
channel becomes usable, i.e., after both sides have sent
`channel_ready`.
We rename `ChannelState::ChannelFunded` to `ChannelState::ChannelReady`
as we'll be in this state when both sides sent the `ChannelReady`
messages, which may also be before funding in the 0conf case.
Previously introduced during release commit.
@tnull
Copy link
Contributor Author

tnull commented Nov 3, 2022

Squashed fixups and included the pending changelog message

> git diff-tree -U2 a8720b2 49dfcb6
diff --git a/pending_changelog/1743.txt b/pending_changelog/1743.txt
new file mode 100644
index 00000000..93e41202
--- /dev/null
    b/pending_changelog/1743.txt
@@ -0,0  1,7 @@
 ## API Updates
 - A new `ChannelReady` event is generated whenever a channel becomes ready to
   be used, i.e., after both sides sent the `channel_ready` message.
 
 ## Backwards Compatibilty
 - No `ChannelReady` events will be generated for previously existing channels, including
   those which become ready after upgrading 0.0.113.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ChannelConfirmed Event
7 participants