Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ Options for both config file and command line:
--sharelog <arg> Append share log to file
--shares <arg> Quit after mining N shares (default: unlimited)
--socks-proxy <arg> Set socks4 proxy (host:port)
--suggest-diff <arg> Suggest miner difficulty for pool to user (default: none)
--syslog Use system log for output messages (default: standard error)
--temp-cutoff <arg> Temperature where a device will be automatically disabled, one value or comma separated list (default: 95)
--text-only|-T Disable ncurses formatted screen output
Expand Down
49 changes: 31 additions & 18 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool opt_loginput;
bool opt_compact;
const int opt_cutofftemp = 95;
int opt_log_interval = 5;
int opt_queue = 9999;
int opt_queue = 1;
static int max_queue = 1;
int opt_scantime = -1;
int opt_expiry = 120;
Expand Down Expand Up @@ -438,7 +438,7 @@ struct stratum_share {
static struct stratum_share *stratum_shares = NULL;

char *opt_socks_proxy = NULL;

int opt_suggest_diff;
static const char def_conf[] = "cgminer.conf";
static char *default_config;
static bool config_loaded;
Expand Down Expand Up @@ -1735,6 +1735,9 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--socks-proxy",
opt_set_charp, NULL, &opt_socks_proxy,
"Set socks4 proxy (host:port)"),
OPT_WITH_ARG("--suggest-diff",
opt_set_intval, NULL, &opt_suggest_diff,
"Suggest miner difficulty for pool to user (default: none)"),
#ifdef HAVE_SYSLOG_H
OPT_WITHOUT_ARG("--syslog",
opt_set_bool, &use_syslog,
Expand Down Expand Up @@ -6236,7 +6239,7 @@ static void stratum_share_result(json_t *val, json_t *res_val, json_t *err_val,
static bool parse_stratum_response(struct pool *pool, char *s)
{
json_t *val = NULL, *err_val, *res_val, *id_val;
struct stratum_share *sshare;
struct stratum_share *sshare = NULL;
json_error_t err;
bool ret = false;
int id;
Expand Down Expand Up @@ -6268,13 +6271,15 @@ static bool parse_stratum_response(struct pool *pool, char *s)

id = json_integer_value(id_val);

mutex_lock(&sshare_lock);
HASH_FIND_INT(stratum_shares, &id, sshare);
if (sshare) {
HASH_DEL(stratum_shares, sshare);
pool->sshares--;
if (!opt_lowmem) {
mutex_lock(&sshare_lock);
HASH_FIND_INT(stratum_shares, &id, sshare);
if (sshare) {
HASH_DEL(stratum_shares, sshare);
pool->sshares--;
}
mutex_unlock(&sshare_lock);
}
mutex_unlock(&sshare_lock);

if (!sshare) {
double pool_diff;
Expand All @@ -6286,7 +6291,8 @@ static bool parse_stratum_response(struct pool *pool, char *s)
cg_runlock(&pool->data_lock);

if (json_is_true(res_val)) {
applog(LOG_NOTICE, "Accepted untracked stratum share from pool %d", pool->pool_no);
applog(LOG_NOTICE, "Accepted%s stratum share from pool %d",
opt_lowmem ? "" : " untracked", pool->pool_no);

/* We don't know what device this came from so we can't
* attribute the work to the relevant cgpu */
Expand All @@ -6297,7 +6303,8 @@ static bool parse_stratum_response(struct pool *pool, char *s)
pool->diff_accepted += pool_diff;
mutex_unlock(&stats_lock);
} else {
applog(LOG_NOTICE, "Rejected untracked stratum share from pool %d", pool->pool_no);
applog(LOG_NOTICE, "Rejected%s stratum share from pool %d",
opt_lowmem ? "" : " untracked", pool->pool_no);

mutex_lock(&stats_lock);
total_rejected++;
Expand Down Expand Up @@ -6626,12 +6633,14 @@ static void *stratum_sthread(void *userdata)
if (pool_tclear(pool, &pool->submit_fail))
applog(LOG_WARNING, "Pool %d communication resumed, submitting work", pool->pool_no);

mutex_lock(&sshare_lock);
HASH_ADD_INT(stratum_shares, id, sshare);
pool->sshares++;
mutex_unlock(&sshare_lock);
if (!opt_lowmem) {
mutex_lock(&sshare_lock);
HASH_ADD_INT(stratum_shares, id, sshare);
pool->sshares++;
mutex_unlock(&sshare_lock);

applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db");
applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db");
}
submitted = true;
break;
}
Expand Down Expand Up @@ -7141,6 +7150,7 @@ bool submit_nonce2_nonce(struct thr_info *thr, struct pool *pool, struct pool *r

work->mined = true;
work->device_diff = MIN(drv->max_diff, work->work_difficulty);
work->device_diff = MAX(drv->min_diff, work->device_diff);

ret = submit_nonce(thr, work, nonce);
free_work(work);
Expand Down Expand Up @@ -7429,6 +7439,7 @@ struct work *get_work(struct thr_info *thr, const int thr_id)
thread_reportin(thr);
work->mined = true;
work->device_diff = MIN(cgpu->drv->max_diff, work->work_difficulty);
work->device_diff = MAX(cgpu->drv->min_diff, work->device_diff);
return work;
}

Expand Down Expand Up @@ -7735,6 +7746,7 @@ static void hash_sole_work(struct thr_info *mythr)
break;
}
work->device_diff = MIN(drv->max_diff, work->work_difficulty);
work->device_diff = MAX(drv->min_diff, work->device_diff);

do {
cgtime(&tv_start);
Expand Down Expand Up @@ -7900,10 +7912,10 @@ struct work *get_queued(struct cgpu_info *cgpu)
work = cgpu->unqueued_work;
if (unlikely(stale_work(work, false))) {
discard_work(work);
wake_gws();
} else
__add_queued(cgpu, work);
cgpu->unqueued_work = NULL;
wake_gws();
}
wr_unlock(&cgpu->qlock);

Expand Down Expand Up @@ -9337,7 +9349,7 @@ void fill_device_drv(struct device_drv *drv)
if (!drv->zero_stats)
drv->zero_stats = &noop_zero_stats;
if (!drv->max_diff)
drv->max_diff = 1;
drv->max_diff = 0xffffffffull;
}

void null_device_drv(struct device_drv *drv)
Expand Down Expand Up @@ -9373,6 +9385,7 @@ void null_device_drv(struct device_drv *drv)

drv->zero_stats = &noop_zero_stats;
drv->max_diff = 1;
drv->min_diff = 1;
}

void enable_device(struct cgpu_info *cgpu)
Expand Down
9 changes: 8 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,14 @@ if test "x$want_usbutils" != xfalse; then
AC_CONFIG_SUBDIRS([compat/libusb-1.0])
LIBUSB_LIBS="compat/libusb-1.0/libusb/.libs/libusb-1.0.a"
if test "x$have_linux" = "xtrue"; then
LIBUSB_LIBS+=" -ludev"
AC_ARG_ENABLE([udev],
[AC_HELP_STRING([--disable-udev],[Disable building libusb with udev])],
[udev=$enableval]
)

if test "x$udev" != xno; then
LIBUSB_LIBS+=" -ludev"
fi
fi
if test "x$have_darwin" = "xtrue"; then
LIBUSB_LIBS+=" -lobjc"
Expand Down
47 changes: 24 additions & 23 deletions driver-bitmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ static int bitmain_set_txtask(uint8_t * sendbuf,
memcpy(bm->works[cursendcount].data2, works[index]->data + 64, 12);

if(cursendcount == 0) {
pooldiff = (unsigned int)(works[index]->sdiff);
pooldiff = (unsigned int)(works[index]->device_diff);
difftmp = pooldiff;
while(1) {
difftmp = difftmp >> 1;
Expand Down Expand Up @@ -1095,6 +1095,8 @@ static void bitmain_update_temps(struct cgpu_info *bitmain, struct bitmain_info
}
}

extern void cg_logwork_uint32(struct work *work, uint32_t nonce, bool ok);

static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info *info,
struct thr_info *thr, uint8_t *buf, int *offset)
{
Expand Down Expand Up @@ -1289,30 +1291,28 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info
free(ob_hex);
}

if(work->work_block < info->last_work_block) {
applog(LOG_ERR, "BitMain: bitmain_parse_rxnonce work(%d) nonce stale", rxnoncedata.nonces[j].work_id);
} else {
if (bitmain_decode_nonce(thr, bitmain, info, rxnoncedata.nonces[j].nonce, work)) {
cg_logwork_uint32(work, rxnoncedata.nonces[j].nonce, true);
if(opt_bitmain_hwerror) {
if(work->work_block < info->last_work_block)
applog(LOG_DEBUG, "BitMain: bitmain_parse_rxnonce work(%d) nonce stale", rxnoncedata.nonces[j].work_id);
if (bitmain_decode_nonce(thr, bitmain, info, rxnoncedata.nonces[j].nonce, work)) {
cg_logwork_uint32(work, rxnoncedata.nonces[j].nonce, true);
if(opt_bitmain_hwerror) {
#ifndef BITMAIN_CALC_DIFF1
mutex_lock(&info->qlock);
idiff = (int)work->sdiff;
info->nonces+=idiff;
info->auto_nonces+=idiff;
mutex_unlock(&info->qlock);
inc_work_status(thr, pool, idiff);
mutex_lock(&info->qlock);
idiff = (int)work->sdiff;
info->nonces+=idiff;
info->auto_nonces+=idiff;
mutex_unlock(&info->qlock);
inc_work_status(thr, pool, idiff);
#endif
} else {
mutex_lock(&info->qlock);
info->nonces++;
info->auto_nonces++;
mutex_unlock(&info->qlock);
}
} else {
//bitmain_inc_nvw(info, thr);
applog(LOG_ERR, "BitMain: bitmain_decode_nonce error work(%d)", rxnoncedata.nonces[j].work_id);
}
} else {
mutex_lock(&info->qlock);
info->nonces++;
info->auto_nonces++;
mutex_unlock(&info->qlock);
}
} else {
//bitmain_inc_nvw(info, thr);
applog(LOG_ERR, "BitMain: bitmain_decode_nonce error work(%d)", rxnoncedata.nonces[j].work_id);
}
free_work(work);
} else {
Expand Down Expand Up @@ -2494,4 +2494,5 @@ struct device_drv bitmain_drv = {
.get_statline_before = get_bitmain_statline_before,
.reinit_device = bitmain_init,
.thread_shutdown = bitmain_shutdown,
.min_diff = 16,
};
2 changes: 1 addition & 1 deletion driver-bitmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ struct bitmain_info {
};

#define BITMAIN_READ_SIZE 12
#define BITMAIN_ARRAY_SIZE 16384
#define BITMAIN_ARRAY_SIZE 32768

#define BTM_GETS_ERROR -1
#define BTM_GETS_OK 0
Expand Down
4 changes: 4 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ struct device_drv {

/* Highest target diff the device supports */
double max_diff;

/* Lowest diff the controller can safely run at */
double min_diff;
};

extern struct device_drv *copy_drv(struct device_drv*);
Expand Down Expand Up @@ -998,6 +1001,7 @@ extern bool opt_protocol;
extern bool have_longpoll;
extern char *opt_kernel_path;
extern char *opt_socks_proxy;
extern int opt_suggest_diff;
extern char *cgminer_path;
extern bool opt_fail_only;
extern bool opt_lowmem;
Expand Down
5 changes: 5 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,11 @@ bool auth_stratum(struct pool *pool)
pool->probed = true;
successful_connect = true;

if (opt_suggest_diff) {
sprintf(s, "{\"id\": %d, \"method\": \"mining.suggest_difficulty(%d)\", \"params\": []}",
swork_id++, opt_suggest_diff);
stratum_send(pool, s, strlen(s));
}
out:
json_decref(val);
return ret;
Expand Down