SON connection pool.

This commit is contained in:
timur 2022-11-16 07:32:17 -04:00
parent 16431b3be5
commit 9fc3536638
3 changed files with 30 additions and 26 deletions

View file

@ -47,7 +47,7 @@ public:
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
private:
std::string rpc_url;
std::vector<std::string> rpc_urls;
std::string rpc_user;
std::string rpc_password;
std::string wallet_account_name;

View file

@ -195,7 +195,7 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options(
"Tuple of [Ethereum public key, Ethereum private key] (may specify multiple times)");
cli.add_options()("hive-sidechain-enabled", bpo::value<bool>()->default_value(false), "Hive sidechain handler enabled");
cli.add_options()("hive-node-rpc-url", bpo::value<string>()->default_value("127.0.0.1:28090"), "Hive node RPC URL [http[s]://]host[:port]");
cli.add_options()("hive-node-rpc-url", bpo::value<vector<string>>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR("127.0.0.1:28090"), "Hive node RPC URL [http[s]://]host[:port]");
cli.add_options()("hive-node-rpc-user", bpo::value<string>(), "Hive node RPC user");
cli.add_options()("hive-node-rpc-password", bpo::value<string>(), "Hive node RPC password");
cli.add_options()("hive-wallet-account-name", bpo::value<string>(), "Hive wallet account name");

View file

@ -120,7 +120,7 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
}
rpc_url = options.at("hive-node-rpc-url").as<std::string>();
rpc_urls = options.at("hive-node-rpc-url").as<std::vector<std::string>>();
if (options.count("hive-rpc-user")) {
rpc_user = options.at("hive-rpc-user").as<std::string>();
} else {
@ -146,31 +146,35 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
}
}
hive_rpc_client *rpc_client = new hive_rpc_client(rpc_url, rpc_user, rpc_password, debug_rpc_calls);
rpc_clients.push_back(rpc_client);
for (const std::string &rpc_url : rpc_urls) {
hive_rpc_client *rpc_client = new hive_rpc_client(rpc_url, rpc_user, rpc_password, debug_rpc_calls);
rpc_clients.push_back(rpc_client);
const std::string chain_id_str = rpc_client->get_chain_id();
if (chain_id_str.empty()) {
elog("No Hive node running at ${url}", ("url", rpc_url));
FC_ASSERT(false);
}
chain_id = chain_id_type(chain_id_str);
const std::string is_test_net = rpc_client->get_is_test_net();
network_type = is_test_net.compare("true") == 0 ? hive::network::testnet : hive::network::mainnet;
if (network_type == hive::network::mainnet) {
ilog("Running on Hive mainnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str));
hive::asset::hbd_symbol_ser = HBD_SYMBOL_SER;
hive::asset::hive_symbol_ser = HIVE_SYMBOL_SER;
hive::public_key_type::prefix = KEY_PREFIX_STM;
} else {
ilog("Running on Hive testnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str));
hive::asset::hbd_symbol_ser = TBD_SYMBOL_SER;
hive::asset::hive_symbol_ser = TESTS_SYMBOL_SER;
hive::public_key_type::prefix = KEY_PREFIX_TST;
}
}
n_active_rpc_client = 0;
const std::string chain_id_str = rpc_client->get_chain_id();
if (chain_id_str.empty()) {
elog("No Hive node running at ${url}", ("url", rpc_url));
FC_ASSERT(false);
}
chain_id = chain_id_type(chain_id_str);
const std::string is_test_net = rpc_client->get_is_test_net();
network_type = is_test_net.compare("true") == 0 ? hive::network::testnet : hive::network::mainnet;
if (network_type == hive::network::mainnet) {
ilog("Running on Hive mainnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str));
hive::asset::hbd_symbol_ser = HBD_SYMBOL_SER;
hive::asset::hive_symbol_ser = HIVE_SYMBOL_SER;
hive::public_key_type::prefix = KEY_PREFIX_STM;
} else {
ilog("Running on Hive testnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str));
hive::asset::hbd_symbol_ser = TBD_SYMBOL_SER;
hive::asset::hive_symbol_ser = TESTS_SYMBOL_SER;
hive::public_key_type::prefix = KEY_PREFIX_TST;
}
last_block_received = 0;
schedule_hive_listener();
event_received.connect([this](const std::string &event_data) {