Skip to content

Commit 1200b75

Browse files
committed
chainntnfs: always notify txns before block
This commit changes the order of notifications when a relevant tx is found in a block and now we will always notify the tx subscribers before notifying the block, which has implications in the upcoming blockbeat. When a block notification is subscribed via `RegisterBlockEpochNtfn` and a confirm or spend is subscribed via `RegisterConfirmationsNtfn` or `RegisterSpendNtfn`, we would always notify the block first before the tx, causing the subsystem to think there's no relevant txns found in this block, while the notifications are sent later. We now fix it by always sending the txns notifications first, so the subsystem can receive the txns, process them, then attempt to advance its state based on the block received.
1 parent 0e999ed commit 1200b75

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

chainntnfs/bitcoindnotify/bitcoind.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,14 @@ func (b *BitcoindNotifier) handleBlockConnected(block chainntnfs.BlockEpoch) err
665665
// satisfy any client requests based upon the new block.
666666
b.bestBlock = block
667667

668+
err = b.txNotifier.NotifyHeight(uint32(block.Height))
669+
if err != nil {
670+
return fmt.Errorf("unable to notify height: %w", err)
671+
}
672+
668673
b.notifyBlockEpochs(block.Height, block.Hash, block.BlockHeader)
669-
return b.txNotifier.NotifyHeight(uint32(block.Height))
674+
675+
return nil
670676
}
671677

672678
// notifyBlockEpochs notifies all registered block epoch clients of the newly

chainntnfs/btcdnotify/btcd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,16 @@ func (b *BtcdNotifier) handleBlockConnected(epoch chainntnfs.BlockEpoch) error {
725725
// satisfy any client requests based upon the new block.
726726
b.bestBlock = epoch
727727

728+
err = b.txNotifier.NotifyHeight(uint32(epoch.Height))
729+
if err != nil {
730+
return fmt.Errorf("unable to notify height: %w", err)
731+
}
732+
728733
b.notifyBlockEpochs(
729734
epoch.Height, epoch.Hash, epoch.BlockHeader,
730735
)
731736

732-
return b.txNotifier.NotifyHeight(uint32(epoch.Height))
737+
return nil
733738
}
734739

735740
// notifyBlockEpochs notifies all registered block epoch clients of the newly

chainntnfs/neutrinonotify/neutrino.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,16 @@ func (n *NeutrinoNotifier) handleBlockConnected(newBlock *filteredBlock) error {
689689
n.bestBlock.Height = int32(newBlock.height)
690690
n.bestBlock.BlockHeader = newBlock.header
691691

692+
err = n.txNotifier.NotifyHeight(newBlock.height)
693+
if err != nil {
694+
return fmt.Errorf("unable to notify height: %w", err)
695+
}
696+
692697
n.notifyBlockEpochs(
693698
int32(newBlock.height), &newBlock.hash, newBlock.header,
694699
)
695-
return n.txNotifier.NotifyHeight(newBlock.height)
700+
701+
return nil
696702
}
697703

698704
// getFilteredBlock is a utility to retrieve the full filtered block from a block epoch.

0 commit comments

Comments
 (0)