Cancel the thread for sync blocks
This commit is contained in:
parent
1846b1709e
commit
e2d9741af8
2 changed files with 12 additions and 1 deletions
|
|
@ -48,6 +48,7 @@
|
||||||
#include <boost/range/algorithm/reverse.hpp>
|
#include <boost/range/algorithm/reverse.hpp>
|
||||||
#include <boost/signals2.hpp>
|
#include <boost/signals2.hpp>
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <fc/log/file_appender.hpp>
|
#include <fc/log/file_appender.hpp>
|
||||||
|
|
@ -107,6 +108,7 @@ public:
|
||||||
fc::optional<fc::temp_file> _lock_file;
|
fc::optional<fc::temp_file> _lock_file;
|
||||||
bool _is_block_producer = false;
|
bool _is_block_producer = false;
|
||||||
bool _force_validate = false;
|
bool _force_validate = false;
|
||||||
|
std::atomic_bool _running{true};
|
||||||
|
|
||||||
void reset_p2p_node(const fc::path &data_dir) {
|
void reset_p2p_node(const fc::path &data_dir) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -450,6 +452,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool handle_block(const graphene::net::block_message &blk_msg, bool sync_mode,
|
virtual bool handle_block(const graphene::net::block_message &blk_msg, bool sync_mode,
|
||||||
std::vector<fc::uint160_t> &contained_transaction_message_ids) override {
|
std::vector<fc::uint160_t> &contained_transaction_message_ids) override {
|
||||||
|
|
||||||
|
// check point for the threads which may be cancled on application shutdown
|
||||||
|
if(!_running.load()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto latency = fc::time_point::now() - blk_msg.block.timestamp;
|
auto latency = fc::time_point::now() - blk_msg.block.timestamp;
|
||||||
FC_ASSERT((latency.count() / 1000) > -5000, "Rejecting block with timestamp in the future");
|
FC_ASSERT((latency.count() / 1000) > -5000, "Rejecting block with timestamp in the future");
|
||||||
|
|
@ -1012,6 +1020,7 @@ void application::shutdown_plugins() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void application::shutdown() {
|
void application::shutdown() {
|
||||||
|
my->_running.store(false);
|
||||||
if (my->_p2p_network)
|
if (my->_p2p_network)
|
||||||
my->_p2p_network->close();
|
my->_p2p_network->close();
|
||||||
if (my->_chain_db)
|
if (my->_chain_db)
|
||||||
|
|
|
||||||
|
|
@ -895,7 +895,7 @@ namespace graphene { namespace net { namespace detail {
|
||||||
void node_impl::p2p_network_connect_loop()
|
void node_impl::p2p_network_connect_loop()
|
||||||
{
|
{
|
||||||
VERIFY_CORRECT_THREAD();
|
VERIFY_CORRECT_THREAD();
|
||||||
while (!_p2p_network_connect_loop_done.canceled())
|
while (!_p2p_network_connect_loop_done.canceled() && !_node_is_shutting_down)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -4051,6 +4051,8 @@ namespace graphene { namespace net { namespace detail {
|
||||||
{
|
{
|
||||||
VERIFY_CORRECT_THREAD();
|
VERIFY_CORRECT_THREAD();
|
||||||
|
|
||||||
|
_node_is_shutting_down = true;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_potential_peer_db.close();
|
_potential_peer_db.close();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue