Skip to content

Conversation

@gijswijs
Copy link
Collaborator

This PR aligns our behavior with latest protocol guidelines. That
is, when we receive a signature announcement when we already have the
full proof we reply with our signature announcement once per
(re)connection.

see: lightning/bolts#1256

fixes: #9843

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 17, 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.

@gijswijs gijswijs changed the title Resend-annsig Re-send AnnouncementSignature not more than once per connection. Jun 17, 2025
@saubyk saubyk requested review from bitromortac and ellemouton June 17, 2025 16:40
@saubyk saubyk added this to lnd v0.20 Jun 17, 2025
@saubyk saubyk added this to the v0.20.0 milestone Jun 17, 2025
@saubyk saubyk moved this to In review in lnd v0.20 Jun 17, 2025
@saubyk saubyk removed this from lnd v0.20 Jun 30, 2025
gijswijs

This comment was marked as duplicate.

Copy link
Collaborator Author

@gijswijs gijswijs left a comment

Choose a reason for hiding this comment

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

Pushed new code. The only thing that still doesn't sit with me well is the simulation of the peer disconnecting.

https://github.com/gijswijs/lnd/blob/b01eea655ac4ba8d93d66c7696dc9049d36f2f7a/discovery/gossiper_test.go#L2004-L2009

Obviously when I recreate the mockPeer the state of the previous mockPeer is gone, so that reasoning is almost circular. (That also holds true for the way we simulated the gossiper before tho).

I think to truly test this we should make an itest. @ellemouton what do you think?

@gijswijs gijswijs requested a review from ellemouton July 8, 2025 13:23
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

looking good - left one more suggestion regarding approach.

I think the suggestion also answers your question:

doesn't sit with me well is the simulation of the peer disconnecting.

cause now with the suggestion, simulating this is quite easily done from a unit test since the "PeerDisconnected" is just a call-back on the gossiper passed to the peer in question.

remoteNSB,
remoteBSB, nil,
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

unaddressed

chanInfo.AuthProof, chanInfo, e1, e2,
chanAP := chanInfo.AuthProof
var remoteNSB []byte
var remoteBSB []byte
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think the name remote* is confusing cause it makes it sound like we are sending them their own proof. local* would make more sense no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this was resolved without a reply? 😊

Comment on lines 1807 to 1821
// We create an active syncer for our remote peer.
err = syncMgr.InitSyncState(remotePeer)
require.NoError(t, err, "failed to init sync state")
remoteSyncer := assertSyncerExistence(t, syncMgr, remotePeer)
assertTransitionToChansSynced(t, remoteSyncer, remotePeer)
assertActiveGossipTimestampRange(t, remotePeer)
assertSyncerStatus(t, remoteSyncer, chansSynced, ActiveSync)
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm do we still need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it into tCtx.gossiper.InitSyncState(remotePeer) which now handles the clearing of the map[peer][chanID]bool and also calls into syncMgr.InitSyncState(remotePeer). I've kept the assertions, which although slight overkill, are an assertion that everything went aOK so far.

@bitromortac bitromortac removed their request for review August 27, 2025 07:19
@saubyk saubyk modified the milestones: v0.20.0, v0.21.0 Sep 5, 2025
@gijswijs gijswijs force-pushed the resend-annsig branch 2 times, most recently from 462f1ee to f0dc8d3 Compare September 22, 2025 21:06
The config file format changed. The tool golangci-lint migrate
was used to migrate the old config. However old comments and also
the structure of the disabled linters was preserved.

Moreover the new v2 version introduced new linters, we disable
3 of them because they are very noise and we do not really want
to check for them: funcorder, noinlineerr, embeddedstructfieldcheck.
The custom file is only needed in the tools directory.
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Straight forward solution.

Main comments are re better encapsluation, and reducing duplication in the unit test.

sentMsgs: sentMsgs,
quit: quit,
}
p.disconnected.Store(disconnected)
Copy link
Member

Choose a reason for hiding this comment

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

A new addition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if I follow. It's just a small refactor that introduces a constructor instead of a ton of &mockPeer{someKey.PubKey(), nil, nil, atomic.Bool{}}

It's never called with anything other than disconnected == false so in theory we could do without that parameter and just initialize it with the zero value of atomic.Bool. It probably doesn't make sense to construct a disconnected peer from the get go.

What do you think?

"announcement signatures to peer=%x",
ann.ChannelID, peerID)

ca, _, _, err := netann.CreateChanAnnouncement(
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to not also send the chan ann as well? So send the ann sig, and the channel ann.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BOLT07 requires us to send the ann sig: https://github.com/ddustin/lightning-rfc/blob/a2d314df9a791dd1a38be7c34d201bf798ad3525/07-routing-gossip.md?plain=1#L93

Is there a good reason to also send the channel ann? We should assume that our peers do not expect a channel ann.

// sentAnnSigs tracks which announcement signatures we've sent to which
// peers. We'll use this to ensure we don't re-send the same signatures
// to a peer during a single connection.
sentAnnSigs map[route.Vertex]map[lnwire.ChannelID]struct{}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to limit the size of this map?

Copy link
Member

Choose a reason for hiding this comment

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

Let's also further encapsulate this new data structure. We can expose easy to use methods that: delete, check existence, and add. All while handling thread safety on behalf of the caller.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it's smart to limit the size of the map. We need to keep state for every channel anyway, so I wouldn't inadvertently run into the limit of the map. It's hardly a DOS-vector since we only ever hit this map after channel_ready has been sent and received AND the funding transaction has enough confirmations. That's enough disincentivization if you'd ask me.

I agree with the proposed methods tho.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've encapsulated the map in its own struct sentAnnSigsTracker. It uses its own sync.Mutex to provide better lock granularity. The memory overhead of an extra mutex is very small, and it (hopefully) reduces contention.

Roasbeef and others added 15 commits October 6, 2025 14:08
And ensure that both versions 1 and 2 implement it.
Define a GossipVersion enum along with a GossipMessage interface to be
satisfied by all gossip related messages. This will be useful later on
when we want to make decisions based on the protocol version that a
message is part of.
Since the gossip protocols are completely disjoint, we need to treat
messages on the two protocols completely separately and should not let
rejections on one protocol affect how we treat messages on the other.
Use a blank identifier when values are intentionally unused.
two constructor funcs that create and return a pointer to an
AnnounceSignatures1. `NewAnnSigFromSignature` takes `nodeSig` and
`bitcoinSig` as pointers to `*ecdsa.Signature`. `NewAnnSigFromWireECDSA`
takes those arguments in the raw 64-byte format we expect.
We change the discovery gossiper to send a signature announcement in
response to receiving a signature announcement, but only if the full
proof is available. Previously the behavior was to send the channel
announcement.
This change aligns our behavior with latest protocol guidelines. That
is, when we receive a signature announcement when we already have the
full proof we reply with our signature announcement once per
(re)connection.

see: lightning/bolts#1256
@gijswijs gijswijs changed the base branch from master to 0-21-0-staging October 8, 2025 15:48
@gijswijs
Copy link
Collaborator Author

gijswijs commented Oct 8, 2025

I think I addressed all comments. Ready for a new round of code review.

Copy link
Collaborator

@ellemouton ellemouton 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! i think just some commit restructuring needed. Other than that, logic LGTM!

chanInfo.AuthProof, chanInfo, e1, e2,
chanAP := chanInfo.AuthProof
var remoteNSB []byte
var remoteBSB []byte
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this was resolved without a reply? 😊

remoteNSB,
remoteBSB, nil,
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

still

Comment on lines 3649 to 3654
if peerIsFirstNode {
localNSB = chanAP.NodeSig2Bytes
localBSB = chanAP.BitcoinSig2Bytes
} else {
remoteNSB = chanAP.NodeSig1Bytes
remoteBSB = chanAP.BitcoinSig1Bytes
localNSB = chanAP.NodeSig1Bytes
localBSB = chanAP.BitcoinSig1Bytes
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, ok yeah, for sake of review, rather make these changes in the commit where the variables are introduced

@yyforyongyu yyforyongyu force-pushed the 0-21-0-staging branch 3 times, most recently from 57eb251 to 6fcdbbb Compare November 7, 2025 09:15
@yyforyongyu yyforyongyu changed the base branch from 0-21-0-staging to master November 13, 2025 08:59
@lightninglabs-deploy
Copy link

@Roasbeef: review reminder
@gijswijs, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature]: Make sure LND re-sends AnnouncementSignature after disconnect.

6 participants