Skip to content

Commit 2dbdd97

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

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

loopd/daemon.go

Lines changed: 1 addition & 0 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.

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)