chainntnfs: remove subscriptions when the relevant tx is confirmed
This commit removes the subscribed inputs from mempool notifier when the relevant transaction is confirmed.
This commit is contained in:
4 files changed
+146
-28
No files matched your search
@@ -505,23 +505,19 @@ out:
|
||||
newSpend := item.(*txUpdate)
|
||||
tx := newSpend.tx
|
||||
|
||||
// If this is a mempool spend, we'll ask the mempool
|
||||
// notifier to hanlde it.
|
||||
// Init values.
|
||||
isMempool := false
|
||||
height := uint32(0)
|
||||
|
||||
// Unwrap values.
|
||||
if newSpend.details == nil {
|
||||
b.memNotifier.ProcessRelevantSpendTx(tx)
|
||||
continue
|
||||
isMempool = true
|
||||
} else {
|
||||
height = uint32(newSpend.details.Height)
|
||||
}
|
||||
|
||||
// Otherwise this is a confirmed spend, and we'll ask
|
||||
// the tx notifier to handle it.
|
||||
err := b.txNotifier.ProcessRelevantSpendTx(
|
||||
tx, uint32(newSpend.details.Height),
|
||||
)
|
||||
if err != nil {
|
||||
chainntnfs.Log.Errorf("Unable to process "+
|
||||
"transaction %v: %v",
|
||||
newSpend.tx.Hash(), err)
|
||||
}
|
||||
// Handle the transaction.
|
||||
b.handleRelevantTx(tx, isMempool, height)
|
||||
|
||||
case <-b.quit:
|
||||
break out
|
||||
@@ -529,6 +525,39 @@ out:
|
||||
}
|
||||
}
|
||||
|
||||
// handleRelevantTx handles a new transaction that has been seen either in a
|
||||
// block or in the mempool. If in mempool, it will ask the mempool notifier to
|
||||
// handle it. If in a block, it will ask the txNotifier to handle it, and
|
||||
// cancel any relevant subscriptions made in the mempool.
|
||||
func (b *BtcdNotifier) handleRelevantTx(tx *btcutil.Tx,
|
||||
mempool bool, height uint32) {
|
||||
|
||||
// If this is a mempool spend, we'll ask the mempool notifier to hanlde
|
||||
// it.
|
||||
if mempool {
|
||||
b.memNotifier.ProcessRelevantSpendTx(tx)
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise this is a confirmed spend, and we'll ask the tx notifier
|
||||
// to handle it.
|
||||
err := b.txNotifier.ProcessRelevantSpendTx(tx, height)
|
||||
if err != nil {
|
||||
chainntnfs.Log.Errorf("Unable to process transaction %v: %v",
|
||||
tx.Hash(), err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Once the tx is processed, we will ask the memNotifier to unsubscribe
|
||||
// the input.
|
||||
//
|
||||
// NOTE(yy): we could build it into txNotifier.ProcessRelevantSpendTx,
|
||||
// but choose to implement it here so we can easily decouple the two
|
||||
// notifiers in the future.
|
||||
b.memNotifier.UnsubsribeConfirmedSpentTx(tx)
|
||||
}
|
||||
|
||||
// historicalConfDetails looks up whether a confirmation request (txid/output
|
||||
// script) has already been included in a block in the active chain and, if so,
|
||||
// returns details about said block.
|
||||
|
||||
Reference in new issue
Block a user