Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reconnect of delayed node #2038

Merged
merged 1 commit into from
Feb 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions libraries/plugins/delayed_node/delayed_node_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,24 @@ void delayed_node_plugin::plugin_set_program_options(bpo::options_description& c

void delayed_node_plugin::connect()
{
fc::http::websocket_connection_ptr con;
try
{
con = my->client.connect(my->remote_endpoint);
}
catch( const fc::exception& e )
{
wlog("Error while connecting: ${e}", ("e", e.to_detail_string()));
connection_failed();
return;
}
my->client_connection = std::make_shared<fc::rpc::websocket_api_connection>(
my->client.connect(my->remote_endpoint),
GRAPHENE_NET_MAX_NESTED_OBJECTS );
con, GRAPHENE_NET_MAX_NESTED_OBJECTS );
my->database_api = my->client_connection->get_remote_api<graphene::app::database_api>(0);
my->database_api->set_block_applied_callback([this]( const fc::variant& block_id )
{
fc::from_variant( block_id, my->last_received_remote_head, GRAPHENE_MAX_NESTED_OBJECTS );
} );
my->client_connection_closed = my->client_connection->closed.connect([this] {
connection_failed();
});
Expand Down Expand Up @@ -141,24 +155,12 @@ void delayed_node_plugin::plugin_startup()
mainloop();
});

try
{
connect();
my->database_api->set_block_applied_callback([this]( const fc::variant& block_id )
{
fc::from_variant( block_id, my->last_received_remote_head, GRAPHENE_MAX_NESTED_OBJECTS );
} );
return;
}
catch (const fc::exception& e)
{
elog("Error during connection: ${e}", ("e", e.to_detail_string()));
}
fc::async([this]{connection_failed();});
connect();
}

void delayed_node_plugin::connection_failed()
{
my->last_received_remote_head = my->last_processed_remote_head;
elog("Connection to trusted node failed; retrying in 5 seconds...");
fc::schedule([this]{connect();}, fc::time_point::now() + fc::seconds(5));
}
Expand Down