Skip to content

Commit 51add8a

Browse files
authored
Merge pull request lightningnetwork#9722 from ziggie1984/fix-notifier-itest-flake
Change RPC call order for the btcd notifier
2 parents 579f6f0 + cadc8d0 commit 51add8a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

chainntnfs/btcdnotify/btcd.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ func (b *BtcdNotifier) startNotifier() error {
223223
return err
224224
}
225225

226+
// Before we fetch the best block/block height we need to register the
227+
// notifications for connected blocks, otherwise we might think we are
228+
// at an earlier block height because during block notification
229+
// registration we might have already mined some new blocks. Hence we
230+
// will not get notified accordingly.
231+
if err := b.chainConn.NotifyBlocks(); err != nil {
232+
b.txUpdates.Stop()
233+
b.chainUpdates.Stop()
234+
return err
235+
}
236+
226237
currentHash, currentHeight, err := b.chainConn.GetBestBlock()
227238
if err != nil {
228239
b.txUpdates.Stop()
@@ -248,12 +259,6 @@ func (b *BtcdNotifier) startNotifier() error {
248259
BlockHeader: &bestBlock.Header,
249260
}
250261

251-
if err := b.chainConn.NotifyBlocks(); err != nil {
252-
b.txUpdates.Stop()
253-
b.chainUpdates.Stop()
254-
return err
255-
}
256-
257262
b.wg.Add(1)
258263
go b.notificationDispatcher()
259264

0 commit comments

Comments
 (0)