Pages:
Author

Topic: An (even more) optimized version of cpuminer (pooler's cpuminer, CPU-only) - page 19. (Read 1958260 times)

full member
Activity: 179
Merit: 100
 stratum+tcp://www.crypthash.fr:3334 -u ser.x -p y
full member
Activity: 179
Merit: 100
Hello I write from Italy who knows settings and procedure mining groundwater stratum + tcp :/ / www.crypthash.fr:3334-u-py ser.x
newbie
Activity: 2
Merit: 0
1) a sharelog
cpuminer runs with debug output, however, the output are often not captured
a share log is needed, i.e. for the shares submitted to a mining pool it would be helpful to log the
- time
- disposition (accept or reject)
- target
- hash
- data

and perhaps some other info in a text sharelog file. this would help with verifying from historical submitted entries if there are issues
As I've already said, this could indeed be useful, but the changes required to implement it properly are nontrivial (cpuminer does not currently keep track of submitted shares). I don't have much free time in this period, but I will put this on my to-do list.

hi pooler,

thanks much for the quick response, here is some codes i'm not sure if this is optimum but the changes are something like this:

i moved struct work into miner.h and added hash field which is the winning hash that scanhash has found

struct work {
   uint32_t data[32];
   uint32_t target[8];
   uint32_t hash[8]; // <-- new field

   char job_id[128];
   size_t xnonce2_len;
   unsigned char xnonce2[32];
};

i modified scanhash* function so that scanhash can pass the winning hash back
e.g.
 miner_thread calls scanhash as such:
      /* scan nonces for a proof-of-work hash */
      switch (opt_algo) {
      case ALGO_SCRYPT:
         rc = scanhash_scrypt(thr_id, work.data, scratchbuf, work.target,
                              max_nonce, &hashes_done, work.hash);
         break;
...

then in scanhash:
int scanhash_scrypt(int thr_id, uint32_t *pdata,
   unsigned char *scratchbuf, const uint32_t *ptarget,
   uint32_t max_nonce, unsigned long *hashes_done,
   uint32_t *phash); {

...
      for (i = 0; i < throughput; i++) {

         if (hash[i * 8 + 7] <= Htarg && fulltest(hash + i * 8, ptarget)) {
            *hashes_done = n - pdata[19] + 1;
            pdata[19] = data[i * 20 + 19];
            memcpy(phash, hash + i * 8, 32); // <- copy the winning hash into struct work
            return 1;
         }
      }


that goes back to miner_thread, which calls submit_work
that in turns gets picked up by workio_thread -> workio_submit_work -> submit_upstream_work

then i modify submit_upstream_work

if (have_stratum) {

   .... codes that build that rpc call ...

      /* place work in the queue for share_result*/
      pwork = malloc(sizeof(struct work));
      if (!pwork)
         goto err_out;
      memcpy(pwork, work, sizeof(struct work));
      if (!tq_push(tq_result_work, pwork))
         goto err_out;

                /* existing code
      if (unlikely(!stratum_send_line(&stratum, s))) {
         applog(LOG_ERR, "submit_upstream_work stratum_send_line failed");
         goto out;
      }
} else { // no stratum

              again before that rpc call

      /* place work in the queue for share_result*/
      pwork = malloc(sizeof(struct work));
      if (!pwork)
         goto err_out;
      memcpy(pwork, work, sizeof(struct work));
      if (!tq_push(tq_result_work, pwork))
         goto err_out;

      /* build JSON-RPC request */
      sprintf(s,
         "{\"method\": \"getwork\", \"params\": [ \"%s\" ], \"id\":1}\r\n",
         str);

      /* issue JSON-RPC request */
      val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL);
      if (unlikely(!val)) {
         applog(LOG_ERR, "submit_upstream_work json_rpc_call failed");
         goto out;
      }

tq_result_work is actually a "thread queue" in util.c i.e.

struct thread_q *tq_result_work;

i simply make tq_result_work a global variable in cpu-miner.c and let the mutexes in thread_q co-ordinate access to that data
- not sure if a deadlock is possible

it is initialised shortly after workio thread is initialised in main
   /* init workio thread info */
   work_thr_id = opt_n_threads;
   thr = &thr_info[work_thr_id];
   thr->id = work_thr_id;
   thr->q = tq_new();
   if (!thr->q)
      return 1;
   /* init work result q
    * used to pass work between workio - submit_upstream_work and
    * and share_result*/
   tq_result_work = tq_new();
   if (!tq_result_work)
      return 1;


i simply make a copy of struct work in submit_upstream work and push the struct work into tq_result_work queue. this queue is used to pass work to share_result as follows:

when stratum_thread process the return results it calls share_result

then i modify share_result
static void share_result(int result, const char *reason)
{
   char s[345];
   double hashrate;
   int i;
   struct work *pwork;

   hashrate = 0.;
   pthread_mutex_lock(&stats_lock);
   for (i = 0; i < opt_n_threads; i++)
      hashrate += thr_hashrates;
   result ? accepted_count++ : rejected_count++;
   pthread_mutex_unlock(&stats_lock);
   
   sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", 1e-3 * hashrate);
   applog(LOG_INFO, "accepted: %lu/%lu (%.2f%%), %s khash/s %s",
         accepted_count,
         accepted_count + rejected_count,
         100. * accepted_count / (accepted_count + rejected_count),
         s,
         result ? "(yay!!!)" : "(booooo)");

   /* retrieve work from queue from submit_upstream_work  and log share to a file*/
   pwork = tq_pop(tq_result_work, NULL);
   if (pwork && opt_sharelog) {
         share_log(result ? "accept" : "reject", pwork);

      free(pwork);
   }

   if (opt_debug && reason)
      applog(LOG_DEBUG, "DEBUG: reject reason: %s", reason);

   return;

then i create the supporting functions for share_log:

void sharelog_init(char *filename) {
   pthread_mutex_init(&sharelog_lock, NULL);
   sharelog_file = fopen(filename, "a");
     if (!sharelog_file)
    applog(LOG_ERR, "Failed to open %s for share log", filename);
}


void share_log(const char*disposition, const struct work *pwork)
{
   char *target, *hash, *data;
   unsigned long int t;
   struct pool *pool;
   char s[1024];
   size_t ret;

   char ts[50];
   int len;
   time_t now;
   struct tm tm, *tm_p;

   uint32_t hash_be[8], target_be[8];

   //sharelog file stream cannot be null
   if (!sharelog_file)
      return;

   time(&now);

   pthread_mutex_lock(&sharelog_lock);
   tm_p = localtime(&now);
   memcpy(&tm, tm_p, sizeof(tm));

   sprintf(ts, "%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900,
         tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);


   for (int i = 0; i < 8; i++) {
      be32enc(hash_be + i, pwork->hash[7 - i]);
      be32enc(target_be + i, pwork->target[7 - i]);
   }

   target = bin2hex((unsigned char *) target_be, sizeof(pwork->target));
   hash = bin2hex((unsigned char *) hash_be, sizeof(pwork->hash));
   data = bin2hex((unsigned char *) pwork->data, sizeof(pwork->data));

   // timestamp,disposition,target,sharehash,sharedata
   len = sprintf(s, "%s,%s,%s,%s,%s\n", ts, disposition, target,
         hash, data);
   free(target);
   free(hash);
   free(data);

   fwrite(s, 1, len, sharelog_file);
   fflush(sharelog_file);
   ret = ferror(sharelog_file);
   pthread_mutex_unlock(&sharelog_lock);

   if (ret)
      applog(LOG_ERR, "sharelog fwrite error");
}

the remaining is to create the opt_sharelog
   case 'L':
      free(opt_sharelog);
      opt_sharelog = strdup(arg);
      applog(LOG_DEBUG, "logging to sharelog: %s", opt_sharelog);
      sharelog_init(opt_sharelog);
      break;

static struct option const options[] = {
...
   { "sharelog", 1, NULL, 'L' },
...
and to update the help text

note that this is more of a 'hack' than a proper solution as the request-response protocol for submit work (e.g. stratum) needs to be strictly honoured. there is no error handling such as if a response is missing or some other permutations occurs, that'd throw things out of order. perhaps a more robust solution may need some re-design to be done in stratum_thread or workio_thread e.g. for one of them to handle the request / response of submit work rather than currently for stratum the request is send in workio_thread but response processed in stratum_thread

hopes the above  may be useful
 

There was a Qt GUI that interfaced with cpuminer, and it worked quite well. The project is now abandoned, but its source code is still available under the MIT license for anybody to fork.
https://bitcointalksearch.org/topic/scryptminer-gui-simple-gui-for-litecoin-mining-62414

thanks for the link ! Smiley

thanks and cheers Smiley
hero member
Activity: 838
Merit: 507
1) a sharelog
cpuminer runs with debug output, however, the output are often not captured
a share log is needed, i.e. for the shares submitted to a mining pool it would be helpful to log the
- time
- disposition (accept or reject)
- target
- hash
- data

and perhaps some other info in a text sharelog file. this would help with verifying from historical submitted entries if there are issues
As I've already said, this could indeed be useful, but the changes required to implement it properly are nontrivial (cpuminer does not currently keep track of submitted shares). I don't have much free time in this period, but I will put this on my to-do list.

2) a GUI
There was a Qt GUI that interfaced with cpuminer, and it worked quite well. The project is now abandoned, but its source code is still available under the MIT license for anybody to fork.
https://bitcointalksearch.org/topic/scryptminer-gui-simple-gui-for-litecoin-mining-62414
newbie
Activity: 2
Merit: 0
hi pooler,

here's some feature requests not sure if these features may have made it into the updated versions

1) a sharelog
cpuminer runs with debug output, however, the output are often not captured
a share log is needed, i.e. for the shares submitted to a mining pool it would be helpful to log the
- time
- disposition (accept or reject)
- target
- hash
- data

and perhaps some other info in a text sharelog file. this would help with verifying from historical submitted entries if there are issues

2) a GUI
today cpuminer is running with text messages, however, most PCs/laptops etc are already running in a windowing gui environment. it'd probably be a good idea to start developing a gui for it instead of showing k/hashes per sec or m/hashes per sec as texts, those could possibly become running graphs / charts in a window. it would also pave the way for more interactivity during the runs, e.g. the user can pause/start the activities and add future options

i'm thinking could use Qt or some similar cross platform gui libs to develop these. This would help simplying the programming task (Qt is cross platform - one code many platforms) and after all most of the offline bitcoin/litecoin etc wallets are using Qt for their Gui wallets.
the 'gui' can run in its own thread and is likely low cpu load consumption for that matter. The makefiles could have options to 'exclude' compiling the gui for those who's not interested in having it.

the 'old' text output can even be accomodated in the 'gui' thread by having applog push the text output into a queue and for the 'gui' thread pop them and to spool them out to stdout/stderr. the 'gui' thread can go in a loop waiting for commands so that you could implement features like pause / continue similar to the gui

just 2 cents
full member
Activity: 326
Merit: 100
I'm getting
Code:
fatal error: openssl/sha.h: no such file or directory
while trying to build on windows with mingw. I don't think there's any openssl packages I need to get for this so what have I done wrong?

OpenSSL is referenced nowhere in the source code of cpuminer. You must be trying to compile something else, probably a fork of it.

Yeah, this is a fork, skeincoin. Thought they were *mostly* identical and I'd get a faster response here (if any!)

Thanks anyway!
hero member
Activity: 838
Merit: 507
I'm getting
Code:
fatal error: openssl/sha.h: no such file or directory
while trying to build on windows with mingw. I don't think there's any openssl packages I need to get for this so what have I done wrong?

OpenSSL is referenced nowhere in the source code of cpuminer. You must be trying to compile something else, probably a fork of it.
full member
Activity: 326
Merit: 100
I'm getting
Code:
fatal error: openssl/sha.h: no such file or directory
while trying to build on windows with mingw. I don't think there's any openssl packages I need to get for this so what have I done wrong?
newbie
Activity: 37
Merit: 0
Quote
minerd -a scrypt -t 12 -s 6 -o stratum+tcp://doge-eu.poolerino.com:3333 -O alalalk71:a1s2d3f4
[2014-06-28 13:18:14] Starting Stratum on stratum+tcp://doge-eu.poolerino.com:33
33
[2014-06-28 13:18:14] Binding thread 2 to cpu 2
[2014-06-28 13:18:14] Binding thread 5 to cpu 5
[2014-06-28 13:18:14] Binding thread 9 to cpu 9
[2014-06-28 13:18:14] Binding thread 11 to cpu 11
[2014-06-28 13:18:14] Binding thread 0 to cpu 0
[2014-06-28 13:18:14] Binding thread 4 to cpu 4
[2014-06-28 13:18:14] Binding thread 6 to cpu 6
[2014-06-28 13:18:14] Binding thread 7 to cpu 7
[2014-06-28 13:18:14] Binding thread 10 to cpu 10
[2014-06-28 13:18:14] 12 miner threads started, using 'scrypt' algorithm.
[2014-06-28 13:18:14] Binding thread 3 to cpu 3
[2014-06-28 13:18:14] Binding thread 8 to cpu 8
[2014-06-28 13:18:14] Binding thread 1 to cpu 1
[2014-06-28 13:18:17] Stratum authentication failed
[2014-06-28 13:18:17] ...retry after 30 seconds
Stratum authentication failed  i  see this error and what can id o for resolve it ?
newbie
Activity: 3
Merit: 0
Hi,
Noob question. I'm using win7-64bit
Can i solo mine using minerd?
If so, can you assist with the command line?
Is there anything else I need to install?

Cheers,
Skimmer.
hero member
Activity: 838
Merit: 507
sr. member
Activity: 322
Merit: 250
does this miner have an api function?
hero member
Activity: 798
Merit: 1000
I'm looking to modify cpu-miner.c to include the entire command line. When compiled, instead of using options and args (./minerd -o XXX:XX -u xxx -p xxx -q -B) i want to specify them all in the source.
This has to work on all/most cpuminer forks, if anyone can do it, PM me for a 0.05BTC bounty.

You want to hardcode command-line parameters into the source code? Why in the world would you want that? Recompiling the software from source everytime a paramater needs to be changed just doesn't make any sense.

If you want a simpler way to launch the program, just put the full command line in a script and then launch that.

Or better yet, make a JSON conf file.  minerd supports using configuration files with the -c parameter.  Any changes to configuration can be put in the conf file and then you'd only need to load ./minerd -c miner.conf everytime.
full member
Activity: 168
Merit: 100
I'm looking to modify cpu-miner.c to include the entire command line. When compiled, instead of using options and args (./minerd -o XXX:XX -u xxx -p xxx -q -B) i want to specify them all in the source.
This has to work on all/most cpuminer forks, if anyone can do it, PM me for a 0.05BTC bounty.

You want to hardcode command-line parameters into the source code? Why in the world would you want that? Recompiling the software from source everytime a paramater needs to be changed just doesn't make any sense.

If you want a simpler way to launch the program, just put the full command line in a script and then launch that.
legendary
Activity: 1092
Merit: 1000
I'm looking to modify cpu-miner.c to include the entire command line. When compiled, instead of using options and args (./minerd -o XXX:XX -u xxx -p xxx -q -B) i want to specify them all in the source.
This has to work on all/most cpuminer forks, if anyone can do it, PM me for a 0.05BTC bounty.

hero member
Activity: 798
Merit: 1000
Hi all. Please tell me how to configure cpuminer under quark algorithm?
Is this usable with Talkcoin?

Read the first post in the thread, the third Q and A item.  Your answers are there.

Basically, you walked into a Catholic Church asking about the Book of Mormon. Or the Koran.
full member
Activity: 210
Merit: 100
Is this usable with Talkcoin?
full member
Activity: 154
Merit: 100
Hi all. Please tell me how to configure cpuminer under quark algorithm?
full member
Activity: 129
Merit: 100
Thanks, I just don't understand why isn't it simply
Code:
sctx->job.xnonce2++

Because xnonce2 is not an integer, but an array of bytes.

Ach, indeed, I didn't notice, thanks!
hero member
Activity: 838
Merit: 507
Thanks, I just don't understand why isn't it simply
Code:
sctx->job.xnonce2++

Because xnonce2 is not an integer, but an array of bytes.
Pages:
Jump to: