Skip to content

Commit

Permalink
mempool: take in utreexo data as an argument for checkMempoolAcceptance
Browse files Browse the repository at this point in the history
checkmempoolacceptance takes in udata and internally uses it for tx
verification if it's not nil. This change is made to support utreexotx
messages.
  • Loading branch information
kcalvinalvin committed Nov 5, 2024
1 parent 12aab72 commit 8bd26e3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit,

// Check for mempool acceptance.
r, err := mp.checkMempoolAcceptance(
tx, isNew, rateLimit, rejectDupOrphans,
tx, nil, isNew, rateLimit, rejectDupOrphans,
)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -1314,13 +1314,19 @@ func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseRe
// input transactions can't be found for some reason.
tx := desc.Tx
var currentPriority float64
// 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)
}
} else {
udata, found := mp.poolLeaves[*tx.Hash()]
if found {
utxos := mp.fetchInputUtxosFromLeaves(tx, udata)
currentPriority = mining.CalcPriority(tx.MsgTx(), utxos,
bestHeight+1)
}
}

mpd := &btcjson.GetRawMempoolVerboseResult{
Expand Down Expand Up @@ -1399,7 +1405,7 @@ func (mp *TxPool) CheckMempoolAcceptance(tx *btcutil.Tx) (
// which has the effect that we always check the fee paid from this tx
// is greater than min relay fee. We also reject this tx if it's
// already an orphan.
result, err := mp.checkMempoolAcceptance(tx, true, true, true)
result, err := mp.checkMempoolAcceptance(tx, nil, true, true, true)
if err != nil {
log.Errorf("CheckMempoolAcceptance: %v", err)
return nil, err
Expand All @@ -1414,7 +1420,7 @@ func (mp *TxPool) CheckMempoolAcceptance(tx *btcutil.Tx) (
// checkMempoolAcceptance performs a series of validations on the given
// transaction. It returns an error when the transaction fails to meet the
// mempool policy, otherwise a `mempoolAcceptResult` is returned.
func (mp *TxPool) checkMempoolAcceptance(tx *btcutil.Tx,
func (mp *TxPool) checkMempoolAcceptance(tx *btcutil.Tx, utreexoData *wire.UData,
isNew, rateLimit, rejectDupOrphans bool) (*MempoolAcceptResult, error) {

txHash := tx.Hash()
Expand Down Expand Up @@ -1478,12 +1484,10 @@ func (mp *TxPool) checkMempoolAcceptance(tx *btcutil.Tx,
}

var utxoView *blockchain.UtxoViewpoint
if mp.cfg.IsUtreexoViewActive != nil && mp.cfg.IsUtreexoViewActive() {
ud := tx.MsgTx().UData

if utreexoData != nil {
// 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)
err = mp.cfg.VerifyUData(utreexoData, tx.MsgTx().TxIn, false)
if err != nil {
str := fmt.Sprintf("transaction %v failed the utreexo data verification. %v",
txHash, err)
Expand All @@ -1492,7 +1496,7 @@ func (mp *TxPool) checkMempoolAcceptance(tx *btcutil.Tx,
log.Debugf("VerifyUData passed for tx %s", txHash.String())

// After the validation passes, turn that proof into a utxoView.
utxoView = mp.fetchInputUtxosFromLeaves(tx, ud.LeafDatas)
utxoView = mp.fetchInputUtxosFromLeaves(tx, utreexoData.LeafDatas)
} else {
// Fetch all of the unspent transaction outputs referenced by the
// inputs to this transaction. This function also attempts to fetch the
Expand Down

0 comments on commit 8bd26e3

Please sign in to comment.