aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp43
-rw-r--r--src/cryptonote_core/blockchain.h4
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.cpp26
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.h12
-rw-r--r--src/cryptonote_core/tx_pool.cpp1
5 files changed, 41 insertions, 45 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index d312d97bd..1baa6bff9 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -48,7 +48,6 @@
#include "file_io_utils.h"
#include "int-util.h"
#include "common/threadpool.h"
-#include "common/boost_serialization_helper.h"
#include "warnings.h"
#include "crypto/hash.h"
#include "cryptonote_core.h"
@@ -456,6 +455,14 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
if (!update_next_cumulative_weight_limit())
return false;
}
+
+ if (m_hardfork->get_current_version() >= RX_BLOCK_VERSION)
+ {
+ const crypto::hash seedhash = get_block_id_by_height(crypto::rx_seedheight(m_db->height()));
+ if (seedhash != crypto::null_hash)
+ rx_set_main_seedhash(seedhash.data, tools::get_max_concurrency());
+ }
+
return true;
}
//------------------------------------------------------------------
@@ -570,6 +577,12 @@ void Blockchain::pop_blocks(uint64_t nblocks)
if (stop_batch)
m_db->batch_stop();
+
+ if (m_hardfork->get_current_version() >= RX_BLOCK_VERSION)
+ {
+ const crypto::hash seedhash = get_block_id_by_height(crypto::rx_seedheight(m_db->height()));
+ rx_set_main_seedhash(seedhash.data, tools::get_max_concurrency());
+ }
}
//------------------------------------------------------------------
// This function tells BlockchainDB to remove the top block from the
@@ -1239,18 +1252,20 @@ 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)
reorg_notify->notify("%s", std::to_string(split_height).c_str(), "%h", std::to_string(m_db->height()).c_str(),
"%n", std::to_string(m_db->height() - split_height).c_str(), "%d", std::to_string(discarded_blocks).c_str(), NULL);
+ const uint64_t new_height = m_db->height();
+ const crypto::hash seedhash = get_block_id_by_height(crypto::rx_seedheight(new_height));
+
crypto::hash prev_id;
if (!get_block_hash(alt_chain.back().bl, prev_id))
MERROR("Failed to get block hash of an alternative chain's tip");
else
- send_miner_notifications(prev_id, alt_chain.back().already_generated_coins);
+ send_miner_notifications(new_height, seedhash, prev_id, alt_chain.back().already_generated_coins);
for (const auto& notifier : m_block_notifiers)
{
@@ -1262,6 +1277,9 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<block_extended_info>
}
}
+ if (m_hardfork->get_current_version() >= RX_BLOCK_VERSION)
+ rx_set_main_seedhash(seedhash.data, tools::get_max_concurrency());
+
MGINFO_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height());
return true;
}
@@ -2001,7 +2019,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
{
seedhash = get_block_id_by_height(seedheight);
}
- get_altblock_longhash(bei.bl, proof_of_work, get_current_blockchain_height(), bei.height, seedheight, seedhash);
+ get_altblock_longhash(bei.bl, proof_of_work, seedhash);
} else
{
get_block_longhash(this, bei.bl, proof_of_work, bei.height, 0);
@@ -4552,11 +4570,15 @@ leave:
}
}
- send_miner_notifications(id, already_generated_coins);
+ const crypto::hash seedhash = get_block_id_by_height(crypto::rx_seedheight(new_height));
+ send_miner_notifications(new_height, seedhash, id, already_generated_coins);
for (const auto& notifier: m_block_notifiers)
notifier(new_height - 1, {std::addressof(bl), 1});
+ if (m_hardfork->get_current_version() >= RX_BLOCK_VERSION)
+ rx_set_main_seedhash(seedhash.data, tools::get_max_concurrency());
+
return true;
}
//------------------------------------------------------------------
@@ -5761,24 +5783,15 @@ void Blockchain::cache_block_template(const block &b, const cryptonote::account_
m_btc_valid = true;
}
-void Blockchain::send_miner_notifications(const crypto::hash &prev_id, uint64_t already_generated_coins)
+void Blockchain::send_miner_notifications(uint64_t height, const crypto::hash &seed_hash, const crypto::hash &prev_id, uint64_t already_generated_coins)
{
if (m_miner_notifiers.empty())
return;
- const uint64_t height = m_db->height();
const uint8_t major_version = m_hardfork->get_ideal_version(height);
const difficulty_type diff = get_difficulty_for_next_block();
const uint64_t median_weight = m_current_block_cumul_weight_median;
- crypto::hash seed_hash = crypto::null_hash;
- if (m_hardfork->get_current_version() >= RX_BLOCK_VERSION)
- {
- uint64_t seed_height, next_height;
- crypto::rx_seedheights(height, &seed_height, &next_height);
- seed_hash = get_block_id_by_height(seed_height);
- }
-
std::vector<tx_block_template_backlog_entry> tx_backlog;
m_tx_pool.get_block_template_backlog(tx_backlog);
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 4795fc55c..c61ce4466 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -1598,9 +1598,11 @@ namespace cryptonote
/**
* @brief sends new block notifications to ZMQ `miner_data` subscribers
*
+ * @param height current blockchain height
+ * @param seed_hash seed hash to use for mining
* @param prev_id hash of new blockchain tip
* @param already_generated_coins total coins mined by the network so far
*/
- void send_miner_notifications(const crypto::hash &prev_id, uint64_t already_generated_coins);
+ void send_miner_notifications(uint64_t height, const crypto::hash &seed_hash, const crypto::hash &prev_id, uint64_t already_generated_coins);
};
} // namespace cryptonote
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 472026217..bf58a120d 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -669,10 +669,10 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------
- void get_altblock_longhash(const block& b, crypto::hash& res, const uint64_t main_height, const uint64_t height, const uint64_t seed_height, const crypto::hash& seed_hash)
+ void get_altblock_longhash(const block& b, crypto::hash& res, const crypto::hash& seed_hash)
{
blobdata bd = get_block_hashing_blob(b);
- rx_slow_hash(main_height, seed_height, seed_hash.data, bd.data(), bd.size(), res.data, 0, 1);
+ rx_slow_hash(seed_hash.data, bd.data(), bd.size(), res.data);
}
bool get_block_longhash(const Blockchain *pbc, const blobdata& bd, crypto::hash& res, const uint64_t height, const int major_version, const crypto::hash *seed_hash, const int miners)
@@ -686,20 +686,16 @@ namespace cryptonote
}
if (major_version >= RX_BLOCK_VERSION)
{
- uint64_t seed_height, main_height;
crypto::hash hash;
if (pbc != NULL)
{
- seed_height = rx_seedheight(height);
+ const uint64_t seed_height = rx_seedheight(height);
hash = seed_hash ? *seed_hash : pbc->get_pending_block_id_by_height(seed_height);
- main_height = pbc->get_current_blockchain_height();
} else
{
memset(&hash, 0, sizeof(hash)); // only happens when generating genesis block
- seed_height = 0;
- main_height = 0;
}
- rx_slow_hash(main_height, seed_height, hash.data, bd.data(), bd.size(), res.data, seed_hash ? 0 : miners, !!seed_hash);
+ rx_slow_hash(hash.data, bd.data(), bd.size(), res.data);
} else {
const int pow_variant = major_version >= 7 ? major_version - 6 : 0;
crypto::cn_slow_hash(bd.data(), bd.size(), res, pow_variant, height);
@@ -713,20 +709,10 @@ namespace cryptonote
return get_block_longhash(pbc, bd, res, height, b.major_version, seed_hash, miners);
}
- bool get_block_longhash(const Blockchain *pbc, const block& b, crypto::hash& res, const uint64_t height, const int miners)
- {
- return get_block_longhash(pbc, b, res, height, NULL, miners);
- }
-
- crypto::hash get_block_longhash(const Blockchain *pbc, const block& b, const uint64_t height, const int miners)
+ crypto::hash get_block_longhash(const Blockchain *pbc, const block& b, const uint64_t height, const crypto::hash *seed_hash, const int miners)
{
crypto::hash p = crypto::null_hash;
- get_block_longhash(pbc, b, p, height, miners);
+ get_block_longhash(pbc, b, p, height, seed_hash, miners);
return p;
}
-
- void get_block_longhash_reorg(const uint64_t split_height)
- {
- rx_reorg(split_height);
- }
}
diff --git a/src/cryptonote_core/cryptonote_tx_utils.h b/src/cryptonote_core/cryptonote_tx_utils.h
index 12d6b8ce5..5f301bb89 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.h
+++ b/src/cryptonote_core/cryptonote_tx_utils.h
@@ -144,14 +144,10 @@ namespace cryptonote
);
class Blockchain;
- bool get_block_longhash(const Blockchain *pb, const blobdata& bd, crypto::hash& res, const uint64_t height,
- const int major_version, const crypto::hash *seed_hash, const int miners);
- bool get_block_longhash(const Blockchain *pb, const block& b, crypto::hash& res, const uint64_t height, const int miners);
- bool get_block_longhash(const Blockchain *pb, const block& b, crypto::hash& res, const uint64_t height, const crypto::hash *seed_hash, const int miners);
- void get_altblock_longhash(const block& b, crypto::hash& res, const uint64_t main_height, const uint64_t height,
- const uint64_t seed_height, const crypto::hash& seed_hash);
- crypto::hash get_block_longhash(const Blockchain *pb, const block& b, const uint64_t height, const int miners);
- void get_block_longhash_reorg(const uint64_t split_height);
+ bool get_block_longhash(const Blockchain *pb, const blobdata& bd, crypto::hash& res, const uint64_t height, const int major_version, const crypto::hash *seed_hash, const int miners = 0);
+ bool get_block_longhash(const Blockchain *pb, const block& b, crypto::hash& res, const uint64_t height, const crypto::hash *seed_hash = nullptr, const int miners = 0);
+ crypto::hash get_block_longhash(const Blockchain *pb, const block& b, const uint64_t height, const crypto::hash *seed_hash = nullptr, const int miners = 0);
+ void get_altblock_longhash(const block& b, crypto::hash& res, const crypto::hash& seed_hash);
}
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 2a514ceae..3346a9aba 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -40,7 +40,6 @@
#include "blockchain.h"
#include "blockchain_db/locked_txn.h"
#include "blockchain_db/blockchain_db.h"
-#include "common/boost_serialization_helper.h"
#include "int-util.h"
#include "misc_language.h"
#include "warnings.h"