Compare commits

..

No commits in common. "master" and "segwit" have entirely different histories.

7 changed files with 13 additions and 72 deletions

View File

@ -170,19 +170,20 @@ static int64_t blktxn_set_gentx_weight(struct blktxn_t * const gentx) {
}
uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const script, const size_t scriptsz, bool * const inout_newcb) {
const bool replace_existing = *inout_newcb;
*inout_newcb = false;
if (tmpl->cbtxn && !(replace_existing && (tmpl->mutations & BMM_GENERATE)))
if (tmpl->cbtxn && !(*inout_newcb && (tmpl->mutations & BMM_GENERATE)))
{
*inout_newcb = false;
return 0;
}
if (!tmpl->has_cbvalue) {
if (!tmpl->cbvalue) {
// TODO: Figure it out from the existing cbtxn
*inout_newcb = false;
return 0;
}
*inout_newcb = true;
if (scriptsz >= 0xfd)
return 0;
@ -279,7 +280,6 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
tmpl->mutations |= BMM_CBAPPEND | BMM_CBSET | BMM_GENERATE;
*inout_newcb = true;
return tmpl->cbvalue;
}
@ -545,9 +545,6 @@ ssize_t blkmk_append_coinbase_safe2(blktemplate_t * const tmpl, const void * con
if (extranoncesz < sizeof(unsigned int))
extranoncesz = sizeof(unsigned int);
}
if (tmpl->cbtxn->datasz <= cbScriptSigLen || tmpl->cbtxn->datasz <= cbScriptSigLen + tmpl->cbtxn->data[cbScriptSigLen]) {
return -6;
}
if (extranoncesz > libblkmaker_coinbase_size_limit || tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit || extranoncesz + tmpl->cbtxn->data[cbScriptSigLen] > libblkmaker_coinbase_size_limit) {
return -5;
}
@ -798,9 +795,7 @@ 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);
}
memcpy(*out_branches, tmpl->_mrklbranch, branches_bytesz);
return true;
}

View File

@ -11,7 +11,7 @@
extern "C" {
#endif
#define BLKMAKER_VERSION (8L)
#define BLKMAKER_VERSION (7L)
#define BLKMAKER_MAX_BLOCK_VERSION (0x3fffffff)
#define BLKMAKER_MAX_PRERULES_BLOCK_VERSION (4)

View File

@ -416,14 +416,7 @@ 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";
}
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;
}
}
GETNUM_O2(cbvalue, coinbasevalue, uint64_t);
GETSTR(workid, workid);
@ -471,7 +464,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->has_cbvalue) {
} else if (!tmpl->cbvalue) {
return "Missing either coinbasetxn or coinbasevalue";
}

View File

@ -158,8 +158,6 @@ 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 *);

View File

@ -5,7 +5,7 @@ dnl * under the terms of the standard MIT license. See COPYING for more details
AC_INIT(
[libblkmaker],
[0.6.0],
[0.5.3],
[luke_libblkmaker@dashjr.org],
[libblkmaker],
[http://gitorious.org/bitcoin/libblkmaker])
@ -19,7 +19,7 @@ m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT([disable-static])
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
AC_SUBST([LIBBLKMAKER_SO_VERSION], [8:0:0])
AC_SUBST([LIBBLKMAKER_SO_VERSION], [7:0:1])
AC_SUBST([LIBBLKMAKER_API_VERSION], [0.1])
AC_CONFIG_FILES([Makefile

View File

@ -7,7 +7,6 @@ Name: @PACKAGE_NAME@_jansson
Description: Bitcoin block maker library.
Version: @PACKAGE_VERSION@
URL: @PACKAGE_URL@
Libs: -L${libdir} -lblkmaker_jansson-@LIBBLKMAKER_API_VERSION@ -lblkmaker-@LIBBLKMAKER_API_VERSION@
Libs: -L${libdir} -lblkmaker-@LIBBLKMAKER_API_VERSION@ -lblkmaker_jansson-@LIBBLKMAKER_API_VERSION@
Cflags: -I${includedir}/libblkmaker-@LIBBLKMAKER_API_VERSION@
Requires: jansson
Requires.private: libbase58

44
test.c
View File

@ -219,7 +219,6 @@ 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
@ -250,13 +249,6 @@ 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();
@ -295,7 +287,6 @@ 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);
@ -484,7 +475,6 @@ 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);
@ -544,7 +534,6 @@ 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);
@ -1133,7 +1122,6 @@ 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)
@ -1249,38 +1237,6 @@ static void test_blkmk_append_coinbase_safe() {
assert(blkmk_init_generation3(tmpl, NULL, 0, &newcb));
assert(blkmk_append_coinbase_safe2(tmpl, "\x05" "testx", 6, 0, true) == 5);
blktmpl_free(tmpl);
tmpl = blktmpl_create();
// Gen tx is cut off immediately after the coinbase.
// We don't *really* care that this works since it's not Bitcoin, but we need to make sure it doesn't corrupt memory or crash
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":3,\"height\":4,\"bits\":\"1d007fff\",\"curtime\":877,\"previousblockhash\":\"00000000a7777777a7777777a7777777a7777777a7777777a7777777a7777777\",\"coinbasetxn\":{\"data\":\"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07010404deadbeef\"},\"mutable\":[\"coinbase/append\"]}", simple_time_rcvd));
assert(blkmk_append_coinbase_safe(tmpl, "\x58", 1) >= 1);
assert(tmpl->cbtxn);
assert(tmpl->cbtxn->datasz == 50);
assert(!memcmp(tmpl->cbtxn->data, "\x01\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\xff\x08\x01\x04\x04\xde\xad\xbe\xef\x58", tmpl->cbtxn->datasz));
blktmpl_free(tmpl);
tmpl = blktmpl_create();
// Gen tx is cut off INSIDE the coinbase.
// Again, we need to make sure it doesn't corrupt memory or crash
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":3,\"height\":4,\"bits\":\"1d007fff\",\"curtime\":877,\"previousblockhash\":\"00000000a7777777a7777777a7777777a7777777a7777777a7777777a7777777\",\"coinbasetxn\":{\"data\":\"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07010404deadbe\"},\"mutable\":[\"coinbase/append\"]}", simple_time_rcvd));
assert(blkmk_append_coinbase_safe(tmpl, "\x58", 1) <= 0);
assert(tmpl->cbtxn);
assert(tmpl->cbtxn->datasz == 48);
assert(!memcmp(tmpl->cbtxn->data, "\x01\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\xff\x07\x01\x04\x04\xde\xad\xbe", tmpl->cbtxn->datasz));
blktmpl_free(tmpl);
tmpl = blktmpl_create();
// Gen tx is cut off BEFORE the coinbase
assert(!blktmpl_add_jansson_str(tmpl, "{\"version\":3,\"height\":4,\"bits\":\"1d007fff\",\"curtime\":877,\"previousblockhash\":\"00000000a7777777a7777777a7777777a7777777a7777777a7777777a7777777\",\"coinbasetxn\":{\"data\":\"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff\"},\"mutable\":[\"coinbase/append\"]}", simple_time_rcvd));
assert(blkmk_append_coinbase_safe(tmpl, "\x58", 1) <= 0);
assert(tmpl->cbtxn);
assert(tmpl->cbtxn->datasz == 41);
assert(!memcmp(tmpl->cbtxn->data, "\x01\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\xff", tmpl->cbtxn->datasz));
blktmpl_free(tmpl);
}