Post
Topic
Board Mining (Altcoins)
Re: An (even more) optimized version of cpuminer (pooler's cpuminer, CPU-only)
by
sandy25007
on 08/12/2022, 02:06:46 UTC
Hi All,

I am trying to understand under the hood working of bitcoin mining and going through the source code of cpuminer. The source code is really helpful, Thanks!

I have a basic question which I tried to ask in another forum, but I could not get clear answer, let me try here.

I feel that the cpuminer is not adding fees along with block-reward.

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;


Please let me know if I am missing anything.

Thanks & Regards,
Sandy