copied merkle tree for nerdnos
This commit is contained in:
parent
c772ac4a91
commit
def93a8579
@ -61,8 +61,8 @@ static void dump(mining_job *job) {
|
|||||||
Serial.printf("ntime: %s\n", job->ntime.c_str());
|
Serial.printf("ntime: %s\n", job->ntime.c_str());
|
||||||
Serial.printf("taget: %lu\n", job->target);
|
Serial.printf("taget: %lu\n", job->target);
|
||||||
Serial.printf("clean_jobs: %s\n", job->clean_jobs ? "true" : "false");
|
Serial.printf("clean_jobs: %s\n", job->clean_jobs ? "true" : "false");
|
||||||
for (size_t i = 0; i < job->merkle_branch.size(); i++) {
|
for (size_t i = 0; i < job->merkle_branch_size; i++) {
|
||||||
const char* m = job->merkle_branch[i];
|
const char* m = job->merkle_branch[i].c_str();
|
||||||
Serial.printf("merkle_branch[%d]: %s\n", i, m);
|
Serial.printf("merkle_branch[%d]: %s\n", i, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,8 +77,8 @@ static void calculate_merkle_root_hash(const char *coinbase_tx, mining_job* job,
|
|||||||
double_sha256_bin(coinbase_tx_bin, coinbase_tx_bin_len, new_root);
|
double_sha256_bin(coinbase_tx_bin, coinbase_tx_bin_len, new_root);
|
||||||
memcpy(both_merkles, new_root, 32);
|
memcpy(both_merkles, new_root, 32);
|
||||||
|
|
||||||
for (size_t i = 0; i < job->merkle_branch.size(); i++) {
|
for (size_t i = 0; i < job->merkle_branch_size; i++) {
|
||||||
const char* m = job->merkle_branch[i];
|
const char* m = job->merkle_branch[i].c_str();
|
||||||
// if merkle branch is not what we expect, dump the job
|
// if merkle branch is not what we expect, dump the job
|
||||||
if (!is_hex_string(m)) {
|
if (!is_hex_string(m)) {
|
||||||
dump(job);
|
dump(job);
|
||||||
|
@ -188,7 +188,20 @@ bool parse_mining_notify(String line, mining_job& mJob)
|
|||||||
mJob.prev_block_hash = String((const char*) doc["params"][1]);
|
mJob.prev_block_hash = String((const char*) doc["params"][1]);
|
||||||
mJob.coinb1 = String((const char*) doc["params"][2]);
|
mJob.coinb1 = String((const char*) doc["params"][2]);
|
||||||
mJob.coinb2 = String((const char*) doc["params"][3]);
|
mJob.coinb2 = String((const char*) doc["params"][3]);
|
||||||
mJob.merkle_branch = doc["params"][4];
|
|
||||||
|
// this only copies references to the static json buffer
|
||||||
|
// and can lead to crashes when there is a new stratum response
|
||||||
|
// and the content of the array is still needed like on NerdNOS
|
||||||
|
// that computes the merkle tree new each 30ms^^
|
||||||
|
//mJob.merkle_branch = doc["params"][4];
|
||||||
|
|
||||||
|
// This copies the merkle branch
|
||||||
|
JsonArray merkle_tree = doc["params"][4];
|
||||||
|
mJob.merkle_branch_size = merkle_tree.size();
|
||||||
|
for (size_t i = 0; i < mJob.merkle_branch_size; i++) {
|
||||||
|
mJob.merkle_branch[i] = String((const char*) merkle_tree[i]);
|
||||||
|
}
|
||||||
|
|
||||||
mJob.version = String((const char*) doc["params"][5]);
|
mJob.version = String((const char*) doc["params"][5]);
|
||||||
mJob.nbits = String((const char*) doc["params"][6]);
|
mJob.nbits = String((const char*) doc["params"][6]);
|
||||||
mJob.ntime = String((const char*) doc["params"][7]);
|
mJob.ntime = String((const char*) doc["params"][7]);
|
||||||
|
@ -31,7 +31,8 @@ typedef struct mining_job {
|
|||||||
String coinb1;
|
String coinb1;
|
||||||
String coinb2;
|
String coinb2;
|
||||||
String nbits;
|
String nbits;
|
||||||
JsonArray merkle_branch;
|
String merkle_branch[MAX_MERKLE_BRANCHES];
|
||||||
|
size_t merkle_branch_size;
|
||||||
String version;
|
String version;
|
||||||
uint32_t target;
|
uint32_t target;
|
||||||
String ntime;
|
String ntime;
|
||||||
|
@ -254,8 +254,8 @@ miner_data calculateMiningData(mining_subscribe& mWorker, mining_job mJob){
|
|||||||
memcpy(mMiner.merkle_result, shaResult, sizeof(shaResult));
|
memcpy(mMiner.merkle_result, shaResult, sizeof(shaResult));
|
||||||
|
|
||||||
byte merkle_concatenated[32 * 2];
|
byte merkle_concatenated[32 * 2];
|
||||||
for (size_t k=0; k < mJob.merkle_branch.size(); k++) {
|
for (size_t k=0; k < mJob.merkle_branch_size; k++) {
|
||||||
const char* merkle_element = (const char*) mJob.merkle_branch[k];
|
const char* merkle_element = (const char*) mJob.merkle_branch[k].c_str();
|
||||||
uint8_t bytearray[32];
|
uint8_t bytearray[32];
|
||||||
size_t res = to_byte_array(merkle_element, 64, bytearray);
|
size_t res = to_byte_array(merkle_element, 64, bytearray);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user