Skip to content

Commit cadc8d0

Browse files
committed
btcdnotify: change order of rpc calls.
We have to make sure we register the block notifier before we fetch the best block for block notifications.
1 parent 06f1ef4 commit cadc8d0

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)