mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-26 21:51:27 +02:00
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.
This commit is contained in:
@@ -665,8 +665,14 @@ func (b *BitcoindNotifier) handleBlockConnected(block chainntnfs.BlockEpoch) err
|
||||
// satisfy any client requests based upon the new block.
|
||||
b.bestBlock = block
|
||||
|
||||
err = b.txNotifier.NotifyHeight(uint32(block.Height))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to notify height: %w", err)
|
||||
}
|
||||
|
||||
b.notifyBlockEpochs(block.Height, block.Hash, block.BlockHeader)
|
||||
return b.txNotifier.NotifyHeight(uint32(block.Height))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// notifyBlockEpochs notifies all registered block epoch clients of the newly
|
||||
|
@@ -725,11 +725,16 @@ func (b *BtcdNotifier) handleBlockConnected(epoch chainntnfs.BlockEpoch) error {
|
||||
// satisfy any client requests based upon the new block.
|
||||
b.bestBlock = epoch
|
||||
|
||||
err = b.txNotifier.NotifyHeight(uint32(epoch.Height))
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to notify height: %w", err)
|
||||
}
|
||||
|
||||
b.notifyBlockEpochs(
|
||||
epoch.Height, epoch.Hash, epoch.BlockHeader,
|
||||
)
|
||||
|
||||
return b.txNotifier.NotifyHeight(uint32(epoch.Height))
|
||||
return nil
|
||||
}
|
||||
|
||||
// notifyBlockEpochs notifies all registered block epoch clients of the newly
|
||||
|
@@ -689,10 +689,16 @@ func (n *NeutrinoNotifier) handleBlockConnected(newBlock *filteredBlock) error {
|
||||
n.bestBlock.Height = int32(newBlock.height)
|
||||
n.bestBlock.BlockHeader = newBlock.header
|
||||
|
||||
err = n.txNotifier.NotifyHeight(newBlock.height)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to notify height: %w", err)
|
||||
}
|
||||
|
||||
n.notifyBlockEpochs(
|
||||
int32(newBlock.height), &newBlock.hash, newBlock.header,
|
||||
)
|
||||
return n.txNotifier.NotifyHeight(newBlock.height)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// getFilteredBlock is a utility to retrieve the full filtered block from a block epoch.
|
||||
|
Reference in New Issue
Block a user