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



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.

Source: [Mastering Bitcoins: Mining Transactions in Blocks]

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.



Posted 2015-01-23T16:14:08.620

Reputation: 1 685



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())
// Added


Posted 2015-01-23T16:14:08.620

Reputation: 13 123

♦ Thank you so much! I'm now reading the lines. – zono – 2015-01-23T16:51:25.007

♦ As far as I read the code, if nBlockPrioritySize is set larger than 1, transaction fee has higher priority than the sum of all the priorities of the inputs. Is it correct? – zono – 2015-01-23T17:15:20.047