mirror of
https://github.com/JayDDee/cpuminer-opt.git
synced 2026-02-22 16:33:08 +00:00
v3.13.2-segwit-test
This commit is contained in:
120
cpu-miner.c
120
cpu-miner.c
@@ -563,6 +563,23 @@ static bool gbt_work_decode( const json_t *val, struct work *work )
|
||||
json_t *tmp, *txa;
|
||||
bool rc = false;
|
||||
|
||||
// Segwit BEGIN
|
||||
bool segwit = false;
|
||||
tmp = json_object_get(val, "rules");
|
||||
if (tmp && json_is_array(tmp)) {
|
||||
n = json_array_size(tmp);
|
||||
for (i = 0; i < n; i++) {
|
||||
const char *s = json_string_value(json_array_get(tmp, i));
|
||||
if (!s)
|
||||
continue;
|
||||
if (!strcmp(s, "segwit") || !strcmp(s, "!segwit"))
|
||||
segwit = true;
|
||||
}
|
||||
}
|
||||
// Segwit END
|
||||
|
||||
if ( segwit ) applog( LOG_INFO, "SEGWIT test, segwit is enabled");
|
||||
|
||||
tmp = json_object_get( val, "mutable" );
|
||||
if ( tmp && json_is_array( tmp ) )
|
||||
{
|
||||
@@ -596,6 +613,8 @@ static bool gbt_work_decode( const json_t *val, struct work *work )
|
||||
}
|
||||
version = (uint32_t) json_integer_value( tmp );
|
||||
|
||||
applog( LOG_INFO, "SEGWIT test, block version= %d", version );
|
||||
|
||||
// yescryptr8g uses block version 5 and sapling.
|
||||
if ( opt_sapling )
|
||||
work->sapling = true;
|
||||
@@ -721,13 +740,59 @@ static bool gbt_work_decode( const json_t *val, struct work *work )
|
||||
cbtx[41] = cbtx_size - 42; /* scriptsig length */
|
||||
le32enc( (uint32_t *)( cbtx+cbtx_size ), 0xffffffff ); /* sequence */
|
||||
cbtx_size += 4;
|
||||
cbtx[ cbtx_size++ ] = 1; /* out-counter */
|
||||
|
||||
// Segwit BEGIN
|
||||
//cbtx[cbtx_size++] = 1; /* out-counter */
|
||||
cbtx[cbtx_size++] = segwit ? 2 : 1; /* out-counter */
|
||||
// Segwit END
|
||||
|
||||
le32enc( (uint32_t *)( cbtx+cbtx_size) , (uint32_t)cbvalue ); /* value */
|
||||
le32enc( (uint32_t *)( cbtx+cbtx_size+4 ), cbvalue >> 32 );
|
||||
cbtx_size += 8;
|
||||
cbtx[ cbtx_size++ ] = (uint8_t) pk_script_size; /* txout-script length */
|
||||
memcpy( cbtx+cbtx_size, pk_script, pk_script_size );
|
||||
cbtx_size += (int) pk_script_size;
|
||||
|
||||
// Segwit BEGIN
|
||||
if (segwit) {
|
||||
|
||||
applog( LOG_INFO, "SEGWIT test: add segwit to tx");
|
||||
|
||||
unsigned char (*wtree)[32] = calloc(tx_count + 2, 32);
|
||||
memset(cbtx+cbtx_size, 0, 8); /* value */
|
||||
cbtx_size += 8;
|
||||
cbtx[cbtx_size++] = 38; /* txout-script length */
|
||||
cbtx[cbtx_size++] = 0x6a; /* txout-script */
|
||||
cbtx[cbtx_size++] = 0x24;
|
||||
cbtx[cbtx_size++] = 0xaa;
|
||||
cbtx[cbtx_size++] = 0x21;
|
||||
cbtx[cbtx_size++] = 0xa9;
|
||||
cbtx[cbtx_size++] = 0xed;
|
||||
for (i = 0; i < tx_count; i++) {
|
||||
const json_t *tx = json_array_get(txa, i);
|
||||
const json_t *hash = json_object_get(tx, "hash");
|
||||
if (!hash || !hex2bin(wtree[1+i], json_string_value(hash), 32)) {
|
||||
applog(LOG_ERR, "JSON invalid transaction hash");
|
||||
free(wtree);
|
||||
goto out;
|
||||
}
|
||||
memrev(wtree[1+i], 32);
|
||||
}
|
||||
n = tx_count + 1;
|
||||
while (n > 1) {
|
||||
if (n % 2)
|
||||
memcpy(wtree[n], wtree[n-1], 32);
|
||||
n = (n + 1) / 2;
|
||||
for (i = 0; i < n; i++)
|
||||
sha256d(wtree[i], wtree[2*i], 64);
|
||||
}
|
||||
memset(wtree[1], 0, 32); /* witness reserved value = 0 */
|
||||
sha256d(cbtx+cbtx_size, wtree[0], 64);
|
||||
cbtx_size += 32;
|
||||
free(wtree);
|
||||
}
|
||||
// Segwit END
|
||||
|
||||
le32enc( (uint32_t *)( cbtx+cbtx_size ), 0 ); /* lock time */
|
||||
cbtx_size += 4;
|
||||
coinbase_append = true;
|
||||
@@ -802,14 +867,36 @@ static bool gbt_work_decode( const json_t *val, struct work *work )
|
||||
tmp = json_array_get( txa, i );
|
||||
const char *tx_hex = json_string_value( json_object_get( tmp, "data" ) );
|
||||
const int tx_size = tx_hex ? (int) ( strlen( tx_hex ) / 2 ) : 0;
|
||||
unsigned char *tx = (uchar*) malloc( tx_size );
|
||||
if ( !tx_hex || !hex2bin( tx, tx_hex, tx_size ) )
|
||||
|
||||
// Segwit BEGIN
|
||||
if ( segwit )
|
||||
{
|
||||
applog( LOG_ERR, "JSON invalid transactions" );
|
||||
free( tx );
|
||||
goto out;
|
||||
const char *txid = json_string_value(json_object_get(tmp, "txid"));
|
||||
if (!txid || !hex2bin(merkle_tree[1 + i], txid, 32))
|
||||
{
|
||||
applog(LOG_ERR, "JSON invalid transaction txid");
|
||||
goto out;
|
||||
}
|
||||
memrev(merkle_tree[1 + i], 32);
|
||||
}
|
||||
sha256d( merkle_tree[1 + i], tx, tx_size );
|
||||
else
|
||||
{
|
||||
// Segwit END
|
||||
|
||||
unsigned char *tx = (uchar*) malloc( tx_size );
|
||||
if ( !tx_hex || !hex2bin( tx, tx_hex, tx_size ) )
|
||||
{
|
||||
applog( LOG_ERR, "JSON invalid transactions" );
|
||||
free( tx );
|
||||
goto out;
|
||||
}
|
||||
sha256d( merkle_tree[1 + i], tx, tx_size );
|
||||
free( tx );
|
||||
|
||||
// Segwit BEGIN
|
||||
}
|
||||
// Segwit END
|
||||
|
||||
if ( !submit_coinbase )
|
||||
strcat( work->txs, tx_hex );
|
||||
}
|
||||
@@ -1405,12 +1492,24 @@ const char *getwork_req =
|
||||
|
||||
#define GBT_CAPABILITIES "[\"coinbasetxn\", \"coinbasevalue\", \"longpoll\", \"workid\"]"
|
||||
|
||||
// Segwit BEGIN
|
||||
#define GBT_RULES "[\"segwit\"]"
|
||||
static const char *gbt_req =
|
||||
"{\"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": "
|
||||
GBT_CAPABILITIES ", \"rules\": " GBT_RULES "}], \"id\":0}\r\n";
|
||||
const char *gbt_lp_req =
|
||||
"{\"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": "
|
||||
GBT_CAPABILITIES ", \"rules\": " GBT_RULES ", \"longpollid\": \"%s\"}], \"id\":0}\r\n";
|
||||
|
||||
/*
|
||||
static const char *gbt_req =
|
||||
"{\"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": "
|
||||
GBT_CAPABILITIES "}], \"id\":0}\r\n";
|
||||
const char *gbt_lp_req =
|
||||
"{\"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": "
|
||||
GBT_CAPABILITIES ", \"longpollid\": \"%s\"}], \"id\":0}\r\n";
|
||||
*/
|
||||
// Segwit END
|
||||
|
||||
static bool get_upstream_work( CURL *curl, struct work *work )
|
||||
{
|
||||
@@ -3219,6 +3318,13 @@ static void show_credits()
|
||||
printf(" A CPU miner with multi algo support and optimized for CPUs\n");
|
||||
printf(" with AVX512, SHA and VAES extensions.\n");
|
||||
printf(" BTC donation address: 12tdvfF7KmAsihBXQXynT6E6th2c2pByTT\n\n");
|
||||
|
||||
printf("/nWarning: this is a test release, it may contain bugs and aditional\n");
|
||||
printf("debug log output. Users who solo mine using getwork or GBT are invited\n\n");
|
||||
printf("to use it for testing purposes. Please report any regressions. Other\n");
|
||||
printf("users may prefer to continue using the latest general release.\n\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool check_cpu_capability ()
|
||||
|
||||
Reference in New Issue
Block a user