Browse Source

Merge branch 'retrodiff' into bfgminer

Luke Dashjr 10 years ago
parent
commit
fbe4f60196
2 changed files with 27 additions and 1 deletions
  1. 26 1
      miner.c
  2. 1 0
      miner.h

+ 26 - 1
miner.c

@@ -1216,6 +1216,19 @@ static
 void pool_set_uri(struct pool * const pool, char * const uri)
 void pool_set_uri(struct pool * const pool, char * const uri)
 {
 {
 	pool->rpc_url = uri;
 	pool->rpc_url = uri;
+	pool->pool_diff_effective_retroactively = uri_get_param_bool2(uri, "retrodiff");
+}
+
+static
+bool pool_diff_effective_retroactively(struct pool * const pool)
+{
+	if (pool->pool_diff_effective_retroactively != BTS_UNKNOWN) {
+		return pool->pool_diff_effective_retroactively;
+	}
+	
+	// By default, we enable retrodiff for stratum pools since some servers implement mining.set_difficulty in this way
+	// Note that share_result will explicitly disable BTS_UNKNOWN -> BTS_FALSE if a retrodiff share is rejected specifically for its failure to meet the target.
+	return pool->stratum_active;
 }
 }
 
 
 /* Pool variant of test and set */
 /* Pool variant of test and set */
@@ -5264,6 +5277,15 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
 		char reason[32];
 		char reason[32];
 		put_in_parens(reason, sizeof(reason), extract_reject_reason(val, res, err, work));
 		put_in_parens(reason, sizeof(reason), extract_reject_reason(val, res, err, work));
 		applog(LOG_DEBUG, "Share above target rejected%s by pool %u as expected, ignoring", reason, pool->pool_no);
 		applog(LOG_DEBUG, "Share above target rejected%s by pool %u as expected, ignoring", reason, pool->pool_no);
+		
+		// Stratum error 23 is "low difficulty share", which suggests this pool tracks job difficulty correctly.
+		// Therefore, we disable retrodiff if it was enabled-by-default.
+		if (pool->pool_diff_effective_retroactively == BTS_UNKNOWN) {
+			json_t *errnum;
+			if (work->stratum && err && json_is_array(err) && json_array_size(err) >= 1 && (errnum = json_array_get(err, 0)) && json_is_number(errnum) && ((int)json_number_value(errnum)) == 23) {
+				pool->pool_diff_effective_retroactively = false;
+			}
+		}
 	} else {
 	} else {
 		mutex_lock(&stats_lock);
 		mutex_lock(&stats_lock);
 		cgpu->rejected++;
 		cgpu->rejected++;
@@ -10599,7 +10621,7 @@ enum test_nonce2_result _test_nonce2(struct work *work, uint32_t nonce, bool che
 	{
 	{
 		bool high_hash = true;
 		bool high_hash = true;
 		struct pool * const pool = work->pool;
 		struct pool * const pool = work->pool;
-		if (pool->stratum_active)
+		if (pool_diff_effective_retroactively(pool))
 		{
 		{
 			// Some stratum pools are buggy and expect difficulty changes to be immediate retroactively, so if the target has changed, check and submit just in case
 			// Some stratum pools are buggy and expect difficulty changes to be immediate retroactively, so if the target has changed, check and submit just in case
 			if (memcmp(pool->next_target, work->target, sizeof(work->target)))
 			if (memcmp(pool->next_target, work->target, sizeof(work->target)))
@@ -10607,7 +10629,10 @@ enum test_nonce2_result _test_nonce2(struct work *work, uint32_t nonce, bool che
 				applog(LOG_DEBUG, "Stratum pool %u target has changed since work job issued, checking that too",
 				applog(LOG_DEBUG, "Stratum pool %u target has changed since work job issued, checking that too",
 				       pool->pool_no);
 				       pool->pool_no);
 				if (hash_target_check_v(work->hash, pool->next_target))
 				if (hash_target_check_v(work->hash, pool->next_target))
+				{
 					high_hash = false;
 					high_hash = false;
+					work->work_difficulty = target_diff(pool->next_target);
+				}
 			}
 			}
 		}
 		}
 		if (high_hash)
 		if (high_hash)

+ 1 - 0
miner.h

@@ -1365,6 +1365,7 @@ struct pool {
 	char work_restart_timestamp[11];
 	char work_restart_timestamp[11];
 	uint32_t	block_id;
 	uint32_t	block_id;
 	struct mining_goal_info *goal;
 	struct mining_goal_info *goal;
+	enum bfg_tristate pool_diff_effective_retroactively;
 
 
 	enum pool_protocol proto;
 	enum pool_protocol proto;