aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-08-12 15:24:39 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-08-15 21:03:37 +0100
commit827afcb7ea10eb2bf03ffb7ad2520f29cd53019f (patch)
treeb0736c05f24b7481b336e79ba7b9d7095d33c21d /src
parentMerge pull request #2286 (diff)
downloadmonero-827afcb7ea10eb2bf03ffb7ad2520f29cd53019f.tar.xz
protocol: pass blockchain cumulative difficulty when syncing
Not used yet.
Diffstat (limited to '')
-rw-r--r--src/cryptonote_core/blockchain.cpp1
-rw-r--r--src/cryptonote_core/blockchain.h10
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp5
-rw-r--r--src/cryptonote_core/cryptonote_core.h7
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_defs.h4
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl1
6 files changed, 28 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 61ddff3d0..14a990131 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -2038,6 +2038,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
{
resp.m_block_ids.push_back(m_db->get_block_hash_from_height(i));
}
+ resp.cumulative_difficulty = m_db->get_block_cumulative_difficulty(m_db->height() - 1);
m_db->block_txn_stop();
return true;
}
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 7137f50a7..7fa78584b 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -831,6 +831,16 @@ namespace cryptonote
*
* @return a reference to the BlockchainDB instance
*/
+ const BlockchainDB& get_db() const
+ {
+ return *m_db;
+ }
+
+ /**
+ * @brief get a reference to the BlockchainDB in use by Blockchain
+ *
+ * @return a reference to the BlockchainDB instance
+ */
BlockchainDB& get_db()
{
return *m_db;
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 62c536ab8..d5acf2ffa 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1103,6 +1103,11 @@ namespace cryptonote
return m_blockchain_storage.get_tail_id();
}
//-----------------------------------------------------------------------------------------------
+ difficulty_type core::get_block_cumulative_difficulty(uint64_t height) const
+ {
+ return m_blockchain_storage.get_db().get_block_cumulative_difficulty(height);
+ }
+ //-----------------------------------------------------------------------------------------------
size_t core::get_pool_transactions_count() const
{
return m_mempool.get_transactions_count();
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 63d3cd16d..3c66d772d 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -521,6 +521,13 @@ namespace cryptonote
crypto::hash get_tail_id() const;
/**
+ * @copydoc Blockchain::get_block_cumulative_difficulty
+ *
+ * @note see Blockchain::get_block_cumulative_difficulty
+ */
+ difficulty_type get_block_cumulative_difficulty(uint64_t height) const;
+
+ /**
* @copydoc Blockchain::get_random_outs_for_amounts
*
* @note see Blockchain::get_random_outs_for_amounts
diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h
index 6e6c83f04..71e205c23 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_defs.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h
@@ -197,11 +197,13 @@ namespace cryptonote
struct CORE_SYNC_DATA
{
uint64_t current_height;
+ uint64_t cumulative_difficulty;
crypto::hash top_id;
uint8_t top_version;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(current_height)
+ KV_SERIALIZE(cumulative_difficulty)
KV_SERIALIZE_VAL_POD_AS_BLOB(top_id)
KV_SERIALIZE_OPT(top_version, (uint8_t)0)
END_KV_SERIALIZE_MAP()
@@ -229,11 +231,13 @@ namespace cryptonote
{
uint64_t start_height;
uint64_t total_height;
+ uint64_t cumulative_difficulty;
std::list<crypto::hash> m_block_ids;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(start_height)
KV_SERIALIZE(total_height)
+ KV_SERIALIZE(cumulative_difficulty)
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
END_KV_SERIALIZE_MAP()
};
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 5b3b059a4..265e60b3f 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -309,6 +309,7 @@ namespace cryptonote
{
m_core.get_blockchain_top(hshd.current_height, hshd.top_id);
hshd.top_version = m_core.get_hard_fork_version(hshd.current_height);
+ hshd.cumulative_difficulty = m_core.get_block_cumulative_difficulty(hshd.current_height);
hshd.current_height +=1;
return true;
}