Skip to content

lnwire+lnwallet: add LocalNonces field for splice nonce coordination w/ taproot channels #9982

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

Open
wants to merge 4 commits into
base: taproot-final-scripts
Choose a base branch
from

Conversation

Roasbeef
Copy link
Member

This PR implements support for the upcoming BOLT specification change that enables coordinated nonce exchange for splice operations in taproot channels. The current LocalNonce field in ChannelReestablish only supports a single nonce, but splice operations require coordination of multiple nonces for different transaction purposes.

Note that we don't support splicing yet, but we aim to make sure the final version of taproot channels is fully compatible with splicing. This new set of fields is only intended to be set with the production taproot channel feature bit. A follow up PR will actually start to gate the script and p2p message changes (like this).

Ultimately for the foreseeable future, we'll support both the staging and prod taproot channel feature bit. Dynamic commitments can be used in the future to upgrade all the staging versions off-chain, which will allow us to eventually remove that feature bit.

Changes

This PR introduces a new LocalNonces field alongside the existing LocalNonce field to enable:

  • Splice nonce coordination: Different nonces for pending splice transactions vs. main channel commitment
  • Multi-transaction scenarios: Support for coordinating nonces across multiple concurrent operations
  • Future extensibility: Foundation for other multi-nonce scenarios in taproot channels

Implementation Details

Wire Protocol Changes

  • Adds LocalNoncesData TLV structure containing a map of transaction IDs to MuSig2 nonces
  • Extends ChannelReestablish message with optional LocalNonces field (TLV)
  • Maintains full backwards compatibility with existing LocalNonce field

Channel Synchronization Logic

  • ChanSyncMsg() now populates both legacy and new nonce fields for taproot channels
  • ProcessChanSyncMsg() prioritizes LocalNonces over LocalNonce when both are present
  • Uses empty hash key chainhash.Hash{} for primary commitment nonce in the map

Key Design Decisions

  1. Backwards Compatibility: Both fields are populated during transition period
  2. Deterministic Encoding: TLV encoding ensures consistent wire format
  3. Clean Fallback: Receiving logic gracefully handles either field type
  4. Future-Ready: Map structure supports arbitrary transaction-specific nonces

Testing

  • Comprehensive unit tests for LocalNoncesData encoding/decoding
  • Property-based testing integration via RandTestMessage
  • New TestChanSyncTaprootLocalNonces covering all sync scenarios
  • Backwards compatibility testing for mixed old/new implementations

Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Roasbeef added 4 commits June 23, 2025 18:45
This commit introduces a new TLV structure LocalNoncesData that contains
a map of transaction IDs to MuSig2 nonces. This structure enables
coordinating multiple nonces for different purposes (e.g., channel
commits, splice operations) within a single wire message.

The implementation includes:
- LocalNoncesData struct with deterministic TLV encoding/decoding
- Comprehensive unit tests covering encoding, decoding, and edge cases
- Helper functions for creating optional LocalNonces values

This is a prep for upcoming spec changes to allow a party that has
in-prorgess splices to tell the remote party which nonces to use for
which splice.
Extends the ChannelReestablish message to include a new optional
LocalNonces field alongside the existing LocalNonce field. This enables
backwards-compatible transmission of multiple nonces for different
purposes during channel reestablishment.

Changes include:
- Add LocalNonces field to ChannelReestablish struct
- Update Encode/Decode methods to handle the new TLV field
- Extend property-based testing to randomly include LocalNonces
- Maintain full backwards compatibility with existing LocalNonce field
Updates channel synchronization to support the new LocalNonces field
while maintaining backwards compatibility with the legacy LocalNonce
field. This enables coordinated nonce exchange for splice operations
and other multi-commitment scenarios.

Key changes:
- ChanSyncMsg now populates both LocalNonce and LocalNonces fields
- ProcessChanSyncMsg prioritizes LocalNonces over LocalNonce
- Uses empty hash key for primary commitment nonce in LocalNonces map
- Maintains full backwards compatibility with existing implementations
Adds extensive test coverage for the new LocalNonces functionality in
channel synchronization, ensuring both legacy and new nonce fields work
correctly together.

Test additions include:
- Helper function to extract nonces from either LocalNonces or LocalNonce
- Comprehensive TestChanSyncTaprootLocalNonces covering all scenarios
- Tests for backwards compatibility when only one field is present
- Error handling tests for missing nonce scenarios
- Updates to existing sync tests to handle both nonce field types
@Roasbeef Roasbeef changed the base branch from master to taproot-final-scripts June 24, 2025 01:45
@Roasbeef
Copy link
Member Author

This is dependent on #9639

@afeezaziz
Copy link

Hope to see this soon!

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.

2 participants