Skip to content

Commit

Permalink
Merge branch 'master' into closed-channel-payment
Browse files Browse the repository at this point in the history
* master:
  add network info in payment failure.
  rescan when force bootstrap is found.
  add missing parameter.
  In case neutrino files are deleted, make sure we sync to chain on start.
  don't return error on bootstrap when chain service already exists. This means the bootstrap has already been done.
  stop chain service before closing the walletDB
  • Loading branch information
roeierez committed Dec 22, 2019
2 parents ede54ae + d9f37e2 commit 37caa35
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 26 deletions.
14 changes: 14 additions & 0 deletions account/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/breez/breez/data"
"github.com/breez/breez/db"
"github.com/golang/protobuf/jsonpb"
"github.com/lightningnetwork/lnd/lnrpc"
)

Expand Down Expand Up @@ -224,6 +225,18 @@ func (a *Service) createPaymentTraceReport(paymentRequest string, amount int64,
return "", err
}

netInfo, err := lnclient.GetNetworkInfo(context.Background(), &lnrpc.NetworkInfoRequest{})
if err != nil {
a.log.Errorf("GetNetworkInfo error: %v", err)
return "", err
}
marshaller := jsonpb.Marshaler{}
netInfoData, err := marshaller.MarshalToString(netInfo)
if err != nil {
a.log.Errorf("failed to marshal network info: %v", err)
return "", err
}

if amount == 0 {
amount = decodedPayReq.NumSatoshis
}
Expand All @@ -233,6 +246,7 @@ func (a *Service) createPaymentTraceReport(paymentRequest string, amount int64,
"source_node": lnInfo.IdentityPubkey,
"amount": amount,
"payment_request": decodedPayReq,
"network_info": netInfoData,
},
}

Expand Down
4 changes: 2 additions & 2 deletions app_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *AuthService) SignIn() (string, error) {
}

// NewApp create a new application
func NewApp(workingDir string, applicationServices AppServices) (*App, error) {
func NewApp(workingDir string, applicationServices AppServices, startBeforeSync bool) (*App, error) {
app := &App{
quitChan: make(chan struct{}),
notificationsChan: make(chan data.NotificationEvent),
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewApp(workingDir string, applicationServices AppServices) (*App, error) {

app.log.Infof("New db")

app.lnDaemon, err = lnnode.NewDaemon(app.cfg, app.breezDB)
app.lnDaemon, err = lnnode.NewDaemon(app.cfg, app.breezDB, startBeforeSync)
if err != nil {
return nil, fmt.Errorf("Failed to create lnnode.Daemon: %v", err)
}
Expand Down
30 changes: 20 additions & 10 deletions bindings/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,18 @@ func Init(tempDir string, workingDir string, services AppServices) (err error) {
return err
}
appLogger.Log("Breez initialization started", "INFO")
startBeforeSync := true
shouldForceRescan := false
shouldForceBootstrap := false
if _, err := os.Stat(path.Join(workingDir, forceRescan)); err == nil {
appLogger.Log(fmt.Sprintf("%v present. Run Drop", forceRescan), "INFO")
shouldForceRescan = true
}
if _, err := os.Stat(path.Join(workingDir, forceBootstrap)); err == nil {
appLogger.Log(fmt.Sprintf("%v present. Deleting neutrino files", forceBootstrap), "INFO")
err = chainservice.ResetChainService(workingDir)
appLogger.Log(fmt.Sprintf("Delete result: %v", err), "INFO")
if err == nil {
err = os.Remove(path.Join(workingDir, forceBootstrap))
appLogger.Log(fmt.Sprintf("Removed file: %v result: %v", forceBootstrap, err), "INFO")
}
shouldForceBootstrap = true
}
if _, err := os.Stat(path.Join(workingDir, forceRescan)); err == nil {
appLogger.Log(fmt.Sprintf("%v present. Run Drop", forceRescan), "INFO")
if shouldForceBootstrap || shouldForceRescan {
err = dropwtx.Drop(workingDir)
appLogger.Log(fmt.Sprintf("Drop result: %v", err), "INFO")
err = drophintcache.Drop(workingDir)
Expand All @@ -138,9 +139,18 @@ func Init(tempDir string, workingDir string, services AppServices) (err error) {
err = os.Remove(path.Join(workingDir, forceRescan))
appLogger.Log(fmt.Sprintf("Removed file: %v result: %v", forceRescan, err), "INFO")
}
if shouldForceBootstrap {
err = chainservice.ResetChainService(workingDir)
appLogger.Log(fmt.Sprintf("Delete result: %v", err), "INFO")
if err == nil {
err = os.Remove(path.Join(workingDir, forceBootstrap))
startBeforeSync = false
appLogger.Log(fmt.Sprintf("Removed file: %v result: %v", forceBootstrap, err), "INFO")
}
}
}
mu.Lock()
breezApp, err = breez.NewApp(workingDir, services)
breezApp, err = breez.NewApp(workingDir, services, startBeforeSync)
mu.Unlock()
if err != nil {
appLogger.Log("Breez initialization failed: %v", "INFO")
Expand Down Expand Up @@ -260,7 +270,7 @@ func RestoreBackup(nodeID string, encryptionKey []byte) (err error) {
}
encKey := append([]byte(nil), encryptionKey...)
_, err = getBreezApp().BackupManager.Restore(nodeID, encKey)
breezApp, _ = breez.NewApp(getBreezApp().GetWorkingDir(), appServices)
breezApp, _ = breez.NewApp(getBreezApp().GetWorkingDir(), appServices, true)
return err
}

Expand Down
4 changes: 2 additions & 2 deletions chainservice/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chainservice
import (
"bytes"
"encoding/binary"
"errors"
"os"
"path"
"sync"
Expand Down Expand Up @@ -95,7 +94,8 @@ func Bootstrap(workingDir string) error {
logger = logBackend.Logger("CHAIN")
logger.Infof("Bootstrap started")
if service != nil {
return errors.New("Chain service already created, can't bootstrap")
logger.Info("Chain service already created, already bootstrapped")
return nil
}

bootstrapped, err := Bootstrapped(workingDir)
Expand Down
11 changes: 5 additions & 6 deletions chainservice/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,17 @@ func createService(workingDir string, breezDB *db.DB) (*neutrino.ChainService, r
}

func stopService() error {

if walletDB != nil {
if err := walletDB.Close(); err != nil {
return err
}
}
if service != nil {
if err := service.Stop(); err != nil {
return err
}
service = nil
}
if walletDB != nil {
if err := walletDB.Close(); err != nil {
return err
}
}
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion lnnode/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ func (d *Daemon) startDaemon() error {
params := []string{"lightning-libs",
"--lnddir", deps.workingDir,
"--bitcoin." + d.cfg.Network,
"--bitcoin.startbeforesynced",
}
if d.startBeforeSync {
params = append(params, "--bitcoin.startbeforesynced")
}
err = lnd.Main(lnd.ListenerCfg{}, params, deps)

Expand Down
12 changes: 7 additions & 5 deletions lnnode/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,22 @@ type Daemon struct {
routerClient routerrpc.RouterClient
ntfnServer *subscribe.Server
quitChan chan struct{}
startBeforeSync bool
}

// NewDaemon is used to create a new daemon that wraps a lightning
// network daemon.
func NewDaemon(cfg *config.Config, db *db.DB) (*Daemon, error) {
func NewDaemon(cfg *config.Config, db *db.DB, startBeforeSync bool) (*Daemon, error) {
logBackend, err := breezlog.GetLogBackend(cfg.WorkingDir)
if err != nil {
return nil, err
}

return &Daemon{
cfg: cfg,
breezDB: db,
ntfnServer: subscribe.NewServer(),
log: logBackend.Logger("DAEM"),
cfg: cfg,
breezDB: db,
ntfnServer: subscribe.NewServer(),
log: logBackend.Logger("DAEM"),
startBeforeSync: startBeforeSync,
}, nil
}

0 comments on commit 37caa35

Please sign in to comment.