Skip to content

Commit d414e05

Browse files
committed
staticaddr: wait for address manager initiation
1 parent 59f67de commit d414e05

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

loopd/daemon.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
849849
}
850850
infof("Static address manager stopped")
851851
}()
852+
staticAddressManager.WaitInitComplete()
852853
}
853854

854855
// Start the static address deposit manager.
@@ -873,14 +874,12 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
873874
go func() {
874875
defer d.wg.Done()
875876

876-
infof("Starting static address deposit withdrawal " +
877-
"manager...")
877+
infof("Starting static address withdrawal manager...")
878878
err := withdrawalManager.Run(d.mainCtx)
879879
if err != nil && !errors.Is(context.Canceled, err) {
880880
d.internalErrChan <- err
881881
}
882-
infof("Static address deposit withdrawal manager " +
883-
"stopped")
882+
infof("Static address withdrawal manager stopped")
884883
}()
885884
withdrawalManager.WaitInitComplete()
886885
}
@@ -896,8 +895,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
896895
if err != nil && !errors.Is(context.Canceled, err) {
897896
d.internalErrChan <- err
898897
}
899-
infof("Starting static address loop-in manager " +
900-
"stopped")
898+
infof("Static address loop-in manager stopped")
901899
}()
902900
staticLoopInManager.WaitInitComplete()
903901
}

staticaddr/address/manager.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ type Manager struct {
5454
sync.Mutex
5555

5656
currentHeight atomic.Int32
57+
58+
// initChan signals the daemon that the address manager has completed
59+
// its initialization.
60+
initChan chan struct{}
5761
}
5862

5963
// NewManager creates a new address manager.
6064
func NewManager(cfg *ManagerConfig, currentHeight int32) *Manager {
6165
m := &Manager{
62-
cfg: cfg,
66+
cfg: cfg,
67+
initChan: make(chan struct{}),
6368
}
6469
m.currentHeight.Store(currentHeight)
6570

@@ -75,6 +80,10 @@ func (m *Manager) Run(ctx context.Context) error {
7580
return err
7681
}
7782

83+
// Communicate to the caller that the address manager has completed its
84+
// initialization.
85+
close(m.initChan)
86+
7887
for {
7988
select {
8089
case currentHeight := <-newBlockChan:
@@ -90,6 +99,14 @@ func (m *Manager) Run(ctx context.Context) error {
9099
}
91100
}
92101

102+
// WaitInitComplete waits until the address manager has completed its setup.
103+
func (m *Manager) WaitInitComplete() {
104+
defer log.Debugf("Static address manager initiation " +
105+
"complete.")
106+
107+
<-m.initChan
108+
}
109+
93110
// NewAddress creates a new static address with the server or returns an
94111
// existing one.
95112
func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,

staticaddr/deposit/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type Manager struct {
7777
// mu guards access to activeDeposits map.
7878
mu sync.Mutex
7979

80-
// initChan signals the daemon that the address manager has completed
80+
// initChan signals the daemon that the deposit manager has completed
8181
// its initialization.
8282
initChan chan struct{}
8383

0 commit comments

Comments
 (0)