mirror of
https://github.com/lightninglabs/faraday.git
synced 2026-08-13 12:33:35 +02:00
faraday: start chan events monitor
This commit is contained in:
parent
14d664e93d
commit
f3a3de9ac4
2 changed files with 42 additions and 3 deletions
|
|
@ -94,15 +94,21 @@ func (m *Monitor) monitorLoop(ctx context.Context) {
|
|||
|
||||
log.Info("Channel events monitor starting")
|
||||
|
||||
var synced bool
|
||||
|
||||
for {
|
||||
// Wait for lnd to be synced to chain, retrying on RPC errors.
|
||||
if !m.waitForReady(ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
// Initial state sync.
|
||||
if err := m.initialSync(ctx); err != nil {
|
||||
log.Errorf("Error during initial sync: %v", err)
|
||||
// Initial state sync, only performed once.
|
||||
if !synced {
|
||||
if err := m.initialSync(ctx); err != nil {
|
||||
log.Errorf("Error during initial sync: %v", err)
|
||||
} else {
|
||||
synced = true
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribe and consume events until the stream breaks or an
|
||||
|
|
|
|||
33
faraday.go
33
faraday.go
|
|
@ -18,6 +18,7 @@ import (
|
|||
proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/jessevdk/go-flags"
|
||||
"github.com/lightninglabs/faraday/chain"
|
||||
"github.com/lightninglabs/faraday/chanevents"
|
||||
"github.com/lightninglabs/faraday/frdrpc"
|
||||
"github.com/lightninglabs/faraday/frdrpcserver"
|
||||
"github.com/lightninglabs/faraday/frdrpcserver/perms"
|
||||
|
|
@ -90,9 +91,15 @@ type Faraday struct {
|
|||
// reuse of the struct, since internal fields are not reset.
|
||||
stopped atomic.Bool
|
||||
|
||||
// monitor is the channel events monitor.
|
||||
monitor *chanevents.Monitor
|
||||
|
||||
// stores contains all the stores used by faraday.
|
||||
stores *stores
|
||||
|
||||
// ctxCancel is a function that can be used to cancel the main context.
|
||||
ctxCancel context.CancelFunc
|
||||
|
||||
lnd *lndclient.GrpcLndServices
|
||||
|
||||
// lndOwned indicates whether Faraday created the lnd connection
|
||||
|
|
@ -446,6 +453,17 @@ func (f *Faraday) Stop() error {
|
|||
// can complete cleanly.
|
||||
f.wg.Wait()
|
||||
|
||||
if f.ctxCancel != nil {
|
||||
f.ctxCancel()
|
||||
}
|
||||
|
||||
if f.monitor != nil {
|
||||
if err := f.monitor.Stop(); err != nil {
|
||||
log.Errorf("Error stopping channel event monitor: %v",
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
if f.stores != nil {
|
||||
if err := f.stores.Close(); err != nil {
|
||||
log.Errorf("Error closing stores: %v", err)
|
||||
|
|
@ -552,6 +570,21 @@ func (f *Faraday) initialize(withMacaroonService bool) error {
|
|||
return fmt.Errorf("could not create stores: %v", err)
|
||||
}
|
||||
|
||||
// Create the channel event monitor.
|
||||
f.monitor = chanevents.NewMonitor(
|
||||
f.lnd.Client, f.stores.ChanEventsStore,
|
||||
)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
f.ctxCancel = cancel
|
||||
|
||||
if err := f.monitor.Start(ctx); err != nil {
|
||||
cancel()
|
||||
|
||||
return fmt.Errorf("could not start channel event "+
|
||||
"monitor: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue