diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_basic/connection_context.h | 8 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 1 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.h | 10 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 5 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 7 | ||||
-rw-r--r-- | src/cryptonote_protocol/cryptonote_protocol_defs.h | 4 | ||||
-rw-r--r-- | src/cryptonote_protocol/cryptonote_protocol_handler.inl | 5 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 17 |
8 files changed, 46 insertions, 11 deletions
diff --git a/src/cryptonote_basic/connection_context.h b/src/cryptonote_basic/connection_context.h index 28bd73918..3283543e2 100644 --- a/src/cryptonote_basic/connection_context.h +++ b/src/cryptonote_basic/connection_context.h @@ -39,12 +39,12 @@ namespace cryptonote struct cryptonote_connection_context: public epee::net_utils::connection_context_base { - cryptonote_connection_context(): m_state(state_befor_handshake), m_remote_blockchain_height(0), m_last_response_height(0), + cryptonote_connection_context(): m_state(state_before_handshake), m_remote_blockchain_height(0), m_last_response_height(0), m_last_known_hash(cryptonote::null_hash) {} enum state { - state_befor_handshake = 0, //default state + state_before_handshake = 0, //default state state_synchronizing, state_standby, state_idle, @@ -66,8 +66,8 @@ namespace cryptonote { switch (s) { - case cryptonote_connection_context::state_befor_handshake: - return "state_befor_handshake"; + case cryptonote_connection_context::state_before_handshake: + return "state_before_handshake"; case cryptonote_connection_context::state_synchronizing: return "state_synchronizing"; case cryptonote_connection_context::state_standby: 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 046b0eca0..19f4aaca9 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1118,6 +1118,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 982d67169..f17a6dfe6 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 60cce4594..daefe88b7 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -204,7 +204,7 @@ namespace cryptonote } std::stringstream peer_id_str; - peer_id_str << std::hex << peer_id; + peer_id_str << std::hex << std::setw(16) << peer_id; peer_id_str >> cnx.peer_id; cnx.support_flags = support_flags; @@ -253,7 +253,7 @@ namespace cryptonote template<class t_core> bool t_cryptonote_protocol_handler<t_core>::process_payload_sync_data(const CORE_SYNC_DATA& hshd, cryptonote_connection_context& context, bool is_inital) { - if(context.m_state == cryptonote_connection_context::state_befor_handshake && !is_inital) + if(context.m_state == cryptonote_connection_context::state_before_handshake && !is_inital) return true; if(context.m_state == cryptonote_connection_context::state_synchronizing) @@ -310,6 +310,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; } diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 995fee484..bd2142ab1 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -55,7 +55,9 @@ namespace { std::string port_str; std::string elapsed = epee::misc_utils::get_time_interval_string(now - last_seen); std::string ip_str = epee::string_tools::get_ip_string_from_int32(peer.ip); - epee::string_tools::xtype_to_string(peer.id, id_str); + std::stringstream peer_id_str; + peer_id_str << std::hex << std::setw(16) << peer.id; + peer_id_str >> id_str; epee::string_tools::xtype_to_string(peer.port, port_str); std::string addr_str = ip_str + ":" + port_str; tools::msg_writer() << boost::format("%-10s %-25s %-25s %s") % prefix % id_str % addr_str % elapsed; @@ -112,10 +114,15 @@ namespace { return base + " -- " + status; } - std::string pad(std::string s, size_t n) + std::string pad(std::string s, size_t n, char c = ' ', bool prepend = false) { if (s.size() < n) - s.append(n - s.size(), ' '); + { + if (prepend) + s = std::string(n - s.size(), c) + s; + else + s.append(n - s.size(), c); + } return s; } } @@ -490,7 +497,7 @@ bool t_rpc_command_executor::print_connections() { tools::msg_writer() //<< std::setw(30) << std::left << in_out << std::setw(30) << std::left << address - << std::setw(20) << info.peer_id + << std::setw(20) << pad(info.peer_id, 16, '0', true) << std::setw(20) << info.support_flags << std::setw(30) << std::to_string(info.recv_count) + "(" + std::to_string(info.recv_idle_time) + ")/" + std::to_string(info.send_count) + "(" + std::to_string(info.send_idle_time) + ")" << std::setw(25) << info.state @@ -1742,7 +1749,7 @@ bool t_rpc_command_executor::sync_info() for (const auto &s: res.spans) if (s.rate > 0.0f && s.connection_id == p.info.connection_id) nblocks += s.nblocks, size += s.size; - tools::success_msg_writer() << address << " " << p.info.peer_id << " " << p.info.height << " " << p.info.current_download << " kB/s, " << nblocks << " blocks / " << size/1e6 << " MB queued"; + tools::success_msg_writer() << address << " " << pad(p.info.peer_id, 16, '0', true) << " " << p.info.height << " " << p.info.current_download << " kB/s, " << nblocks << " blocks / " << size/1e6 << " MB queued"; } uint64_t total_size = 0; |