diff --git a/ckpool.conf b/ckpool.conf index ed823703..fffa2571 100644 --- a/ckpool.conf +++ b/ckpool.conf @@ -11,7 +11,7 @@ "pass" : "pass" } ], -"btcaddress" : "15qSxP1SQcUX3o4nhkfdbgyoWEFMomJ4rZ", +"btcaddress" : "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e", "btcsig" : "/mined by ck/", "blockpoll" : 500, "update_interval" : 30, diff --git a/src/bitcoin.c b/src/bitcoin.c index 8a7e2f23..3f22e2ac 100644 --- a/src/bitcoin.c +++ b/src/bitcoin.c @@ -68,7 +68,7 @@ bool validate_address(connsock_t *cs, const char *address) goto out; } if (!json_is_true(valid_val)) - LOGWARNING("Bitcoin address %s is NOT valid", address); + LOGDEBUG("Bitcoin address %s is NOT valid", address); else { LOGDEBUG("Bitcoin address %s IS valid", address); ret = true; diff --git a/src/ckpool.c b/src/ckpool.c index c4dc5c04..090c5b56 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -1200,8 +1200,9 @@ int main(int argc, char **argv) } } + ckp.donaddress = "14BMjogz69qe8hk9thyzbmR5pg34mVKB1e"; if (!ckp.btcaddress) - ckp.btcaddress = strdup("15qSxP1SQcUX3o4nhkfdbgyoWEFMomJ4rZ"); + ckp.btcaddress = ckp.donaddress; if (!ckp.blockpoll) ckp.blockpoll = 500; if (!ckp.update_interval) diff --git a/src/ckpool.h b/src/ckpool.h index 8c708cb8..b1cd43fa 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -152,6 +152,8 @@ struct ckpool_instance { /* Coinbase data */ char *btcaddress; // Address to mine to char *btcsig; // Optional signature to add to coinbase + char *donaddress; // Donation address + bool donvalid; // Donation address works on this network /* Stratum options */ server_instance_t **servers; diff --git a/src/stratifier.c b/src/stratifier.c index 1125a212..fe21ccef 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -34,7 +34,7 @@ static const char *scriptsig_header = "01000000010000000000000000000000000000000 static uchar scriptsig_header_bin[41]; static char pubkeytxnbin[25]; -static char pubkeytxn[52]; +static char donkeytxnbin[25]; /* Add unaccounted shares when they arrive, remove them with each update of * rolling stats. */ @@ -281,9 +281,9 @@ static const char *ckdb_ids[] = { static void generate_coinbase(ckpool_t *ckp, workbase_t *wb) { + uint64_t *u64, g64, d64 = 0; char header[228]; int len, ofs = 0; - uint64_t *u64; ts_t now; /* 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->enonce2varlen; - wb->coinb2bin = ckzalloc(128); + wb->coinb2bin = ckzalloc(256); memcpy(wb->coinb2bin, "\x0a\x63\x6b\x70\x6f\x6f\x6c", 7); wb->coinb2len = 7; 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); 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 = htole64(wb->coinbasevalue); + *u64 = htole64(g64); wb->coinb2len += 8; wb->coinb2bin[wb->coinb2len++] = 25; - memcpy(wb->coinb2bin + wb->coinb2len, pubkeytxnbin, 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->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) { int transactions = wb->transactions + 1; - char hexcoinbase[512], blockhash[68]; + char hexcoinbase[1024], blockhash[68]; char *gbt_block, varint[12]; json_t *val = NULL; char cdfield[64]; @@ -1557,7 +1574,7 @@ test_blocksolve(stratum_instance_t *client, workbase_t *wb, const uchar *data, c ts_realtime(&ts_now); sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec); - gbt_block = ckalloc(512); + gbt_block = ckalloc(1024); sprintf(gbt_block, "submitblock:"); __bin2hex(gbt_block + 12, data, 80); if (transactions < 0xfd) { @@ -2544,12 +2561,27 @@ static void *statsupdate(void *arg) 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) { pthread_t pth_blockupdate, pth_statsupdate; ckpool_t *ckp = pi->ckp; - char *buf, *msg; int ret = 1; + char *buf; LOGWARNING("%s stratifier starting", ckp->name); @@ -2562,23 +2594,19 @@ int stratifier(proc_instance_t *pi) buf = send_recv_proc(ckp->generator, "ping"); } while (!buf); - ASPRINTF(&msg, "checkaddr:%s", ckp->btcaddress); - buf = send_recv_proc(ckp->generator, msg); - dealloc(msg); - if (!buf) { - LOGEMERG("Fatal: No response to checkaddr from generator"); - goto out; - } - if (cmdmatch(buf, "false")) { - LOGEMERG("Fatal: btcaddress invalid accoring to bitcoind"); - dealloc(buf); + 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); - __bin2hex(pubkeytxn, pubkeytxnbin, 25); + + 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 */