Bitcoin advocate explains how unconfirmed txns get queued up based on txn fee
According to him, “every node has its own reservoir or copy of reservoirs” where they put transactions that haven’t been confirmed yet, in order to keep a track of transactions that are not yet confirmed and are waiting for inclusion in the block. The author of ‘Mastering Bitcoin‘ further explained,
“Now this reservoir is obviously very important, the mempool is what it’s called. Miners have this mempool and they use it to collect transactions in between blocks, so when they are ready to produce a block or try to solve a block, they have transactions to put into the block, so they can earn fees.”
“When they take transactions out of the mempool, and they put them in the candidate block, if that block is successfully solved and propagated to the rest of the network. As the other nodes in the system see that block, they will look at what transactions are in the block and they will remove those transactions from their own mempool because they are no longer unconfirmed, they are now in a properly solved block.”
Following this, the queue of the remaining transactions gets slightly smaller every time the block is small. Talking about the circumstances when a block gets rejected after they have been solved, Antonopoulos elaborated that all the transactions from the rejected block are not included in another block, they will get “dumped back” in the mempool.
They will now have to wait for their turn again. These transactions will be sequenced again based on priority of fees per byte. That way, the ones paying the highest fee get included in the next block. In short, he explained that the “transactions don’t get dropped if they are included in a block and that block isn’t validated”, they get “queued again” in the mempool to include it in the next block. However, he stated,
“..if a transaction just sits in the queue and doesn’t get included in a block usually because it’s fees are too low then eventually that transaction will get dropped from the mempool and each node decide how long it’s going to keep transactions in the mempool.”