Skip to content

Commit

Permalink
chainntnfs: stop lnd when received witness stack is empty
Browse files Browse the repository at this point in the history
This commit uses `Criticalf` to gracefully stop `lnd` when the received
witness data is empty.
  • Loading branch information
yyforyongyu committed Aug 18, 2023
1 parent 3865413 commit 0e1f8eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 11 additions & 3 deletions chainntnfs/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,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
Expand Down
9 changes: 6 additions & 3 deletions chainntnfs/txnotifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,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
}

Expand Down

0 comments on commit 0e1f8eb

Please sign in to comment.