Browse Source

New --pool-goal option to set a distinct named goal per-pool

Luke Dashjr 11 years ago
parent
commit
4eba0db526
4 changed files with 58 additions and 23 deletions
  1. 1 0
      README
  2. 1 1
      api.c
  3. 51 21
      miner.c
  4. 5 1
      miner.h

+ 1 - 0
README

@@ -289,6 +289,7 @@ Options for both config file and command line:
 --noncelog <arg>    Create log of all nonces found
 --pass|-p <arg>     Password for bitcoin JSON-RPC server
 --per-device-stats  Force verbose mode and output per-device statistics
+--pool-goal <arg>   Named goal for the previous-defined pool
 --pool-priority <arg> Priority for just the previous-defined pool
 --pool-proxy|-x     Proxy URI to use for connecting to just the previous-defined pool
 --protocol-dump|-P  Verbose dump of protocol-level activities

+ 1 - 1
api.c

@@ -3076,7 +3076,7 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
 		root = api_add_const(root, "Hash Method", SHA256STR, false);
 
 	cg_rlock(&ch_lock);
-	struct mining_goal_info * const goal = &global_mining_goal;
+	struct mining_goal_info * const goal = get_mining_goal("default");
 	struct blockchain_info * const blkchain = goal->blkchain;
 	struct block_info * const blkinfo = blkchain->currentblk;
 	root = api_add_time(root, "Current Block Time", &blkinfo->first_seen_time, true);

+ 51 - 21
miner.c

@@ -371,11 +371,7 @@ static char datestamp[40];
 static char best_share[ALLOC_H2B_SHORTV] = "0";
 double best_diff = 0;
 
-static struct blockchain_info global_blkchain;
-struct mining_goal_info global_mining_goal = {
-	.blkchain = &global_blkchain,
-	.current_diff = 0xFFFFFFFFFFFFFFFFULL,
-};
+struct mining_goal_info *mining_goals;
 
 
 int swork_id;
@@ -992,6 +988,33 @@ static void sharelog(const char*disposition, const struct work*work)
 		applog(LOG_ERR, "sharelog fwrite error");
 }
 
+struct mining_goal_info *get_mining_goal(const char * const name)
+{
+	struct mining_goal_info *goal;
+	HASH_FIND_STR(mining_goals, name, goal);
+	if (!goal)
+	{
+		struct block_info * const dummy_block = calloc(sizeof(*dummy_block), 1);
+		memset(dummy_block->prevblkhash, 0, 0x20);
+		
+		struct blockchain_info * const blkchain = malloc(sizeof(*blkchain) + sizeof(*goal));
+		goal = (void*)(&blkchain[1]);
+		
+		*blkchain = (struct blockchain_info){
+			.currentblk = dummy_block,
+		};
+		HASH_ADD(hh, blkchain->blocks, prevblkhash, sizeof(dummy_block->prevblkhash), dummy_block);
+		
+		*goal = (struct mining_goal_info){
+			.name = strdup(name),
+			.blkchain = blkchain,
+			.current_diff = 0xFFFFFFFFFFFFFFFFULL,
+		};
+		HASH_ADD_STR(mining_goals, name, goal);
+	}
+	return goal;
+}
+
 static char *getwork_req = "{\"method\": \"getwork\", \"params\": [], \"id\":0}\n";
 
 /* Adjust all the pools' quota to the greatest common denominator after a pool
@@ -1053,7 +1076,7 @@ struct pool *add_pool(void)
 	mutex_init(&pool->stratum_lock);
 	timer_unset(&pool->swork.tv_transparency);
 	pool->swork.pool = pool;
-	pool->goal = &global_mining_goal;
+	pool->goal = get_mining_goal("default");
 
 	pool->idle = true;
 	/* Make sure the pool doesn't think we've been idle since time 0 */
@@ -1660,6 +1683,20 @@ static char *set_cbcperc(const char *arg)
 	return NULL;
 }
 
+static
+char *set_pool_goal(const char * const arg)
+{
+	struct pool *pool;
+	
+	if (!total_pools)
+		return "Usage of --pool-goal before pools are defined does not make sense";
+	
+	pool = pools[total_pools - 1];
+	pool->goal = get_mining_goal(arg);
+	
+	return NULL;
+}
+
 static char *set_pool_priority(const char *arg)
 {
 	struct pool *pool;
@@ -2350,6 +2387,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--userpass|-O",
 	             set_userpass, NULL, NULL,
 	             "Username:Password pair for bitcoin JSON-RPC server"),
+	OPT_WITH_ARG("--pool-goal",
+			 set_pool_goal, NULL, NULL,
+			 "Named goal for the previous-defined pool"),
 	OPT_WITH_ARG("--pool-priority",
 			 set_pool_priority, NULL, NULL,
 			 "Priority for just the previous-defined pool"),
@@ -3022,7 +3062,8 @@ int work_ntime_range(struct work * const work, const struct timeval * const tvp_
 static
 void refresh_bitcoind_address(const bool fresh)
 {
-	struct blockchain_info * const blkchain = &global_blkchain;
+	struct mining_goal_info * const goal = get_mining_goal("default");
+	struct blockchain_info * const blkchain = goal->blkchain;
 	
 	if (!have_at_least_one_getcbaddr)
 		return;
@@ -3040,7 +3081,7 @@ void refresh_bitcoind_address(const bool fresh)
 		struct pool * const pool = pools[i];
 		if (!uri_get_param_bool(pool->rpc_url, "getcbaddr", false))
 			continue;
-		if (pool->goal->blkchain != blkchain)
+		if (pool->goal != goal)
 			// TODO: Multi-blockchain support
 			continue;
 		
@@ -4186,7 +4227,7 @@ static bool pool_unworkable(const struct pool *);
 static void curses_print_status(const int ts)
 {
 	// TODO: Multi-blockchain support
-	struct mining_goal_info * const goal = &global_mining_goal;
+	struct mining_goal_info * const goal = get_mining_goal("default");
 	struct blockchain_info * const blkchain = goal->blkchain;
 	struct pool *pool = currentpool;
 	struct timeval now, tv;
@@ -7114,7 +7155,7 @@ static void display_pool_summary(struct pool *pool)
 	int pool_secs;
 
 	if (curses_active_locked()) {
-		wlog("Pool: %s\n", pool->rpc_url);
+		wlog("Pool: %s  Goal: %s\n", pool->rpc_url, pool->goal->name);
 		if (pool->solved)
 			wlog("SOLVED %d BLOCK%s!\n", pool->solved, pool->solved > 1 ? "S" : "");
 		if (!pool->has_stratum)
@@ -12488,7 +12529,6 @@ int main(int argc, char *argv[])
 {
 	struct sigaction handler;
 	struct thr_info *thr;
-	struct block_info *block;
 	unsigned int k;
 	int i;
 	int rearrange_pools = 0;
@@ -12631,16 +12671,6 @@ int main(int argc, char *argv[])
 	logstart = devcursor;
 	logcursor = logstart;
 
-	block = calloc(sizeof(*block), 1);
-	if (unlikely(!block))
-		quit (1, "main OOM");
-	memset(block->prevblkhash, 0, 0x20);
-	{
-		struct blockchain_info * const blkchain = &global_blkchain;
-		HASH_ADD(hh, blkchain->blocks, prevblkhash, sizeof(block->prevblkhash), block);
-		blkchain->currentblk = block;
-	}
-
 	mutex_init(&submitting_lock);
 
 #ifdef HAVE_OPENCL

+ 5 - 1
miner.h

@@ -1094,6 +1094,7 @@ extern int enabled_pools;
 extern bool get_intrange(const char *arg, int *val1, int *val2);
 extern bool detect_stratum(struct pool *pool, char *url);
 extern void print_summary(void);
+extern struct mining_goal_info *get_mining_goal(const char *name);
 extern void adjust_quota_gcd(void);
 extern struct pool *add_pool(void);
 extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
@@ -1141,6 +1142,8 @@ struct blockchain_info {
 };
 
 struct mining_goal_info {
+	char *name;
+	
 	struct blockchain_info *blkchain;
 	
 	double current_diff;
@@ -1148,6 +1151,8 @@ struct mining_goal_info {
 	char net_hashrate[ALLOC_H2B_SHORT];
 	
 	char *current_goal_detail;
+	
+	UT_hash_handle hh;
 };
 
 extern struct string_elist *scan_devices;
@@ -1198,7 +1203,6 @@ extern int opt_fail_pause;
 extern int opt_log_interval;
 extern unsigned long long global_hashrate;
 extern unsigned unittest_failures;
-extern struct mining_goal_info global_mining_goal;
 extern double best_diff;
 
 struct curl_ent {