Miners determine which of the valid transactions in their mempool are selected for inclusion in a block.
Aside from the need for transactions to be valid, there are no consensus rules around transaction selection, miners are able to use whatever selection method they wish.
So how do block templates compare? Let's examine what happened prior to block 821498 (mined within the last hour).
The block mined by Antpool had a max total bid of 7.73789496 BTC. You can find this using bitcoin-cli getblockstats
My local instance of bitcoin core running the default policy rules + FullRBF had a max total bid of 7.71806816 BTC, lower than the mined block by 0.01982680 BTC.
The block templates provided by mempool (npub18d4…6lt3)
had a max total bid of 7.7334687 BTC, lower than the mined block by 0.00442626 BTC.
The block template provided by ocean npub1qtvl2em0llpnnllffhat8zltugwwz97x79gfmxfz4qk52n6zpk3qq87dze
had a max total bid of 6.6127135 BTC, lower than the mined block by 0.43183364 BTC
Filtering policy and sorting method vary by pool, but mining is highly competitive. For how long can mining pools who do not maximise fee revenue survive?
The rate of my data logging (every few seconds) means it's inevitable that I don't capture the latest templates, so that accounts for a small part of the delta. You can see on the mempool block audit page that the expected mempool space template for the mempool block is 7.737 BTC , slightly higher than the 7.7335 BTC template I captured.
An additional source of the delta is that there were some transactions (in blue) which AntPool included which were not in
@mempool
's mempool and likely not in mine or oceans (I didn't save the block template so can't check).
These 6 transactions pay a total of 4,072,619 sats in fees. Plus there is a transaction that was included which had a marginal fee rate, paying a 73,828 sats.
A total of 4,146,447 sats
To create space to include these transactions 45 transactions were dropped, each paying 89,833 sats.
A total of 4,042,485 sats
Including these transactions resulted in a net increase for the in band fees of 103,962 sats (0.00103962 BTC)
Check the block audit at https://mempool.space/block/000000000000000000028bdf4456e7e2519b0ba4b6d52cea0cc18c726f60a578