2

I want to get the mempool data ordered by sat/vbyte to understand which transaction will be confirmed.

In order to get the mempool txs I use: "bitcoin-cli getrawmempool" in command prompt. The query returns a string array of txs. But this string array is not ordered by sat/vbyte. How can I order this Txs to understand which transaction will be confirmed in what order?

1 Answer 1

3

I want to get the mempool data ordered by sat/vbyte to understand which transaction will be confirmed.

These two questions are not identical.

While of course mining prefers higher fees over lower fees, there are some reasons why the mining order is not exactly high to low fee:

  • Dependencies: when a transaction A in the mempool spends an output of transaction B which is also in the mempool, then B must go into the block before A can. In practice, Bitcoin Core does take such dependencies into account to some extent: if A has a higher feerate than B, then the combination of A and B are treated as a single package, so that B "pays for" A, possibly bumping up A's mining priority.
  • Tail effects: near the "end" of a block, it's possible that the highest feerate transaction is too large to fit in the block. In that case the problem of block template building becomes a bin-packing problem, and may include whatever fits.

To answer your question:

  • If you want the mempool transactions sorted by fee/vbyte, use getrawmempool, and sort the result yourself by feerate. You could do this using jq for example:

    bitcoin-cli getrawmempool true | jq '[to_entries[] | .value] | sort_by(.fees.modified / .vsize)'
    
  • If you want the (order in which) transactions will end up in a block, use getblocktemplate (which is the RPC that mining pools use to get information of block transactions from Bitcoin Core):

    bitcoin-cli getblocktemplate '{"rules":["segwit"]}
    
4
  • bitcoin-cli getrawmempool true | jq '[to_entries[] | .value] | sort_by(.fees.modified / .vsize)' this method works but I also need to find the transaction hex but that data is not embeded in this query response how can I also get the hex of each transaction Jun 12, 2023 at 12:59
  • Try using bitcoin-cli getrawmempool true | jq -r '[to_entries[] | .value + {"txid":.key}] | sort_by(.fees.modified / .vsize) | .[] | .txid'. Jun 12, 2023 at 13:14
  • Due to child pay for parent effective fee rates could be smaller but due to higher sat/vbyte these txs are ordered and therefore a transaction which wont be confirmed is being listed in the tx array how can I prevent this Jun 12, 2023 at 14:05
  • 1
    @GencehanARPAÇAY As I said, if you want the mining order, and not actual feerate comparisons, use getblocktemplate, not getrawmempool. Jun 12, 2023 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.