Skip to content

Commit

Permalink
mempool: don't fetch from the utxo set for csns
Browse files Browse the repository at this point in the history
Because Utreexo nodes don't have an initialized utxo set, attempting to
fetch from them will result in a runtime panic. We check if we're a
utreexo node before attempting any fetches.
  • Loading branch information
kcalvinalvin committed Nov 5, 2024
1 parent bbfa799 commit 6a52210
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,13 @@ func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseRe
// input transactions can't be found for some reason.
tx := desc.Tx
var currentPriority float64
utxos, err := mp.fetchInputUtxos(tx)
if err == nil {
currentPriority = mining.CalcPriority(tx.MsgTx(), utxos,
bestHeight+1)
// Don't calculate for utreexo nodes yet.
if mp.cfg.IsUtreexoViewActive == nil && !mp.cfg.IsUtreexoViewActive() {
utxos, err := mp.fetchInputUtxos(tx)
if err == nil {
currentPriority = mining.CalcPriority(tx.MsgTx(), utxos,
bestHeight+1)
}
}

mpd := &btcjson.GetRawMempoolVerboseResult{
Expand Down Expand Up @@ -1474,17 +1477,35 @@ func (mp *TxPool) checkMempoolAcceptance(tx *btcutil.Tx,
return nil, err
}

// Fetch all of the unspent transaction outputs referenced by the
// inputs to this transaction. This function also attempts to fetch the
// transaction itself to be used for detecting a duplicate transaction
// without needing to do a separate lookup.
utxoView, err := mp.fetchInputUtxos(tx)
if err != nil {
if cerr, ok := err.(blockchain.RuleError); ok {
return nil, chainRuleError(cerr)
var utxoView *blockchain.UtxoViewpoint
if mp.cfg.IsUtreexoViewActive != nil && mp.cfg.IsUtreexoViewActive() {
ud := tx.MsgTx().UData

// First verify the proof to ensure that the proof the peer has
// sent was over valid.
err = mp.cfg.VerifyUData(ud, tx.MsgTx().TxIn, false)
if err != nil {
str := fmt.Sprintf("transaction %v failed the utreexo data verification. %v",
txHash, err)
return nil, txRuleError(wire.RejectInvalid, str)
}
log.Debugf("VerifyUData passed for tx %s", txHash.String())

// After the validation passes, turn that proof into a utxoView.
utxoView = mp.fetchInputUtxosFromUData(tx, ud)
} else {
// Fetch all of the unspent transaction outputs referenced by the
// inputs to this transaction. This function also attempts to fetch the
// transaction itself to be used for detecting a duplicate transaction
// without needing to do a separate lookup.
utxoView, err = mp.fetchInputUtxos(tx)
if err != nil {
if cerr, ok := err.(blockchain.RuleError); ok {
return nil, chainRuleError(cerr)
}

return nil, err
return nil, err
}
}

// Don't allow the transaction if it exists in the main chain and is
Expand Down

0 comments on commit 6a52210

Please sign in to comment.