Bugfix: Consider extranonce rolling in jansson submissions
This commit is contained in:
27
blkmaker.c
27
blkmaker.c
@@ -55,9 +55,17 @@ bool build_merkle_root(unsigned char *mrklroot_out, blktemplate_t *tmpl, unsigne
|
||||
|
||||
static const int cbScriptSigLen = 4 + 1 + 36;
|
||||
|
||||
bool _blkmk_extranonce(void *vout, void *vin, size_t insz, unsigned int workid) {
|
||||
bool _blkmk_extranonce(blktemplate_t *tmpl, void *vout, unsigned int workid, size_t *offs) {
|
||||
unsigned char *out = vout;
|
||||
unsigned char *in = vin;
|
||||
unsigned char *in = tmpl->cbtxn->data;
|
||||
size_t insz = tmpl->cbtxn->datasz;
|
||||
|
||||
if (!workid)
|
||||
{
|
||||
memcpy(vout, in, insz);
|
||||
*offs += insz;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in[cbScriptSigLen] > 100 - sizeof(workid))
|
||||
return false;
|
||||
@@ -70,7 +78,8 @@ bool _blkmk_extranonce(void *vout, void *vin, size_t insz, unsigned int workid)
|
||||
unsigned char *outPostScriptSig = &out[cbPostScriptSig];
|
||||
unsigned int *outExtranonce = (void*)outPostScriptSig;
|
||||
outPostScriptSig += sizeof(workid);
|
||||
*outExtranonce = workid;
|
||||
*offs += insz + sizeof(workid);
|
||||
*outExtranonce = 0xd1cedeed; //workid;
|
||||
|
||||
memcpy(outPostScriptSig, &in[cbPostScriptSig], insz - cbPostScriptSig);
|
||||
|
||||
@@ -89,16 +98,10 @@ size_t blkmk_get_data(blktemplate_t *tmpl, void *buf, size_t bufsz, time_t useti
|
||||
memcpy(&cbuf[4], &tmpl->prevblk, 32);
|
||||
|
||||
unsigned char cbtxndata[tmpl->cbtxn->datasz + sizeof(*out_dataid)];
|
||||
size_t cbtxndatasz = tmpl->cbtxn->datasz;
|
||||
size_t cbtxndatasz = 0;
|
||||
*out_dataid = tmpl->next_dataid++;
|
||||
if (*out_dataid)
|
||||
{
|
||||
if (!_blkmk_extranonce(cbtxndata, tmpl->cbtxn->data, tmpl->cbtxn->datasz, *out_dataid))
|
||||
return 0;
|
||||
cbtxndatasz += sizeof(*out_dataid);
|
||||
}
|
||||
else
|
||||
memcpy(cbtxndata, tmpl->cbtxn->data, cbtxndatasz);
|
||||
if (!_blkmk_extranonce(tmpl, cbtxndata, *out_dataid, &cbtxndatasz))
|
||||
return 0;
|
||||
if (!build_merkle_root(&cbuf[36], tmpl, cbtxndata, cbtxndatasz))
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
extern bool (*blkmk_sha256_impl)(void *hash_out, const void *data, size_t datasz);
|
||||
|
||||
extern bool _blkmk_extranonce(blktemplate_t *tmpl, void *vout, unsigned int workid, size_t *offs);
|
||||
extern size_t blkmk_get_data(blktemplate_t *, void *buf, size_t bufsz, time_t usetime, int16_t *out_expire, unsigned int *out_dataid);
|
||||
extern blktime_diff_t blkmk_time_left(const blktemplate_t *, time_t nowtime);
|
||||
extern unsigned long blkmk_work_left(const blktemplate_t *);
|
||||
|
||||
@@ -277,13 +277,8 @@ json_t *blkmk_submit_jansson(blktemplate_t *tmpl, const unsigned char *data, uns
|
||||
{
|
||||
offs += varintEncode(&blk[offs], 1 + tmpl->txncount);
|
||||
|
||||
memcpy(&blk[offs], tmpl->cbtxn->data, tmpl->cbtxn->datasz);
|
||||
offs += tmpl->cbtxn->datasz;
|
||||
if (dataid)
|
||||
{
|
||||
*(int*)&blk[offs] = dataid;
|
||||
offs += sizeof(dataid);
|
||||
}
|
||||
if (!_blkmk_extranonce(tmpl, &blk[offs], dataid, &offs))
|
||||
return NULL;
|
||||
|
||||
if (!(tmpl->mutations & BMAb_COINBASE))
|
||||
for (int i = 0; i < tmpl->txncount; ++i)
|
||||
|
||||
Reference in New Issue
Block a user