mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
decred stratum hack with extranonce field
override the coinbase field with the static part of the decred header...
This commit is contained in:
parent
e4d7dfe37d
commit
5ef293e938
11 changed files with 138 additions and 7 deletions
1
rc.local
1
rc.local
|
@ -39,6 +39,7 @@ screen -dmS lyra2v2 $STRATUM_DIR/run.sh lyra2v2
|
|||
|
||||
screen -dmS blake $STRATUM_DIR/run.sh blake
|
||||
screen -dmS vanilla $STRATUM_DIR/run.sh vanilla # blake 8
|
||||
screen -dmS decred $STRATUM_DIR/run.sh decred # blake 14
|
||||
|
||||
#screen -dmS keccak $STRATUM_DIR/run.sh keccak
|
||||
screen -dmS whirlpool $STRATUM_DIR/run.sh whirlpool
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "blake.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include <sha3/sph_blake.h>
|
||||
|
||||
|
||||
void blake_hash(const char* input, char* output, uint32_t len)
|
||||
|
@ -17,3 +16,30 @@ void blake_hash(const char* input, char* output, uint32_t len)
|
|||
sph_blake256(&ctx_blake, input, len);
|
||||
sph_blake256_close(&ctx_blake, output);
|
||||
}
|
||||
|
||||
static void hexlify(char *hex, const unsigned char *bin, int len)
|
||||
{
|
||||
hex[0] = 0;
|
||||
for(int i=0; i < len; i++)
|
||||
sprintf(hex+strlen(hex), "%02x", bin[i]);
|
||||
}
|
||||
|
||||
void decred_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake256_context ctx_blake;
|
||||
|
||||
sph_blake256_set_rounds(14);
|
||||
|
||||
uint32_t* in = (uint32_t*) input;
|
||||
fprintf(stderr, "decred input len=%u n=%08x %08x %08x %08x\n",
|
||||
len, in[35], in[36], in[37], in[38]);
|
||||
if (len > 180) len = 180;
|
||||
|
||||
//char hex[512];
|
||||
//hexlify(hex, input, len);
|
||||
//fprintf(stderr, "decred %s\n", hex);
|
||||
|
||||
sph_blake256_init(&ctx_blake);
|
||||
sph_blake256(&ctx_blake, input, len);
|
||||
sph_blake256_close(&ctx_blake, output);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
|
||||
void blake_hash(const char* input, char* output, uint32_t len);
|
||||
void decred_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -35,6 +35,14 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params)
|
|||
strcpy(client->extranonce1, client->extranonce1_default);
|
||||
client->extranonce2size = client->extranonce2size_default;
|
||||
|
||||
// decred uses an extradata field in block header, 2 first uint32 are set by the miner
|
||||
if (g_current_algo->name && !strcmp(g_current_algo->name,"decred")) {
|
||||
memset(client->extranonce1, '0', sizeof(client->extranonce1));
|
||||
memcpy(&client->extranonce1[16], client->extranonce1_default, YAAMP_EXTRANONCE2_SIZE*2);
|
||||
client->extranonce1[24] = '\0';
|
||||
client->extranonce2size = client->extranonce2size_default = 12;
|
||||
}
|
||||
|
||||
get_random_key(client->notify_id);
|
||||
|
||||
if(json_params->u.array.length>0)
|
||||
|
|
|
@ -44,6 +44,79 @@ void build_submit_values(YAAMP_JOB_VALUES *submitvalues, YAAMP_JOB_TEMPLATE *tem
|
|||
string_be(submitvalues->hash_hex, submitvalues->hash_be);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
||||
static void create_decred_header(YAAMP_JOB_TEMPLATE *templ, YAAMP_JOB_VALUES *out,
|
||||
const char *ntime, const char *nonce, const char *nonce2)
|
||||
{
|
||||
struct __attribute__((__packed__)) {
|
||||
uint32_t version;
|
||||
char prevblock[32];
|
||||
char merkleroot[32];
|
||||
char stakeroot[32];
|
||||
uint16_t votebits;
|
||||
char finalstate[6];
|
||||
uint16_t voters;
|
||||
uint8_t freshstake;
|
||||
uint8_t revoc;
|
||||
uint32_t poolsize;
|
||||
uint32_t nbits;
|
||||
uint64_t sbits;
|
||||
uint32_t height;
|
||||
uint32_t size;
|
||||
uint32_t ntime;
|
||||
uint32_t nonce;
|
||||
unsigned char extra[36];
|
||||
} header;
|
||||
|
||||
memcpy(&header, templ->header, sizeof(header));
|
||||
|
||||
memset(header.extra, 0, 36);
|
||||
sscanf(nonce, "%08x", &header.nonce);
|
||||
binlify(header.extra, (const char*) nonce2);
|
||||
|
||||
hexlify(out->header, (const unsigned char*) &header, 192);
|
||||
memcpy(out->header_bin, &header, sizeof(header));
|
||||
}
|
||||
|
||||
void build_submit_values_decred(YAAMP_JOB_VALUES *submitvalues, YAAMP_JOB_TEMPLATE *templ,
|
||||
const char *nonce1, const char *nonce2, const char *ntime, const char *nonce)
|
||||
{
|
||||
sprintf(submitvalues->coinbase, "%s%s%s%s", templ->coinb1, nonce1, nonce2, templ->coinb2);
|
||||
int coinbase_len = strlen(submitvalues->coinbase);
|
||||
|
||||
unsigned char coinbase_bin[1024];
|
||||
memset(coinbase_bin, 0, 1024);
|
||||
binlify(coinbase_bin, submitvalues->coinbase);
|
||||
|
||||
char doublehash[128];
|
||||
memset(doublehash, 0, 128);
|
||||
|
||||
// some (old) wallet/algos need a simple SHA256 (blakecoin, whirlcoin, groestlcoin...)
|
||||
YAAMP_HASH_FUNCTION merkle_hash = sha256_double_hash_hex;
|
||||
if (g_current_algo->merkle_func)
|
||||
merkle_hash = g_current_algo->merkle_func;
|
||||
merkle_hash((char *)coinbase_bin, doublehash, coinbase_len/2);
|
||||
|
||||
string merkleroot = merkle_with_first(templ->txsteps, doublehash);
|
||||
ser_string_be(merkleroot.c_str(), submitvalues->merkleroot_be, 8);
|
||||
|
||||
#ifdef MERKLE_DEBUGLOG
|
||||
printf("merkle root %s\n", merkleroot.c_str());
|
||||
#endif
|
||||
create_decred_header(templ, submitvalues, ntime, nonce, nonce2);
|
||||
|
||||
//ser_string_be(submitvalues->header, submitvalues->header_be, 20);
|
||||
//binlify(submitvalues->header_bin, submitvalues->header_be);
|
||||
|
||||
// printf("%s\n", submitvalues->header_be);
|
||||
int header_len = strlen(submitvalues->header)/2;
|
||||
g_current_algo->hash_function((char *)submitvalues->header_bin, (char *)submitvalues->hash_bin, header_len);
|
||||
|
||||
hexlify(submitvalues->hash_hex, submitvalues->hash_bin, 32);
|
||||
string_be(submitvalues->hash_hex, submitvalues->hash_be);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VALUES *submitvalues, char *extranonce2, char *ntime, char *nonce)
|
||||
|
@ -286,7 +359,10 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params)
|
|||
YAAMP_JOB_VALUES submitvalues;
|
||||
memset(&submitvalues, 0, sizeof(submitvalues));
|
||||
|
||||
build_submit_values(&submitvalues, templ, client->extranonce1, extranonce2, ntime, nonce);
|
||||
if(job->coind && !strcmp(job->coind->symbol,"DCR"))
|
||||
build_submit_values_decred(&submitvalues, templ, client->extranonce1, extranonce2, ntime, nonce);
|
||||
else
|
||||
build_submit_values(&submitvalues, templ, client->extranonce1, extranonce2, ntime, nonce);
|
||||
|
||||
// minimum hash diff begins with 0000, for all...
|
||||
uint8_t pfx = submitvalues.hash_bin[30] | submitvalues.hash_bin[31];
|
||||
|
|
|
@ -196,6 +196,12 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
|
|||
job_pack_tx(coind, templ->coinb2, available, NULL);
|
||||
strcat(templ->coinb2, "00000000"); // locktime
|
||||
|
||||
if(!strcmp(coind->symbol, "DCR")) {
|
||||
// bypass coinbase and merkle for now... sent without changes
|
||||
const unsigned char *hdr = (unsigned char *) &templ->header[36];
|
||||
hexlify(templ->coinb1, hdr, 192 - 80);
|
||||
}
|
||||
|
||||
//if(coind->txmessage)
|
||||
// strcat(templ->coinb2, "00");
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ void coind_init(YAAMP_COIND *coind)
|
|||
yaamp_create_mutex(&coind->mutex);
|
||||
|
||||
coind->rpc.curl = 0;
|
||||
if(!strcmp(coind->symbol, "DCR") || !strcmp(coind->symbol, "DCRD")) {
|
||||
if(!strcmp(coind->symbol, "DCR")) {
|
||||
coind->rpc.curl = 1;
|
||||
sprintf(account, "default");
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ static int coind_parse_decred_header(YAAMP_JOB_TEMPLATE *templ, json_value *json
|
|||
uint32_t size;
|
||||
uint32_t ntime;
|
||||
uint32_t nonce;
|
||||
char extra[36];
|
||||
unsigned char extra[36];
|
||||
} header;
|
||||
|
||||
const char *header_hex = json_get_string(json, "header");
|
||||
|
@ -125,7 +125,7 @@ static int coind_parse_decred_header(YAAMP_JOB_TEMPLATE *templ, json_value *json
|
|||
binlify((unsigned char*) &header, header_hex);
|
||||
|
||||
templ->height = header.height;
|
||||
sprintf(templ->version, "%08x", header.version);
|
||||
sprintf(templ->version, "%08x", bswap32(header.version));
|
||||
sprintf(templ->ntime, "%08x", header.ntime);
|
||||
sprintf(templ->nbits, "%08x", header.nbits);
|
||||
|
||||
|
@ -134,6 +134,9 @@ static int coind_parse_decred_header(YAAMP_JOB_TEMPLATE *templ, json_value *json
|
|||
for(int i=0; i < 32; i++)
|
||||
sprintf(templ->prevhash_hex + (i*2), "%02x", (uint8_t) header.prevblock[31-i]);
|
||||
|
||||
// store all other stuff
|
||||
memcpy(templ->header, &header, sizeof(header));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -192,7 +195,7 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind)
|
|||
const char *flags = json_get_string(json_coinbaseaux, "flags");
|
||||
strcpy(templ->flags, flags ? flags : "");
|
||||
|
||||
if (!strcmp(coind->symbol, "DCR") || !strcmp(coind->symbol, "DCRD")) {
|
||||
if (!strcmp(coind->symbol, "DCR")) {
|
||||
coind_parse_decred_header(templ, json_result);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -89,6 +89,13 @@ static bool job_assign_client(YAAMP_JOB *job, YAAMP_CLIENT *client, double maxha
|
|||
strcpy(client->extranonce1, client->extranonce1_default);
|
||||
client->extranonce2size = client->extranonce2size_default;
|
||||
|
||||
// decred uses an extradata field in block header, 2 first uint32 are set by the miner
|
||||
if (g_current_algo->name && !strcmp(g_current_algo->name,"decred")) {
|
||||
memset(client->extranonce1, '0', sizeof(client->extranonce1));
|
||||
memcpy(&client->extranonce1[16], client->extranonce1_default, 8);
|
||||
client->extranonce1[24] = '\0';
|
||||
}
|
||||
|
||||
client->difficulty_remote = 0;
|
||||
client->jobid_locked = 0;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ struct YAAMP_JOB_TEMPLATE
|
|||
char coinb1[4*1024];
|
||||
char coinb2[4*1024];
|
||||
|
||||
char header[256];
|
||||
|
||||
int auxs_size;
|
||||
YAAMP_COIND_AUX *auxs[MAX_AUXS];
|
||||
};
|
||||
|
|
|
@ -99,6 +99,7 @@ YAAMP_ALGO g_algos[] =
|
|||
{"blake", blake_hash, 1, 0 },
|
||||
{"blakecoin", blakecoin_hash, 0x100, 0, sha256_hash_hex },
|
||||
{"vanilla", blakecoin_hash, 1, 0 },
|
||||
{"decred", decred_hash, 1, 0 },
|
||||
|
||||
{"fresh", fresh_hash, 0x100, 0, 0},
|
||||
{"quark", quark_hash, 1, 0, 0},
|
||||
|
|
Loading…
Add table
Reference in a new issue