mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 07:00:55 +02:00
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:
@@ -455,23 +455,19 @@ out:
|
||||
case chain.RelevantTx:
|
||||
tx := btcutil.NewTx(&item.TxRecord.MsgTx)
|
||||
|
||||
// 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 item.Block == nil {
|
||||
b.memNotifier.ProcessRelevantSpendTx(tx)
|
||||
continue
|
||||
isMempool = true
|
||||
} else {
|
||||
height = uint32(item.Block.Height)
|
||||
}
|
||||
|
||||
// Otherwise this is a confirmed spend, and
|
||||
// we'll ask the tx notifier to handle it.
|
||||
err := b.txNotifier.ProcessRelevantSpendTx(
|
||||
tx, uint32(item.Block.Height),
|
||||
)
|
||||
if err != nil {
|
||||
chainntnfs.Log.Errorf("Unable to "+
|
||||
"process transaction %v: %v",
|
||||
tx.Hash(), err)
|
||||
}
|
||||
// Handle the transaction.
|
||||
b.handleRelevantTx(tx, isMempool, height)
|
||||
}
|
||||
|
||||
case <-b.quit:
|
||||
@@ -480,6 +476,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 *BitcoindNotifier) 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