Refactor construction of block submissions to allow for results from get_mdata
This commit is contained in:
38
blkmaker.c
38
blkmaker.c
@@ -501,9 +501,9 @@ char varintEncode(unsigned char *out, uint64_t n) {
|
||||
return L;
|
||||
}
|
||||
|
||||
char *blkmk_assemble_submission_(blktemplate_t * const tmpl, const unsigned char * const data, const unsigned int dataid, blknonce_t nonce, const bool foreign)
|
||||
static char *blkmk_assemble_submission2_internal(blktemplate_t * const tmpl, const unsigned char * const data, const void * const extranonce, const size_t extranoncesz, blknonce_t nonce, const bool foreign)
|
||||
{
|
||||
const bool incl_gentxn = (foreign || (!(tmpl->mutations & BMAb_TRUNCATE && !dataid)));
|
||||
const bool incl_gentxn = (foreign || (!(tmpl->mutations & BMAb_TRUNCATE && !extranoncesz)));
|
||||
const bool incl_alltxn = (foreign || !(tmpl->mutations & BMAb_COINBASE));
|
||||
|
||||
size_t blkbuf_sz = libblkmaker_blkheader_size;
|
||||
@@ -527,10 +527,17 @@ char *blkmk_assemble_submission_(blktemplate_t * const tmpl, const unsigned char
|
||||
if (incl_gentxn) {
|
||||
offs += varintEncode(&blk[offs], 1 + tmpl->txncount);
|
||||
|
||||
if (!_blkmk_extranonce(tmpl, &blk[offs], dataid, &offs))
|
||||
{
|
||||
free(blk);
|
||||
return NULL;
|
||||
// Essentially _blkmk_extranonce
|
||||
if (extranoncesz) {
|
||||
if (!_blkmk_append_cb(tmpl, &blk[offs], extranonce, extranoncesz, NULL)) {
|
||||
free(blk);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
offs += tmpl->cbtxn->datasz + extranoncesz;
|
||||
} else {
|
||||
memcpy(&blk[offs], tmpl->cbtxn->data, tmpl->cbtxn->datasz);
|
||||
offs += tmpl->cbtxn->datasz;
|
||||
}
|
||||
|
||||
if (incl_alltxn) {
|
||||
@@ -548,3 +555,22 @@ char *blkmk_assemble_submission_(blktemplate_t * const tmpl, const unsigned char
|
||||
|
||||
return blkhex;
|
||||
}
|
||||
|
||||
char *blkmk_assemble_submission2_(blktemplate_t * const tmpl, const unsigned char * const data, const void * const extranonce, const size_t extranoncesz, const blknonce_t nonce, const bool foreign)
|
||||
{
|
||||
if (extranoncesz == sizeof(unsigned int)) {
|
||||
// Avoid overlapping with blkmk_get_data use
|
||||
unsigned char extended_extranonce[extranoncesz + 1];
|
||||
memcpy(extended_extranonce, extranonce, extranoncesz);
|
||||
extended_extranonce[extranoncesz] = 0;
|
||||
return blkmk_assemble_submission2_internal(tmpl, data, extended_extranonce, extranoncesz + 1, nonce, foreign);
|
||||
}
|
||||
return blkmk_assemble_submission2_internal(tmpl, data, extranonce, extranoncesz, nonce, foreign);
|
||||
}
|
||||
|
||||
char *blkmk_assemble_submission_(blktemplate_t * const tmpl, const unsigned char * const data, const unsigned int dataid, const blknonce_t nonce, const bool foreign)
|
||||
{
|
||||
const void * const extranonce = &dataid;
|
||||
const size_t extranoncesz = dataid ? sizeof(dataid) : 0;
|
||||
return blkmk_assemble_submission2_internal(tmpl, data, extranonce, extranoncesz, nonce, foreign);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
extern bool _blkmk_dblsha256(void *hash, const void *data, size_t datasz);
|
||||
extern bool blkmk_sample_data_(blktemplate_t *, uint8_t *, unsigned int dataid);
|
||||
extern char *blkmk_assemble_submission_(blktemplate_t *, const unsigned char *data, unsigned int dataid, blknonce_t nonce, bool foreign);
|
||||
extern char *blkmk_assemble_submission2_(blktemplate_t *, const unsigned char *data, const void *extranonce, size_t extranoncesz, blknonce_t nonce, bool foreign);
|
||||
|
||||
// blktemplate.c
|
||||
extern void _blktxn_free(struct blktxn_t *);
|
||||
|
||||
Reference in New Issue
Block a user