Skip to content

Commit

Permalink
multinode binary
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Nov 13, 2024
1 parent 14e4c52 commit 89023c6
Show file tree
Hide file tree
Showing 5 changed files with 730 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ build:
@$(call print, "Building debug lnd and lncli.")
$(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(DEV_GCFLAGS) $(DEV_LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(DEV_GCFLAGS) $(DEV_LDFLAGS) $(PKG)/cmd/lncli
$(GOBUILD) -tags="$(DEV_TAGS)" -o multinode-debug $(DEV_GCFLAGS) $(DEV_LDFLAGS) $(PKG)/cmd/multinode

#? build-itest: Build integration test binaries, place them in itest directory
build-itest:
Expand All @@ -136,6 +137,7 @@ install-binaries:
@$(call print, "Installing lnd and lncli.")
$(GOINSTALL) -tags="${tags}" -ldflags="$(RELEASE_LDFLAGS)" $(PKG)/cmd/lnd
$(GOINSTALL) -tags="${tags}" -ldflags="$(RELEASE_LDFLAGS)" $(PKG)/cmd/lncli
$(GOINSTALL) -tags="${tags}" -ldflags="$(RELEASE_LDFLAGS)" $(PKG)/cmd/multinode

#? manpages: generate and install man pages
manpages:
Expand Down
111 changes: 111 additions & 0 deletions cmd/multinode/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package main

import (
"context"
"fmt"
"os"

"github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd"
graphsources "github.com/lightningnetwork/lnd/graph/sources"
"github.com/lightningnetwork/lnd/signal"
)

func main() {
// Hook interceptor for os signals.
shutdownInterceptor, err := signal.Intercept()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
lndProviders := setupGraphSourceNode(shutdownInterceptor)
setupDependentNode(shutdownInterceptor, lndProviders)
<-shutdownInterceptor.ShutdownChannel()
}
func setupGraphSourceNode(interceptor signal.Interceptor) lnd.Providers {
preCfg := graphConfig()
cfg, err := lnd.LoadConfigNoFlags(*preCfg, interceptor)
if err != nil {
os.Exit(1)
}
implCfg := cfg.ImplementationConfig(interceptor)
lndProviders := make(chan lnd.Providers, 1)
go func() {
if err := lnd.Main(
cfg, lnd.ListenerCfg{}, implCfg, interceptor,
lndProviders,
); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
}
fmt.Println("Graph node has stopped")

Check failure on line 40 in cmd/multinode/main.go

View workflow job for this annotation

GitHub Actions / lint code

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
os.Exit(1)
}()
return <-lndProviders

Check failure on line 43 in cmd/multinode/main.go

View workflow job for this annotation

GitHub Actions / lint code

return with no blank line before (nlreturn)
}
func setupDependentNode(interceptor signal.Interceptor,
lndProviders lnd.Providers) {
// Load the configuration, and parse any command line options. This
// function will also set up logging properly.
loadedConfig, err := lnd.LoadConfig(interceptor)
if err != nil {
if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {

Check failure on line 51 in cmd/multinode/main.go

View workflow job for this annotation

GitHub Actions / lint code

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
// Print error if not due to help request.
err = fmt.Errorf("failed to load config: %w", err)
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// Help was requested, exit normally.
os.Exit(0)
}
loadedConfig.Gossip.NoSync = true
implCfg := loadedConfig.ImplementationConfig(interceptor)
implCfg.GraphProvider = &graphProvider{lndProviders: lndProviders}
// Call the "real" main in a nested manner so the defers will properly
// be executed in the case of a graceful shutdown.
if err = lnd.Main(
loadedConfig, lnd.ListenerCfg{}, implCfg, interceptor, nil,
); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

type graphProvider struct {
lndProviders lnd.Providers
}

func (g *graphProvider) Graph(_ context.Context,
dbs *lnd.DatabaseInstances) (graphsources.GraphSource, error) {

graphSource, err := g.lndProviders.GraphSource()
if err != nil {
return nil, err
}

return NewGraphBackend(
graphsources.NewDBGSource(dbs.GraphDB), graphSource,
), nil
}
func graphConfig() *lnd.Config {
cfg := lnd.DefaultConfig()
//if _, err := flags.Parse(&cfg); err != nil {

Check failure on line 91 in cmd/multinode/main.go

View workflow job for this annotation

GitHub Actions / lint code

commentFormatting: put a space between `//` and comment text (gocritic)
// os.Exit(1)
//}
cfg.Bitcoin.RegTest = true
cfg.LndDir = "/Users/elle/.lnd-dev-graph"
cfg.BitcoindMode.RPCHost = "localhost:18443"
cfg.Bitcoin.Node = "bitcoind"
cfg.RawRPCListeners = []string{"localhost:10020"}
cfg.BitcoindMode.RPCUser = "lightning"
cfg.BitcoindMode.RPCPass = "lightning"
cfg.BitcoindMode.ZMQPubRawBlock = "tcp://localhost:28332"
cfg.BitcoindMode.ZMQPubRawTx = "tcp://localhost:28333"
cfg.TrickleDelay = 50
cfg.NoSeedBackup = true
cfg.RawRESTListeners = []string{"localhost:11020"}
cfg.RawListeners = []string{"localhost:9736"}
cfg.DebugLevel = "debug"
cfg.LogConfig.Console.Disable = true

return &cfg
}
Loading

0 comments on commit 89023c6

Please sign in to comment.