@ -92,6 +92,7 @@ bool use_syslog;
@@ -92,6 +92,7 @@ bool use_syslog;
bool opt_quiet ;
bool opt_realquiet ;
bool opt_loginput ;
bool opt_compact ;
const int opt_cutofftemp = 95 ;
int opt_log_interval = 5 ;
int opt_queue = 1 ;
@ -213,15 +214,17 @@ const
@@ -213,15 +214,17 @@ const
# endif
bool curses_active ;
static char current_block [ 37 ] ;
static char current_block [ 40 ] ;
static char * current_hash ;
char * current_fullhash ;
static char datestamp [ 40 ] ;
static char blocktime [ 30 ] ;
struct timeval block_timeval ;
static char best_share [ 8 ] = " 0 " ;
static uint64_t best_diff = 0 ;
struct block {
char hash [ 37 ] ;
char hash [ 40 ] ;
UT_hash_handle hh ;
int block_no ;
} ;
@ -549,10 +552,10 @@ static char *set_rr(enum pool_strategy *strategy)
@@ -549,10 +552,10 @@ static char *set_rr(enum pool_strategy *strategy)
* stratum + tcp or by detecting a stratum server response */
bool detect_stratum ( struct pool * pool , char * url )
{
if ( opt_scrypt )
if ( ! extract_sockaddr ( pool , url ) )
return false ;
if ( ! extract_sockaddr ( pool , url ) )
if ( opt_scrypt )
return false ;
if ( ! strncasecmp ( url , " stratum+tcp:// " , 14 ) ) {
@ -852,6 +855,13 @@ static struct opt_table opt_config_table[] = {
@@ -852,6 +855,13 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG ( " --bench-algo|-b " ,
set_int_0_to_9999 , opt_show_intval , & opt_bench_algo ,
opt_hidden ) ,
# endif
# ifdef HAVE_CURSES
OPT_WITHOUT_ARG ( " --compact " ,
opt_set_bool , & opt_compact ,
" Use compact display without per device statistics " ) ,
# endif
# ifdef WANT_CPUMINE
OPT_WITH_ARG ( " --cpu-threads|-t " ,
force_nthreads_int , opt_show_intval , & opt_n_threads ,
" Number of miner CPU threads " ) ,
@ -1578,16 +1588,16 @@ static void curses_print_status(void)
@@ -1578,16 +1588,16 @@ static void curses_print_status(void)
wclrtoeol ( statuswin ) ;
if ( pool - > has_stratum ) {
mvwprintw ( statuswin , 4 , 0 , " Connected to %s with stratum as user %s " ,
pool - > stratum _url , pool - > rpc_user ) ;
pool - > sockaddr _url , pool - > rpc_user ) ;
} else if ( ( pool_strategy = = POOL_LOADBALANCE | | pool_strategy = = POOL_BALANCE ) & & total_pools > 1 ) {
mvwprintw ( statuswin , 4 , 0 , " Connected to multiple pools with%s LP " ,
have_longpoll ? " " : " out " ) ;
} else {
mvwprintw ( statuswin , 4 , 0 , " Connected to %s with%s LP as user %s " ,
pool - > rpc _url , have_longpoll ? " " : " out " , pool - > rpc_user ) ;
pool - > sockadd r_url, have_longpoll ? " " : " out " , pool - > rpc_user ) ;
}
wclrtoeol ( statuswin ) ;
mvwprintw ( statuswin , 5 , 0 , " Block: %s... Started: %s " , current_hash , blocktime ) ;
mvwprintw ( statuswin , 5 , 0 , " Block: %s... Started: %s Best share: %s " , current_hash , blocktime , best_shar e ) ;
mvwhline ( statuswin , 6 , 0 , ' - ' , 80 ) ;
mvwhline ( statuswin , statusy - 1 , 0 , ' - ' , 80 ) ;
mvwprintw ( statuswin , devcursor - 1 , 1 , " [P]ool management %s[S]ettings [D]isplay options [Q]uit " ,
@ -1610,7 +1620,7 @@ static void curses_print_devstatus(int thr_id)
@@ -1610,7 +1620,7 @@ static void curses_print_devstatus(int thr_id)
char displayed_hashes [ 16 ] , displayed_rolling [ 16 ] ;
uint64_t dh64 , dr64 ;
if ( devcursor + cgpu - > cgminer_id > LINES - 2 )
if ( devcursor + cgpu - > cgminer_id > LINES - 2 | | opt_compact )
return ;
cgpu - > utility = cgpu - > accepted / total_secs * 60 ;
@ -1670,14 +1680,13 @@ static void print_status(int thr_id)
@@ -1670,14 +1680,13 @@ static void print_status(int thr_id)
# ifdef HAVE_CURSES
/* Check for window resize. Called with curses mutex locked */
static inline bool change_logwinsize ( void )
static inline void change_logwinsize ( void )
{
int x , y , logx , logy ;
bool ret = false ;
getmaxyx ( mainwin , y , x ) ;
if ( x < 80 | | y < 25 )
return ret ;
return ;
if ( y > statusy + 2 & & statusy < logstart ) {
if ( y - 2 < logstart )
@ -1687,17 +1696,13 @@ static inline bool change_logwinsize(void)
@@ -1687,17 +1696,13 @@ static inline bool change_logwinsize(void)
logcursor = statusy + 1 ;
mvwin ( logwin , logcursor , 0 ) ;
wresize ( statuswin , statusy , x ) ;
ret = true ;
}
y - = logcursor ;
getmaxyx ( logwin , logy , logx ) ;
/* Detect screen size change */
if ( x ! = logx | | y ! = logy ) {
if ( x ! = logx | | y ! = logy )
wresize ( logwin , y , x ) ;
ret = true ;
}
return ret ;
}
static void check_winsizes ( void )
@ -1707,6 +1712,7 @@ static void check_winsizes(void)
@@ -1707,6 +1712,7 @@ static void check_winsizes(void)
if ( curses_active_locked ( ) ) {
int y , x ;
erase ( ) ;
x = getmaxx ( statuswin ) ;
if ( logstart > LINES - 2 )
statusy = LINES - 2 ;
@ -1722,6 +1728,18 @@ static void check_winsizes(void)
@@ -1722,6 +1728,18 @@ static void check_winsizes(void)
}
}
static void switch_compact ( void )
{
if ( opt_compact ) {
logstart = devcursor + 1 ;
logcursor = logstart + 1 ;
} else {
logstart = devcursor + total_devices + 1 ;
logcursor = logstart + 1 ;
}
check_winsizes ( ) ;
}
/* For mandatory printing when mutex is already locked */
void wlog ( const char * f , . . . )
{
@ -1770,6 +1788,7 @@ bool log_curses_only(int prio, const char *f, va_list ap)
@@ -1770,6 +1788,7 @@ bool log_curses_only(int prio, const char *f, va_list ap)
void clear_logwin ( void )
{
if ( curses_active_locked ( ) ) {
erase ( ) ;
wclear ( logwin ) ;
unlock_curses ( ) ;
}
@ -1980,17 +1999,26 @@ static uint64_t share_diff(const struct work *work)
@@ -1980,17 +1999,26 @@ static uint64_t share_diff(const struct work *work)
if ( unlikely ( ! d64 ) )
d64 = 1 ;
ret = diffone / d64 ;
if ( ret > best_diff ) {
best_diff = ret ;
suffix_string ( best_diff , best_share , 0 ) ;
}
return ret ;
}
static uint32_t scrypt_diff ( const struct work * work )
{
const uint32_t scrypt_diffone = 0x0000fffful ;
uint32_t d32 = work - > outputhash ;
uint32_t d32 = work - > outputhash , ret ;
if ( unlikely ( ! d32 ) )
d32 = 1 ;
return scrypt_diffone / d32 ;
ret = scrypt_diffone / d32 ;
if ( ret > best_diff ) {
best_diff = ret ;
suffix_string ( best_diff , best_share , 0 ) ;
}
return ret ;
}
static bool submit_upstream_work ( struct work * work , CURL * curl , bool resubmit )
@ -2887,34 +2915,41 @@ static void *submit_work_thread(void *userdata)
@@ -2887,34 +2915,41 @@ static void *submit_work_thread(void *userdata)
}
if ( work - > stratum ) {
struct stratum_share * sshare = calloc ( sizeof ( struct stratum_share ) , 1 ) ;
uint32_t * hash32 = ( uint32_t * ) work - > hash , nonce ;
char * noncehex ;
char s [ 1024 ] ;
memcpy ( & sshare - > work , work , sizeof ( struct work ) ) ;
/* Give the stratum share a unique id */
mutex_lock ( & sshare_lock ) ;
sshare - > id = swork_id + + ;
HASH_ADD_INT ( stratum_shares , id , sshare ) ;
mutex_unlock ( & sshare_lock ) ;
swork_id + + ;
nonce = * ( ( uint32_t * ) ( work - > data + 76 ) ) ;
noncehex = bin2hex ( ( const unsigned char * ) & nonce , 4 ) ;
memset ( s , 0 , 1024 ) ;
sprintf ( s , " { \" params \" : [ \" %s \" , \" %s \" , \" %s \" , \" %s \" , \" %s \" ], \" id \" : %d, \" method \" : \" mining.submit \" } " ,
pool - > rpc_user , work - > job_id , work - > nonce2 , work - > ntime , noncehex , sshare - > id ) ;
pool - > rpc_user , work - > job_id , work - > nonce2 , work - > ntime , noncehex , swork_ id ) ;
free ( noncehex ) ;
applog ( LOG_INFO , " Submitting share %08lx to pool %d " , ( unsigned long ) ( hash32 [ 6 ] ) , pool - > pool_no ) ;
if ( unlikely ( ! stratum_send ( pool , s , strlen ( s ) ) ) ) {
if ( likely ( stratum_send ( pool , s , strlen ( s ) ) ) ) {
struct stratum_share * sshare = calloc ( sizeof ( struct stratum_share ) , 1 ) ;
if ( pool_tclear ( pool , & pool - > submit_fail ) )
applog ( LOG_WARNING , " Pool %d communication resumed, submitting work " , pool - > pool_no ) ;
applog ( LOG_DEBUG , " Successfully submitted, adding to stratum_shares db " ) ;
memcpy ( & sshare - > work , work , sizeof ( struct work ) ) ;
mutex_lock ( & sshare_lock ) ;
HASH_DEL ( stratum_shares , sshare ) ;
sshare - > id = swork_id ;
HASH_ADD_INT ( stratum_shares , id , sshare ) ;
mutex_unlock ( & sshare_lock ) ;
free ( sshare ) ;
} else {
applog ( LOG_INFO , " Failed to submit stratum share " ) ;
if ( ! pool_tset ( pool , & pool - > submit_fail ) ) {
total_ro + + ;
pool - > remotefail_occasions + + ;
applog ( LOG_WARNING , " Pool %d share submission failure " , pool - > pool_no ) ;
}
}
goto out ;
@ -3143,14 +3178,14 @@ static void set_curblock(char *hexstr, unsigned char *hash)
@@ -3143,14 +3178,14 @@ static void set_curblock(char *hexstr, unsigned char *hash)
strcpy ( current_block , hexstr ) ;
swap256 ( hash_swap , hash ) ;
swap256 ( block_hash_swap , hash + 4 ) ;
swap256 ( block_hash_swap , hash + 4 ) ;
/* Don't free current_hash directly to avoid dereferencing when read
* elsewhere - and update block_timeval inside the same lock */
mutex_lock ( & ch_lock ) ;
gettimeofday ( & block_timeval , NULL ) ;
old_hash = current_hash ;
current_hash = bin2hex ( hash_swap , 16 ) ;
current_hash = bin2hex ( hash_swap + 2 , 12 ) ;
free ( old_hash ) ;
old_hash = current_fullhash ;
current_fullhash = bin2hex ( block_hash_swap , 32 ) ;
@ -3793,13 +3828,16 @@ static void display_options(void)
@@ -3793,13 +3828,16 @@ static void display_options(void)
clear_logwin ( ) ;
retry :
wlogprint ( " [N]ormal [C]lear [S]ilent mode (disable all output) \n " ) ;
wlogprint ( " [D]ebug:%s \n [P]er-device:%s \n [Q]uiet:%s \n [V]erbose:%s \n [R]PC debug:%s \n [W]orkTime details:%s \n [L]og interval:%d \n " ,
wlogprint ( " [D]ebug:%s \n [P]er-device:%s \n [Q]uiet:%s \n [V]erbose:%s \n "
" [R]PC debug:%s \n [W]orkTime details:%s \n co[M]pact: %s \n "
" [L]og interval:%d \n " ,
opt_debug ? " on " : " off " ,
want_per_device_stats ? " on " : " off " ,
opt_quiet ? " on " : " off " ,
opt_log_output ? " on " : " off " ,
opt_protocol ? " on " : " off " ,
opt_worktime ? " on " : " off " ,
opt_compact ? " on " : " off " ,
opt_log_interval ) ;
wlogprint ( " Select an option or any other key to return \n " ) ;
input = getch ( ) ;
@ -3818,8 +3856,10 @@ retry:
@@ -3818,8 +3856,10 @@ retry:
opt_debug = false ;
opt_quiet = false ;
opt_protocol = false ;
opt_compact = false ;
want_per_device_stats = false ;
wlogprint ( " Output mode reset to normal \n " ) ;
switch_compact ( ) ;
goto retry ;
} else if ( ! strncasecmp ( & input , " d " , 1 ) ) {
opt_debug ^ = true ;
@ -3828,6 +3868,11 @@ retry:
@@ -3828,6 +3868,11 @@ retry:
opt_quiet = false ;
wlogprint ( " Debug mode %s \n " , opt_debug ? " enabled " : " disabled " ) ;
goto retry ;
} else if ( ! strncasecmp ( & input , " m " , 1 ) ) {
opt_compact ^ = true ;
wlogprint ( " Compact mode %s \n " , opt_compact ? " enabled " : " disabled " ) ;
switch_compact ( ) ;
goto retry ;
} else if ( ! strncasecmp ( & input , " p " , 1 ) ) {
want_per_device_stats ^ = true ;
opt_log_output = want_per_device_stats ;
@ -4278,11 +4323,11 @@ static void *stratum_thread(void *userdata)
@@ -4278,11 +4323,11 @@ static void *stratum_thread(void *userdata)
FD_ZERO ( & rd ) ;
FD_SET ( pool - > sock , & rd ) ;
timeout . tv_sec = 12 0;
timeout . tv_sec = 9 0;
timeout . tv_usec = 0 ;
/* The protocol specifies that notify messages should be sent
* every minute so if we fail to receive any for 2 minute s we
* every minute so if we fail to receive any for 90 second s we
* assume the connection has been dropped and treat this pool
* as dead */
select ( pool - > sock + 1 , & rd , NULL , NULL , & timeout ) ;
@ -5646,6 +5691,7 @@ static void print_summary(void)
@@ -5646,6 +5691,7 @@ static void print_summary(void)
applog ( LOG_WARNING , " Average hashrate: %.1f %shash/s " , displayed_hashes , mhash_base ? " Mega " : " Kilo " ) ;
applog ( LOG_WARNING , " Solved blocks: %d " , found_blocks ) ;
applog ( LOG_WARNING , " Best share difficulty: %s " , best_share ) ;
applog ( LOG_WARNING , " Queued work requests: %d " , total_getworks ) ;
applog ( LOG_WARNING , " Share submissions: %d " , total_accepted + total_rejected ) ;
applog ( LOG_WARNING , " Accepted shares: %d " , total_accepted ) ;
@ -6291,12 +6337,13 @@ int main(int argc, char *argv[])
@@ -6291,12 +6337,13 @@ int main(int argc, char *argv[])
for ( i = 0 ; i < total_devices ; + + i )
devices [ i ] - > cgminer_stats . getwork_wait_min . tv_sec = MIN_SEC_UNSET ;
logstart + = total_devices ;
logcursor = logstart + 1 ;
if ( ! opt_compact ) {
logstart + = total_devices ;
logcursor = logstart + 1 ;
# ifdef HAVE_CURSES
check_winsizes ( ) ;
check_winsizes ( ) ;
# endif
}
if ( ! total_pools ) {
applog ( LOG_WARNING , " Need to specify at least one pool server. " ) ;