From 14c557faa9ca9cab65cf91672667baeb5977d17b Mon Sep 17 00:00:00 2001 From: Kano Date: Sun, 18 Sep 2011 14:48:40 +1000 Subject: [PATCH 1/5] Watch USB disk space in /var/log/ --- linux-usb-cgminer | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/linux-usb-cgminer b/linux-usb-cgminer index 0b9dd9eb..f35092df 100644 --- a/linux-usb-cgminer +++ b/linux-usb-cgminer @@ -135,3 +135,27 @@ In my case it takes away 50Mh/s when the screen isn't blanked This is of course just the basics ... but it should get you a computer up and running and able to run cgminer + +======== + +You should keep an eye on USB disk space +The system logger writes log files in the /var/log/ directory +The two main ones that grow large are 'kern.log' and 'syslog' +If you want to keep them, save them away to some other computer +When space is low, just delete them. + +The 'df' command will show you the current space e.g.: + +Filesystem 1K-blocks Used Available Use% Mounted on +aufs 2099420 892024 1100748 45% / +none 1015720 628 1015092 1% /dev +/dev/sda1 3909348 2837248 1072100 73% /cdrom +/dev/loop0 670848 670848 0 100% /rofs +none 1023772 136 1023636 1% /dev/shm +tmpfs 1023772 16 1023756 1% /tmp +none 1023772 124 1023648 1% /var/run +none 1023772 0 1023772 0% /var/lock + + +This shows the 2GB space allocated when you setup the USB as '/' (aufs) +In this example, it's currently 45% full with almost 1.1GB of free space From 31a9176977d5d01a6ba765cb695146cd870927f8 Mon Sep 17 00:00:00 2001 From: Kano Date: Sun, 18 Sep 2011 21:16:24 +1000 Subject: [PATCH 2/5] Add details of how to set the password for ssh --- linux-usb-cgminer | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/linux-usb-cgminer b/linux-usb-cgminer index f35092df..3e3091d4 100644 --- a/linux-usb-cgminer +++ b/linux-usb-cgminer @@ -16,13 +16,13 @@ CD (or DVD/BD) writer, a USB port and of course an internet connection to the PC ( look here for mirrors: http://www.xubuntu.org/getubuntu ) 2) Burn it to CD then boot that temporarily on any PC with a CD/DVD/BD and a USB -port (this and the next 2 step won't effect that PC) + port (this and the next 2 step won't effect that PC) 3) Plug in your 4GB USB device and it should appear on the desktop - you can -leave it's contents as long as there is at least 2.8GB free + leave it's contents as long as there is at least 2.8GB free -4) Now run "Startup Disk Creator" in "Applications->System" (the system menu is -the little rat in the top left corner) +4) Now run "Startup Disk Creator" in "Applications->System" + (the system menu is the little rat in the top left corner) (if you have no mouse you can get the menu with and navigate the menu with the arrow keys and key) @@ -38,8 +38,7 @@ After about 10-15 minutes you have a base xubuntu 11.04 boot USB 5) Boot your cgminer PC with this USB stick, select "English" then select "Try Xubuntu without installing" and wait for the desktop to -appear - (this happens by default if you wait for the timeouts) + appear (this happens by default if you wait for the timeouts) 6) Start a terminal "Applications->Accessories->Terminal Emulator" @@ -54,7 +53,7 @@ available ... sort that out by reading elsewhere about routers etc sudo shutdown -r now N.B. always do a "sudo sync" and wait for it to finish every time before -shutting down the PC to ensure all data is written to the USB + shutting down the PC to ensure all data is written to the USB 9) sudo aticonfig --lsa this lists your ATI cards so you can see them @@ -92,8 +91,8 @@ shutting down the PC to ensure all data is written to the USB 13) cgminer: sudo apt-get install curl - get the binary linux cgminer (see the bitcoin forum cgminer thread for where to -get it) + get the binary linux cgminer (see the bitcoin forum cgminer thread + for where to get it) ./cgminer -n this shows you the GPU's it found on your PC @@ -107,8 +106,8 @@ get it) 15) set the screen saver to ONLY blank ... - Move the mouse to the bottom of the screen and you see a set of icons like on -an Apple PC + Move the mouse to the bottom of the screen and you see a set of icons + like on an Apple PC Click on Settings, then in the Settings window "Screensaver" Set "Mode:" to "Blank Screen Only" @@ -116,6 +115,12 @@ Edit: originally left this somewhat useful addition out: 16) apt-get install ntpd An accurate clock is always a good idea Smiley +Edit2: another item that seems I missed +17) if you wish to ssh into the box you must set a password + to do this you simply have to be logged into it at the screen and type + sudo passwd ubuntu + it will prompt you (twice) to enter a password for the ubuntu account + Initial setup complete. ======== From 9696b4d6ba89c384b4926f2266760819ea93b125 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 18 Sep 2011 23:17:50 +1000 Subject: [PATCH 3/5] Get rid of the convoluted way we detect whether LP discovered the new block and just use the work retrieved by the LP to know. --- main.c | 46 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/main.c b/main.c index 48d58830..11b87ff9 100644 --- a/main.c +++ b/main.c @@ -259,14 +259,6 @@ static int total_getworks, total_stale, total_discarded; static int total_queued; static unsigned int new_blocks; -enum block_change { - BLOCK_NONE, - BLOCK_LP, - BLOCK_DETECT, - BLOCK_FIRST, -}; - -static enum block_change block_changed = BLOCK_FIRST; static unsigned int local_work; static unsigned int total_go, total_ro; @@ -2626,7 +2618,7 @@ static void set_curblock(char *hexstr, unsigned char *hash) free(old_hash); } -static void test_work_current(struct work *work) +static void test_work_current(struct work *work, bool longpoll) { struct block *s; char *hexstr; @@ -2651,19 +2643,18 @@ static void test_work_current(struct work *work) HASH_ADD_STR(blocks, hash, s); wr_unlock(&blk_lock); set_curblock(hexstr, work->data); + if (++new_blocks == 1) + goto out_free; - new_blocks++; - if (block_changed != BLOCK_LP && block_changed != BLOCK_FIRST) { - block_changed = BLOCK_DETECT; - if (have_longpoll) - applog(LOG_NOTICE, "New block detected on network before longpoll, waiting on fresh work"); - else - applog(LOG_NOTICE, "New block detected on network, waiting on fresh work"); - } else - block_changed = BLOCK_NONE; + if (longpoll) + applog(LOG_NOTICE, "LONGPOLL detected new block on network, waiting on fresh work"); + else if (have_longpoll) + applog(LOG_NOTICE, "New block detected on network before longpoll, waiting on fresh work"); + else + applog(LOG_NOTICE, "New block detected on network, waiting on fresh work"); restart_threads(); } - +out_free: free(hexstr); } @@ -2709,7 +2700,7 @@ static void *stage_thread(void *userdata) break; } - test_work_current(work); + test_work_current(work, false); if (opt_debug) applog(LOG_DEBUG, "Pushing work to getwork queue"); @@ -4335,8 +4326,9 @@ static void convert_to_work(json_t *val, bool rolltime) work->rolltime = rolltime; /* We'll be checking this work item twice, but we already know it's * from a new block so explicitly force the new block detection now - * rather than waiting for it to hit the stage thread */ - test_work_current(work); + * rather than waiting for it to hit the stage thread. This also + * allows testwork to know whether LP discovered the block or not. */ + test_work_current(work, true); if (opt_debug) applog(LOG_DEBUG, "Pushing converted work to stage thread"); @@ -4403,16 +4395,6 @@ static void *longpoll_thread(void *userdata) val = json_rpc_call(curl, lp_url, pool->rpc_userpass, rpc_req, false, true, &rolltime, pool); if (likely(val)) { - /* Keep track of who ordered a restart_threads to make - * sure it's only done once per new block */ - if (block_changed != BLOCK_DETECT) { - block_changed = BLOCK_LP; - applog(LOG_NOTICE, "LONGPOLL detected new block on network, waiting on fresh work"); - } else { - applog(LOG_INFO, "LONGPOLL received after new block already detected"); - block_changed = BLOCK_NONE; - } - convert_to_work(val, rolltime); failures = 0; json_decref(val); From ba14a6705ebca24f0508eb8eed1d449372567bf4 Mon Sep 17 00:00:00 2001 From: Kano Date: Wed, 21 Sep 2011 21:45:24 +1000 Subject: [PATCH 4/5] Remove EOL spaces from stderr and curses --- main.c | 2 +- miner.h | 1 + util.c | 13 +++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 11b87ff9..d64652e0 100644 --- a/main.c +++ b/main.c @@ -216,7 +216,7 @@ static int opt_n_threads; static int mining_threads; static int num_processors; static int scan_intensity; -static bool use_curses = true; +bool use_curses = true; static bool opt_submit_stale; static bool opt_nogpu; static bool opt_usecpu; diff --git a/miner.h b/miner.h index cfcf83f7..3c9d376f 100644 --- a/miner.h +++ b/miner.h @@ -314,6 +314,7 @@ extern char *opt_kernel_path; extern char *cgminer_path; extern bool opt_autofan; extern bool opt_autoengine; +extern bool use_curses; extern const uint32_t sha256_init_state[]; extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, diff --git a/util.c b/util.c index 1fddeada..01dbdd1f 100644 --- a/util.c +++ b/util.c @@ -84,7 +84,7 @@ void vapplog(int prio, const char *fmt, va_list ap) len = 40 + strlen(fmt) + 22; f = alloca(len); - sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s \n", + sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, @@ -100,7 +100,16 @@ void vapplog(int prio, const char *fmt, va_list ap) vfprintf(stderr, f, apc); /* atomic write to stderr */ fflush(stderr); } - log_curses(prio, f, ap); + + if (use_curses) + log_curses(prio, f, ap); + else { + int len = strlen(f); + + strcpy(f + len - 1, " \n"); + + log_curses(prio, f, ap); + } } } From 037e8ac8874ac46b1bdf1b8b7b3f37495dcc0abc Mon Sep 17 00:00:00 2001 From: Kano Date: Wed, 21 Sep 2011 21:48:23 +1000 Subject: [PATCH 5/5] Change Accept/Reject message to show hash and BLOCK notification --- main.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index d64652e0..6d2f5daf 100644 --- a/main.c +++ b/main.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "compat.h" #include "miner.h" @@ -1996,6 +1997,58 @@ void clear_logwin(void) } } +/* regenerate the full work->hash value and also return true if it's a block */ +bool regeneratehash(const struct work *work) +{ + uint32_t *data32 = (uint32_t *)(work->data); + unsigned char swap[128]; + uint32_t *swap32 = (uint32_t *)swap; + unsigned char hash1[SHA256_DIGEST_LENGTH]; + uint32_t *hash32 = (uint32_t *)(work->hash); + uint32_t difficulty = 0; + uint32_t diffbytes = 0; + uint32_t diffvalue = 0; + uint32_t diffcmp[8]; + int diffshift = 0; + int i; + + for (i = 0; i < 80/4; i++) + swap32[i] = swab32(data32[i]); + + SHA256(swap, 80, hash1); + SHA256(hash1, SHA256_DIGEST_LENGTH, (unsigned char *)(work->hash)); + + difficulty = swab32(*((uint32_t *)(work->data + 72))); + + diffbytes = ((difficulty >> 24) & 0xff) - 3; + diffvalue = difficulty & 0x00ffffff; + + diffshift = (diffbytes % 4) * 8; + if (diffshift == 0) { + diffshift = 32; + diffbytes--; + } + + memset(diffcmp, 0, 32); + diffcmp[(diffbytes >> 2) + 1] = diffvalue >> (32 - diffshift); + diffcmp[diffbytes >> 2] = diffvalue << diffshift; + + for (i = 7; i >= 0; i--) { + if (hash32[i] > diffcmp[i]) + return false; + if (hash32[i] < diffcmp[i]) + return true; + } + + // https://en.bitcoin.it/wiki/Block says: "numerically below" + // https://en.bitcoin.it/wiki/Target says: "lower than or equal to" + // code in bitcoind 0.3.24 main.cpp CheckWork() says: if (hash > hashTarget) return false; + if (hash32[0] == diffcmp[0]) + return true; + else + return false; +} + static bool submit_upstream_work(const struct work *work) { char *hexstr = NULL; @@ -2007,6 +2060,9 @@ static bool submit_upstream_work(const struct work *work) CURL *curl = curl_easy_init(); struct pool *pool = work->pool; bool rolltime; + uint32_t *hash32; + char hashshow[64+1] = ""; + bool isblock; if (unlikely(!curl)) { applog(LOG_ERR, "CURL initialisation failed"); @@ -2046,6 +2102,14 @@ static bool submit_upstream_work(const struct work *work) res = json_object_get(val, "result"); + if (!QUIET) { + isblock = regeneratehash(work); + hash32 = (uint32_t *)(work->hash); + sprintf(hashshow, "%08lx.%08lx.%08lx%s", + (unsigned long)(hash32[7]), (unsigned long)(hash32[6]), (unsigned long)(hash32[5]), + isblock ? " BLOCK!" : ""); + } + /* Theoretically threads could race when modifying accepted and * rejected values but the chance of two submits completing at the * same time is zero so there is no point adding extra locking */ @@ -2057,11 +2121,11 @@ static bool submit_upstream_work(const struct work *work) applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)"); if (!QUIET) { if (total_pools > 1) - applog(LOG_NOTICE, "Accepted %.8s %sPU %d thread %d pool %d", - hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no); + applog(LOG_NOTICE, "Accepted %s %sPU %d thread %d pool %d", + hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no); else - applog(LOG_NOTICE, "Accepted %.8s %sPU %d thread %d", - hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id); + applog(LOG_NOTICE, "Accepted %s %sPU %d thread %d", + hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id); } if (opt_shares && total_accepted >= opt_shares) { applog(LOG_WARNING, "Successfully mined %d accepted shares as requested and exiting.", opt_shares); @@ -2076,11 +2140,11 @@ static bool submit_upstream_work(const struct work *work) applog(LOG_DEBUG, "PROOF OF WORK RESULT: false (booooo)"); if (!QUIET) { if (total_pools > 1) - applog(LOG_NOTICE, "Rejected %.8s %sPU %d thread %d pool %d", - hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no); + applog(LOG_NOTICE, "Rejected %s %sPU %d thread %d pool %d", + hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id, work->pool->pool_no); else - applog(LOG_NOTICE, "Rejected %.8s %sPU %d thread %d", - hexstr + 152, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id); + applog(LOG_NOTICE, "Rejected %s %sPU %d thread %d", + hashshow, cgpu->is_gpu? "G" : "C", cgpu->cpu_gpu, thr_id); } }