Skip to content

Commit

Permalink
wildkeccak, basic stratum port of rpc 2.0
Browse files Browse the repository at this point in the history
scratchpad delete fix and redownload, reduce rejects

(work in progress)
  • Loading branch information
tpruvot committed Jan 6, 2017
1 parent 099389f commit 2bbccc5
Show file tree
Hide file tree
Showing 22 changed files with 3,038 additions and 21 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ccminer_SOURCES = elist.h miner.h compat.h \
Algo256/blake256.cu Algo256/decred.cu Algo256/vanilla.cu Algo256/keccak256.cu \
Algo256/blake2s.cu sph/blake2s.c \
Algo256/bmw.cu Algo256/cuda_bmw.cu \
crypto/xmr-rpc.cpp crypto/wildkeccak-cpu.cpp crypto/wildkeccak.cu \
JHA/jackpotcoin.cu JHA/cuda_jha_keccak512.cu \
JHA/cuda_jha_compactionTest.cu cuda_checkhash.cu \
quark/cuda_jh512.cu quark/cuda_quark_blake512.cu quark/cuda_quark_groestl512.cu quark/cuda_skein512.cu \
Expand Down
12 changes: 11 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

ccminer 1.8.4 (Dec. 2016) "Winter boosts: sib, veltor, blake2s"
ccminer 2.0 (December 2016) "Boolberry's WildKeccak RPC 2.0"
---------------------------------------------------------------

***************************************************************
Expand Down Expand Up @@ -51,6 +51,7 @@ Woodcoin (Double Skein)
Vanilla (Blake256 8-rounds - double sha256)
Vertcoin Lyra2RE
Ziftrcoin (ZR5)
Boolberry (Wild Keccak)

where some of these coins have a VERY NOTABLE nVidia advantage
over competing AMD (OpenCL Only) implementations.
Expand Down Expand Up @@ -110,6 +111,7 @@ its command line interface and options.
vanilla use to mine Vanilla (Blake256)
veltor use to mine VeltorCoin
whirlpool use to mine Joincoin
wildkeccak use to mine Boolberry (Stratum only)
zr5 use to mine ZiftrCoin

-d, --devices gives a comma separated list of CUDA device IDs
Expand Down Expand Up @@ -184,6 +186,12 @@ Scrypt specific options:
--no-autotune disable auto-tuning of kernel launch parameters


Boolberry specific:
-l, --launch-config gives the launch configuration for each kernel
in a comma separated list, one per device.
-k, --scratchpad url Url used to download the scratchpad cache.


>>> Examples <<<


Expand All @@ -206,6 +214,8 @@ Example for Fuguecoin pool mining on dwarfpool.com with all your GPUs
Example for Groestlcoin solo mining
ccminer -q -s 1 -a groestl -o http://127.0.0.1:1441/ -u USERNAME -p PASSWORD

Example for Boolberry
ccminer -a wildkeccak -o stratum+tcp://bbr.suprnova.cc:7777 -u tpruvot.donate -p x -k http://bbr.suprnova.cc/scratchpad.bin -l 64x360

Example for Scrypt-N (2048) on Nicehash
ccminer -a scrypt:10 -o stratum+tcp://stratum.nicehash.com:3335 -u 3EujYFcoBzWvpUEvbe3obEG95mBuU88QBD -p x
Expand Down
2 changes: 2 additions & 0 deletions algos.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum sha_algos {
ALGO_WHIRLCOIN,
ALGO_WHIRLPOOL,
ALGO_WHIRLPOOLX,
ALGO_WILDKECCAK,
ALGO_ZR5,
ALGO_AUTO,
ALGO_COUNT
Expand Down Expand Up @@ -99,6 +100,7 @@ static const char *algo_names[] = {
"whirlcoin",
"whirlpool",
"whirlpoolx",
"wildkeccak",
"zr5",
"auto", /* reserved for multi algo */
""
Expand Down
1 change: 1 addition & 0 deletions bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void algo_free_all(int thr_id)
free_veltor(thr_id);
free_whirl(thr_id);
//free_whirlx(thr_id);
free_wildkeccak(thr_id);
free_x11evo(thr_id);
free_x11(thr_id);
free_x13(thr_id);
Expand Down
107 changes: 96 additions & 11 deletions ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "miner.h"
#include "algos.h"
#include "sia/sia-rpc.h"
#include "crypto/xmr-rpc.h"

#include <cuda_runtime.h>

#ifdef WIN32
Expand Down Expand Up @@ -95,7 +97,7 @@ bool allow_mininginfo = true;
bool check_dups = false;
bool check_stratum_jobs = false;

static bool submit_old = false;
bool submit_old = false;
bool use_syslog = false;
bool use_colors = true;
int use_pok = 0;
Expand Down Expand Up @@ -160,6 +162,8 @@ volatile bool pool_is_switching = false;
volatile int pool_switch_count = 0;
bool conditional_pool_rotate = false;

extern char* opt_scratchpad_url;

// current connection
char *rpc_user = NULL;
char *rpc_pass;
Expand Down Expand Up @@ -257,6 +261,7 @@ Options:\n\
x14 X14\n\
x15 X15\n\
x17 X17\n\
wildkeccak Boolberry\n\
zr5 ZR5 (ZiftrCoin)\n\
-d, --devices Comma separated list of CUDA devices to use.\n\
Device IDs start counting from 0! Alternatively takes\n\
Expand Down Expand Up @@ -335,7 +340,7 @@ static char const short_options[] =
#ifdef HAVE_SYSLOG_H
"S"
#endif
"a:Bc:i:Dhp:Px:f:m:nqr:R:s:t:T:o:u:O:Vd:N:b:l:L:";
"a:Bc:k:i:Dhp:Px:f:m:nqr:R:s:t:T:o:u:O:Vd:N:b:l:L:";

struct option options[] = {
{ "algo", 1, NULL, 'a' },
Expand All @@ -360,9 +365,10 @@ struct option options[] = {
{ "no-stratum", 0, NULL, 1007 },
{ "no-autotune", 0, NULL, 1004 }, // scrypt
{ "interactive", 1, NULL, 1050 }, // scrypt
{ "launch-config", 1, NULL, 'l' }, // scrypt
{ "lookup-gap", 1, NULL, 'L' }, // scrypt
{ "texture-cache", 1, NULL, 1051 },// scrypt
{ "launch-config", 1, NULL, 'l' }, // scrypt & bbr
{ "scratchpad", 1, NULL, 'k' }, // bbr
{ "max-temp", 1, NULL, 1060 },
{ "max-diff", 1, NULL, 1061 },
{ "max-rate", 1, NULL, 1062 },
Expand Down Expand Up @@ -431,6 +437,13 @@ Scrypt specific options:\n\
--no-autotune disable auto-tuning of kernel launch parameters\n\
";

static char const xmr_usage[] = "\n\
CryptoNote specific options:\n\
-l, --launch-config gives the launch configuration for each kernel\n\
in a comma separated list, one per device.\n\
-k, --scratchpad url Url used to download the scratchpad cache.\n\
";

struct work _ALIGN(64) g_work;
volatile time_t g_work_time;
pthread_mutex_t g_work_lock;
Expand Down Expand Up @@ -544,8 +557,7 @@ void proper_exit(int reason)
exit(reason);
}

static bool jobj_binary(const json_t *obj, const char *key,
void *buf, size_t buflen)
bool jobj_binary(const json_t *obj, const char *key, void *buf, size_t buflen)
{
const char *hexstr;
json_t *tmp;
Expand Down Expand Up @@ -608,6 +620,8 @@ static bool work_decode(const json_t *val, struct work *work)
data_size = 80;
adata_sz = data_size / 4;
break;
case ALGO_WILDKECCAK:
return rpc2_job_decode(val, work);
default:
data_size = 128;
adata_sz = data_size / 4;
Expand Down Expand Up @@ -780,6 +794,18 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
bool stale_work = false;
int idnonce = 0;

if (pool->type & POOL_STRATUM && stratum.rpc2) {
struct work submit_work;
memcpy(&submit_work, work, sizeof(struct work));
bool sent = hashlog_already_submittted(submit_work.job_id, submit_work.nonces[0]);
if (sent) {
return true;
}
bool ret = rpc2_stratum_submit(pool, &submit_work);
hashlog_remember_submit(&submit_work, submit_work.nonces[0]);
return ret;
}

/* discard if a newer block was received */
stale_work = work->height && work->height < g_work.height;
if (have_stratum && !stale_work && opt_algo != ALGO_ZR5 && opt_algo != ALGO_SCRYPT_JANE) {
Expand Down Expand Up @@ -1405,6 +1431,9 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
uchar merkle_root[64] = { 0 };
int i;

if (sctx->rpc2)
return rpc2_stratum_gen_work(sctx, work);

if (!sctx->job.job_id) {
// applog(LOG_WARNING, "stratum_gen_work: job not yet retrieved");
return false;
Expand Down Expand Up @@ -1733,10 +1762,16 @@ static void *miner_thread(void *userdata)

uint32_t *nonceptr = (uint32_t*) (((char*)work.data) + wcmplen);

if (opt_algo == ALGO_WILDKECCAK) {
nonceptr = (uint32_t*) (((char*)work.data) + 1);
wcmpoft = 2;
wcmplen = 32;
}

if (have_stratum) {
uint32_t sleeptime = 0;

if (opt_algo == ALGO_DECRED)
if (opt_algo == ALGO_DECRED || stratum.rpc2)
work_done = true; // force "regen" hash
while (!work_done && time(NULL) >= (g_work_time + opt_scantime)) {
usleep(100*1000);
Expand All @@ -1748,7 +1783,7 @@ static void *miner_thread(void *userdata)
}
if (sleeptime && opt_debug && !opt_quiet)
applog(LOG_DEBUG, "sleeptime: %u ms", sleeptime*100);
nonceptr = (uint32_t*) (((char*)work.data) + wcmplen);
//nonceptr = (uint32_t*) (((char*)work.data) + wcmplen);
pthread_mutex_lock(&g_work_lock);
extrajob |= work_done;

Expand Down Expand Up @@ -1835,6 +1870,8 @@ static void *miner_thread(void *userdata)
nonceptr[1] += 1;
nonceptr[2] |= thr_id;

} else if (opt_algo == ALGO_WILDKECCAK) {
//nonceptr[1] += 1;
} else if (opt_algo == ALGO_SIA) {
// suprnova job_id check without data/target/height change...
if (have_stratum && strcmp(work.job_id, g_work.job_id)) {
Expand Down Expand Up @@ -1879,6 +1916,11 @@ static void *miner_thread(void *userdata)
gpulog(LOG_DEBUG, thr_id, "no data");
continue;
}
if (stratum.rpc2 && !scratchpad_size) {
sleep(1);
if (!thr_id) pools[cur_pooln].wait_time += 1;
continue;
}

/* conditional mining */
if (!wanna_mine(thr_id)) {
Expand Down Expand Up @@ -2196,6 +2238,9 @@ static void *miner_thread(void *userdata)
//case ALGO_WHIRLPOOLX:
// rc = scanhash_whirlx(thr_id, &work, max_nonce, &hashes_done);
// break;
case ALGO_WILDKECCAK:
rc = scanhash_wildkeccak(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_X11EVO:
rc = scanhash_x11evo(thr_id, &work, max_nonce, &hashes_done);
break;
Expand Down Expand Up @@ -2242,6 +2287,7 @@ static void *miner_thread(void *userdata)
case ALGO_LBRY:
case ALGO_SIA:
case ALGO_VELTOR:
case ALGO_WILDKECCAK:
// migrated algos
break;
case ALGO_ZR5:
Expand All @@ -2254,6 +2300,13 @@ static void *miner_thread(void *userdata)
work.nonces[1] = nonceptr[2];
}

if (stratum.rpc2 && rc == -EBUSY || work_restart[thr_id].restart) {
// bbr scratchpad download or stale result
sleep(1);
if (!thr_id) pools[cur_pooln].wait_time += 1;
continue;
}

if (rc > 0 && opt_debug)
applog(LOG_NOTICE, CL_CYN "found => %08x" CL_GRN " %08x", work.nonces[0], swab32(work.nonces[0]));
if (rc > 1 && opt_debug)
Expand Down Expand Up @@ -2548,7 +2601,7 @@ static bool stratum_handle_response(char *buf)
err_val = json_object_get(val, "error");
id_val = json_object_get(val, "id");

if (!id_val || json_is_null(id_val) || !res_val)
if (!id_val || json_is_null(id_val))
goto out;

// ignore late login answers
Expand All @@ -2564,8 +2617,24 @@ static bool stratum_handle_response(char *buf)
// store time required to the pool to answer to a submit
stratum.answer_msec = (1000 * diff.tv_sec) + (uint32_t) (0.001 * diff.tv_usec);

share_result(json_is_true(res_val), stratum.pooln, stratum.sharediff,
err_val ? json_string_value(json_array_get(err_val, 1)) : NULL);
if (stratum.rpc2) {

const char* reject_reason = err_val ? json_string_value(json_object_get(err_val, "message")) : NULL;
// {"id":4,"jsonrpc":"2.0","error":null,"result":{"status":"OK"}}
share_result(json_is_null(err_val), stratum.pooln, stratum.sharediff, reject_reason);
if (reject_reason) {
g_work_time = 0;
restart_threads();
}

} else {

if (!res_val)
goto out;

share_result(json_is_true(res_val), stratum.pooln, stratum.sharediff,
err_val ? json_string_value(json_array_get(err_val, 1)) : NULL);
}

ret = true;
out:
Expand Down Expand Up @@ -2641,6 +2710,10 @@ static void *stratum_thread(void *userdata)
}
}

if (opt_algo == ALGO_WILDKECCAK) {
rpc2_stratum_thread_stuff(pool);
}

if (switchn != pool_switch_count) goto pool_switched;

if (stratum.job.job_id &&
Expand Down Expand Up @@ -2733,6 +2806,9 @@ static void show_usage_and_exit(int status)
if (opt_algo == ALGO_SCRYPT || opt_algo == ALGO_SCRYPT_JANE) {
printf(scrypt_usage);
}
if (opt_algo == ALGO_WILDKECCAK) {
printf(xmr_usage);
}
proper_exit(status);
}

Expand Down Expand Up @@ -2814,6 +2890,9 @@ void parse_arg(int key, char *arg)
}
break;
}
case 'k':
opt_scratchpad_url = strdup(arg);
break;
case 'i':
d = atof(arg);
v = (uint32_t) d;
Expand Down Expand Up @@ -3011,7 +3090,7 @@ void parse_arg(int key, char *arg)
case 1004:
opt_autotune = false;
break;
case 'l': /* scrypt --launch-config */
case 'l': /* --launch-config */
{
char *last = NULL, *pch = strtok(arg,",");
int n = 0;
Expand Down Expand Up @@ -3582,6 +3661,12 @@ int main(int argc, char *argv[])
allow_mininginfo = false;
}

if (opt_algo == ALGO_WILDKECCAK) {
rpc2_init();
applog(LOG_INFO, "Using CryptoNote JSON-RPC 2.0");
GetScratchpad();
}

flags = !opt_benchmark && strncmp(rpc_url, "https:", 6)
? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)
: CURL_GLOBAL_ALL;
Expand Down
Loading

0 comments on commit 2bbccc5

Please sign in to comment.