-
Notifications
You must be signed in to change notification settings - Fork 385
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 channel_id to SpendableOutputs event #2511
Add channel_id to SpendableOutputs event #2511
Conversation
lightning/src/ln/monitor_tests.rs
Outdated
assert_eq!(outputs.len(), 1); | ||
// let funding_outpoint = OutPoint { txid: chan_a.3.txid(), index: 0 }; | ||
// assert_eq!(channel_id, &funding_outpoint.to_channel_id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tnull this bit here is failing, whats the best way to construct the channel_id on the right side of the assertion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one event for each channel chan_a
and chan_b
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
changed the test to use .contains
as the events are not ordered so the test was flaky
lightning/src/ln/monitor_tests.rs
Outdated
assert_eq!(outputs.len(), 1); | ||
// let funding_outpoint = OutPoint { txid: chan_a.3.txid(), index: 0 }; | ||
// assert_eq!(channel_id, &funding_outpoint.to_channel_id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one event for each channel chan_a
and chan_b
.
lightning/src/events/mod.rs
Outdated
read_tlv_fields!(reader, { | ||
(0, outputs, required), | ||
(1, channel_id, required), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to write this as option
to not break upgrades.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To give a little more context on our serialization logic: we generally use Lightning's TLV (type-length-value) format and apply the corresponding "it's okay to be odd" rule, i.e., when reading TLV fields we ignore any unknown fields if they are odd numbered and would refuse to continue if they were even.
Moreover, we would refuse to continue if any required
field would not be present at the time of reading. As we aim for forwards- and backwards-compatiblity, we usually need to make new fields odd option
s. Otherwise users upgrading from a prior version might get a panic when LDK refuses to read a SpendableOutputs
event in which the required channel_id
is not present.
lightning/src/events/mod.rs
Outdated
@@ -673,6 +673,8 @@ pub enum Event { | |||
SpendableOutputs { | |||
/// The outputs which you should store as spendable by you. | |||
outputs: Vec<SpendableOutputDescriptor>, | |||
/// Channel id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: comments seems incomplete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add a compatibility notice here: as mentioned below this should be Option<[u8; 32]>
to not break backwards compatibility and we should specify starting from which version users can expect this to be Some
.
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #2511 +/- ##
==========================================
+ Coverage 90.40% 90.59% +0.18%
==========================================
Files 106 106
Lines 56268 56531 +263
Branches 56268 56531 +263
==========================================
+ Hits 50868 51213 +345
+ Misses 5400 5318 -82
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up!
A few notes regarding commits and commit messages: please try to break down the changes into logical steps of which each should live in in its own commit. Note that with each commit (except for maybe fixups that will be squashed before merging) the code should still be in a buildable and testable state, i.e., in this PR probably all changes need to live in one commit. Please clearly mark fixups to make them distinguishable from commits that should be present when merging.
In general I'd recommend getting familiar with git rebase -i
as it's a very powerful tool when managing commits, and you might want to refer to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits.
Commit messages should consist of a short summary (no longer than 50 chars wide) and a body that summarizes not only the changes themselves but also gives more context on the how and why. This guide gives a good summary of best practices: https://cbea.ms/git-commit/
lightning/src/events/mod.rs
Outdated
@@ -673,6 +673,8 @@ pub enum Event { | |||
SpendableOutputs { | |||
/// The outputs which you should store as spendable by you. | |||
outputs: Vec<SpendableOutputDescriptor>, | |||
/// Channel id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add a compatibility notice here: as mentioned below this should be Option<[u8; 32]>
to not break backwards compatibility and we should specify starting from which version users can expect this to be Some
.
lightning/src/events/mod.rs
Outdated
read_tlv_fields!(reader, { | ||
(0, outputs, required), | ||
(1, channel_id, required), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To give a little more context on our serialization logic: we generally use Lightning's TLV (type-length-value) format and apply the corresponding "it's okay to be odd" rule, i.e., when reading TLV fields we ignore any unknown fields if they are odd numbered and would refuse to continue if they were even.
Moreover, we would refuse to continue if any required
field would not be present at the time of reading. As we aim for forwards- and backwards-compatiblity, we usually need to make new fields odd option
s. Otherwise users upgrading from a prior version might get a panic when LDK refuses to read a SpendableOutputs
event in which the required channel_id
is not present.
lightning/src/ln/monitor_tests.rs
Outdated
@@ -95,7 +95,7 @@ fn chanmon_fail_from_stale_commitment() { | |||
fn test_spendable_output<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, spendable_tx: &Transaction) { | |||
let mut spendable = node.chain_monitor.chain_monitor.get_and_clear_pending_events(); | |||
assert_eq!(spendable.len(), 1); | |||
if let Event::SpendableOutputs { outputs } = spendable.pop().unwrap() { | |||
if let Event::SpendableOutputs { outputs, channel_id } = spendable.pop().unwrap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either check the channel_id
here, or avoid the unused variable:
if let Event::SpendableOutputs { outputs, channel_id } = spendable.pop().unwrap() { | |
if let Event::SpendableOutputs { outputs, .. } = spendable.pop().unwrap() { |
87abb91
to
ead7332
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, besides some doc nits.
lightning/src/events/mod.rs
Outdated
@@ -673,6 +673,10 @@ pub enum Event { | |||
SpendableOutputs { | |||
/// The outputs which you should store as spendable by you. | |||
outputs: Vec<SpendableOutputDescriptor>, | |||
/// Channel id to help you locate the corresponding `ChannelMonitor`, | |||
/// We define this as an option so we dont break backwards compatibility. | |||
/// This will always be `Some` for events generated by LDK versions 0.0.XX and above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's safe to assume this will land with 0.0.117 :)
This will make it possible to link between SpendableOuts and ChannelMonitor - change channel_id to option so we dont break upgrade - remove unused channel_id - document channel_id - extract channel id dynamically to pass test - use contains to check channel_id in test as the events are not ordered - update docs framing - specify ldk version channel_id will be introduced in Co-authored-by: Elias Rohrer <[email protected]> Update lightning/src/events/mod.rs Co-authored-by: Elias Rohrer <[email protected]>
4f71cf5
to
14b7612
Compare
added docs suggestion(s), updated ldk version to 0.0.117 and squashed 🎈 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference, commit messages must start with a single line (the title) and then be followed by an empty line. In this case you missed the blank line after the title.
resolves #2480