Skip to content

Commit a636c35

Browse files
authored
Merge pull request #210 from kcalvinalvin/2024-11-05-take-in-utreexodata-for-checkmempoolacceptance
mempool: take in utreexo data as an argument for checkMempoolAcceptance
2 parents d801339 + 51a1050 commit a636c35

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

mempool/mempool.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit,
10101010

10111011
// Check for mempool acceptance.
10121012
r, err := mp.checkMempoolAcceptance(
1013-
tx, isNew, rateLimit, rejectDupOrphans,
1013+
tx, nil, isNew, rateLimit, rejectDupOrphans,
10141014
)
10151015
if err != nil {
10161016
return nil, nil, err
@@ -1314,13 +1314,19 @@ func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseRe
13141314
// input transactions can't be found for some reason.
13151315
tx := desc.Tx
13161316
var currentPriority float64
1317-
// Don't calculate for utreexo nodes yet.
13181317
if mp.cfg.IsUtreexoViewActive == nil && !mp.cfg.IsUtreexoViewActive() {
13191318
utxos, err := mp.fetchInputUtxos(tx)
13201319
if err == nil {
13211320
currentPriority = mining.CalcPriority(tx.MsgTx(), utxos,
13221321
bestHeight+1)
13231322
}
1323+
} else {
1324+
udata, found := mp.poolLeaves[*tx.Hash()]
1325+
if found {
1326+
utxos := mp.fetchInputUtxosFromLeaves(tx, udata)
1327+
currentPriority = mining.CalcPriority(tx.MsgTx(), utxos,
1328+
bestHeight+1)
1329+
}
13241330
}
13251331

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

14201426
txHash := tx.Hash()
@@ -1479,11 +1485,9 @@ func (mp *TxPool) checkMempoolAcceptance(tx *btcutil.Tx,
14791485

14801486
var utxoView *blockchain.UtxoViewpoint
14811487
if mp.cfg.IsUtreexoViewActive != nil && mp.cfg.IsUtreexoViewActive() {
1482-
ud := tx.MsgTx().UData
1483-
14841488
// First verify the proof to ensure that the proof the peer has
14851489
// sent was over valid.
1486-
err = mp.cfg.VerifyUData(ud, tx.MsgTx().TxIn, false)
1490+
err = mp.cfg.VerifyUData(utreexoData, tx.MsgTx().TxIn, false)
14871491
if err != nil {
14881492
str := fmt.Sprintf("transaction %v failed the utreexo data verification. %v",
14891493
txHash, err)
@@ -1492,7 +1496,7 @@ func (mp *TxPool) checkMempoolAcceptance(tx *btcutil.Tx,
14921496
log.Debugf("VerifyUData passed for tx %s", txHash.String())
14931497

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

0 commit comments

Comments
 (0)