diff --git a/config_builder.go b/config_builder.go index b675cacaa..cf32115fc 100644 --- a/config_builder.go +++ b/config_builder.go @@ -44,6 +44,7 @@ import ( "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/btcwallet" "github.com/lightningnetwork/lnd/lnwallet/rpcwallet" + "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/macaroons" "github.com/lightningnetwork/lnd/protofsm" "github.com/lightningnetwork/lnd/routing" @@ -123,6 +124,32 @@ type ChainControlBuilder interface { *btcwallet.Config) (*chainreg.ChainControl, func(), error) } +// AliasAdder is an interface that can add SCID aliases to the local alias +// store. +type AliasAdder interface { + // AddLocalAlias adds a database mapping from the passed alias to the + // passed base SCID. The gossip boolean marks whether 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. + AddLocalAlias(alias, baseScid lnwire.ShortChannelID, gossip, + linkUpdate bool) error + + // DeleteLocalAlias removes a mapping from the database and the + // Manager's maps. + DeleteLocalAlias(alias, baseScid lnwire.ShortChannelID) error +} + +// DependenciesReceiver is an interface that can be implemented by auxiliary +// components that need to receive dependencies from lnd. +type DependenciesReceiver interface { + // RegisterComponents allows the auxiliary component to register the + // given lnd components it might depend on. + RegisterComponents(aliasAdder AliasAdder) error +} + // ImplementationCfg is a struct that holds all configuration items for // components that can be implemented outside lnd itself. type ImplementationCfg struct { @@ -182,6 +209,10 @@ type AuxComponents struct { // AuxDataParser is an optional data parser that can be used to parse // auxiliary data for certain custom channel types. AuxDataParser fn.Option[AuxDataParser] + + // DependenciesReceiver is an optional endpoint to receive access to lnd + // components once they are fully initialized. + DependenciesReceiver fn.Option[DependenciesReceiver] } // DefaultWalletImpl is the default implementation of our normal, btcwallet diff --git a/lnd.go b/lnd.go index 9f628ff81..fb7e2c591 100644 --- a/lnd.go +++ b/lnd.go @@ -25,6 +25,7 @@ import ( "github.com/lightningnetwork/lnd/build" "github.com/lightningnetwork/lnd/chanacceptor" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" @@ -613,8 +614,20 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg, err) } - // Now we have created all dependencies necessary to populate and - // start the RPC server. + // Now we have created all dependencies necessary to register them with + // the auxiliary components. + err = fn.MapOptionZ( + implCfg.DependenciesReceiver, + func(r DependenciesReceiver) error { + return r.RegisterComponents(server.aliasMgr) + }, + ) + if err != nil { + return mkErr("unable to add deps to aux components: %v", err) + } + + // And with those dependencies available, we can populate and start the + // RPC server as well. err = rpcServer.addDeps( server, interceptorChain.MacaroonService(), cfg.SubRPCServers, atplManager, server.invoices, tower, multiAcceptor,