Skip to content

Conversation

GeorgeTsagk
Copy link
Collaborator

Description

This PR exposes a new RPC method XFindBaseLocalChanAlias which enhances the set of alias-related RPCs by allowing the user to look up the base scid for an alias that they added.

We also enhance the alias manager with an extra flag that explicitly indicates that we want the backwards mapping (baseScid -> aliasScid) to be stored. This flag is used when calling XAddLocalChanAlias

@GeorgeTsagk GeorgeTsagk self-assigned this Aug 6, 2025
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.

Summary of Changes

Hello @GeorgeTsagk, 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!

I've introduced a new RPC endpoint, XFindBaseLocalChanAlias, to enhance the alias management capabilities. This RPC allows users to easily retrieve the base Short Channel ID (SCID) associated with a local channel alias they've added. To support this, I've updated the alias manager to explicitly store the reverse mapping from alias to base SCID when a new alias is added, ensuring that these lookups are possible.

Highlights

  • New RPC Endpoint: Added a new experimental RPC, XFindBaseLocalChanAlias, enabling users to query the base SCID for a given local channel alias.
  • Alias Manager Enhancement: Enhanced the AddLocalAlias function in the alias manager with a baseLookup flag to control the explicit storage of the alias-to-base SCID mapping.
  • RPC Integration: Modified the XAddLocalChanAlias RPC to utilize this new baseLookup flag, ensuring that manually added aliases can be looked up using the new XFindBaseLocalChanAlias RPC.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@lightninglabs-deploy
Copy link

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

@saubyk saubyk added this to lnd v0.20 Sep 10, 2025
@saubyk saubyk added this to the v0.20.0 milestone Sep 10, 2025
@saubyk saubyk moved this to In progress in lnd v0.20 Sep 10, 2025
@saubyk saubyk moved this from In progress to In review in lnd v0.20 Sep 15, 2025
@GeorgeTsagk
Copy link
Collaborator Author

/gemini review

@GeorgeTsagk
Copy link
Collaborator Author

(previous run failed)

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 a new RPC, XFindBaseLocalChanAlias, which allows users to look up the base SCID for a given alias. To support this, the alias manager's AddLocalAlias function is updated with a baseLookup flag to control the creation of the in-memory reverse mapping. The changes are logical and include corresponding tests. My feedback includes a few minor suggestions to improve comment clarity, fix a style issue, and correct a typo in the release notes.

@GeorgeTsagk GeorgeTsagk force-pushed the rpc-find-base-alias branch 2 times, most recently from 4d15b66 to d821318 Compare September 17, 2025 10:39
if gossip {
// Only store the gossiper map if gossip is true, or if the caller
// explicitly asked to store this reverse mapping.
if gossip || baseLookup {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it the desired behaviour that this reverse lookup is not persisted? currently, all these mappings added will be lost on restart

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When we add a local alias we also store a (kvdb) entry that maps the alias to its base

return aliasToBaseBucket.Put(aliasBytes[:], baseBytes[:])

Then on restart when we call the helper populateMaps() we read the entries from the map:

err = aliasToBaseBucket.ForEach(func(k, v []byte) error {

and populate aliasToBase accordingly for each entry:

lnd/aliasmgr/aliasmgr.go

Lines 225 to 234 in d821318

for aliasSCID, baseSCID := range aliasMap {
m.baseToSet[baseSCID] = append(m.baseToSet[baseSCID], aliasSCID)
// Skip if baseSCID is in the baseConfMap.
if _, ok := baseConfMap[baseSCID]; ok {
continue
}
m.aliasToBase[aliasSCID] = baseSCID
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok now I realise that baseConfMap is causing issues here.

After looking over the baseConfMap its entries only affect whether a baseScid will get the aliasToBase values populated on restart:

  • When we call DeleteSixConfs we mark the base scid in the conf bucket
  • If an alias entry's base scid is in the conf bucket we skip adding it to aliasToBase on startup

If we make sure to also delete the alias entries from the kvdb aliasToBase bucket here

lnd/aliasmgr/aliasmgr.go

Lines 385 to 391 in d821318

// Now that the database state has been updated, we'll delete all of
// the aliasToBase mappings for this SCID.
for alias, base := range m.aliasToBase {
if base.ToUint64() == baseScid.ToUint64() {
delete(m.aliasToBase, alias)
}
}

Then we can totally strip away the baseToConf bucket, as it won't be needed anymore:

  • When a baseScid is marked as confirmed we'll purge all previous aliases both from memory and the bucket.
  • This way on restart any conf'd baseScids will by default not populate any aliasToBase entries, as there won't be any left.
  • We're now free to add any manual aliasToBase entries which will persist and be restored by default on startup.

Note: if an RPC user added custom aliases before six confs, then those would also be deleted by above approach. In this case:
a) Can make it super clear in the docs that custom aliases are persisted only post-confirmation.
b) Keep the conf bucket after all, only to prohibit RPC user from adding custom entries before the channel is confirmed.

I lean towards a) for the last note.

Also worth investigating how this affects interaction with other systems

@GeorgeTsagk
Copy link
Collaborator Author

I just pushed some commits that change the approach. We don't use the baseLookup flag, instead we simplify the aliasmgr to not need the baseLookup flag at all (also we get rid of the previously used gossip flag).

With the latest set of commits, we instead change the behavior of aliasmgr:

  • All added aliases will populate aliasToBase map and also persist in the db
  • On deletion we remove both the in-memory mappings and the db entries for aliases
  • On restart we don't consult the base-conf bucket at all, we just load all values that are still in storage (because of previous bullet point we're now safe to do so)

One interesting call site was from brontide:
https://github.com/lightningnetwork/lnd/blob/master/peer/brontide.go#L1045-L1062

We explicitly used the gossip flag there to make sure we don't accept channel alias updates after the channel confirmation.


After reviewing this approach I realized it's very hard to reason about. Current unit & itest coverage seems happy but not sure if they capture all funding flow edge cases that can lead to buggy behavior -- will have to investigate more deeply.

Some alternative approaches, if this one is not deemed worthy:

  • Keep the gossip flag to directly affect the in-memory population of aliasToBase and also skip persistence altogether
  • Serve the persistence needs of XFindBaseLocalChanAlias (the original scope of this PR) with a workaround, like keeping direct track of them in a new kvdb bucket.

Comment on lines +67 to +69
was added for looking up the base scid for an scid alias. Aliases that were
manually created via the `XAddLocalChanAliases` endpoint will get lost on
restart.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted back to the non-persistent approach, turns out there's too many things to deal with to properly support persistence for manually added aliases. Added the note on the release doc as per your suggestion @ellemouton.

Will re-iterate in the future for persistence.

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.

lgtm 👍

I think that warning in the release notes should also be mentioned in the code.
One other suggestion about turning the new option into a functional option since it is experimental & doesnt work across restarts.. that would also eliminate the need to update every call-site. Non-blocking though (but defs please add a warning comment at least)

@GeorgeTsagk
Copy link
Collaborator Author

lgtm 👍

I think that warning in the release notes should also be mentioned in the code. One other suggestion about turning the new option into a functional option since it is experimental & doesnt work across restarts.. that would also eliminate the need to update every call-site. Non-blocking though (but defs please add a warning comment at least)

Thanks for the extra recommendations. Applied all of them 👍

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.

LGTM 💥

@Roasbeef
Copy link
Member

Needs a rebase!

Then should be good to land.

We add an extra option to the AddLocalAlias method which only controls
whether we store a reverse lookup from the alias back to the base scid
it corresponds to. The previous flag "gossip" is still maintained, and
in a way supercedes the new flag (it will also store the base scid
lookup even if the base lookup flag isn't set). The only call that sets
this option is the XAddLocalChanAlias RPC endpoint, where we want to
make sure that a reverse lookup is stored in the alias manager in order
to later expose it via the new RPC method.
Add the new RPC method that looks up the base scid for a given alias.
Given the previous stepping stones this commit is fairly simple, we just
call into the alias manager and return the lookup result.
@yyforyongyu yyforyongyu merged commit b09b20c into lightningnetwork:master Sep 25, 2025
36 of 39 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in lnd v0.20 Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants