Browse Source

proxy: Minimise minimum difficulty for proxy clients

Luke Dashjr 11 years ago
parent
commit
0d7f31efa9
3 changed files with 13 additions and 5 deletions
  1. 6 3
      driver-proxy.c
  2. 5 2
      driver-stratum.c
  3. 2 0
      miner.h

+ 6 - 3
driver-proxy.c

@@ -99,7 +99,7 @@ struct proxy_client *proxy_find_or_create_client(const char *username)
 			.threads = 0,
 			.threads = 0,
 			.device_data = client,
 			.device_data = client,
 			.device_path = user,
 			.device_path = user,
-			.min_nonce_diff = (opt_scrypt ? (1./0x10000) : 1.),
+			.min_nonce_diff = minimum_pdiff,
 		};
 		};
 		timer_set_now(&cgpu->cgminer_stats.start_tv);
 		timer_set_now(&cgpu->cgminer_stats.start_tv);
 		if (unlikely(!create_new_cgpus(add_cgpu_live, cgpu)))
 		if (unlikely(!create_new_cgpus(add_cgpu_live, cgpu)))
@@ -133,14 +133,17 @@ struct proxy_client *proxy_find_or_create_client(const char *username)
 	return client;
 	return client;
 }
 }
 
 
+// See also, stratumsrv_init_diff in driver-stratum.c
 static
 static
 const char *proxy_set_diff(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const success)
 const char *proxy_set_diff(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const success)
 {
 {
 	struct proxy_client * const client = proc->device_data;
 	struct proxy_client * const client = proc->device_data;
-	const double nv = atof(newvalue);
-	if (nv <= 0)
+	double nv = atof(newvalue);
+	if (nv < 0)
 		return "Invalid difficulty";
 		return "Invalid difficulty";
 	
 	
+	if (nv <= minimum_pdiff)
+		nv = minimum_pdiff;
 	client->desired_share_pdiff = nv;
 	client->desired_share_pdiff = nv;
 	
 	
 #ifdef USE_LIBEVENT
 #ifdef USE_LIBEVENT

+ 5 - 2
driver-stratum.c

@@ -644,15 +644,18 @@ void stratumsrv_event(struct bufferevent *bev, short events, void *p)
 	}
 	}
 }
 }
 
 
+// See also, proxy_set_diff in driver-proxy.c
 static
 static
 const char *stratumsrv_init_diff(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const success)
 const char *stratumsrv_init_diff(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const success)
 {
 {
 	struct stratumsrv_conn * const conn = proc->device_data;
 	struct stratumsrv_conn * const conn = proc->device_data;
 	
 	
-	const double nv = atof(newvalue);
-	if (nv <= 0)
+	double nv = atof(newvalue);
+	if (nv < 0)
 		return "Invalid difficulty";
 		return "Invalid difficulty";
 	
 	
+	if (nv <= minimum_pdiff)
+		nv = minimum_pdiff;
 	conn->desired_share_pdiff = nv;
 	conn->desired_share_pdiff = nv;
 	
 	
 	return NULL;
 	return NULL;

+ 2 - 0
miner.h

@@ -21,6 +21,7 @@
 #include <winsock2.h>
 #include <winsock2.h>
 #endif
 #endif
 
 
+#include <float.h>
 #include <stdbool.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdint.h>
 #include <sys/time.h>
 #include <sys/time.h>
@@ -1061,6 +1062,7 @@ extern void hashmeter2(struct thr_info *);
 extern bool stale_work(struct work *, bool share);
 extern bool stale_work(struct work *, bool share);
 extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
 extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
 extern void blkhashstr(char *out, const unsigned char *hash);
 extern void blkhashstr(char *out, const unsigned char *hash);
+static const float minimum_pdiff = max(FLT_MIN, 1./0x100000000);
 extern void set_target_to_pdiff(void *dest_target, double pdiff);
 extern void set_target_to_pdiff(void *dest_target, double pdiff);
 #define bdiff_to_pdiff(n) (n * 1.0000152587)
 #define bdiff_to_pdiff(n) (n * 1.0000152587)
 extern void set_target_to_bdiff(void *dest_target, double bdiff);
 extern void set_target_to_bdiff(void *dest_target, double bdiff);