From ee883c332fd6a90a0aa465ea440c72c94a056f52 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 18 Aug 2023 17:59:47 +0800 Subject: [PATCH] chainntnfs: stop `lnd` when received witness stack is empty This commit uses `Criticalf` to gracefully stop `lnd` when the received witness data is empty. --- chainntnfs/mempool.go | 14 +++++++++++--- chainntnfs/txnotifier.go | 9 ++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/chainntnfs/mempool.go b/chainntnfs/mempool.go index 414861f59..4cd181df8 100644 --- a/chainntnfs/mempool.go +++ b/chainntnfs/mempool.go @@ -223,11 +223,19 @@ func (m *MempoolNotifier) findRelevantInputs(tx *btcutil.Tx) (inputsWithTx, } watchedInputs[*op] = details + // Sanity check the witness stack. If it's not empty, continue + // to next iteration. + if details.HasSpenderWitness() { + continue + } + // Return an error if the witness data is not present in the // spending transaction. - if !details.HasSpenderWitness() { - return nil, ErrEmptyWitnessStack - } + Log.Criticalf("Found spending tx for outpoint=%v in mempool, "+ + "but the transaction %v does not have witness", + op, details.SpendingTx.TxHash()) + + return nil, ErrEmptyWitnessStack } return watchedInputs, nil diff --git a/chainntnfs/txnotifier.go b/chainntnfs/txnotifier.go index 63c8746d0..f6cd0c1b8 100644 --- a/chainntnfs/txnotifier.go +++ b/chainntnfs/txnotifier.go @@ -1305,10 +1305,13 @@ func (n *TxNotifier) updateSpendDetails(spendRequest SpendRequest, // Return an error if the witness data is not present in the spending // transaction. // - // TODO(yy): maybe we should do a panic here instead to inform the user - // to reindex the bitcoind since it's critical error? - // panic("Please re-index your bitcoind...") + // NOTE: if the witness stack is empty, we will do a critical log which + // shuts down the node. if !details.HasSpenderWitness() { + Log.Criticalf("Found spending tx for outpoint=%v, but the "+ + "transaction %v does not have witness", + spendRequest.OutPoint, details.SpendingTx.TxHash()) + return ErrEmptyWitnessStack }