Add blktemplate_t.has_cbvalue boolean to differentiate between cbvalue 0 being unknown or zero
This commit is contained in:
@@ -178,7 +178,7 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!tmpl->cbvalue) {
|
||||
if (!tmpl->has_cbvalue) {
|
||||
// TODO: Figure it out from the existing cbtxn
|
||||
return 0;
|
||||
}
|
||||
@@ -798,7 +798,9 @@ bool blkmk_get_mdata(blktemplate_t * const tmpl, void * const buf, const size_t
|
||||
free(*out_cbtxn);
|
||||
return false;
|
||||
}
|
||||
if (branches_bytesz) {
|
||||
memcpy(*out_branches, tmpl->_mrklbranch, branches_bytesz);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -416,7 +416,14 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
||||
return "Unrecognized block version, and not allowed to reduce or force it";
|
||||
}
|
||||
|
||||
GETNUM_O2(cbvalue, coinbasevalue, uint64_t);
|
||||
if ((v = json_object_get(json, "coinbasevalue")) && json_is_number(v)) {
|
||||
const double tmpd = json_number_value(v);
|
||||
const uint64_t tmp = tmpd;
|
||||
if (tmpd == tmp) {
|
||||
tmpl->has_cbvalue = true;
|
||||
tmpl->cbvalue = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
GETSTR(workid, workid);
|
||||
|
||||
@@ -464,7 +471,7 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
||||
tmpl->cbtxn = calloc(1, sizeof(*tmpl->cbtxn));
|
||||
if ((s = parse_txn(tmpl->cbtxn, v, 0)))
|
||||
return s;
|
||||
} else if (!tmpl->cbvalue) {
|
||||
} else if (!tmpl->has_cbvalue) {
|
||||
return "Missing either coinbasetxn or coinbasevalue";
|
||||
}
|
||||
|
||||
|
||||
@@ -158,6 +158,8 @@ typedef struct {
|
||||
libblkmaker_hash_t *_witnessmrklroot;
|
||||
int64_t weightlimit;
|
||||
int64_t txns_weight;
|
||||
|
||||
bool has_cbvalue;
|
||||
} blktemplate_t;
|
||||
|
||||
extern void blktxn_init(struct blktxn_t *);
|
||||
|
||||
12
test.c
12
test.c
@@ -219,6 +219,7 @@ static void blktmpl_jansson_simple() {
|
||||
assert(tmpl->prevblk[i] == 0x77777777);
|
||||
}
|
||||
assert(!tmpl->prevblk[7]);
|
||||
assert(tmpl->has_cbvalue);
|
||||
assert(tmpl->cbvalue == 512);
|
||||
|
||||
// Check clear values
|
||||
@@ -249,6 +250,13 @@ static void blktmpl_jansson_simple() {
|
||||
blktmpl_free(tmpl);
|
||||
tmpl = blktmpl_create();
|
||||
|
||||
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":2,\"height\":3,\"bits\":\"1d00ffff\",\"curtime\":777,\"previousblockhash\":\"0000000077777777777777777777777777777777777777777777777777777777\",\"coinbasevalue\":0}", simple_time_rcvd));
|
||||
assert(tmpl->has_cbvalue);
|
||||
assert(tmpl->cbvalue == 0);
|
||||
|
||||
blktmpl_free(tmpl);
|
||||
tmpl = blktmpl_create();
|
||||
|
||||
assert(blktmpl_add_jansson_str(tmpl, "{\"height\":3,\"bits\":\"1d00ffff\",\"curtime\":777,\"previousblockhash\":\"0000000077777777777777777777777777777777777777777777777777777777\",\"coinbasevalue\":512}", simple_time_rcvd));
|
||||
blktmpl_free(tmpl);
|
||||
tmpl = blktmpl_create();
|
||||
@@ -287,6 +295,7 @@ static void blktmpl_jansson_bip22_required() {
|
||||
assert(tmpl->prevblk[i] == 0xa7777777);
|
||||
}
|
||||
assert(!tmpl->prevblk[7]);
|
||||
assert(tmpl->has_cbvalue);
|
||||
assert(tmpl->cbvalue == 640);
|
||||
assert(tmpl->sigoplimit == 100);
|
||||
assert(tmpl->sizelimit == 1000);
|
||||
@@ -475,6 +484,7 @@ static void test_blktmpl_jansson_floaty() {
|
||||
assert(tmpl->prevblk[i] == 0x77777777);
|
||||
}
|
||||
assert(!tmpl->prevblk[7]);
|
||||
assert(tmpl->has_cbvalue);
|
||||
assert(tmpl->cbvalue == 512);
|
||||
|
||||
assert(tmpl->txncount == 2);
|
||||
@@ -534,6 +544,7 @@ static void test_blktmpl_jansson_floaty() {
|
||||
assert(tmpl->prevblk[i] == 0x77777777);
|
||||
}
|
||||
assert(!tmpl->prevblk[7]);
|
||||
assert(!tmpl->has_cbvalue);
|
||||
assert(!tmpl->cbvalue);
|
||||
|
||||
assert(tmpl->expires == 33);
|
||||
@@ -1122,6 +1133,7 @@ static void test_blkmk_init_generation() {
|
||||
assert(!blkmk_init_generation(tmpl, NULL, 0));
|
||||
tmpl->height = 4;
|
||||
assert(blkmk_init_generation(tmpl, NULL, 0) == 640);
|
||||
tmpl->has_cbvalue = false;
|
||||
tmpl->cbvalue = 0;
|
||||
newcb = true;
|
||||
// Unknown cbvalue needs to either fail, or figure it out from an existing cbtxn (which we don't support yet)
|
||||
|
||||
Reference in New Issue
Block a user