Browse Source

Merge branch 'stratum_transparency' into bfgminer

Luke Dashjr 13 years ago
parent
commit
d664097c67
2 changed files with 19 additions and 2 deletions
  1. 17 1
      miner.c
  2. 2 1
      util.c

+ 17 - 1
miner.c

@@ -5344,8 +5344,23 @@ bool parse_stratum_response(struct pool *pool, char *s)
 
 	if (!json_is_integer(id_val)) {
 		if (json_is_string(id_val)
-		 && !strcmp(json_string_value(id_val), "txlist")
+		 && !strncmp(json_string_value(id_val), "txlist", 6)
+		 && !strcmp(json_string_value(id_val) + 6, pool->swork.job_id)
 		 && json_is_array(res_val)) {
+			// Check that the transactions actually hash to the merkle links
+			{
+				size_t maxtx = 1 << pool->swork.merkles;
+				size_t mintx = maxtx >> 1;
+				--maxtx;
+				size_t acttx = json_array_size(res_val);
+				if (acttx < mintx || acttx > maxtx) {
+					applog(LOG_WARNING, "Pool %u is sending mismatched block contents to us (%u is not %u-%u)",
+					       pool->pool_no, acttx, mintx, maxtx);
+					goto fishy;
+				}
+				// TODO: Check hashes match actual merkle links
+			}
+
 			if (pool->swork.opaque) {
 				pool->swork.opaque = false;
 				applog(LOG_NOTICE, "Pool %u now providing block contents to us",
@@ -5353,6 +5368,7 @@ bool parse_stratum_response(struct pool *pool, char *s)
 			}
 			pool->swork.transparency_time = (time_t)-1;
 
+fishy:
 			ret = true;
 		}
 

+ 2 - 1
util.c

@@ -1110,7 +1110,8 @@ static bool parse_notify(struct pool *pool, json_t *val)
 		// Request transaction data to discourage pools from doing anything shady
 		char s[1024];
 		int sLen;
-		sLen = sprintf(s, "{\"params\": [\"%s\"], \"id\": \"txlist\", \"method\": \"mining.get_transactions\"}",
+		sLen = sprintf(s, "{\"params\": [\"%s\"], \"id\": \"txlist%s\", \"method\": \"mining.get_transactions\"}",
+		        pool->swork.job_id,
 		        pool->swork.job_id);
 		stratum_send(pool, s, sLen);
 		if ((!pool->swork.opaque) && pool->swork.transparency_time == (time_t)-1)