Skip to content

Conversation

@ellemouton
Copy link
Collaborator

Description TBD

Depends on #10379
Part of #10293

@ellemouton ellemouton self-assigned this Nov 19, 2025
@gemini-code-assist
Copy link

Summary of Changes

Hello @ellemouton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request continues the ongoing work to evolve the graph database for Gossip V2 support. It introduces version-awareness to critical graph database operations, enabling the system to correctly distinguish and process both V1 and V2 channel announcements. The SQL database backend is extended to store and retrieve V2-specific channel information, including new cryptographic details for funding outputs, while the KV store explicitly retains its V1-only scope. These infrastructural changes are crucial for a smooth transition to Gossip V2 without impacting existing V1 functionality.

Highlights

  • Gossip V2 Data Preparation: The graph database is being prepared to handle Gossip V2 channel data, introducing version-awareness to core graph operations across various components.
  • Versioned Graph Operations: Key database operations such as deleting channel edges, checking public nodes, and fetching channel edges now explicitly accept a gossip version parameter, allowing for differentiated handling of V1 and V2 data.
  • SQL Store V2 Support: The SQL database store has been updated to support V2 channel insertion, proof addition, and public node checks, including new fields specific to V2 channels like MerkleRootHash and FundingScript.
  • KV Store V1 Limitation: The Key-Value store implementation is explicitly limited to Gossip V1 data, returning an error if operations for other gossip versions are attempted.
  • V2 Channel Model Enhancements: The ChannelEdgeInfo model now includes fields and logic specific to V2 channels, such as optional Bitcoin keys, MerkleRootHash, FundingScript, and ExtraSignedFields, along with a new NewV2Channel constructor.
  • Updated Testing Framework: The testing suite has been enhanced to run graph database tests against both V1 and V2 gossip versions, ensuring future compatibility and correctness.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces versioning to the channel graph database to support Gossip V2. The changes are extensive, touching the DB interfaces, KV and SQL store implementations, data models, and tests. The approach of creating a VersionedGraph wrapper and updating the Store interface is clean. The SQL store implementation seems to be getting the bulk of the V2 support, while the KV store is temporarily updated to reject V2 calls, which is a reasonable strategy.

My review found a critical issue in the V2 funding script generation logic within graph/db/models/channel_edge_info.go. The incorrect use of musig2.AggregateKeys for applying the taproot tweak would result in an incorrect funding script, potentially leading to loss of funds. I've provided a detailed comment and a suggested fix for this.

Otherwise, the refactoring and new additions seem well-structured and consistent with the goal of adding V2 support. The test refactoring to make them version-aware is also a good step.

Comment on lines +403 to +424
combinedKey, _, _, err := musig2.AggregateKeys(
[]*btcec.PublicKey{pubKey1, pubKey2}, true,
musig2.WithKeyTweaks(musig2.KeyTweakDesc{
Tweak: *tapTweakHash,
IsXOnly: true,
}),
)
if err != nil {
return nil, err
}

// Now that we have the combined key, we can create a taproot
// pkScript from this, and then make the txout given the amount.
fundingScript, err := input.PayToTaprootScript(
combinedKey.FinalKey,
)
if err != nil {
return nil, fmt.Errorf("unable to make taproot "+
"pkscript: %w", err)
}

return fundingScript, nil

Choose a reason for hiding this comment

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

critical

The current logic for computing the final taproot output key appears to be incorrect. The musig2.AggregateKeys function with WithKeyTweaks applies the tweak to each individual public key before aggregation, which is not the correct procedure for creating a taproot output key. The tweak should be applied to the aggregated internal key.

This also results in an unnecessary second call to musig2.AggregateKeys.

I suggest using input.TweakTaprootKey which correctly applies the taproot tweak to an internal public key. This will correct the logic and simplify the code.

This is a critical issue as it would produce an incorrect funding script.

		// Tweak the internal key with the tap tweak hash to get the final
		// output key.
		outputKey := input.TweakTaprootKey(
			internalKey.FinalKey, tapTweakHash[:],
		)

		// Now that we have the output key, we can create a taproot
		// pkScript from this.
		fundingScript, err := input.PayToTaprootScript(outputKey)
		if err != nil {
			return nil, fmt.Errorf("unable to make taproot "+
				"pkscript: %w", err)
		}

		return fundingScript, nil

@saubyk saubyk added this to v0.21 Nov 20, 2025
@saubyk saubyk moved this to In progress in v0.21 Nov 20, 2025
@lightninglabs-deploy
Copy link

@ellemouton, remember to re-request review from reviewers when ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants