Browse Source

Begin implementing a hash database of submissions and attempt sending results.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
7415d7aaa0
  1. 39
      cgminer.c
  2. 4
      miner.h
  3. 6
      util.c
  4. 1
      util.h

39
cgminer.c

@ -170,6 +170,7 @@ static pthread_mutex_t *stgd_lock;
pthread_mutex_t console_lock; pthread_mutex_t console_lock;
pthread_mutex_t ch_lock; pthread_mutex_t ch_lock;
static pthread_rwlock_t blk_lock; static pthread_rwlock_t blk_lock;
static pthread_mutex_t sshare_lock;
pthread_rwlock_t netacc_lock; pthread_rwlock_t netacc_lock;
@ -225,6 +226,21 @@ struct block {
static struct block *blocks = NULL; 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; char *opt_socks_proxy = NULL;
static const char def_conf[] = "cgminer.conf"; static const char def_conf[] = "cgminer.conf";
@ -2712,6 +2728,28 @@ static void *submit_work_thread(void *userdata)
work->stale = true; 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); ce = pop_curl_entry(pool);
/* submit solution to bitcoin via JSON-RPC */ /* submit solution to bitcoin via JSON-RPC */
while (!submit_upstream_work(work, ce->curl, resubmit)) { while (!submit_upstream_work(work, ce->curl, resubmit)) {
@ -5650,6 +5688,7 @@ int main(int argc, char *argv[])
mutex_init(&control_lock); mutex_init(&control_lock);
mutex_init(&sharelog_lock); mutex_init(&sharelog_lock);
mutex_init(&ch_lock); mutex_init(&ch_lock);
mutex_init(&sshare_lock);
rwlock_init(&blk_lock); rwlock_init(&blk_lock);
rwlock_init(&netacc_lock); rwlock_init(&netacc_lock);

4
miner.h

@ -595,6 +595,7 @@ extern bool opt_worktime;
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
extern bool opt_bfl_noncerange; extern bool opt_bfl_noncerange;
#endif #endif
extern int swork_id;
extern pthread_rwlock_t netacc_lock; extern pthread_rwlock_t netacc_lock;
@ -752,9 +753,6 @@ enum pool_enable {
}; };
struct stratum_work { struct stratum_work {
/* id we sent to receive this work */
int id;
char *job_id; char *job_id;
char *prev_hash; char *prev_hash;
char *coinbase1; char *coinbase1;

6
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 */ /* 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; ssize_t sent = 0;
@ -1115,7 +1115,7 @@ bool auth_stratum(struct pool *pool)
s = alloca(RECVSIZE); s = alloca(RECVSIZE);
sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}", 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 */ /* Parse all data prior sending auth request */
while (sock_full(pool->sock, false)) { while (sock_full(pool->sock, false)) {
@ -1171,7 +1171,7 @@ bool initiate_stratum(struct pool *pool)
bool ret = false; bool ret = false;
s = alloca(RECVSIZE); 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); pool->sock = socket(AF_INET, SOCK_STREAM, 0);
if (pool->sock == INVSOCK) if (pool->sock == INVSOCK)

1
util.h

@ -109,6 +109,7 @@
#endif #endif
#endif #endif
struct pool; struct pool;
bool sock_send(int sock, char *s, ssize_t len);
char *recv_line(SOCKETTYPE sock); char *recv_line(SOCKETTYPE sock);
bool parse_stratum(struct pool *pool, char *s); bool parse_stratum(struct pool *pool, char *s);
bool extract_sockaddr(struct pool *pool, char *url); bool extract_sockaddr(struct pool *pool, char *url);

Loading…
Cancel
Save