## What is criteria of mining priority except for transaction-fee?

2

2

I am reading "Mastering Bitcoin written by Andreas" and I found this explanation of mining.

Transactions are added to the new block, prioritized by the highest-fee transactions first and a few other criteria.

I want to know what the a few other criteria are. And I want to see the source code where the system prioritizes by highest-fee transactions first and a few other criteria.

I guess that the code is in miner.cpp. But I don't understand the exact line.

https://github.com/bitcoin/bitcoin/blob/master/src/miner.cpp

6

The code you're looking for is in CreateNewBlock.

The usual way transactions are added to a block is by sorting by priority. The priority of an input is the value being spent in the input multiplied by the number of confirmations it has. The priority of a transaction is the sum of all the priorities of the inputs. See this line:

dPriority += (double)nValueIn * nConf;


Transactions are added to a vector of transaction priority:

vector<TxPriority> vecPriority;


Then they are sorted according to their priority:

TxPriorityCompare comparer(fSortedByFee);
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);


And one by one, transactions are verified to be valid and then added to the block, done by order of priority, higher priority first.:

while (!vecPriority.empty())
...