chainntnfs: return an error when witness stack is empty

This commit adds a check when receiving transactions from
`BitcoindClient` so an error is returned when empty witness is found.
This commit is contained in:
yyforyongyu
2023-07-11 17:58:42 +08:00
parent 971d3d8d9c
commit 28c3c835bf
7 changed files with 139 additions and 14 deletions

View File

@@ -74,6 +74,11 @@ var (
// out of range.
ErrNumConfsOutOfRange = fmt.Errorf("number of confirmations must be "+
"between %d and %d", 1, MaxNumConfs)
// ErrEmptyWitnessStack is returned when a spending transaction has an
// empty witness stack. More details in,
// - https://github.com/bitcoin/bitcoin/issues/28730
ErrEmptyWitnessStack = errors.New("witness stack is empty")
)
// rescanState indicates the progression of a registration before the notifier
@@ -1297,6 +1302,16 @@ func (n *TxNotifier) updateSpendDetails(spendRequest SpendRequest,
return nil
}
// 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...")
if !details.HasSpenderWitness() {
return ErrEmptyWitnessStack
}
// If the historical rescan found the spending transaction for this
// request, but it's at a later height than the notifier (this can
// happen due to latency with the backend during a reorg), then we'll