Merge pull request #2287

827afcb7 protocol: pass blockchain cumulative difficulty when syncing (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2017-08-17 21:35:02 +02:00
commit 4b2cc123ff
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
8 changed files with 30 additions and 0 deletions

View file

@ -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.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(); m_db->block_txn_stop();
return true; return true;
} }

View file

@ -826,6 +826,16 @@ namespace cryptonote
*/ */
bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)>) const; bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)>) const;
/**
* @brief get a reference to the BlockchainDB in use by Blockchain
*
* @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 * @brief get a reference to the BlockchainDB in use by Blockchain
* *

View file

@ -1110,6 +1110,11 @@ namespace cryptonote
return m_blockchain_storage.get_tail_id(); 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 size_t core::get_pool_transactions_count() const
{ {
return m_mempool.get_transactions_count(); return m_mempool.get_transactions_count();

View file

@ -520,6 +520,13 @@ namespace cryptonote
*/ */
crypto::hash get_tail_id() const; 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 * @copydoc Blockchain::get_random_outs_for_amounts
* *

View file

@ -197,11 +197,13 @@ namespace cryptonote
struct CORE_SYNC_DATA struct CORE_SYNC_DATA
{ {
uint64_t current_height; uint64_t current_height;
uint64_t cumulative_difficulty;
crypto::hash top_id; crypto::hash top_id;
uint8_t top_version; uint8_t top_version;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(current_height) KV_SERIALIZE(current_height)
KV_SERIALIZE(cumulative_difficulty)
KV_SERIALIZE_VAL_POD_AS_BLOB(top_id) KV_SERIALIZE_VAL_POD_AS_BLOB(top_id)
KV_SERIALIZE_OPT(top_version, (uint8_t)0) KV_SERIALIZE_OPT(top_version, (uint8_t)0)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
@ -229,11 +231,13 @@ namespace cryptonote
{ {
uint64_t start_height; uint64_t start_height;
uint64_t total_height; uint64_t total_height;
uint64_t cumulative_difficulty;
std::list<crypto::hash> m_block_ids; std::list<crypto::hash> m_block_ids;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(start_height) KV_SERIALIZE(start_height)
KV_SERIALIZE(total_height) KV_SERIALIZE(total_height)
KV_SERIALIZE(cumulative_difficulty)
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids) KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View file

@ -309,6 +309,7 @@ namespace cryptonote
{ {
m_core.get_blockchain_top(hshd.current_height, hshd.top_id); m_core.get_blockchain_top(hshd.current_height, hshd.top_id);
hshd.top_version = m_core.get_hard_fork_version(hshd.current_height); 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; hshd.current_height +=1;
return true; return true;
} }

View file

@ -98,5 +98,6 @@ namespace tests
bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; } bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; }
uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; } uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; }
uint8_t get_hard_fork_version(uint64_t height) const { return 0; } uint8_t get_hard_fork_version(uint64_t height) const { return 0; }
cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
}; };
} }

View file

@ -75,6 +75,7 @@ public:
bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; } bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; }
uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; } uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; }
uint8_t get_hard_fork_version(uint64_t height) const { return 0; } uint8_t get_hard_fork_version(uint64_t height) const { return 0; }
cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return 0; }
}; };
typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_core>> Server; typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_core>> Server;