Merge branch 'master' into segwit
This commit is contained in:
34
blkmaker.c
34
blkmaker.c
@@ -104,6 +104,37 @@ char varintEncode(unsigned char *out, uint64_t n) {
|
||||
return L;
|
||||
}
|
||||
|
||||
static
|
||||
int16_t blkmk_count_sigops(const uint8_t * const script, const size_t scriptsz) {
|
||||
int16_t sigops = 0;
|
||||
for (size_t i = 0; i < scriptsz; ++i) {
|
||||
if (script[i] <= 0x4c /* OP_PUSHDATA1 */) {
|
||||
if (script[i] == 0x4c) {
|
||||
if (i + 1 >= scriptsz) {
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
i += script[i];
|
||||
} else if (script[i] == 0x4d /* OP_PUSHDATA2 */) {
|
||||
if (i + 2 >= scriptsz) {
|
||||
break;
|
||||
}
|
||||
i += 2 + upk_u16le(script, i + 1);
|
||||
} else if (script[i] == 0x4e /* OP_PUSHDATA4 */) {
|
||||
if (i + 4 >= scriptsz) {
|
||||
break;
|
||||
}
|
||||
i += 4 + upk_u32le(script, i + 1);
|
||||
} else if (script[i] == 0xac /* OP_CHECKSIG */ || script[i] == 0xad /* OP_CHECKSIGVERIFY */) {
|
||||
++sigops;
|
||||
} else if (script[i] == 0xae /* OP_CHECKMULTISIG */ || script[i] == 0xaf /* OP_CHECKMULTISIGVERIFY */) {
|
||||
sigops += 20;
|
||||
}
|
||||
}
|
||||
return sigops;
|
||||
}
|
||||
|
||||
uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const script, const size_t scriptsz, bool * const inout_newcb) {
|
||||
if (tmpl->cbtxn && !(*inout_newcb && (tmpl->mutations & BMM_GENERATE)))
|
||||
{
|
||||
@@ -175,7 +206,8 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
|
||||
memset(&data[off], 0, 4); // lock time
|
||||
off += 4;
|
||||
|
||||
if (tmpl->txns_datasz + off > tmpl->sizelimit) {
|
||||
if (tmpl->txns_datasz + off > tmpl->sizelimit
|
||||
|| (tmpl->txns_sigops >= 0 && tmpl->txns_sigops + blkmk_count_sigops(script, scriptsz) > tmpl->sigoplimit)) {
|
||||
free(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -302,6 +302,7 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
||||
size_t txns = tmpl->txncount = json_array_size(v);
|
||||
tmpl->txns = malloc(txns * sizeof(*tmpl->txns));
|
||||
tmpl->txns_datasz = 0;
|
||||
tmpl->txns_sigops = 0;
|
||||
for (size_t i = 0; i < txns; ++i)
|
||||
{
|
||||
struct blktxn_t * const txn = &tmpl->txns[i];
|
||||
@@ -309,6 +310,14 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
||||
return s;
|
||||
}
|
||||
tmpl->txns_datasz += txn->datasz;
|
||||
if (tmpl->txns_sigops == -1) {
|
||||
; // Impossible to tally the unknown
|
||||
} else if (txn->sigops_ == -1) {
|
||||
tmpl->txns_sigops = -1;
|
||||
} else {
|
||||
tmpl->txns_sigops += txn->sigops_;
|
||||
}
|
||||
tmpl->txns_sigops += txn->sigops_;
|
||||
}
|
||||
|
||||
if ((v = json_object_get(json, "coinbasetxn")) && json_is_object(v))
|
||||
|
||||
@@ -141,6 +141,7 @@ typedef struct {
|
||||
struct blkaux_t *auxs;
|
||||
|
||||
unsigned long txns_datasz;
|
||||
signed long txns_sigops;
|
||||
|
||||
bool _calculated_witness;
|
||||
libblkmaker_hash_t *_witnessmrklroot;
|
||||
|
||||
Reference in New Issue
Block a user