aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authorHoward Chu <hyc@symas.com>2019-04-23 20:32:27 +0100
committerHoward Chu <hyc@symas.com>2019-09-25 21:29:42 +0100
commit81c2ad6d5b17cf280a4a55fd6159e8dde423f5a8 (patch)
tree7bb731b721183e73afbb60e01cf3759723e4948b /src/cryptonote_core/blockchain.cpp
parentMerge pull request #5909 (diff)
downloadmonero-81c2ad6d5b17cf280a4a55fd6159e8dde423f5a8.tar.xz
RandomX integration
Support RandomX PoW algorithm
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 5cf4952ae..bcf99bbed 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -95,7 +95,8 @@ Blockchain::Blockchain(tx_memory_pool& tx_pool) :
m_difficulty_for_next_block_top_hash(crypto::null_hash),
m_difficulty_for_next_block(1),
m_btc_valid(false),
- m_batch_success(true)
+ m_batch_success(true),
+ m_prepare_height(0)
{
LOG_PRINT_L3("Blockchain::" << __func__);
}
@@ -754,6 +755,13 @@ crypto::hash Blockchain::get_block_id_by_height(uint64_t height) const
return null_hash;
}
//------------------------------------------------------------------
+crypto::hash Blockchain::get_pending_block_id_by_height(uint64_t height) const
+{
+ if (m_prepare_height && height >= m_prepare_height && height - m_prepare_height < m_prepare_nblocks)
+ return (*m_prepare_blocks)[height - m_prepare_height].hash;
+ return get_block_id_by_height(height);
+}
+//------------------------------------------------------------------
bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk, bool *orphan) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
@@ -1029,6 +1037,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<block_extended_info>
}
m_hardfork->reorganize_from_chain_height(split_height);
+ get_block_longhash_reorg(split_height);
std::shared_ptr<tools::Notify> reorg_notify = m_reorg_notify;
if (reorg_notify)
@@ -1684,7 +1693,30 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
difficulty_type current_diff = get_next_difficulty_for_alternative_chain(alt_chain, bei);
CHECK_AND_ASSERT_MES(current_diff, false, "!!!!!!! DIFFICULTY OVERHEAD !!!!!!!");
crypto::hash proof_of_work = null_hash;
- get_block_longhash(bei.bl, proof_of_work, bei.height);
+ if (b.major_version >= RX_BLOCK_VERSION)
+ {
+ crypto::hash seedhash = null_hash;
+ uint64_t seedheight = rx_seedheight(bei.height);
+ // seedblock is on the alt chain somewhere
+ if (alt_chain.size() && alt_chain.front().height <= seedheight)
+ {
+ for (auto it=alt_chain.begin(); it != alt_chain.end(); it++)
+ {
+ if (it->height == seedheight+1)
+ {
+ seedhash = it->bl.prev_id;
+ break;
+ }
+ }
+ } else
+ {
+ seedhash = get_block_id_by_height(seedheight);
+ }
+ get_altblock_longhash(bei.bl, proof_of_work, get_current_blockchain_height(), bei.height, seedheight, seedhash);
+ } else
+ {
+ get_block_longhash(this, bei.bl, proof_of_work, bei.height, 0);
+ }
if(!check_hash(proof_of_work, current_diff))
{
MERROR_VER("Block with id: " << id << std::endl << " for alternative chain, does not have enough proof of work: " << proof_of_work << std::endl << " expected difficulty: " << current_diff);
@@ -3613,7 +3645,7 @@ leave:
proof_of_work = it->second;
}
else
- proof_of_work = get_block_longhash(bl, blockchain_height);
+ proof_of_work = get_block_longhash(this, bl, blockchain_height, 0);
// validate proof_of_work versus difficulty target
if(!check_hash(proof_of_work, current_diffic))
@@ -4114,7 +4146,7 @@ void Blockchain::block_longhash_worker(uint64_t height, const epee::span<const b
if (m_cancel)
break;
crypto::hash id = get_block_hash(block);
- crypto::hash pow = get_block_longhash(block, height++);
+ crypto::hash pow = get_block_longhash(this, block, height++, 0);
map.emplace(id, pow);
}
@@ -4430,6 +4462,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
m_blocks_longhash_table.clear();
uint64_t thread_height = height;
tools::threadpool::waiter waiter;
+ m_prepare_height = height;
+ m_prepare_nblocks = blocks_entry.size();
+ m_prepare_blocks = &blocks;
for (unsigned int i = 0; i < threads; i++)
{
unsigned nblocks = batches;
@@ -4440,6 +4475,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
}
waiter.wait(&tpool);
+ m_prepare_height = 0;
if (m_cancel)
return false;