SON connection pool.
This commit is contained in:
parent
9fc3536638
commit
b908d7f12f
10 changed files with 57 additions and 2 deletions
|
|
@ -47,6 +47,7 @@ public:
|
|||
virtual std::string process_sidechain_transaction(const sidechain_transaction_object &sto) = 0;
|
||||
virtual std::string send_sidechain_transaction(const sidechain_transaction_object &sto) = 0;
|
||||
virtual bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) = 0;
|
||||
virtual void select_active_rpc_client() = 0;
|
||||
|
||||
void add_to_son_listener_log(std::string trx_id);
|
||||
std::vector<std::string> get_son_listener_log();
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ public:
|
|||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
|
||||
void select_active_rpc_client();
|
||||
|
||||
private:
|
||||
std::string ip;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ public:
|
|||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
|
||||
void select_active_rpc_client();
|
||||
|
||||
private:
|
||||
std::string rpc_url;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public:
|
|||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
|
||||
void select_active_rpc_client();
|
||||
|
||||
private:
|
||||
std::vector<std::string> rpc_urls;
|
||||
|
|
@ -65,7 +66,6 @@ private:
|
|||
void hive_listener_loop();
|
||||
void handle_event(const std::string &event_data);
|
||||
hive_rpc_client *get_active_rpc_client();
|
||||
void select_active_rpc_client();
|
||||
};
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public:
|
|||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
|
||||
void select_active_rpc_client();
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ public:
|
|||
void send_sidechain_transactions(sidechain_type sidechain);
|
||||
void settle_sidechain_transactions(sidechain_type sidechain);
|
||||
|
||||
void schedule_rpc_client_selection();
|
||||
void rpc_client_selection();
|
||||
|
||||
private:
|
||||
peerplays_sidechain_plugin &plugin;
|
||||
|
||||
|
|
@ -94,6 +97,7 @@ private:
|
|||
std::set<chain::son_id_type> sons;
|
||||
std::map<chain::public_key_type, fc::ecc::private_key> private_keys;
|
||||
fc::future<void> _heartbeat_task;
|
||||
fc::future<void> _rpc_client_selection_task;
|
||||
std::map<sidechain_type, std::future<void>> _son_processing_task;
|
||||
std::map<son_proposal_type, uint16_t> son_retry_count;
|
||||
uint16_t retries_threshold = 150;
|
||||
|
|
@ -157,6 +161,15 @@ peerplays_sidechain_plugin_impl::~peerplays_sidechain_plugin_impl() {
|
|||
} catch (fc::exception &e) {
|
||||
edump((e.to_detail_string()));
|
||||
}
|
||||
|
||||
try {
|
||||
if (_rpc_client_selection_task.valid())
|
||||
_rpc_client_selection_task.cancel_and_wait(__FUNCTION__);
|
||||
} catch (fc::canceled_exception &) {
|
||||
//Expected exception. Move along.
|
||||
} catch (fc::exception &e) {
|
||||
edump((e.to_detail_string()));
|
||||
}
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::plugin_set_program_options(
|
||||
|
|
@ -323,6 +336,8 @@ void peerplays_sidechain_plugin_impl::plugin_startup() {
|
|||
plugin.database().applied_block.connect([&](const signed_block &b) {
|
||||
on_applied_block(b);
|
||||
});
|
||||
|
||||
schedule_rpc_client_selection();
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::plugin_shutdown() {
|
||||
|
|
@ -840,6 +855,26 @@ void peerplays_sidechain_plugin_impl::on_applied_block(const signed_block &b) {
|
|||
}
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::schedule_rpc_client_selection() {
|
||||
fc::time_point now = fc::time_point::now();
|
||||
static const int64_t time_to_next_rpc_selection = 5000000;
|
||||
fc::time_point next_wakeup = now + fc::microseconds(time_to_next_rpc_selection);
|
||||
_rpc_client_selection_task = fc::schedule([this] {
|
||||
rpc_client_selection();
|
||||
},
|
||||
next_wakeup, "SON RPC client selection");
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::rpc_client_selection() {
|
||||
for (const auto &active_sidechain_type : active_sidechain_types) {
|
||||
if (net_handlers.at(active_sidechain_type)) {
|
||||
net_handlers.at(active_sidechain_type)->select_active_rpc_client();
|
||||
}
|
||||
}
|
||||
schedule_rpc_client_selection();
|
||||
}
|
||||
|
||||
|
||||
} // namespace detail
|
||||
|
||||
peerplays_sidechain_plugin::peerplays_sidechain_plugin() :
|
||||
|
|
|
|||
|
|
@ -1419,6 +1419,10 @@ void sidechain_net_handler_bitcoin::on_changed_objects_cb(const vector<object_id
|
|||
}
|
||||
}
|
||||
|
||||
void sidechain_net_handler_bitcoin::select_active_rpc_client()
|
||||
{
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
}
|
||||
} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -804,4 +804,8 @@ void sidechain_net_handler_ethereum::handle_event(const std::string &block_numbe
|
|||
}
|
||||
}
|
||||
|
||||
void sidechain_net_handler_ethereum::select_active_rpc_client()
|
||||
{
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -970,7 +970,11 @@ hive_rpc_client *sidechain_net_handler_hive::get_active_rpc_client()
|
|||
|
||||
void sidechain_net_handler_hive::select_active_rpc_client()
|
||||
{
|
||||
n_active_rpc_client = 0;
|
||||
if (rpc_clients.size())
|
||||
{
|
||||
n_active_rpc_client = (n_active_rpc_client + 1) % rpc_clients.size();
|
||||
ilog("n_active_rpc_client=${n}", ("n", n_active_rpc_client));
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -290,4 +290,8 @@ bool sidechain_net_handler_peerplays::settle_sidechain_transaction(const sidecha
|
|||
return true;
|
||||
}
|
||||
|
||||
void sidechain_net_handler_peerplays::select_active_rpc_client()
|
||||
{
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
Loading…
Reference in a new issue