chainntnfs/txnotifier: notify confirmations and spends of scripts at tip

This commit is contained in:
Wilmer Paulino 2018-12-06 21:13:47 -08:00
parent ecd70deb8c
commit 83c8ccb3eb
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -1295,21 +1295,21 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
defer n.Unlock() defer n.Unlock()
// First, we'll dispatch an update to all of the notification clients // First, we'll dispatch an update to all of the notification clients
// for our watched transactions with the number of confirmations left at // for our watched requests with the number of confirmations left at
// this new height. // this new height.
for _, txHashes := range n.txsByInitialHeight { for _, confRequests := range n.confsByInitialHeight {
for txHash := range txHashes { for confRequest := range confRequests {
confSet := n.confNotifications[txHash] confSet := n.confNotifications[confRequest]
for _, ntfn := range confSet.ntfns { for _, ntfn := range confSet.ntfns {
txConfHeight := confSet.details.BlockHeight + txConfHeight := confSet.details.BlockHeight +
ntfn.NumConfirmations - 1 ntfn.NumConfirmations - 1
numConfsLeft := txConfHeight - height numConfsLeft := txConfHeight - height
// Since we don't clear notifications until // Since we don't clear notifications until
// transactions are no longer under the risk of // transactions/output scripts are no longer
// being reorganized out of the chain, we'll // under the risk of being reorganized out of
// skip sending updates for transactions that // the chain, we'll skip sending updates for
// have already been confirmed. // those that have already been confirmed.
if int32(numConfsLeft) < 0 { if int32(numConfsLeft) < 0 {
continue continue
} }
@ -1323,13 +1323,13 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
} }
} }
// Then, we'll dispatch notifications for all the transactions that have // Then, we'll dispatch notifications for all the requests that have
// become confirmed at this new block height. // become confirmed at this new block height.
for ntfn := range n.ntfnsByConfirmHeight[height] { for ntfn := range n.ntfnsByConfirmHeight[height] {
confSet := n.confNotifications[*ntfn.TxID] confSet := n.confNotifications[ntfn.ConfRequest]
Log.Infof("Dispatching %v conf notification for %v", Log.Infof("Dispatching %v confirmation notification for %v",
ntfn.NumConfirmations, ntfn.TxID) ntfn.NumConfirmations, ntfn.ConfRequest)
select { select {
case ntfn.Event.Confirmed <- confSet.details: case ntfn.Event.Confirmed <- confSet.details:
@ -1340,10 +1340,10 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
} }
delete(n.ntfnsByConfirmHeight, height) delete(n.ntfnsByConfirmHeight, height)
// We'll also dispatch spend notifications for all the outpoints that // We'll also dispatch spend notifications for all the requests that
// were spent at this new block height. // were spent at this new block height.
for op := range n.opsBySpendHeight[height] { for spendRequest := range n.spendsByHeight[height] {
spendSet := n.spendNotifications[op] spendSet := n.spendNotifications[spendRequest]
for _, ntfn := range spendSet.ntfns { for _, ntfn := range spendSet.ntfns {
err := n.dispatchSpendDetails(ntfn, spendSet.details) err := n.dispatchSpendDetails(ntfn, spendSet.details)
if err != nil { if err != nil {
@ -1353,18 +1353,18 @@ func (n *TxNotifier) NotifyHeight(height uint32) error {
} }
// Finally, we'll clear the entries from our set of notifications for // Finally, we'll clear the entries from our set of notifications for
// transactions and outpoints that are no longer under the risk of being // requests that are no longer under the risk of being reorged out of
// reorged out of the chain. // the chain.
if height >= n.reorgSafetyLimit { if height >= n.reorgSafetyLimit {
matureBlockHeight := height - n.reorgSafetyLimit matureBlockHeight := height - n.reorgSafetyLimit
for tx := range n.txsByInitialHeight[matureBlockHeight] { for confRequest := range n.confsByInitialHeight[matureBlockHeight] {
delete(n.confNotifications, tx) delete(n.confNotifications, confRequest)
} }
delete(n.txsByInitialHeight, matureBlockHeight) delete(n.confsByInitialHeight, matureBlockHeight)
for op := range n.opsBySpendHeight[matureBlockHeight] { for spendRequest := range n.spendsByHeight[matureBlockHeight] {
delete(n.spendNotifications, op) delete(n.spendNotifications, spendRequest)
} }
delete(n.opsBySpendHeight, matureBlockHeight) delete(n.spendsByHeight, matureBlockHeight)
} }
return nil return nil