@@ -239,14 +239,43 @@ func (m *Manager) populateMaps() error {
239239 return nil
240240}
241241
242+ // addAliasCfg is a struct that hosts various options related to adding a local
243+ // alias to the alias manager.
244+ type addAliasCfg struct {
245+ // baseLookup signals that the alias should also store a reverse look-up
246+ // to the base scid.
247+ baseLookup bool
248+ }
249+
250+ // AddLocalAliasOption is a functional option that modifies the configuration
251+ // for adding a local alias.
252+ type AddLocalAliasOption func (cfg * addAliasCfg )
253+
254+ // WithBaseLookup is a functional option that controls whether a reverse lookup
255+ // will be stored from the alias to the base scid.
256+ func WithBaseLookup () AddLocalAliasOption {
257+ return func (cfg * addAliasCfg ) {
258+ cfg .baseLookup = true
259+ }
260+ }
261+
242262// AddLocalAlias adds a database mapping from the passed alias to the passed
243263// base SCID. The gossip boolean marks whether or not to create a mapping
244264// that the gossiper will use. It is set to false for the upgrade path where
245265// the feature-bit is toggled on and there are existing channels. The linkUpdate
246- // flag is used to signal whether this function should also trigger an update
247- // on the htlcswitch scid alias maps.
266+ // flag is used to signal whether this function should also trigger an update on
267+ // the htlcswitch scid alias maps.
268+ //
269+ // NOTE: The following aliases will not be persisted (will be lost on restart):
270+ // - Aliases that were created without gossip flag.
271+ // - Aliases that correspond to confirmed channels.
248272func (m * Manager ) AddLocalAlias (alias , baseScid lnwire.ShortChannelID ,
249- gossip , linkUpdate bool ) error {
273+ gossip , linkUpdate bool , opts ... AddLocalAliasOption ) error {
274+
275+ cfg := addAliasCfg {}
276+ for _ , opt := range opts {
277+ opt (& cfg )
278+ }
250279
251280 // We need to lock the manager for the whole duration of this method,
252281 // except for the very last part where we call the link updater. In
@@ -302,8 +331,9 @@ func (m *Manager) AddLocalAlias(alias, baseScid lnwire.ShortChannelID,
302331 // Update the aliasToBase and baseToSet maps.
303332 m .baseToSet [baseScid ] = append (m .baseToSet [baseScid ], alias )
304333
305- // Only store the gossiper map if gossip is true.
306- if gossip {
334+ // Only store the gossiper map if gossip is true, or if the caller
335+ // explicitly asked to store this reverse mapping.
336+ if gossip || cfg .baseLookup {
307337 m .aliasToBase [alias ] = baseScid
308338 }
309339
@@ -342,7 +372,9 @@ func (m *Manager) GetAliases(
342372}
343373
344374// FindBaseSCID finds the base SCID for a given alias. This is used in the
345- // gossiper to find the correct SCID to lookup in the graph database.
375+ // gossiper to find the correct SCID to lookup in the graph database. It can
376+ // also be used to look up the base for manual aliases that were added over the
377+ // RPC.
346378func (m * Manager ) FindBaseSCID (
347379 alias lnwire.ShortChannelID ) (lnwire.ShortChannelID , error ) {
348380
@@ -446,7 +478,7 @@ func (m *Manager) DeleteLocalAlias(alias,
446478 }
447479
448480 // Finally, we'll delete the aliasToBase mapping from the Manager's
449- // cache (but this is only set if we gossip the alias) .
481+ // cache.
450482 delete (m .aliasToBase , alias )
451483
452484 // We definitely need to unlock the Manager before calling the link
0 commit comments