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
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (s *Client) Run(ctx context.Context,
}

// Log connected node.
log.Infof("Connected to lnd node '%v' with pubkey %x (version %s)",
log.Infof("Connected to lnd node '%v' with pubkey %s (version %s)",
s.lndServices.NodeAlias, s.lndServices.NodePubkey,
lndclient.VersionString(s.lndServices.Version))

Expand Down
24 changes: 14 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
module github.com/lightninglabs/loop

require (
github.com/btcsuite/btcd v0.21.0-beta.0.20201208033208-6bd4c64a54fa
github.com/btcsuite/btcd v0.21.0-beta.0.20210429225535-ce697fe7e82b
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v1.0.2
github.com/btcsuite/btcwallet/wtxmgr v1.2.0
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/btcsuite/btcwallet/wtxmgr v1.3.0
github.com/coreos/bbolt v1.3.3
github.com/fortytw2/leaktest v1.3.0
github.com/golang/protobuf v1.3.2
github.com/golang/protobuf v1.4.3
github.com/grpc-ecosystem/grpc-gateway v1.14.3
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/aperture v0.1.6-beta
github.com/lightninglabs/lndclient v0.11.0-5
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d
github.com/lightningnetwork/lnd v0.12.0-beta.rc3
github.com/lightninglabs/lndclient v0.11.1-6
github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display
github.com/lightningnetwork/lnd v0.13.0-beta.rc2
github.com/lightningnetwork/lnd/cert v1.0.3
github.com/lightningnetwork/lnd/clock v1.0.1
github.com/lightningnetwork/lnd/queue v1.0.4
github.com/lightningnetwork/lnd/ticker v1.0.0
github.com/stretchr/testify v1.5.1
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.20.0
golang.org/x/net v0.0.0-20191112182307-2180aed22343
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7
google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c
google.golang.org/grpc v1.25.1
google.golang.org/grpc v1.29.1
gopkg.in/macaroon-bakery.v2 v2.0.1
gopkg.in/macaroon.v2 v2.1.0
)

// Fix incompatibility of etcd go.mod package.
// See https://github.com/etcd-io/etcd/issues/11154
replace go.etcd.io/etcd => go.etcd.io/etcd v0.5.0-alpha.5.0.20201125193152-8a03d2e9614b

go 1.15
171 changes: 126 additions & 45 deletions go.sum

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion loopd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ func (d *Daemon) startWebServers() error {
// With our client created, let's now finish setting up and start our
// RPC server. First we add the security interceptor to our gRPC server
// options that checks the macaroons for validity.
serverOpts := d.macaroonInterceptor()
serverOpts, err := d.macaroonInterceptor()
if err != nil {
return fmt.Errorf("error with macaroon interceptor: %v", err)
}
d.grpcServer = grpc.NewServer(serverOpts...)
looprpc.RegisterSwapClientServer(d.grpcServer, d)

Expand Down
63 changes: 40 additions & 23 deletions loopd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,55 @@ import (
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/liquidity"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/signal"
)

var (
logWriter = build.NewRotatingLogWriter()
const Subsystem = "LOOPD"

log = build.NewSubLogger("LOOPD", logWriter.GenSubLogger)
var (
logWriter *build.RotatingLogWriter
log btclog.Logger
interceptor signal.Interceptor
)

func init() {
setSubLogger("LOOPD", log, nil)
addSubLogger("LOOP", loop.UseLogger)
addSubLogger("LNDC", lndclient.UseLogger)
addSubLogger("STORE", loopdb.UseLogger)
addSubLogger(lsat.Subsystem, lsat.UseLogger)
addSubLogger(liquidity.Subsystem, liquidity.UseLogger)
}
// SetupLoggers initializes all package-global logger variables.
func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
genLogger := genSubLogger(root, intercept)

logWriter = root
log = build.NewSubLogger(Subsystem, genLogger)
interceptor = intercept

// addSubLogger is a helper method to conveniently create and register the
// logger of a sub system.
func addSubLogger(subsystem string, useLogger func(btclog.Logger)) {
logger := build.NewSubLogger(subsystem, logWriter.GenSubLogger)
setSubLogger(subsystem, logger, useLogger)
lnd.SetSubLogger(root, Subsystem, log)
lnd.AddSubLogger(root, "LOOP", intercept, loop.UseLogger)
lnd.AddSubLogger(root, "LNDC", intercept, lndclient.UseLogger)
lnd.AddSubLogger(root, "STORE", intercept, loopdb.UseLogger)
lnd.AddSubLogger(root, lsat.Subsystem, intercept, lsat.UseLogger)
lnd.AddSubLogger(
root, liquidity.Subsystem, intercept, liquidity.UseLogger,
)
}

// setSubLogger is a helper method to conveniently register the logger of a sub
// system.
func setSubLogger(subsystem string, logger btclog.Logger,
useLogger func(btclog.Logger)) {
// genSubLogger creates a logger for a subsystem. We provide an instance of
// a signal.Interceptor to be able to shutdown in the case of a critical error.
func genSubLogger(root *build.RotatingLogWriter,
interceptor signal.Interceptor) func(string) btclog.Logger {

// Create a shutdown function which will request shutdown from our
// interceptor if it is listening.
shutdown := func() {
if !interceptor.Listening() {
return
}

interceptor.RequestShutdown()
}

logWriter.RegisterSubLogger(subsystem, logger)
if useLogger != nil {
useLogger(logger)
// Return a function which will create a sublogger from our root
// logger without shutdown fn.
return func(tag string) btclog.Logger {
return root.GenSubLogger(tag, shutdown)
}
}
29 changes: 21 additions & 8 deletions loopd/macaroons.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/lightninglabs/loop/loopdb"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/rpcperms"
"google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery"
)
Expand Down Expand Up @@ -210,21 +211,33 @@ func (d *Daemon) stopMacaroonService() error {

// macaroonInterceptor creates gRPC server options with the macaroon security
// interceptors.
func (d *Daemon) macaroonInterceptor() []grpc.ServerOption {
func (d *Daemon) macaroonInterceptor() ([]grpc.ServerOption, error) {
// Add our debug permissions to our main set of required permissions
// if compiled in.
for endpoint, perm := range debugRequiredPermissions {
RequiredPermissions[endpoint] = perm
}

unaryInterceptor := d.macaroonService.UnaryServerInterceptor(
RequiredPermissions,
)
streamInterceptor := d.macaroonService.StreamServerInterceptor(
RequiredPermissions,
)
interceptor := rpcperms.NewInterceptorChain(log, false)
err := interceptor.Start()
if err != nil {
return nil, err
}

interceptor.SetWalletUnlocked()
interceptor.AddMacaroonService(d.macaroonService)

for method, permissions := range RequiredPermissions {
err := interceptor.AddPermission(method, permissions)
if err != nil {
return nil, err
}
}

unaryInterceptor := interceptor.MacaroonUnaryServerInterceptor()
streamInterceptor := interceptor.MacaroonStreamServerInterceptor()
return []grpc.ServerOption{
grpc.UnaryInterceptor(unaryInterceptor),
grpc.StreamInterceptor(streamInterceptor),
}
}, nil
}
26 changes: 15 additions & 11 deletions loopd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
// listed build tags/subservers need to be enabled.
LoopMinRequiredLndVersion = &verrpc.Version{
AppMajor: 0,
AppMinor: 10,
AppMinor: 11,
AppPatch: 1,
BuildTags: []string{
"signrpc", "walletrpc", "chainrpc", "invoicesrpc",
Expand Down Expand Up @@ -115,7 +115,7 @@ func newListenerCfg(config *Config, rpcCfg RPCConfig) *listenerCfg {
// If the client decides to kill loop before
// lnd is synced, we cancel our context, which
// will unblock lndclient.
case <-signal.ShutdownChannel():
case <-interceptor.ShutdownChannel():
cancel()

// If our sync context was cancelled, we know
Expand Down Expand Up @@ -187,7 +187,19 @@ func Run(rpcCfg RPCConfig) error {
return err
}

// Start listening for signal interrupts regardless of which command
// we are running. When our command tries to get a lnd connection, it
// blocks until lnd is synced. We listen for interrupts so that we can
// shutdown the daemon while waiting for sync to complete.
shutdownInterceptor, err := signal.Intercept()
if err != nil {
return err
}

// Initialize logging at the default logging level.
logWriter := build.NewRotatingLogWriter()
SetupLoggers(logWriter, shutdownInterceptor)

err = logWriter.InitLogRotator(
filepath.Join(config.LogDir, defaultLogFilename),
config.MaxLogFileSize, config.MaxLogFiles,
Expand All @@ -205,14 +217,6 @@ func Run(rpcCfg RPCConfig) error {

lisCfg := newListenerCfg(&config, rpcCfg)

// Start listening for signal interrupts regardless of which command
// we are running. When our command tries to get a lnd connection, it
// blocks until lnd is synced. We listen for interrupts so that we can
// shutdown the daemon while waiting for sync to complete.
if err := signal.Intercept(); err != nil {
return err
}

// Execute command.
if parser.Active == nil {
daemon := New(&config, lisCfg)
Expand All @@ -221,7 +225,7 @@ func Run(rpcCfg RPCConfig) error {
}

select {
case <-signal.ShutdownChannel():
case <-interceptor.ShutdownChannel():
log.Infof("Received SIGINT (Ctrl+C).")
daemon.Stop()

Expand Down
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ This file tracks release notes for the loop client.
#### New Features

#### Breaking Changes
- Bumped the minimum required version of `lnd` to `v0.11.1-beta`.

#### Bug Fixes
4 changes: 2 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr
const (
// Note: please update release_notes.md when you change these values.
appMajor uint = 0
appMinor uint = 12
appPatch uint = 2
appMinor uint = 13
appPatch uint = 0

// appPreRelease MUST only contain characters from semanticAlphabet per
// the semantic versioning spec.
Expand Down