RandomX integration

Support RandomX PoW algorithm
This commit is contained in:
Howard Chu
2019-04-23 20:32:27 +01:00
parent cb6f96b9d1
commit 81c2ad6d5b
24 changed files with 610 additions and 49 deletions

View File

@@ -1060,6 +1060,7 @@ namespace cryptonote
case 1: res.pow_algorithm = "CNv1 (Cryptonight variant 1)"; break;
case 2: case 3: res.pow_algorithm = "CNv2 (Cryptonight variant 2)"; break;
case 4: case 5: res.pow_algorithm = "CNv4 (Cryptonight variant 4)"; break;
case 6: res.pow_algorithm = "RandomX"; break;
default: res.pow_algorithm = "I'm not sure actually"; break;
}
if (res.is_background_mining_enabled)
@@ -1440,6 +1441,18 @@ namespace cryptonote
LOG_ERROR("Failed to create block template");
return false;
}
if (b.major_version >= RX_BLOCK_VERSION)
{
uint64_t seed_height, next_height;
crypto::hash seed_hash;
crypto::rx_seedheights(res.height, &seed_height, &next_height);
seed_hash = m_core.get_block_id_by_height(seed_height);
res.seed_hash = string_tools::pod_to_hex(seed_hash);
if (next_height != seed_height) {
seed_hash = m_core.get_block_id_by_height(next_height);
res.next_seed_hash = string_tools::pod_to_hex(seed_hash);
}
}
store_difficulty(wdiff, res.difficulty, res.wide_difficulty, res.difficulty_top64);
blobdata block_blob = t_serializable_object_to_blob(b);
crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(b.miner_tx);
@@ -1582,7 +1595,7 @@ namespace cryptonote
return false;
}
b.nonce = req.starting_nonce;
miner::find_nonce_for_given_block(b, template_res.difficulty, template_res.height);
miner::find_nonce_for_given_block(&(m_core.get_blockchain_storage()), b, template_res.difficulty, template_res.height);
submit_req.front() = string_tools::buff_to_hex_nodelimer(block_to_blob(b));
r = on_submitblock(submit_req, submit_res, error_resp, ctx);
@@ -1627,7 +1640,7 @@ namespace cryptonote
response.reward = get_block_reward(blk);
response.block_size = response.block_weight = m_core.get_blockchain_storage().get_db().get_block_weight(height);
response.num_txes = blk.tx_hashes.size();
response.pow_hash = fill_pow_hash ? string_tools::pod_to_hex(get_block_longhash(blk, height)) : "";
response.pow_hash = fill_pow_hash ? string_tools::pod_to_hex(get_block_longhash(&(m_core.get_blockchain_storage()), blk, height, 0)) : "";
response.long_term_weight = m_core.get_blockchain_storage().get_db().get_block_long_term_weight(height);
response.miner_tx_hash = string_tools::pod_to_hex(cryptonote::get_transaction_hash(blk.miner_tx));
return true;