mirror of
https://github.com/monero-project/monero.git
synced 2025-05-02 13:56:06 -04:00
RandomX integration
Support RandomX PoW algorithm
This commit is contained in:
parent
cb6f96b9d1
commit
81c2ad6d5b
24 changed files with 610 additions and 49 deletions
|
@ -1218,21 +1218,6 @@ namespace cryptonote
|
|||
return p;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height)
|
||||
{
|
||||
// block 202612 bug workaround
|
||||
if (height == 202612)
|
||||
{
|
||||
static const std::string longhash_202612 = "84f64766475d51837ac9efbef1926486e58563c95a19fef4aec3254f03000000";
|
||||
string_tools::hex_to_pod(longhash_202612, res);
|
||||
return true;
|
||||
}
|
||||
blobdata bd = get_block_hashing_blob(b);
|
||||
const int cn_variant = b.major_version >= 7 ? b.major_version - 6 : 0;
|
||||
crypto::cn_slow_hash(bd.data(), bd.size(), res, cn_variant, height);
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
std::vector<uint64_t> relative_output_offsets_to_absolute(const std::vector<uint64_t>& off)
|
||||
{
|
||||
std::vector<uint64_t> res = off;
|
||||
|
@ -1253,13 +1238,6 @@ namespace cryptonote
|
|||
return res;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
crypto::hash get_block_longhash(const block& b, uint64_t height)
|
||||
{
|
||||
crypto::hash p = null_hash;
|
||||
get_block_longhash(b, p, height);
|
||||
return p;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b, crypto::hash *block_hash)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
|
|
@ -117,8 +117,6 @@ namespace cryptonote
|
|||
bool calculate_block_hash(const block& b, crypto::hash& res, const blobdata *blob = NULL);
|
||||
bool get_block_hash(const block& b, crypto::hash& res);
|
||||
crypto::hash get_block_hash(const block& b);
|
||||
bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height);
|
||||
crypto::hash get_block_longhash(const block& b, uint64_t height);
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b, crypto::hash *block_hash);
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b);
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b, crypto::hash &block_hash);
|
||||
|
|
|
@ -36,8 +36,10 @@
|
|||
#include "syncobj.h"
|
||||
#include "cryptonote_basic_impl.h"
|
||||
#include "cryptonote_format_utils.h"
|
||||
#include "cryptonote_core/cryptonote_tx_utils.h"
|
||||
#include "file_io_utils.h"
|
||||
#include "common/command_line.h"
|
||||
#include "common/util.h"
|
||||
#include "string_coding.h"
|
||||
#include "string_tools.h"
|
||||
#include "storages/portable_storage_template_helper.h"
|
||||
|
@ -98,12 +100,13 @@ namespace cryptonote
|
|||
}
|
||||
|
||||
|
||||
miner::miner(i_miner_handler* phandler):m_stop(1),
|
||||
miner::miner(i_miner_handler* phandler, Blockchain* pbc):m_stop(1),
|
||||
m_template{},
|
||||
m_template_no(0),
|
||||
m_diffic(0),
|
||||
m_thread_index(0),
|
||||
m_phandler(phandler),
|
||||
m_pbc(pbc),
|
||||
m_height(0),
|
||||
m_threads_active(0),
|
||||
m_pausers_count(0),
|
||||
|
@ -429,6 +432,7 @@ namespace cryptonote
|
|||
{
|
||||
boost::interprocess::ipcdetail::atomic_write32(&m_stop, 1);
|
||||
}
|
||||
extern "C" void rx_stop_mining(void);
|
||||
//-----------------------------------------------------------------------------------------------------
|
||||
bool miner::stop()
|
||||
{
|
||||
|
@ -461,15 +465,16 @@ namespace cryptonote
|
|||
MINFO("Mining has been stopped, " << m_threads.size() << " finished" );
|
||||
m_threads.clear();
|
||||
m_threads_autodetect.clear();
|
||||
rx_stop_mining();
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------
|
||||
bool miner::find_nonce_for_given_block(block& bl, const difficulty_type& diffic, uint64_t height)
|
||||
bool miner::find_nonce_for_given_block(const Blockchain *pbc, block& bl, const difficulty_type& diffic, uint64_t height)
|
||||
{
|
||||
for(; bl.nonce != std::numeric_limits<uint32_t>::max(); bl.nonce++)
|
||||
{
|
||||
crypto::hash h;
|
||||
get_block_longhash(bl, h, height);
|
||||
get_block_longhash(pbc, bl, h, height, tools::get_max_concurrency());
|
||||
|
||||
if(check_hash(h, diffic))
|
||||
{
|
||||
|
@ -565,7 +570,7 @@ namespace cryptonote
|
|||
|
||||
b.nonce = nonce;
|
||||
crypto::hash h;
|
||||
get_block_longhash(b, h, height);
|
||||
get_block_longhash(m_pbc, b, h, height, tools::get_max_concurrency());
|
||||
|
||||
if(check_hash(h, local_diff))
|
||||
{
|
||||
|
|
|
@ -52,13 +52,15 @@ namespace cryptonote
|
|||
~i_miner_handler(){};
|
||||
};
|
||||
|
||||
class Blockchain;
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
class miner
|
||||
{
|
||||
public:
|
||||
miner(i_miner_handler* phandler);
|
||||
miner(i_miner_handler* phandler, Blockchain* pbc);
|
||||
~miner();
|
||||
bool init(const boost::program_options::variables_map& vm, network_type nettype);
|
||||
static void init_options(boost::program_options::options_description& desc);
|
||||
|
@ -74,7 +76,7 @@ namespace cryptonote
|
|||
bool on_idle();
|
||||
void on_synchronized();
|
||||
//synchronous analog (for fast calls)
|
||||
static bool find_nonce_for_given_block(block& bl, const difficulty_type& diffic, uint64_t height);
|
||||
static bool find_nonce_for_given_block(const Blockchain *pbc, block& bl, const difficulty_type& diffic, uint64_t height);
|
||||
void pause();
|
||||
void resume();
|
||||
void do_print_hashrate(bool do_hr);
|
||||
|
@ -133,6 +135,7 @@ namespace cryptonote
|
|||
std::list<boost::thread> m_threads;
|
||||
epee::critical_section m_threads_lock;
|
||||
i_miner_handler* m_phandler;
|
||||
Blockchain* m_pbc;
|
||||
account_public_address m_mine_address;
|
||||
epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval;
|
||||
epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue