Skip to content

Commit

Permalink
mempool: refactor fetchInputUtxosFromUData to fetchInputUtxosFromLeaves
Browse files Browse the repository at this point in the history
Since the leaves are the actual data we need, it's better that the
function argument is the leaves and not the udata. This allows for
calling fetchInputUtxosFromLeaves from a different mempool method as
the leaves are kept track of.
  • Loading branch information
kcalvinalvin committed Nov 5, 2024
1 parent 6ed428f commit 12aab72
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,18 +826,18 @@ func (mp *TxPool) fetchInputUtxos(tx *btcutil.Tx) (*blockchain.UtxoViewpoint, er
return utxoView, nil
}

// fetchInputUtxosFromUData extracts utxo details about the input transactions
// provided in the UData for the passed transaction. First, it extracts the
// fetchInputUtxosFromLeaves extracts utxo details about the input transactions
// provided in the leaves for the passed transaction. First, it extracts the
// details from the udata, then it adjusts them based upon the contents of the
// transaction pool.
//
// This function MUST be called with the mempool lock held (for reads).
func (mp *TxPool) fetchInputUtxosFromUData(tx *btcutil.Tx, ud *wire.UData) *blockchain.UtxoViewpoint {
func (mp *TxPool) fetchInputUtxosFromLeaves(tx *btcutil.Tx, leaves []wire.LeafData) *blockchain.UtxoViewpoint {
utxoView := blockchain.NewUtxoViewpoint()
viewEntries := utxoView.Entries()

// Loop through leaf datas and convert them into UtxoEntries.
for _, ld := range ud.LeafDatas {
for _, ld := range leaves {
// If the leaf data was marked to be unconfirmed, set as nil.
// The outpoint for the txIn that this LeafData is supposed to
// represent will be attempted to be fetched from the mempool
Expand Down Expand Up @@ -1492,7 +1492,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.fetchInputUtxosFromUData(tx, ud)
utxoView = mp.fetchInputUtxosFromLeaves(tx, ud.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 12aab72

Please sign in to comment.