Hi All,
I am trying to understand working of bitcoin mining and going through the source code of cpuminer-opt. The source code is really helpful, Thanks!
I have a basic question, my understanding is that in a coinbase transaction miner adds Coinbase_reward + fees (total fees from all the transactions included in the block being mined).
I can see the cpu-miner.c code adding Coinbase_reward by taking coinbasevalue, but I could not find code for fees getting added. Can someone please point me to the code that does that?
Thanks & Regards,
Sandy
PS
Referring :
https://github.com/JayDDee/cpuminer-opt/blob/master/cpu-miner.cI think you're looking for the merkle tree but that's not my area of expertise. You might get better advice elsewhere.
No, actually I am looking at coinbase transaction generation, code under section /* build coinbase transaction */
tmp = json_object_get( val, "coinbasevalue" );
if ( !tmp || !json_is_number( tmp ) )
{
applog( LOG_ERR, "JSON invalid coinbasevalue" );
goto out;
}
cbvalue = (int64_t) ( json_is_integer( tmp ) ? json_integer_value( tmp )
: json_number_value( tmp ) );
I feel it is missing the fees addition, below is the
code I was expecting to compute and add fees.
tmp = json_object_get( val, "coinbasevalue" );
if ( !tmp || !json_is_number( tmp ) )
{
applog( LOG_ERR, "JSON invalid coinbasevalue" );
goto out;
}
cbvalue = (int64_t) ( json_is_integer( tmp ) ? json_integer_value( tmp )
: json_number_value( tmp ) );
/* add fee */
int64_t total_fees=0;
int64_t fee=0;
for (i = 0; i < tx_count; i++) {
const json_t *tx = json_array_get(txa, i);
tmp = json_object_get(tx, "fee");
if (!tmp || !json_is_number(tmp)) {
applog(LOG_ERR, "JSON invalid Fee");
goto out;
}
fee = json_is_integer(tmp) ? json_integer_value(tmp) : json_number_value(tmp);
total_fees = total_fees + fee;
}
cbvalue = cbvalue + total_fees;
Thanks & Regards,
Sandy