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.
This commit is contained in:
ziggie 2025-04-16 15:11:18 +02:00
parent 06f1ef47fa
commit cadc8d0fba
No known key found for this signature in database
GPG Key ID: 1AFF9C4DCED6D666

View File

@ -223,6 +223,17 @@ func (b *BtcdNotifier) startNotifier() error {
return err return err
} }
// Before we fetch the best block/block height we need to register the
// notifications for connected blocks, otherwise we might think we are
// at an earlier block height because during block notification
// registration we might have already mined some new blocks. Hence we
// will not get notified accordingly.
if err := b.chainConn.NotifyBlocks(); err != nil {
b.txUpdates.Stop()
b.chainUpdates.Stop()
return err
}
currentHash, currentHeight, err := b.chainConn.GetBestBlock() currentHash, currentHeight, err := b.chainConn.GetBestBlock()
if err != nil { if err != nil {
b.txUpdates.Stop() b.txUpdates.Stop()
@ -248,12 +259,6 @@ func (b *BtcdNotifier) startNotifier() error {
BlockHeader: &bestBlock.Header, BlockHeader: &bestBlock.Header,
} }
if err := b.chainConn.NotifyBlocks(); err != nil {
b.txUpdates.Stop()
b.chainUpdates.Stop()
return err
}
b.wg.Add(1) b.wg.Add(1)
go b.notificationDispatcher() go b.notificationDispatcher()