Browse Source

Update donation address and encode default 0.5% donation into coinbase

master
Con Kolivas 10 years ago
parent
commit
22ef55be05
  1. 2
      ckpool.conf
  2. 2
      src/bitcoin.c
  3. 3
      src/ckpool.c
  4. 2
      src/ckpool.h
  5. 68
      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;

68
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,12 +2561,27 @@ 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;
char *buf, *msg;
int ret = 1; int ret = 1;
char *buf;
LOGWARNING("%s stratifier starting", ckp->name); LOGWARNING("%s stratifier starting", ckp->name);
@ -2562,23 +2594,19 @@ int stratifier(proc_instance_t *pi)
buf = send_recv_proc(ckp->generator, "ping"); buf = send_recv_proc(ckp->generator, "ping");
} while (!buf); } while (!buf);
ASPRINTF(&msg, "checkaddr:%s", ckp->btcaddress); if (!test_address(ckp, ckp->btcaddress)) {
buf = send_recv_proc(ckp->generator, msg); LOGEMERG("Fatal: btcaddress invalid according to bitcoind");
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);
goto out; goto out;
} }
/* Store this for use elsewhere */ /* Store this for use elsewhere */
hex2bin(scriptsig_header_bin, scriptsig_header, 41); hex2bin(scriptsig_header_bin, scriptsig_header, 41);
address_to_pubkeytxn(pubkeytxnbin, ckp->btcaddress); 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 /* Set the initial id to time as high bits so as to not send the same
* id on restarts */ * id on restarts */

Loading…
Cancel
Save