Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions aliasmgr/aliasmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,43 @@ func (m *Manager) populateMaps() error {
return nil
}

// addAliasCfg is a struct that hosts various options related to adding a local
// alias to the alias manager.
type addAliasCfg struct {
// baseLookup signals that the alias should also store a reverse look-up
// to the base scid.
baseLookup bool
}

// AddLocalAliasOption is a functional option that modifies the configuration
// for adding a local alias.
type AddLocalAliasOption func(cfg *addAliasCfg)

// WithBaseLookup is a functional option that controls whether a reverse lookup
// will be stored from the alias to the base scid.
func WithBaseLookup() AddLocalAliasOption {
return func(cfg *addAliasCfg) {
cfg.baseLookup = true
}
}

// AddLocalAlias adds a database mapping from the passed alias to the passed
// base SCID. The gossip boolean marks whether or not to create a mapping
// that the gossiper will use. It is set to false for the upgrade path where
// the feature-bit is toggled on and there are existing channels. The linkUpdate
// flag is used to signal whether this function should also trigger an update
// on the htlcswitch scid alias maps.
// flag is used to signal whether this function should also trigger an update on
// the htlcswitch scid alias maps.
//
// NOTE: The following aliases will not be persisted (will be lost on restart):
// - Aliases that were created without gossip flag.
// - Aliases that correspond to confirmed channels.
func (m *Manager) AddLocalAlias(alias, baseScid lnwire.ShortChannelID,
gossip, linkUpdate bool) error {
gossip, linkUpdate bool, opts ...AddLocalAliasOption) error {

cfg := addAliasCfg{}
for _, opt := range opts {
opt(&cfg)
}

// We need to lock the manager for the whole duration of this method,
// except for the very last part where we call the link updater. In
Expand Down Expand Up @@ -302,8 +331,9 @@ func (m *Manager) AddLocalAlias(alias, baseScid lnwire.ShortChannelID,
// Update the aliasToBase and baseToSet maps.
m.baseToSet[baseScid] = append(m.baseToSet[baseScid], alias)

// Only store the gossiper map if gossip is true.
if gossip {
// Only store the gossiper map if gossip is true, or if the caller
// explicitly asked to store this reverse mapping.
if gossip || cfg.baseLookup {
m.aliasToBase[alias] = baseScid
}

Expand Down Expand Up @@ -342,7 +372,9 @@ func (m *Manager) GetAliases(
}

// FindBaseSCID finds the base SCID for a given alias. This is used in the
// gossiper to find the correct SCID to lookup in the graph database.
// gossiper to find the correct SCID to lookup in the graph database. It can
// also be used to look up the base for manual aliases that were added over the
// RPC.
func (m *Manager) FindBaseSCID(
alias lnwire.ShortChannelID) (lnwire.ShortChannelID, error) {

Expand Down Expand Up @@ -446,7 +478,7 @@ func (m *Manager) DeleteLocalAlias(alias,
}

// Finally, we'll delete the aliasToBase mapping from the Manager's
// cache (but this is only set if we gossip the alias).
// cache.
delete(m.aliasToBase, alias)

// We definitely need to unlock the Manager before calling the link
Expand Down
11 changes: 10 additions & 1 deletion aliasmgr/aliasmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,19 @@ func TestAliasLifecycle(t *testing.T) {
require.Equal(t, StartingAlias, firstRequested)

// We now manually add the next alias from the range as a custom alias.
// This time we also use the base lookup option, in order to be able to
// go from alias back to the base scid.
secondAlias := getNextScid(firstRequested)
err = aliasStore.AddLocalAlias(secondAlias, baseScid, false, true)
err = aliasStore.AddLocalAlias(
secondAlias, baseScid, false, true, WithBaseLookup(),
)
require.NoError(t, err)

baseLookup, err := aliasStore.FindBaseSCID(secondAlias)
require.NoError(t, err)

require.Equal(t, baseScid, baseLookup)

// When we now request another alias from the allocation list, we expect
// the third one (tx position 2) to be returned.
thirdRequested, err := aliasStore.RequestAlias()
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes/release-notes-0.20.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ a certain amount of msats.
- Added support for [P2TR Fallback Addresses](
https://github.com/lightningnetwork/lnd/pull/9975) in BOLT-11 invoices.

- A new experimental RPC endpoint
[XFindBaseLocalChanAlias](https://github.com/lightningnetwork/lnd/pull/10133)
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.
Comment on lines +67 to +69
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.


## Functional Enhancements
* [Add](https://github.com/lightningnetwork/lnd/pull/9677)
`ConfirmationsUntilActive` and `ConfirmationHeight` field to the
Expand Down
5 changes: 3 additions & 2 deletions funding/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package funding

import (
"github.com/lightningnetwork/lnd/aliasmgr"
"github.com/lightningnetwork/lnd/lnpeer"
"github.com/lightningnetwork/lnd/lnwire"
)
Expand Down Expand Up @@ -36,8 +37,8 @@ type aliasHandler interface {
GetPeerAlias(lnwire.ChannelID) (lnwire.ShortChannelID, error)

// AddLocalAlias persists an alias to an underlying alias store.
AddLocalAlias(lnwire.ShortChannelID, lnwire.ShortChannelID, bool,
bool) error
AddLocalAlias(lnwire.ShortChannelID, lnwire.ShortChannelID, bool, bool,
...aliasmgr.AddLocalAliasOption) error

// GetAliases returns the set of aliases given the main SCID of a
// channel. This SCID will be an alias for zero-conf channels and will
Expand Down
4 changes: 3 additions & 1 deletion funding/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/wallet"
"github.com/lightningnetwork/lnd/aliasmgr"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/chainreg"
acpt "github.com/lightningnetwork/lnd/chanacceptor"
Expand Down Expand Up @@ -162,7 +163,8 @@ func (m *mockAliasMgr) GetPeerAlias(lnwire.ChannelID) (lnwire.ShortChannelID,
}

func (m *mockAliasMgr) AddLocalAlias(lnwire.ShortChannelID,
lnwire.ShortChannelID, bool, bool) error {
lnwire.ShortChannelID, bool, bool,
...aliasmgr.AddLocalAliasOption) error {

return nil
}
Expand Down
Loading
Loading