Get nettype from m_core don't cache in rpc server (#320)

This goes out of sync with m_core's nettype if you try to launch in
fakechain mode and use RPC server.
This commit is contained in:
Doyle 2018-11-16 16:31:11 +11:00 committed by GitHub
parent 6d763041e0
commit 4a9b482035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 21 deletions

View file

@ -76,18 +76,15 @@ public:
protocol.set_p2p_endpoint(p2p.get());
core.set_protocol(protocol.get());
const auto testnet = command_line::get_arg(vm, cryptonote::arg_testnet_on);
const auto stagenet = command_line::get_arg(vm, cryptonote::arg_stagenet_on);
const auto regtest = command_line::get_arg(vm, cryptonote::arg_regtest_on);
const auto restricted = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_restricted_rpc);
const auto main_rpc_port = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, testnet ? cryptonote::TESTNET : stagenet ? cryptonote::STAGENET : regtest ? cryptonote::FAKECHAIN : cryptonote::MAINNET, main_rpc_port, "core"});
rpcs.emplace_back(new t_rpc{vm, core, p2p, restricted, main_rpc_port, "core"});
auto restricted_rpc_port_arg = cryptonote::core_rpc_server::arg_rpc_restricted_bind_port;
if(!command_line::is_arg_defaulted(vm, restricted_rpc_port_arg))
{
auto restricted_rpc_port = command_line::get_arg(vm, restricted_rpc_port_arg);
rpcs.emplace_back(new t_rpc{vm, core, p2p, true, testnet ? cryptonote::TESTNET : stagenet ? cryptonote::STAGENET : cryptonote::MAINNET, restricted_rpc_port, "restricted"});
rpcs.emplace_back(new t_rpc{vm, core, p2p, true, restricted_rpc_port, "restricted"});
}
}
};

View file

@ -55,7 +55,6 @@ public:
, t_core & core
, t_p2p & p2p
, const bool restricted
, const cryptonote::network_type nettype
, const std::string & port
, const std::string & description
)
@ -63,7 +62,7 @@ public:
{
MGINFO("Initializing " << m_description << " RPC server...");
if (!m_server.init(vm, restricted, nettype, port))
if (!m_server.init(vm, restricted, port))
{
throw std::runtime_error("Failed to initialize " + m_description + " RPC server.");
}

View file

@ -82,12 +82,10 @@ namespace cryptonote
bool core_rpc_server::init(
const boost::program_options::variables_map& vm
, const bool restricted
, const network_type nettype
, const std::string& port
)
{
m_restricted = restricted;
m_nettype = nettype;
m_net_server.set_threads_prefix("RPC");
auto rpc_config = cryptonote::rpc_args::process(vm);
@ -182,10 +180,13 @@ namespace cryptonote
res.rpc_connections_count = get_connections_count();
res.white_peerlist_size = m_p2p.get_peerlist_manager().get_white_peers_count();
res.grey_peerlist_size = m_p2p.get_peerlist_manager().get_gray_peers_count();
res.mainnet = m_nettype == MAINNET;
res.testnet = m_nettype == TESTNET;
res.stagenet = m_nettype == STAGENET;
res.nettype = m_nettype == MAINNET ? "mainnet" : m_nettype == TESTNET ? "testnet" : m_nettype == STAGENET ? "stagenet" : "fakechain";
cryptonote::network_type nettype = m_core.get_nettype();
res.mainnet = nettype == MAINNET;
res.testnet = nettype == TESTNET;
res.stagenet = nettype == STAGENET;
res.nettype = nettype == MAINNET ? "mainnet" : nettype == TESTNET ? "testnet" : nettype == STAGENET ? "stagenet" : "fakechain";
res.cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1);
res.block_size_limit = res.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
res.block_size_median = res.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
@ -743,7 +744,7 @@ namespace cryptonote
PERF_TIMER(on_start_mining);
CHECK_CORE_READY();
cryptonote::address_parse_info info;
if(!get_account_address_from_str(info, m_nettype, req.miner_address))
if(!get_account_address_from_str(info, m_core.get_nettype(), req.miner_address))
{
res.status = "Failed, wrong address";
LOG_PRINT_L0(res.status);
@ -817,7 +818,7 @@ namespace cryptonote
res.speed = lMiner.get_speed();
res.threads_count = lMiner.get_threads_count();
const account_public_address& lMiningAdr = lMiner.get_mining_address();
res.address = get_account_address_as_str(m_nettype, false, lMiningAdr);
res.address = get_account_address_as_str(m_core.get_nettype(), false, lMiningAdr);
}
res.status = CORE_RPC_STATUS_OK;
@ -1050,7 +1051,7 @@ namespace cryptonote
cryptonote::address_parse_info info;
if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(info, m_nettype, req.wallet_address))
if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(info, m_core.get_nettype(), req.wallet_address))
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_WALLET_ADDRESS;
error_resp.message = "Failed to parse wallet address";
@ -2248,7 +2249,7 @@ namespace cryptonote
COMMAND_RPC_GET_SERVICE_NODES::response::contribution new_contributor = {};
new_contributor.amount = contributor.amount;
new_contributor.reserved = contributor.reserved;
new_contributor.address = cryptonote::get_account_address_as_str(nettype(), false/*is_subaddress*/, contributor.address);
new_contributor.address = cryptonote::get_account_address_as_str(m_core.get_nettype(), false/*is_subaddress*/, contributor.address);
entry.contributors.push_back(new_contributor);
}
@ -2256,7 +2257,7 @@ namespace cryptonote
entry.total_reserved = pubkey_info.info.total_reserved;
entry.staking_requirement = pubkey_info.info.staking_requirement;
entry.portions_for_operator = pubkey_info.info.portions_for_operator;
entry.operator_address = cryptonote::get_account_address_as_str(nettype(), false/*is_subaddress*/, pubkey_info.info.operator_address);
entry.operator_address = cryptonote::get_account_address_as_str(m_core.get_nettype(), false/*is_subaddress*/, pubkey_info.info.operator_address);
res.service_node_states.push_back(entry);
}
@ -2267,7 +2268,7 @@ namespace cryptonote
bool core_rpc_server::on_get_staking_requirement(const COMMAND_RPC_GET_STAKING_REQUIREMENT::request& req, COMMAND_RPC_GET_STAKING_REQUIREMENT::response& res, epee::json_rpc::error& error_resp)
{
PERF_TIMER(on_get_staking_requirement);
res.staking_requirement = service_nodes::get_staking_requirement(nettype(), req.height);
res.staking_requirement = service_nodes::get_staking_requirement(m_core.get_nettype(), req.height);
res.status = CORE_RPC_STATUS_OK;
return true;
}

View file

@ -70,10 +70,10 @@ namespace cryptonote
bool init(
const boost::program_options::variables_map& vm,
const bool restricted,
const network_type nettype,
const std::string& port
);
network_type nettype() const { return m_nettype; }
network_type nettype() const { return m_core.get_nettype(); }
CHAIN_HTTP_TO_MAP2(connection_context); //forward http requests to uri map