Use new sigop counting (ie, quadrupled) when "segwit" in rules list

This commit is contained in:
Luke Dashjr
2016-07-26 04:18:10 +00:00
parent 048483d97c
commit b5c6d97be7
3 changed files with 11 additions and 4 deletions

View File

@@ -119,7 +119,7 @@ char varintEncode(unsigned char *out, uint64_t n) {
}
static
int16_t blkmk_count_sigops(const uint8_t * const script, const size_t scriptsz) {
int16_t blkmk_count_sigops(const uint8_t * const script, const size_t scriptsz, const bool bip141) {
int16_t sigops = 0;
for (size_t i = 0; i < scriptsz; ++i) {
if (script[i] <= 0x4c /* OP_PUSHDATA1 */) {
@@ -146,6 +146,9 @@ int16_t blkmk_count_sigops(const uint8_t * const script, const size_t scriptsz)
sigops += 20;
}
}
if (bip141) {
sigops *= 4;
}
return sigops;
}
@@ -220,7 +223,7 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
memset(&data[off], 0, 4); // lock time
off += 4;
const int16_t sigops_counted = blkmk_count_sigops(script, scriptsz);
const int16_t sigops_counted = blkmk_count_sigops(script, scriptsz, tmpl->_bip141_sigops);
if (tmpl->txns_datasz + off > tmpl->sizelimit
|| (tmpl->txns_sigops >= 0 && tmpl->txns_sigops + sigops_counted > tmpl->sigoplimit)) {
free(data);
@@ -439,7 +442,7 @@ bool _blkmk_append_cb(blktemplate_t * const tmpl, void * const vout, const void
return false;
}
const int16_t orig_scriptSig_sigops = blkmk_count_sigops(&in[cbScriptSigLen + 1], in[cbScriptSigLen]);
const int16_t orig_scriptSig_sigops = blkmk_count_sigops(&in[cbScriptSigLen + 1], in[cbScriptSigLen], tmpl->_bip141_sigops);
int cbPostScriptSig = cbScriptSigLen + 1 + in[cbScriptSigLen];
if (appended_at_offset)
*appended_at_offset = cbPostScriptSig;
@@ -458,7 +461,7 @@ bool _blkmk_append_cb(blktemplate_t * const tmpl, void * const vout, const void
out[cbScriptSigLen] += appendsz;
memcpy(outExtranonce, append, appendsz);
const int16_t sigops_counted = (tmpl->cbtxn->sigops_ - orig_scriptSig_sigops) + blkmk_count_sigops(&out[cbScriptSigLen + 1], out[cbScriptSigLen]);
const int16_t sigops_counted = (tmpl->cbtxn->sigops_ - orig_scriptSig_sigops) + blkmk_count_sigops(&out[cbScriptSigLen + 1], out[cbScriptSigLen], tmpl->_bip141_sigops);
if (tmpl->txns_sigops >= 0 && tmpl->txns_sigops + sigops_counted > tmpl->sigoplimit) {
// Overflowed :(
if (out == in) {

View File

@@ -343,6 +343,9 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
if (!tmpl->rules[i]) {
return "Memory allocation error parsing rules";
}
if (!strcmp(s, "segwit")) {
tmpl->_bip141_sigops = true;
}
}
v = json_object_get(json, "vbavailable");

View File

@@ -153,6 +153,7 @@ typedef struct {
struct blktmpl_vbassoc **vbavailable;
uint32_t vbrequired;
bool _bip141_sigops;
bool _calculated_witness;
libblkmaker_hash_t *_witnessmrklroot;
} blktemplate_t;