From 8b8007bb5a3a400ea336f8e45e6abd6905029adf Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 24 Aug 2018 20:09:11 -0700 Subject: [PATCH] chainntnfs/txconfnotifier: query conf hint in Register --- chainntnfs/txconfnotifier.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/chainntnfs/txconfnotifier.go b/chainntnfs/txconfnotifier.go index 099066c1..e64da77d 100644 --- a/chainntnfs/txconfnotifier.go +++ b/chainntnfs/txconfnotifier.go @@ -35,6 +35,11 @@ type ConfNtfn struct { // be sent over. Event *ConfirmationEvent + // HeightHint is the minimum height in the chain that we expect to find + // this txid. This value will be overridden by the height hint cache if + // a more recent value is available. + HeightHint uint32 + // details describes the transaction's position is the blockchain. May be // nil for unconfirmed transactions. details *TxConfirmation @@ -172,6 +177,17 @@ func (tcn *TxConfNotifier) Register(ntfn *ConfNtfn) (bool, uint32, error) { default: } + // Before proceeding to register the notification, we'll query our + // height hint cache to determine whether a better one exists. + hint, err := tcn.hintCache.QueryConfirmHint(*ntfn.TxID) + if err == nil { + if hint > ntfn.HeightHint { + Log.Debugf("Using height hint %d retrieved "+ + "from cache for %v", hint, *ntfn.TxID) + ntfn.HeightHint = hint + } + } + tcn.Lock() defer tcn.Unlock()