From 2bcdc4bcce20c7b18d74e038401b731446ac1787 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 22 Apr 2014 16:04:23 +1000 Subject: [PATCH] Cache the header binary that will be used for work reconstruction --- src/stratifier.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/stratifier.c b/src/stratifier.c index b7d8b1c8..ce79d976 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -17,6 +17,8 @@ #include "libckpool.h" #include "bitcoin.h" +static const char *workpadding = "000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"; + static const char *scriptsig_header = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff"; static uchar scriptsig_header_bin[41]; @@ -59,6 +61,9 @@ struct workbase { char coinb2[128]; // coinbase2 uchar coinb2bin[64]; int coinb2len; // length of above + + /* Cached header binary */ + char headerbin[112]; }; typedef struct workbase workbase_t; @@ -95,6 +100,7 @@ static inline void json_strdup(char **buf, json_t *val, const char *key) static void generate_coinbase(ckpool_t *ckp, workbase_t *wb) { + char header[228]; int len, ofs = 0; uint64_t *u64; tv_t now; @@ -166,6 +172,15 @@ static void generate_coinbase(ckpool_t *ckp, workbase_t *wb) __bin2hex(wb->coinb2, wb->coinb2bin, wb->coinb2len); LOGDEBUG("Coinb2: %s", wb->coinb2); /* Coinbase 2 complete */ + + snprintf(header, 225, "%08x%s%s%s%s%s%s", + wb->version, wb->prevhash, + "0000000000000000000000000000000000000000000000000000000000000000", + wb->ntime, wb->nbit, + "00000000", /* nonce */ + workpadding); + LOGDEBUG("Header: %s", header); + hex2bin(wb->headerbin, header, 112); } /* This function assumes it will only receive a valid json gbt base template