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

Introduce new ChannelId struct #2485

Merged
merged 2 commits into from
Aug 27, 2023

Conversation

optout21
Copy link
Contributor

@optout21 optout21 commented Aug 9, 2023

Fixes #2408 . Introduces a new ChannelId struct, enclosing the 32-byte data. It has specific constructors, for normal funding-tx-based and for temporary channel ID cases.

ChannelId is exposed as lightning::ln::ChannelId.

This is a breaking change. The type of channel_id parameter has been changed from [u8; 32] to ChannelId in several ChannelManager APIs, namely:

  • create_chan_between_nodes()
  • create_chan_between_nodes_with_value()
  • create_funding_transaction()
  • sign_funding_transaction()
  • open_zero_conf_channel()
  • create_chan_between_nodes_with_value_confirm_second()
  • create_chan_between_nodes_with_value_confirm()
  • create_chan_between_nodes_with_value_a()
  • create_announced_chan_between_nodes()
  • create_announced_chan_between_nodes_with_value()
  • close_channel()
  • test_txn_broadcast()

The type has been changed in several events as well (FundingGenerationReady, PaymentClaimable, PaymentForwarded, ChannelPending, etc.).

Review hints:

TODO:

  • Determine how it affects APIs, uses, backward-compatibility
  • Tests for ChannelId serialization/deserialization
  • New macro log_channel_id!()
  • Review hints

@optout21 optout21 mentioned this pull request Aug 9, 2023
4 tasks
@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2023

Codecov Report

Patch coverage: 84.16% and project coverage change: +0.02% 🎉

Comparison is base (3dffe54) 90.56% compared to head (e99e6ab) 90.59%.
Report is 2 commits behind head on main.

❗ 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    #2485      +/-   ##
==========================================
+ Coverage   90.56%   90.59%   +0.02%     
==========================================
  Files         109      110       +1     
  Lines       57304    57410     +106     
  Branches    57304    57410     +106     
==========================================
+ Hits        51899    52008     +109     
+ Misses       5405     5402       -3     
Files Changed Coverage Δ
lightning/src/ln/mod.rs 96.15% <ø> (ø)
lightning/src/routing/gossip.rs 89.94% <0.00%> (-0.13%) ⬇️
lightning/src/util/test_utils.rs 73.61% <ø> (ø)
lightning/src/ln/peer_handler.rs 61.45% <13.79%> (+0.40%) ⬆️
lightning/src/util/macro_logger.rs 93.61% <50.00%> (+4.03%) ⬆️
lightning/src/events/mod.rs 48.33% <78.94%> (-0.10%) ⬇️
lightning/src/ln/msgs.rs 85.82% <81.66%> (+0.21%) ⬆️
lightning/src/ln/channelmanager.rs 87.19% <88.23%> (-0.02%) ⬇️
lightning/src/ln/channel.rs 89.83% <95.83%> (+<0.01%) ⬆️
lightning-invoice/src/utils.rs 97.67% <100.00%> (ø)
... and 7 more

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@optout21 optout21 marked this pull request as ready for review August 10, 2023 07:54
@optout21 optout21 changed the title [WIP] Introduce new ChannelId struct Introduce new ChannelId struct Aug 10, 2023
@dunxen
Copy link
Contributor

dunxen commented Aug 10, 2023

This overall looks like an improvement, but I'd like to maybe see what others had to say about types for different IDs like

  • temporary channel IDs for V1 unfunded channels
  • channel IDs for V1 funded channels with known funding txids
  • temporary channel IDs (revocation basepoint XORed with zero) for V2 channels for open_channel2 and accept_channel2
  • channel IDs (both party revocation basepoints XORed) for V2 channels after accept_channel2.

For me currently I don't see a huge benefit in splitting all these cases into distinct types or even enum variants. So I think this PR is all we need so that we at least have type safety for channel ID bytes vs hash bytes for example.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Mostly some minor process nits on commit construction, but LGTM.

lightning/src/chain/transaction.rs Outdated Show resolved Hide resolved
lightning/src/chain/transaction.rs Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning-invoice/src/utils.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
@optout21 optout21 force-pushed the channel-id-4struct1 branch 2 times, most recently from 50565dc to c84dad1 Compare August 22, 2023 15:23
@optout21
Copy link
Contributor Author

Review comments addressed. commits regrouped (into 2 commits) as suggested.
Only outstanding issue is where to have the ChannelId declaration -- leave in channel.rs, in mod.rs, or in new, own mod.

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.

LGTM with moving the ChannelId stuff to its own mod.

lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
@optout21 optout21 force-pushed the channel-id-4struct1 branch 2 times, most recently from 31cf609 to 7ec2b2e Compare August 24, 2023 09:38
@optout21
Copy link
Contributor Author

Moved ChannelId to its own new module (channel_id.rs); but need to clean up the commits

dunxen
dunxen previously approved these changes Aug 24, 2023
lightning/src/ln/channel_id.rs Outdated Show resolved Hide resolved
@dunxen
Copy link
Contributor

dunxen commented Aug 24, 2023

Oops sorry, yeah looks good for squash. Also missing module docs for the new module

@optout21
Copy link
Contributor Author

Per-commit check failed, fixed (moved last fix in first commit)

dunxen
dunxen previously approved these changes Aug 24, 2023
@optout21
Copy link
Contributor Author

optout21 commented Aug 25, 2023

This PR touches many logging lines, so it frequently gets in conflict with current main... I keep rebasing+resolving conflicts, but it would be nice to get more approvals ;)
Rebased again.

@TheBlueMatt
Copy link
Collaborator

Heh, sorry, been a super busy merge week. Will review now and hopefully @dunxen is still around to ack.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Two quick comments, didnt look at the second commit but i assume its fine.

lightning/src/ln/channel_id.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel_id.rs Outdated Show resolved Hide resolved
@optout21
Copy link
Contributor Author

Simplified as suggested (@TheBlueMatt): changed struct into a pub tuple; removed .bytes() (use .0 instead).
Also found some instances in tests where temp ID is generated, but from_bytes() was used.
Also some rustdoc formatting.

lightning/src/ln/channel_id.rs Show resolved Hide resolved
lightning/src/ln/channel.rs Show resolved Hide resolved
@@ -16,10 +16,10 @@ use crate::chain::channelmonitor::{ANTI_REORG_DELAY, HTLC_FAIL_BACK_BUFFER, LATE
use crate::sign::EntropySource;
use crate::chain::transaction::OutPoint;
use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentFailureReason, PaymentPurpose};
use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS;
use crate::ln::channel::{EXPIRE_PREV_CONFIG_TICKS};
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you add brackets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, typo, after subsequent add and delete.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good to keep the blame layer clean (doesn't matter much for use statements), but makes it easier to read stuff back later :)

@optout21
Copy link
Contributor Author

2 CI builds fail, likely due to #2527 . 2 approvals.

@TheBlueMatt TheBlueMatt merged commit 61d896d into lightningdevkit:main Aug 27, 2023
12 of 14 checks passed
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.

Abstraction of ChannelId type
5 participants