Post
Topic
Board Mining (Altcoins)
Re: [ANN] cpuminer-opt v3.20.3, open source optimized multi-algo x86_64 CPU miner
by
sandy25007
on 07/12/2022, 05:57:11 UTC
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.c

I 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 */

Code:
      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