Skip to content

Commit

Permalink
lnd: introduce the Providers interface
Browse files Browse the repository at this point in the history
This is an interface that the LND can provide to other callers systems
in the same process.
  • Loading branch information
ellemouton committed Nov 4, 2024
1 parent f12ec12 commit 713e323
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/lnd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func main() {
// be executed in the case of a graceful shutdown.
if err = lnd.Main(
loadedConfig, lnd.ListenerCfg{}, implCfg, shutdownInterceptor,
nil,
); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions cmd/multinode/graph_mux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package multinode
1 change: 1 addition & 0 deletions cmd/multinode/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package multinode
18 changes: 18 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ type GraphSource interface {
// found.
LookupAlias(pub *btcec.PublicKey) (string, error)
}

// Providers is an interface that LND itself can satisfy.
type Providers interface {
// GraphSource can be used to obtain the graph source that this LND node
// provides.
GraphSource() (GraphSource, error)
}

// A compile-time check to ensure that LND's main server struct satisfies the
// Provider interface.
var _ Providers = (*server)(nil)

// GraphSource returns this LND nodes graph DB as a GraphSource.
//
// NOTE: this method is part of the Providers interface.
func (s *server) GraphSource() (GraphSource, error) {
return s.graphDB, nil
}
9 changes: 8 additions & 1 deletion lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ var errStreamIsolationWithProxySkip = errors.New(
// validated main configuration struct and an optional listener config struct.
// This function starts all main system components then blocks until a signal
// is received on the shutdownChan at which point everything is shut down again.
// If a providers channel is provided, LND will send back a result on it once
// all the necessary providers are ready.
func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
interceptor signal.Interceptor) error {
interceptor signal.Interceptor, providers chan<- Providers) error {

defer func() {
ltndLog.Info("Shutdown complete\n")
Expand Down Expand Up @@ -612,6 +614,11 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
return mkErr("unable to create server: %v", err)
}

select {
case providers <- server:
default:
}

// Set up an autopilot manager from the current config. This will be
// used to manage the underlying autopilot agent, starting and stopping
// it at will.
Expand Down
2 changes: 1 addition & 1 deletion mobile/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Start(extraArgs string, rpcReady Callback) {
defer close(quit)

if err := lnd.Main(
loadedConfig, cfg, implCfg, shutdownInterceptor,
loadedConfig, cfg, implCfg, shutdownInterceptor, nil,
); err != nil {
if e, ok := err.(*flags.Error); ok &&
e.Type == flags.ErrHelp {
Expand Down

0 comments on commit 713e323

Please sign in to comment.