Skip to content

Commit 02fabfd

Browse files
committed
attempt to fix wtxid on block generation
1 parent 03e9f3e commit 02fabfd

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ else
120120
JANSSON_LIBS=-ljansson
121121
fi
122122

123-
LIBCURL_CHECK_CONFIG(, 7.15.2, ,
123+
LIBCURL_CHECK_CONFIG([curl], 7.15.2, ,
124124
[AC_MSG_ERROR([Missing required libcurl >= 7.15.2])])
125125

126126
AC_SUBST(JANSSON_LIBS)

cpu-miner.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,24 @@ static bool gbt_work_decode(const json_t *val, struct work *work)
585585
merkle_tree = malloc(32 * ((1 + tx_count + 1) & ~1));
586586
size_t tx_buf_size = 32 * 1024;
587587
tx = malloc(tx_buf_size);
588-
sha256d(merkle_tree[0], cbtx, cbtx_size);
588+
589+
/* For SegWit, use the provided txid field instead of hashing the full coinbase data */
590+
if (segwit) {
591+
tmp = json_object_get(val, "coinbasetxn");
592+
if (tmp) {
593+
const char *cbtx_txid = json_string_value(json_object_get(tmp, "txid"));
594+
if (!cbtx_txid || !hex2bin(merkle_tree[0], cbtx_txid, 32)) {
595+
applog(LOG_ERR, "JSON invalid coinbase txid");
596+
goto out;
597+
}
598+
memrev(merkle_tree[0], 32);
599+
} else {
600+
/* Fallback to hashing coinbase data if no txid provided */
601+
sha256d(merkle_tree[0], cbtx, cbtx_size);
602+
}
603+
} else {
604+
sha256d(merkle_tree[0], cbtx, cbtx_size);
605+
}
589606
for (i = 0; i < tx_count; i++) {
590607
tmp = json_array_get(txa, i);
591608
const char *tx_hex = json_string_value(json_object_get(tmp, "data"));

0 commit comments

Comments
 (0)