Skip to content

Commit

Permalink
mempool/estimatefee: Fix negative index bug
Browse files Browse the repository at this point in the history
Fixes a negative index bug that makes the node crash on chain
reorganizations.  The bug is detailed in
github.com//issues/1660.

A better design than just skipping the transaction would make
the fee estimator more accurate and that should implemented
at a later date.
  • Loading branch information
kcalvinalvin committed Feb 21, 2022
1 parent 4dc4ff7 commit 2ce1c60
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mempool/estimatefee.go
Expand Up @@ -275,7 +275,16 @@ func (ef *FeeEstimator) RegisterBlock(block *btcutil.Block) error {

// This shouldn't happen but check just in case to avoid
// an out-of-bounds array index later.
if blocksToConfirm >= estimateFeeDepth {
//
// Also check that blocksToConfirm is not negative as this causes
// the node to crash on reorgs. A tx that was observed at height X
// might be included in heights less than X because of chain reorgs.
// Refer to github.com/btcsuite/btcd/issues/1660 for more information.
//
// TODO(kcalvinalvin) a better design that doesn't just skip over the
// transaction would result in a more accurate fee estimator. Properly
// implement this later.
if blocksToConfirm >= estimateFeeDepth || blocksToConfirm < 0 {
continue
}

Expand Down

0 comments on commit 2ce1c60

Please sign in to comment.