kanoi 10 years ago
parent
commit
0bbb87a30b
  1. 2
      ckpool.conf
  2. 2
      src/bitcoin.c
  3. 3
      src/ckpool.c
  4. 2
      src/ckpool.h
  5. 5
      src/generator.c
  6. 80
      src/stratifier.c

2
ckpool.conf

@ -11,7 +11,7 @@
"pass" : "pass" "pass" : "pass"
} }
], ],
"btcaddress" : "15qSxP1SQcUX3o4nhkfdbgyoWEFMomJ4rZ", "btcaddress" : "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e",
"btcsig" : "/mined by ck/", "btcsig" : "/mined by ck/",
"blockpoll" : 500, "blockpoll" : 500,
"update_interval" : 30, "update_interval" : 30,

2
src/bitcoin.c

@ -68,7 +68,7 @@ bool validate_address(connsock_t *cs, const char *address)
goto out; goto out;
} }
if (!json_is_true(valid_val)) if (!json_is_true(valid_val))
LOGWARNING("Bitcoin address %s is NOT valid", address); LOGDEBUG("Bitcoin address %s is NOT valid", address);
else { else {
LOGDEBUG("Bitcoin address %s IS valid", address); LOGDEBUG("Bitcoin address %s IS valid", address);
ret = true; ret = true;

3
src/ckpool.c

@ -1200,8 +1200,9 @@ int main(int argc, char **argv)
} }
} }
ckp.donaddress = "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e";
if (!ckp.btcaddress) if (!ckp.btcaddress)
ckp.btcaddress = strdup("15qSxP1SQcUX3o4nhkfdbgyoWEFMomJ4rZ"); ckp.btcaddress = ckp.donaddress;
if (!ckp.blockpoll) if (!ckp.blockpoll)
ckp.blockpoll = 500; ckp.blockpoll = 500;
if (!ckp.update_interval) if (!ckp.update_interval)

2
src/ckpool.h

@ -152,6 +152,8 @@ struct ckpool_instance {
/* Coinbase data */ /* Coinbase data */
char *btcaddress; // Address to mine to char *btcaddress; // Address to mine to
char *btcsig; // Optional signature to add to coinbase char *btcsig; // Optional signature to add to coinbase
char *donaddress; // Donation address
bool donvalid; // Donation address works on this network
/* Stratum options */ /* Stratum options */
server_instance_t **servers; server_instance_t **servers;

5
src/generator.c

@ -311,6 +311,11 @@ retry:
LOGNOTICE("Submitting block data!"); LOGNOTICE("Submitting block data!");
if (submit_block(cs, buf + 12)) if (submit_block(cs, buf + 12))
send_proc(ckp->stratifier, "block"); send_proc(ckp->stratifier, "block");
} else if (cmdmatch(buf, "checkaddr:")) {
if (validate_address(cs, buf + 10))
send_unix_msg(sockd, "true");
else
send_unix_msg(sockd, "false");
} else if (cmdmatch(buf, "loglevel")) { } else if (cmdmatch(buf, "loglevel")) {
sscanf(buf, "loglevel=%d", &ckp->loglevel); sscanf(buf, "loglevel=%d", &ckp->loglevel);
} else if (cmdmatch(buf, "ping")) { } else if (cmdmatch(buf, "ping")) {

80
src/stratifier.c

@ -34,7 +34,7 @@ static const char *scriptsig_header = "01000000010000000000000000000000000000000
static uchar scriptsig_header_bin[41]; static uchar scriptsig_header_bin[41];
static char pubkeytxnbin[25]; static char pubkeytxnbin[25];
static char pubkeytxn[52]; static char donkeytxnbin[25];
/* Add unaccounted shares when they arrive, remove them with each update of /* Add unaccounted shares when they arrive, remove them with each update of
* rolling stats. */ * rolling stats. */
@ -281,9 +281,9 @@ static const char *ckdb_ids[] = {
static void generate_coinbase(ckpool_t *ckp, workbase_t *wb) static void generate_coinbase(ckpool_t *ckp, workbase_t *wb)
{ {
uint64_t *u64, g64, d64 = 0;
char header[228]; char header[228];
int len, ofs = 0; int len, ofs = 0;
uint64_t *u64;
ts_t now; ts_t now;
/* Strings in wb should have been zero memset prior. Generate binary /* Strings in wb should have been zero memset prior. Generate binary
@ -324,7 +324,7 @@ static void generate_coinbase(ckpool_t *ckp, workbase_t *wb)
len += wb->enonce1varlen; len += wb->enonce1varlen;
len += wb->enonce2varlen; len += wb->enonce2varlen;
wb->coinb2bin = ckzalloc(128); wb->coinb2bin = ckzalloc(256);
memcpy(wb->coinb2bin, "\x0a\x63\x6b\x70\x6f\x6f\x6c", 7); memcpy(wb->coinb2bin, "\x0a\x63\x6b\x70\x6f\x6f\x6c", 7);
wb->coinb2len = 7; wb->coinb2len = 7;
if (ckp->btcsig) { if (ckp->btcsig) {
@ -347,16 +347,33 @@ static void generate_coinbase(ckpool_t *ckp, workbase_t *wb)
memcpy(wb->coinb2bin + wb->coinb2len, "\xff\xff\xff\xff", 4); memcpy(wb->coinb2bin + wb->coinb2len, "\xff\xff\xff\xff", 4);
wb->coinb2len += 4; wb->coinb2len += 4;
wb->coinb2bin[wb->coinb2len++] = 1; // Generation value
g64 = wb->coinbasevalue;
if (ckp->donvalid) {
d64 = g64 / 200; // 0.5% donation
g64 -= d64; // To guarantee integers add up to the original coinbasevalue
wb->coinb2bin[wb->coinb2len++] = 2; // 2 transactions
} else
wb->coinb2bin[wb->coinb2len++] = 1; // 2 transactions
u64 = (uint64_t *)&wb->coinb2bin[wb->coinb2len]; u64 = (uint64_t *)&wb->coinb2bin[wb->coinb2len];
*u64 = htole64(wb->coinbasevalue); *u64 = htole64(g64);
wb->coinb2len += 8; wb->coinb2len += 8;
wb->coinb2bin[wb->coinb2len++] = 25; wb->coinb2bin[wb->coinb2len++] = 25;
memcpy(wb->coinb2bin + wb->coinb2len, pubkeytxnbin, 25); memcpy(wb->coinb2bin + wb->coinb2len, pubkeytxnbin, 25);
wb->coinb2len += 25; wb->coinb2len += 25;
if (ckp->donvalid) {
u64 = (uint64_t *)&wb->coinb2bin[wb->coinb2len];
*u64 = htole64(d64);
wb->coinb2len += 8;
wb->coinb2bin[wb->coinb2len++] = 25;
memcpy(wb->coinb2bin + wb->coinb2len, donkeytxnbin, 25);
wb->coinb2len += 25;
}
wb->coinb2len += 4; // Blank lock wb->coinb2len += 4; // Blank lock
wb->coinb2 = bin2hex(wb->coinb2bin, wb->coinb2len); wb->coinb2 = bin2hex(wb->coinb2bin, wb->coinb2len);
@ -1537,7 +1554,7 @@ test_blocksolve(stratum_instance_t *client, workbase_t *wb, const uchar *data, c
double diff, const char *coinbase, int cblen, const char *nonce2, const char *nonce) double diff, const char *coinbase, int cblen, const char *nonce2, const char *nonce)
{ {
int transactions = wb->transactions + 1; int transactions = wb->transactions + 1;
char hexcoinbase[512], blockhash[68]; char hexcoinbase[1024], blockhash[68];
char *gbt_block, varint[12]; char *gbt_block, varint[12];
json_t *val = NULL; json_t *val = NULL;
char cdfield[64]; char cdfield[64];
@ -1557,7 +1574,7 @@ test_blocksolve(stratum_instance_t *client, workbase_t *wb, const uchar *data, c
ts_realtime(&ts_now); ts_realtime(&ts_now);
sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec); sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec);
gbt_block = ckalloc(512); gbt_block = ckalloc(1024);
sprintf(gbt_block, "submitblock:"); sprintf(gbt_block, "submitblock:");
__bin2hex(gbt_block + 12, data, 80); __bin2hex(gbt_block + 12, data, 80);
if (transactions < 0xfd) { if (transactions < 0xfd) {
@ -2544,24 +2561,30 @@ static void *statsupdate(void *arg)
return NULL; return NULL;
} }
static bool test_address(ckpool_t *ckp, const char *address)
{
bool ret = false;
char *buf, *msg;
ASPRINTF(&msg, "checkaddr:%s", address);
buf = send_recv_proc(ckp->generator, msg);
dealloc(msg);
if (!buf)
return ret;
ret = cmdmatch(buf, "true");
dealloc(buf);
return ret;
}
int stratifier(proc_instance_t *pi) int stratifier(proc_instance_t *pi)
{ {
pthread_t pth_blockupdate, pth_statsupdate; pthread_t pth_blockupdate, pth_statsupdate;
ckpool_t *ckp = pi->ckp; ckpool_t *ckp = pi->ckp;
int ret = 1;
char *buf; char *buf;
int ret;
LOGWARNING("%s stratifier starting", ckp->name); LOGWARNING("%s stratifier starting", ckp->name);
/* Store this for use elsewhere */
hex2bin(scriptsig_header_bin, scriptsig_header, 41);
address_to_pubkeytxn(pubkeytxnbin, ckp->btcaddress);
__bin2hex(pubkeytxn, pubkeytxnbin, 25);
/* Set the initial id to time as high bits so as to not send the same
* id on restarts */
blockchange_id = workbase_id = ((int64_t)time(NULL)) << 32;
/* Wait for the generator to have something for us */ /* Wait for the generator to have something for us */
do { do {
if (!ping_main(ckp)) { if (!ping_main(ckp)) {
@ -2570,6 +2593,27 @@ int stratifier(proc_instance_t *pi)
} }
buf = send_recv_proc(ckp->generator, "ping"); buf = send_recv_proc(ckp->generator, "ping");
} while (!buf); } while (!buf);
if (!ckp->proxy) {
if (!test_address(ckp, ckp->btcaddress)) {
LOGEMERG("Fatal: btcaddress invalid according to bitcoind");
goto out;
}
/* Store this for use elsewhere */
hex2bin(scriptsig_header_bin, scriptsig_header, 41);
address_to_pubkeytxn(pubkeytxnbin, ckp->btcaddress);
if (test_address(ckp, ckp->donaddress)) {
ckp->donvalid = true;
address_to_pubkeytxn(donkeytxnbin, ckp->donaddress);
}
}
/* Set the initial id to time as high bits so as to not send the same
* id on restarts */
blockchange_id = workbase_id = ((int64_t)time(NULL)) << 32;
dealloc(buf); dealloc(buf);
if (!ckp->serverurl) if (!ckp->serverurl)

Loading…
Cancel
Save