From 7695880c13e1a2a9e49bcd4e63e694196fb06d0d Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 19 Nov 2024 16:02:19 +0800 Subject: [PATCH] chainntnfs: add new method `notifyNumConfsLeft` So it's easier to handle the following commit where we start skipping duplicate notifications. --- chainntnfs/txnotifier.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/chainntnfs/txnotifier.go b/chainntnfs/txnotifier.go index ee48bd65a..f7e29486f 100644 --- a/chainntnfs/txnotifier.go +++ b/chainntnfs/txnotifier.go @@ -942,10 +942,9 @@ func (n *TxNotifier) dispatchConfDetails( // We'll send a 0 value to the Updates channel, // indicating that the transaction/output script has already // been confirmed. - select { - case ntfn.Event.Updates <- 0: - case <-n.quit: - return ErrTxNotifierExiting + err := n.notifyNumConfsLeft(ntfn, 0) + if err != nil { + return err } select { @@ -972,10 +971,9 @@ func (n *TxNotifier) dispatchConfDetails( // confirmations are left for the transaction/output script to // be confirmed. numConfsLeft := confHeight - n.currentHeight - select { - case ntfn.Event.Updates <- numConfsLeft: - case <-n.quit: - return ErrTxNotifierExiting + err := n.notifyNumConfsLeft(ntfn, numConfsLeft) + if err != nil { + return err } } @@ -1740,10 +1738,9 @@ func (n *TxNotifier) NotifyHeight(height uint32) error { continue } - select { - case ntfn.Event.Updates <- numConfsLeft: - case <-n.quit: - return ErrTxNotifierExiting + err := n.notifyNumConfsLeft(ntfn, numConfsLeft) + if err != nil { + return err } } } @@ -2081,3 +2078,15 @@ func (n *TxNotifier) TearDown() { } } } + +// notifyNumConfsLeft sends the number of confirmations left to the +// notification subscriber through the Event.Updates channel. +func (n *TxNotifier) notifyNumConfsLeft(ntfn *ConfNtfn, num uint32) error { + select { + case ntfn.Event.Updates <- num: + case <-n.quit: + return ErrTxNotifierExiting + } + + return nil +}