From 0de018c10db3c74d1d53a40b5588cebf6192c1ea Mon Sep 17 00:00:00 2001 From: "cr.zoidberg" Date: Fri, 2 Nov 2018 22:05:35 +0300 Subject: [PATCH 1/3] Fixed detecting online state(explicit idle connections handshake) --- .../currency_protocol_handler.h | 1 + .../currency_protocol_handler.inl | 22 +++++++++++++++++++ src/p2p/net_node.h | 3 +++ src/p2p/net_node.inl | 18 +++++++++------ src/p2p/net_node_common.h | 8 +++++++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/currency_protocol/currency_protocol_handler.h b/src/currency_protocol/currency_protocol_handler.h index 0879ea8b..11feb5af 100644 --- a/src/currency_protocol/currency_protocol_handler.h +++ b/src/currency_protocol/currency_protocol_handler.h @@ -78,6 +78,7 @@ namespace currency bool request_missing_objects(currency_connection_context& context, bool check_having_blocks); size_t get_synchronizing_connections_count(); bool on_connection_synchronized(); + bool do_force_handshake_idle_connections(); bool check_stop_flag_and_exit(currency_connection_context& context); t_core& m_core; diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index e24d745c..46b8baf3 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -696,10 +696,32 @@ namespace currency LOG_PRINT_CCONTEXT_MAGENTA("[REQUEST_MISSING_OBJECTS] m_state set state_normal", LOG_LEVEL_0); context.m_state = currency_connection_context::state_normal; LOG_PRINT_CCONTEXT_GREEN(" SYNCHRONIZED OK", LOG_LEVEL_0); + do_force_handshake_idle_connections(); } return true; } //------------------------------------------------------------------------------------------------------------------------ + template + bool t_currency_protocol_handler::do_force_handshake_idle_connections() + { + nodetool::connections_list_type peer_list; + size_t count = 0; + m_p2p->for_each_connection([&](currency_connection_context& context, nodetool::peerid_type peer_id)->bool{ + if (context.m_state == currency_connection_context::state_idle) + { + peer_list.push_back(std::make_pair(static_cast(context), peer_id)); + } + return true; + }); + if (peer_list.size()) + { + LOG_PRINT_CCONTEXT_MAGENTA("[ON_SYNCHRONIZED] Explicit resync idle connections (" << peer_list.size() << ")", LOG_LEVEL_0); + return m_p2p->do_idle_sync_with_peers(peer_list); + } + else + return true; + } + //------------------------------------------------------------------------------------------------------------------------ template bool t_currency_protocol_handler::on_connection_synchronized() { diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 767749a9..3c2427b9 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -57,6 +57,7 @@ namespace nodetool typedef COMMAND_TIMED_SYNC_T COMMAND_TIMED_SYNC; public: + typedef t_payload_net_handler payload_net_handler; // Some code node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), @@ -150,6 +151,7 @@ namespace nodetool virtual bool block_ip(uint32_t adress); virtual bool add_ip_fail(uint32_t address); virtual bool is_stop_signal_sent(); + virtual bool do_idle_sync_with_peers(const nodetool::connections_list_type& concts); //----------------- i_connection_filter -------------------------------------------------------- virtual bool is_remote_ip_allowed(uint32_t adress); //----------------------------------------------------------------------------------------------- @@ -165,6 +167,7 @@ namespace nodetool bool connections_maker(); bool peer_sync_idle_maker(); + bool do_handshake_with_peer(peerid_type& pi, p2p_connection_context& context, bool just_take_peerlist = false); bool do_peer_timed_sync(const net_utils::connection_context_base& context, peerid_type peer_id); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 8057addf..73a6d8d9 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -900,19 +900,23 @@ namespace nodetool //----------------------------------------------------------------------------------- template bool node_server::peer_sync_idle_maker() - { - LOG_PRINT_L2("STARTED PEERLIST IDLE HANDSHAKE"); - typedef std::list > local_connects_type; - local_connects_type cncts; + { + connections_list_type cncts; m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) { if(cntxt.peer_id) - cncts.push_back(local_connects_type::value_type(cntxt, cntxt.peer_id));//do idle sync only with handshaked connections + cncts.push_back(connections_list_type::value_type(cntxt, cntxt.peer_id));//do idle sync only with handshaked connections return true; }); - std::for_each(cncts.begin(), cncts.end(), [&](const typename local_connects_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second);}); - + return do_idle_sync_with_peers(cncts); + } + //----------------------------------------------------------------------------------- + template + bool node_server::do_idle_sync_with_peers(const nodetool::connections_list_type& cncts) + { + LOG_PRINT_L2("STARTED PEERLIST IDLE HANDSHAKE"); + std::for_each(cncts.begin(), cncts.end(), [&](const typename nodetool::connections_list_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second); }); LOG_PRINT_L2("FINISHED PEERLIST IDLE HANDSHAKE"); return true; } diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h index a52dc778..8c905a3a 100644 --- a/src/p2p/net_node_common.h +++ b/src/p2p/net_node_common.h @@ -14,6 +14,9 @@ namespace nodetool typedef boost::uuids::uuid uuid; typedef boost::uuids::uuid net_connection_id; + + typedef std::list > connections_list_type; + template struct i_p2p_endpoint { @@ -27,6 +30,7 @@ namespace nodetool virtual bool block_ip(uint32_t adress)=0; virtual bool add_ip_fail(uint32_t adress)=0; virtual bool is_stop_signal_sent()=0; + virtual bool do_idle_sync_with_peers(const connections_list_type& concts) = 0; }; template @@ -72,5 +76,9 @@ namespace nodetool { return true; } + virtual bool do_idle_sync_with_peers(const connections_list_type& concts) + { + return true; + } }; } From c171e2acc6fb4048b22d75b0ece6856e2885db3c Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 5 Nov 2018 07:37:29 +0300 Subject: [PATCH 2/3] msvc compilation fix, minor log msg for wallet2 --- src/p2p/net_node_common.h | 2 +- src/wallet/wallet2.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h index 8c905a3a..f0b8c1af 100644 --- a/src/p2p/net_node_common.h +++ b/src/p2p/net_node_common.h @@ -15,7 +15,7 @@ namespace nodetool typedef boost::uuids::uuid net_connection_id; - typedef std::list > connections_list_type; + typedef std::list > connections_list_type; template struct i_p2p_endpoint diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5b42b51d..d0873899 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -568,6 +568,7 @@ bool wallet2::deinit() //---------------------------------------------------------------------------------------------------- bool wallet2::clear() { + LOG_PRINT_L0("clear internal wallet structures..."); m_blockchain.clear(); m_transfers.clear(); m_payments.clear(); From 4dcc29623e25248a2eb6d9a3d8fe711a87fc61b4 Mon Sep 17 00:00:00 2001 From: "cr.zoidberg" Date: Tue, 13 Nov 2018 20:11:32 +0300 Subject: [PATCH 3/3] reward_halwing adjustments --- contrib/epee/include/time_helper.h | 22 +++++++++++++++++++++ src/currency_core/currency_format_utils.cpp | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/contrib/epee/include/time_helper.h b/contrib/epee/include/time_helper.h index 73314c4d..1e38c3fe 100644 --- a/contrib/epee/include/time_helper.h +++ b/contrib/epee/include/time_helper.h @@ -97,6 +97,28 @@ POP_WARNINGS return tmpbuf; } + inline + std::string get_date_str(const time_t& time_) + { + + char tmpbuf[200] = { 0 }; + tm* pt = NULL; + PUSH_WARNINGS + DISABLE_VS_WARNINGS(4996) + pt = localtime(&time_); + POP_WARNINGS + + if (pt) + strftime(tmpbuf, 199, "%Y-%m-%d", pt); + else + { + std::stringstream strs; + strs << "[wrong_time: " << std::hex << time_ << "]"; + return strs.str(); + } + return tmpbuf; + } + inline std::string get_time_str_v3(const boost::posix_time::ptime& time_) { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 998e5f4d..7a0d2ecb 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -931,13 +931,13 @@ namespace currency void print_reward_halwing() { std::cout << std::endl << "Reward halving for 10 years:" << std::endl; - std::cout << std::setw(10) << std::left << "day" << std::setw(19) << "block reward" << std::setw(19) << "generated coins" << std::endl; + std::cout << std::setw(10) << std::left << "day" << std::setw(19) << std::left << "date" << std::setw(19) << "block reward" << std::setw(19) << "generated coins" << std::endl; uint64_t already_generated_coins = 0; uint64_t already_donated_coins = 0; uint64_t total_money_supply = TOTAL_MONEY_SUPPLY; - for(uint64_t day = 0; day != 365*10; ++day) + for(uint64_t day = 0; day != 365*30; ++day) { uint64_t emission_reward = 0; uint64_t stub = 0; @@ -946,6 +946,7 @@ namespace currency { std::cout << std::left << std::setw(10) << day + << std::setw(19) << epee::misc_utils::get_date_str(1400342511 + (day * 86400)) << std::setw(19) << print_money(emission_reward) << std::setw(4) << std::string(std::to_string(GET_PERECENTS_BIG_NUMBERS((already_generated_coins + already_donated_coins), total_money_supply)) + "%") << print_money(already_generated_coins + already_donated_coins)