Begin implementing a hash database of submissions and attempt sending results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
diff --git a/cgminer.c b/cgminer.c
index 285cd53..55a2ca0 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -170,6 +170,7 @@ static pthread_mutex_t *stgd_lock;
pthread_mutex_t console_lock;
pthread_mutex_t ch_lock;
static pthread_rwlock_t blk_lock;
+static pthread_mutex_t sshare_lock;
pthread_rwlock_t netacc_lock;
@@ -225,6 +226,21 @@ struct block {
static struct block *blocks = NULL;
+
+int swork_id;
+
+/* For creating a hash database of stratum shares submitted that have not had
+ * a response yet */
+struct stratum_share {
+ struct pool *pool;
+ char hash6[8];
+ UT_hash_handle hh;
+ bool block;
+ int id;
+};
+
+static struct stratum_share *stratum_shares = NULL;
+
char *opt_socks_proxy = NULL;
static const char def_conf[] = "cgminer.conf";
@@ -2712,6 +2728,28 @@ static void *submit_work_thread(void *userdata)
work->stale = true;
}
+ if (work->stratum) {
+ struct stratum_share *sshare = calloc(sizeof(struct stratum_share), 1);
+ uint32_t *hash32 = (uint32_t *)work->hash;
+ char *s = alloca(1024);
+
+ sprintf(sshare->hash6, "%08lx", (unsigned long)hash32[6]);
+ sshare->block = work->block;
+ sshare->pool = pool;
+ /* 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);
+
+ sprintf(s, "{\"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%08lx\"], \"id\": %d, \"method\": \"mining.submit\"}",
+ pool->rpc_user, work->job_id, work->nonce2, work->ntime, (unsigned long)work->blk.nonce, sshare->id);
+
+ sock_send(pool->sock, s, strlen(s));
+
+ goto out;
+ }
+
ce = pop_curl_entry(pool);
/* submit solution to bitcoin via JSON-RPC */
while (!submit_upstream_work(work, ce->curl, resubmit)) {
@@ -5650,6 +5688,7 @@ int main(int argc, char *argv[])
mutex_init(&control_lock);
mutex_init(&sharelog_lock);
mutex_init(&ch_lock);
+ mutex_init(&sshare_lock);
rwlock_init(&blk_lock);
rwlock_init(&netacc_lock);
diff --git a/miner.h b/miner.h
index c220b9c..e216be6 100644
--- a/miner.h
+++ b/miner.h
@@ -595,6 +595,7 @@ extern bool opt_worktime;
#ifdef USE_BITFORCE
extern bool opt_bfl_noncerange;
#endif
+extern int swork_id;
extern pthread_rwlock_t netacc_lock;
@@ -752,9 +753,6 @@ enum pool_enable {
};
struct stratum_work {
- /* id we sent to receive this work */
- int id;
-
char *job_id;
char *prev_hash;
char *coinbase1;
diff --git a/util.c b/util.c
index 0c4b736..b5888ea 100644
--- a/util.c
+++ b/util.c
@@ -848,7 +848,7 @@ bool extract_sockaddr(struct pool *pool, char *url)
}
/* Send a single command across a socket, appending \n to it */
-static bool sock_send(int sock, char *s, ssize_t len)
+bool sock_send(int sock, char *s, ssize_t len)
{
ssize_t sent = 0;
@@ -1115,7 +1115,7 @@ bool auth_stratum(struct pool *pool)
s = alloca(RECVSIZE);
sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}",
- pool->swork.id++, pool->rpc_user, pool->rpc_pass);
+ swork_id++, pool->rpc_user, pool->rpc_pass);
/* Parse all data prior sending auth request */
while (sock_full(pool->sock, false)) {
@@ -1171,7 +1171,7 @@ bool initiate_stratum(struct pool *pool)
bool ret = false;
s = alloca(RECVSIZE);
- sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", pool->swork.id++);
+ sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
pool->sock = socket(AF_INET, SOCK_STREAM, 0);
if (pool->sock == INVSOCK)
diff --git a/util.h b/util.h
index 4eb51a7..2746e10 100644
--- a/util.h
+++ b/util.h
@@ -109,6 +109,7 @@
#endif
#endif
struct pool;
+bool sock_send(int sock, char *s, ssize_t len);
char *recv_line(SOCKETTYPE sock);
bool parse_stratum(struct pool *pool, char *s);
bool extract_sockaddr(struct pool *pool, char *url);