switch to SHA-3 PoW

Co-authored-by: fuwa <fuwa0529@users.noreply.github.com>
This commit is contained in:
wowario
2020-05-15 08:37:36 +03:00
co-authored by fuwa
parent 116d29906c
commit 87dcc37776
18 changed files with 89 additions and 23 deletions
+14 -2
View File
@@ -449,14 +449,26 @@ namespace cryptonote
uint8_t minor_version; // now used as a voting mechanism, rather than how this particular block is built
uint64_t timestamp;
crypto::hash prev_id;
uint32_t nonce;
uint64_t nonce;
BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
VARINT_FIELD(minor_version)
VARINT_FIELD(timestamp)
FIELD(prev_id)
FIELD(nonce)
if (major_version >= HF_VERSION_SHA3_POW)
{
FIELD(nonce)
}
else
{
uint32_t nonce32;
if (typename Archive<W>::is_saving())
nonce32 = (uint32_t)nonce;
FIELD_N("nonce", nonce32);
if (!typename Archive<W>::is_saving())
nonce = nonce32;
}
END_SERIALIZE()
};
+4 -4
View File
@@ -144,7 +144,7 @@ namespace cryptonote
m_height = height;
m_block_reward = block_reward;
++m_template_no;
m_starter_nonce = crypto::rand<uint32_t>();
m_starter_nonce = crypto::rand<uint64_t>();
return true;
}
//-----------------------------------------------------------------------------------------------------
@@ -375,7 +375,7 @@ namespace cryptonote
m_threads_autodetect.push_back({epee::misc_utils::get_ns_count(), m_total_hashes});
m_threads_total = 1;
}
m_starter_nonce = crypto::rand<uint32_t>();
m_starter_nonce = crypto::rand<uint64_t>();
CRITICAL_REGION_LOCAL(m_threads_lock);
if(is_mining())
{
@@ -473,7 +473,7 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------------
bool miner::find_nonce_for_given_block(const get_block_hash_t &gbh, block& bl, const difficulty_type& diffic, uint64_t height)
{
for(; bl.nonce != std::numeric_limits<uint32_t>::max(); bl.nonce++)
for(; bl.nonce != std::numeric_limits<uint64_t>::max(); bl.nonce++)
{
crypto::hash h;
gbh(bl, height, diffic <= 100 ? 0 : tools::get_max_concurrency(), h);
@@ -524,7 +524,7 @@ namespace cryptonote
uint32_t th_local_index = boost::interprocess::ipcdetail::atomic_inc32(&m_thread_index);
MLOG_SET_THREAD_NAME(std::string("[miner ") + std::to_string(th_local_index) + "]");
MGINFO("Miner thread was started ["<< th_local_index << "]");
uint32_t nonce = m_starter_nonce + th_local_index;
uint64_t nonce = m_starter_nonce + th_local_index;
uint64_t height = 0;
difficulty_type local_diff = 0;
uint32_t local_template_ver = 0;
+1 -1
View File
@@ -123,7 +123,7 @@ namespace cryptonote
epee::critical_section m_template_lock;
block m_template;
std::atomic<uint32_t> m_template_no;
std::atomic<uint32_t> m_starter_nonce;
std::atomic<uint64_t> m_starter_nonce;
difficulty_type m_diffic;
uint64_t m_height;
volatile uint32_t m_thread_index;