Align params/constructor flow with upstream p2pool
This commit is contained in:
+59
-14
@@ -229,7 +229,32 @@ int p2pool_test()
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::vector<std::vector<std::string>> get_params(int argc, char* argv[]) noexcept
|
||||
static void init_params(p2pool::Params& params)
|
||||
{
|
||||
for (p2pool::Params::Host& h : params.m_hosts) {
|
||||
if (!h.init_display_name(params)) {
|
||||
printf("Failed to initialize host display name\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
const int p2p_port = params.m_mini ? p2pool::DEFAULT_P2P_PORT_MINI : (params.m_nano ? p2pool::DEFAULT_P2P_PORT_NANO : p2pool::DEFAULT_P2P_PORT);
|
||||
|
||||
if (params.m_noClearnetP2P) {
|
||||
char buf[48] = {};
|
||||
p2pool::log::Stream s(buf);
|
||||
s << "127.0.0.1:" << p2p_port;
|
||||
params.m_p2pAddresses = buf;
|
||||
}
|
||||
else if (params.m_p2pAddresses.empty()) {
|
||||
char buf[48] = {};
|
||||
p2pool::log::Stream s(buf);
|
||||
s << "[::]:" << p2p_port << ",0.0.0.0:" << p2p_port;
|
||||
params.m_p2pAddresses = buf;
|
||||
}
|
||||
}
|
||||
|
||||
static p2pool::Params get_params(int argc, char* argv[]) noexcept
|
||||
{
|
||||
try {
|
||||
std::vector<std::vector<std::string>> args;
|
||||
@@ -250,13 +275,35 @@ static std::vector<std::vector<std::string>> get_params(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
p2pool::Params params(args);
|
||||
|
||||
if (params.valid()) {
|
||||
init_params(params);
|
||||
return params;
|
||||
}
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
}
|
||||
|
||||
printf("Invalid or missing command line. Try \"p2pool --help\".\n");
|
||||
exit(1);
|
||||
abort();
|
||||
}
|
||||
|
||||
static p2pool::Params get_params(const std::string& params_file) noexcept
|
||||
{
|
||||
try {
|
||||
p2pool::Params params(p2pool::parse_config(params_file));
|
||||
|
||||
if (params.valid()) {
|
||||
init_params(params);
|
||||
return params;
|
||||
}
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
}
|
||||
|
||||
printf("Invalid or missing command line. Try \"p2pool --help\".\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
@@ -354,16 +401,21 @@ int main(int argc, char* argv[])
|
||||
|
||||
memory_tracking_start();
|
||||
|
||||
int result;
|
||||
{
|
||||
|
||||
// Create default loop here
|
||||
uv_default_loop();
|
||||
|
||||
const p2pool::Params params = params_file.empty() ? get_params(argc, argv) : get_params(params_file);
|
||||
|
||||
p2pool::log::start();
|
||||
|
||||
printf("Reticulating splines...\n");
|
||||
|
||||
p2pool::init_crypto_cache();
|
||||
|
||||
int result = static_cast<int>(curl_global_init_mem(CURL_GLOBAL_ALL, p2pool::malloc_hook, p2pool::free_hook, p2pool::realloc_hook, p2pool::strdup_hook, p2pool::calloc_hook));
|
||||
result = static_cast<int>(curl_global_init_mem(CURL_GLOBAL_ALL, p2pool::malloc_hook, p2pool::free_hook, p2pool::realloc_hook, p2pool::strdup_hook, p2pool::calloc_hook));
|
||||
if (result != CURLE_OK) {
|
||||
return result;
|
||||
}
|
||||
@@ -379,17 +431,8 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<std::vector<std::string>> args;
|
||||
try {
|
||||
args = params_file.empty() ? get_params(argc, argv) : p2pool::parse_config(params_file);
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
fprintf(stderr, "Invalid or missing command line. Try \"p2pool --help\".\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
p2pool::p2pool pool(args);
|
||||
p2pool::p2pool pool(params);
|
||||
result = pool.run();
|
||||
}
|
||||
catch (...) {
|
||||
@@ -416,6 +459,8 @@ int main(int argc, char* argv[])
|
||||
uv_library_shutdown();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
if (!memory_tracking_stop()) {
|
||||
result = 1;
|
||||
}
|
||||
|
||||
+53
-87
@@ -70,8 +70,9 @@ namespace p2pool {
|
||||
|
||||
static uint64_t BLOCK_HEADERS_REQUIRED = 720;
|
||||
|
||||
p2pool::p2pool(const std::vector<std::vector<std::string>>& args)
|
||||
p2pool::p2pool(const Params& params)
|
||||
: m_stopped(false)
|
||||
, m_params(params)
|
||||
, m_updateSeed(true)
|
||||
, m_submitBlockData{}
|
||||
, m_zmqLastActive(0)
|
||||
@@ -80,59 +81,43 @@ p2pool::p2pool(const std::vector<std::vector<std::string>>& args)
|
||||
{
|
||||
LOGINFO(1, log::LightCyan() << VERSION);
|
||||
|
||||
Params* p = new Params(args);
|
||||
|
||||
if (!p->valid()) {
|
||||
LOGERR(1, "Invalid or missing command line. Try \"p2pool --help\".");
|
||||
delete p;
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
m_params = p;
|
||||
|
||||
#ifdef WITH_REDIS
|
||||
// Initialize Redis connection
|
||||
RedisStorage& redis = get_redis_storage();
|
||||
if (!redis.connect(p->m_redisHost, p->m_redisPort, p->m_redisDb)) {
|
||||
LOGERR(1, "Failed to connect to Redis at " << p->m_redisHost << ":" << p->m_redisPort);
|
||||
if (!redis.connect(m_params.m_redisHost, m_params.m_redisPort, m_params.m_redisDb)) {
|
||||
LOGERR(1, "Failed to connect to Redis at " << m_params.m_redisHost << ":" << m_params.m_redisPort);
|
||||
throw std::exception();
|
||||
}
|
||||
LOGINFO(1, "Connected to Redis at " << p->m_redisHost << ":" << p->m_redisPort << " (db " << p->m_redisDb << ")");
|
||||
LOGINFO(1, "Connected to Redis at " << m_params.m_redisHost << ":" << m_params.m_redisPort << " (db " << m_params.m_redisDb << ")");
|
||||
#endif
|
||||
|
||||
// P2Pool-nano requires more Monero blocks for the initial sync
|
||||
if (m_params->m_nano) {
|
||||
if (m_params.m_nano) {
|
||||
BLOCK_HEADERS_REQUIRED = 1440;
|
||||
}
|
||||
|
||||
bkg_jobs_tracker = new BackgroundJobTracker();
|
||||
|
||||
#ifdef WITH_UPNP
|
||||
if (p->m_upnp) {
|
||||
if (m_params.m_upnp) {
|
||||
init_upnp();
|
||||
}
|
||||
#endif
|
||||
|
||||
for (Params::Host& h : p->m_hosts) {
|
||||
if (!h.init_display_name(*p)) {
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
m_currentHostIndex = 0;
|
||||
|
||||
m_hostPing.resize(p->m_hosts.size());
|
||||
m_hostPing.resize(m_params.m_hosts.size());
|
||||
|
||||
hash pub, sec, eph_public_key;
|
||||
generate_keys(pub, sec);
|
||||
|
||||
uint8_t view_tag;
|
||||
if (!p->m_miningWallet.get_eph_public_key(sec, 0, eph_public_key, view_tag)) {
|
||||
if (!m_params.m_miningWallet.get_eph_public_key(sec, 0, eph_public_key, view_tag)) {
|
||||
LOGERR(1, "Invalid wallet address: get_eph_public_key failed");
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
const NetworkType type = p->m_miningWallet.type();
|
||||
const NetworkType type = m_params.m_miningWallet.type();
|
||||
|
||||
if (type == NetworkType::Testnet) {
|
||||
LOGWARN(1, "Mining to a testnet wallet address");
|
||||
@@ -215,37 +200,20 @@ p2pool::p2pool(const std::vector<std::vector<std::string>>& args)
|
||||
|
||||
#ifdef WITH_REDIS
|
||||
// Always create API in Redis mode - data goes to Redis, not files
|
||||
m_api = new p2pool_api("redis", p->m_localStats);
|
||||
m_api = new p2pool_api("redis", m_params.m_localStats);
|
||||
#else
|
||||
m_api = p->m_apiPath.empty() ? nullptr : new p2pool_api(p->m_apiPath, p->m_localStats);
|
||||
m_api = m_params.m_apiPath.empty() ? nullptr : new p2pool_api(m_params.m_apiPath, m_params.m_localStats);
|
||||
|
||||
if (p->m_localStats && !m_api) {
|
||||
if (m_params.m_localStats && !m_api) {
|
||||
LOGERR(1, "--local-api and --stratum-api command line parameters can't be used without --data-api");
|
||||
throw std::exception();
|
||||
}
|
||||
#endif
|
||||
|
||||
m_sideChain = new SideChain(this, type, p->m_mini ? "mini" : (p->m_nano ? "nano" : nullptr), &p->m_devWallet);
|
||||
|
||||
const int p2p_port = m_sideChain->is_mini() ? DEFAULT_P2P_PORT_MINI : (m_sideChain->is_nano() ? DEFAULT_P2P_PORT_NANO : DEFAULT_P2P_PORT);
|
||||
|
||||
if (p->m_noClearnetP2P) {
|
||||
char buf[48] = {};
|
||||
log::Stream s(buf);
|
||||
s << "127.0.0.1:" << p2p_port;
|
||||
|
||||
p->m_p2pAddresses = buf;
|
||||
}
|
||||
else if (p->m_p2pAddresses.empty()) {
|
||||
char buf[48] = {};
|
||||
log::Stream s(buf);
|
||||
s << "[::]:" << p2p_port << ",0.0.0.0:" << p2p_port;
|
||||
|
||||
p->m_p2pAddresses = buf;
|
||||
}
|
||||
m_sideChain = new SideChain(this, type, m_params.m_mini ? "mini" : (m_params.m_nano ? "nano" : nullptr), &m_params.m_devWallet);
|
||||
|
||||
#ifdef WITH_RANDOMX
|
||||
if (p->m_disableRandomX) {
|
||||
if (m_params.m_disableRandomX) {
|
||||
m_hasher = new RandomX_Hasher_RPC(this);
|
||||
}
|
||||
else {
|
||||
@@ -274,7 +242,7 @@ p2pool::p2pool(const std::vector<std::vector<std::string>>& args)
|
||||
p2pool::~p2pool()
|
||||
{
|
||||
#ifdef WITH_UPNP
|
||||
if (m_params->m_upnp) {
|
||||
if (m_params.m_upnp) {
|
||||
destroy_upnp();
|
||||
}
|
||||
#endif
|
||||
@@ -321,8 +289,6 @@ p2pool::~p2pool()
|
||||
delete m_hasher;
|
||||
delete m_blockTemplate;
|
||||
delete m_mempool;
|
||||
delete m_params;
|
||||
|
||||
{
|
||||
auto* p = bkg_jobs_tracker;
|
||||
bkg_jobs_tracker = nullptr;
|
||||
@@ -344,7 +310,7 @@ void p2pool::update_host_ping(const std::string& display_name, double ping)
|
||||
LOGWARN(1, display_name << " ping is " << ping << " ms, this is too high for an efficient mining. Try to use a different node, or your own local node.");
|
||||
}
|
||||
|
||||
const std::vector<Params::Host>& v = m_params->m_hosts;
|
||||
const std::vector<Params::Host>& v = m_params.m_hosts;
|
||||
|
||||
for (size_t i = 0, n = v.size(); i < n; ++i) {
|
||||
if (v[i].m_displayName == display_name) {
|
||||
@@ -358,8 +324,8 @@ void p2pool::print_hosts() const
|
||||
{
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
for (size_t i = 0, n = m_params->m_hosts.size(); i < n; ++i) {
|
||||
const Params::Host& h = m_params->m_hosts[i];
|
||||
for (size_t i = 0, n = m_params.m_hosts.size(); i < n; ++i) {
|
||||
const Params::Host& h = m_params.m_hosts[i];
|
||||
|
||||
char buf[64] = {};
|
||||
if (m_hostPing[i] > 0.0) {
|
||||
@@ -449,7 +415,7 @@ void p2pool::handle_tx(TxMempoolData& tx)
|
||||
}
|
||||
|
||||
#if TEST_MEMPOOL_PICKING_ALGORITHM
|
||||
m_blockTemplate->update(miner_data(), *m_mempool, &m_params->m_wallet);
|
||||
m_blockTemplate->update(miner_data(), *m_mempool, &m_params.m_wallet);
|
||||
#endif
|
||||
|
||||
m_zmqLastActive = seconds_since_epoch();
|
||||
@@ -589,7 +555,7 @@ void p2pool::get_missing_heights()
|
||||
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, h](const char* data, size_t size, double)
|
||||
{
|
||||
ChainMain block;
|
||||
@@ -870,14 +836,14 @@ void p2pool::update_aux_data(const hash& chain_id)
|
||||
void p2pool::send_aux_job_donation()
|
||||
{
|
||||
#ifdef WITH_TLS
|
||||
if (m_params->m_authorKeyFile.empty()) {
|
||||
if (m_params.m_authorKeyFile.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream f(m_params->m_authorKeyFile, std::ios::binary | std::ios::ate);
|
||||
std::ifstream f(m_params.m_authorKeyFile, std::ios::binary | std::ios::ate);
|
||||
|
||||
if (!f.good()) {
|
||||
LOGERR(1, "send_aux_job_donation: failed to open " << m_params->m_authorKeyFile);
|
||||
LOGERR(1, "send_aux_job_donation: failed to open " << m_params.m_authorKeyFile);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -885,7 +851,7 @@ void p2pool::send_aux_job_donation()
|
||||
ON_SCOPE_LEAVE([&key](){ secure_zero_memory(key); });
|
||||
|
||||
if (f.tellg() != static_cast<std::streampos>(sizeof(key))) {
|
||||
LOGERR(1, "send_aux_job_donation: " << m_params->m_authorKeyFile << " has an invalid size");
|
||||
LOGERR(1, "send_aux_job_donation: " << m_params.m_authorKeyFile << " has an invalid size");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -893,21 +859,21 @@ void p2pool::send_aux_job_donation()
|
||||
f.read(reinterpret_cast<char*>(&key), sizeof(key));
|
||||
|
||||
if (!f.good()) {
|
||||
LOGERR(1, "send_aux_job_donation: failed to read data from " << m_params->m_authorKeyFile);
|
||||
LOGERR(1, "send_aux_job_donation: failed to read data from " << m_params.m_authorKeyFile);
|
||||
return;
|
||||
}
|
||||
|
||||
const uint64_t timestamp = time(nullptr);
|
||||
|
||||
if (timestamp >= read_unaligned(reinterpret_cast<uint64_t*>(key.expiration_time))) {
|
||||
LOGERR(1, "send_aux_job_donation: " << m_params->m_authorKeyFile << " is expired");
|
||||
LOGERR(1, "send_aux_job_donation: " << m_params.m_authorKeyFile << " is expired");
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t* p = reinterpret_cast<uint8_t*>(&key);
|
||||
|
||||
if (!ED25519_verify(p, sizeof(key.pub_key) + sizeof(key.expiration_time), key.master_key_signature, ED25519_MASTER_PUBLIC_KEY)) {
|
||||
LOGERR(1, "send_aux_job_donation: " << m_params->m_authorKeyFile << ": signature verification failed");
|
||||
LOGERR(1, "send_aux_job_donation: " << m_params.m_authorKeyFile << ": signature verification failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1255,7 +1221,7 @@ void p2pool::submit_block() const
|
||||
|
||||
const uint64_t t1 = microseconds_since_epoch();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, request, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, request, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[height, diff, template_id, nonce, extra_nonce, merge_mining_root, is_external](const char* data, size_t size, double)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
@@ -1347,7 +1313,7 @@ void p2pool::update_block_template()
|
||||
m_hasher->set_seed_async(data.seed_hash);
|
||||
}
|
||||
|
||||
m_blockTemplate->update(data, *m_mempool, m_params, in_donation_mode(data.height));
|
||||
m_blockTemplate->update(data, *m_mempool, &m_params, in_donation_mode(data.height));
|
||||
|
||||
// Fetch real protocol_tx from daemon in parallel (used at submit_block time)
|
||||
if (!data.protocol_tx_loaded) {
|
||||
@@ -1380,7 +1346,7 @@ void p2pool::download_block_headers1(uint64_t current_height)
|
||||
s.m_pos = 0;
|
||||
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_header_by_height\",\"params\":{\"height\":" << prev_seed_height << "}}" << '\0';
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, prev_seed_height, current_height](const char* data, size_t size, double) {
|
||||
ChainMain block;
|
||||
if (parse_block_header(data, size, block)) {
|
||||
@@ -1413,7 +1379,7 @@ void p2pool::download_block_headers2(uint64_t current_height)
|
||||
s.m_pos = 0;
|
||||
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_header_by_height\",\"params\":{\"height\":" << seed_height << "}}" << '\0';
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, seed_height, current_height](const char* data, size_t size, double) {
|
||||
ChainMain block;
|
||||
if (parse_block_header(data, size, block)) {
|
||||
@@ -1449,7 +1415,7 @@ void p2pool::download_block_headers3(uint64_t start_height, uint64_t current_hei
|
||||
s.m_pos = 0;
|
||||
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_headers_range\",\"params\":{\"start_height\":" << start_height << ",\"end_height\":" << next_height << "}}" << '\0';
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, start_height, next_height, current_height](const char* data, size_t size, double) {
|
||||
if (parse_block_headers_range(data, size) == next_height - start_height + 1) {
|
||||
download_block_headers3(next_height + 1, current_height);
|
||||
@@ -1482,7 +1448,7 @@ void p2pool::download_block_headers4(uint64_t start_height, uint64_t current_hei
|
||||
s.m_pos = 0;
|
||||
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_headers_range\",\"params\":{\"start_height\":" << start_height << ",\"end_height\":" << current_height - 1 << "}}" << '\0';
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, start_height, current_height, host](const char* data, size_t size, double)
|
||||
{
|
||||
if (parse_block_headers_range(data, size) == current_height - start_height) {
|
||||
@@ -1522,14 +1488,14 @@ void p2pool::download_block_headers4(uint64_t start_height, uint64_t current_hei
|
||||
|
||||
m_stratumServer = new StratumServer(this);
|
||||
#if defined(WITH_RANDOMX) && !defined(P2POOL_UNIT_TESTS)
|
||||
if (m_params->m_minerThreads) {
|
||||
start_mining(m_params->m_minerThreads);
|
||||
if (m_params.m_minerThreads) {
|
||||
start_mining(m_params.m_minerThreads);
|
||||
}
|
||||
{
|
||||
WriteLock lock(m_ZMQReaderLock);
|
||||
|
||||
try {
|
||||
m_ZMQReader = new ZMQReader(host.m_address, host.m_zmqPort, m_params->m_socks5Proxy, this);
|
||||
m_ZMQReader = new ZMQReader(host.m_address, host.m_zmqPort, m_params.m_socks5Proxy, this);
|
||||
m_zmqLastActive = seconds_since_epoch();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
@@ -1552,10 +1518,10 @@ void p2pool::download_block_headers4(uint64_t start_height, uint64_t current_hei
|
||||
get_miner_data();
|
||||
|
||||
// Get ping times for all other hosts
|
||||
for (const Params::Host& h : m_params->m_hosts) {
|
||||
for (const Params::Host& h : m_params.m_hosts) {
|
||||
const std::string& name = h.m_displayName;
|
||||
if (name != host.m_displayName) {
|
||||
JSONRPCRequest::call(h.m_address, h.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_version\"}", h.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(h.m_address, h.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_version\"}", h.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, name](const char*, size_t, double tcp_ping) { update_host_ping(name, tcp_ping); },
|
||||
[](const char*, size_t, double) {});
|
||||
}
|
||||
@@ -1563,7 +1529,7 @@ void p2pool::download_block_headers4(uint64_t start_height, uint64_t current_hei
|
||||
|
||||
std::vector<IMergeMiningClient*> merge_mining_clients;
|
||||
|
||||
for (const auto& h : m_params->m_mergeMiningHosts) {
|
||||
for (const auto& h : m_params.m_mergeMiningHosts) {
|
||||
IMergeMiningClient* c = IMergeMiningClient::create(this, h.m_host, h.m_wallet);
|
||||
if (c) {
|
||||
merge_mining_clients.push_back(c);
|
||||
@@ -1664,7 +1630,7 @@ void p2pool::get_info()
|
||||
{
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_info\"}", host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_info\"}", host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this](const char* data, size_t size, double)
|
||||
{
|
||||
parse_get_info_rpc(data, size);
|
||||
@@ -1820,7 +1786,7 @@ void p2pool::get_version()
|
||||
{
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_version\"}", host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_version\"}", host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this](const char* data, size_t size, double)
|
||||
{
|
||||
parse_get_version_rpc(data, size);
|
||||
@@ -1897,7 +1863,7 @@ void p2pool::get_miner_data(bool retry)
|
||||
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_miner_data\"}", host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_miner_data\"}", host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, host](const char* data, size_t size, double tcp_ping)
|
||||
{
|
||||
parse_get_miner_data_rpc(data, size);
|
||||
@@ -2139,7 +2105,7 @@ void p2pool::fetch_block_template()
|
||||
|
||||
const Params::Host& host = current_host();
|
||||
char wallet_buf[Wallet::ADDRESS_LENGTH];
|
||||
m_params->m_miningWallet.encode(wallet_buf);
|
||||
m_params.m_miningWallet.encode(wallet_buf);
|
||||
const std::string wallet_addr(wallet_buf);
|
||||
|
||||
uint64_t height;
|
||||
@@ -2150,7 +2116,7 @@ void p2pool::fetch_block_template()
|
||||
|
||||
std::string request = "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"getblocktemplate\",\"params\":{\"wallet_address\":\"" + wallet_addr + "\",\"reserve_size\":1}}";
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, request, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, request, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, height](const char* data, size_t size, double)
|
||||
{
|
||||
parse_block_template_rpc(data, size, height);
|
||||
@@ -2404,7 +2370,7 @@ void p2pool::prefetch_mainchain_blocks(uint64_t current_height)
|
||||
s.m_pos = 0;
|
||||
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_headers_range\",\"params\":{\"start_height\":" << start_height << ",\"end_height\":" << (current_height - 1) << "}}" << '\0';
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this](const char* data, size_t size, double) {
|
||||
const uint32_t parsed = parse_block_headers_range(data, size);
|
||||
if (parsed > 0) {
|
||||
@@ -2439,7 +2405,7 @@ void p2pool::fetch_mainchain_block(uint64_t height)
|
||||
|
||||
const Params::Host& host = current_host();
|
||||
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params->m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
JSONRPCRequest::call(host.m_address, host.m_rpcPort, buf, host.m_rpcLogin, m_params.m_socks5Proxy, host.m_rpcSSL, host.m_rpcSSL_Fingerprint,
|
||||
[this, height](const char* data, size_t size, double) {
|
||||
ChainMain block;
|
||||
if (parse_block_header(data, size, block)) {
|
||||
@@ -2715,7 +2681,7 @@ void p2pool::on_external_block(const PoolBlock& block)
|
||||
|
||||
void p2pool::api_update_aux_data()
|
||||
{
|
||||
if (!m_api || !m_params->m_localStats || m_stopped) {
|
||||
if (!m_api || !m_params.m_localStats || m_stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2865,7 +2831,7 @@ bool p2pool::zmq_running() const
|
||||
|
||||
const Params::Host& p2pool::switch_host()
|
||||
{
|
||||
const std::vector<Params::Host>& v = m_params->m_hosts;
|
||||
const std::vector<Params::Host>& v = m_params.m_hosts;
|
||||
return v[++m_currentHostIndex % v.size()];
|
||||
}
|
||||
|
||||
@@ -2890,7 +2856,7 @@ void p2pool::reconnect_to_host()
|
||||
m_ZMQReader = nullptr;
|
||||
|
||||
try {
|
||||
ZMQReader* new_reader = new ZMQReader(new_host.m_address, new_host.m_zmqPort, m_params->m_socks5Proxy, this);
|
||||
ZMQReader* new_reader = new ZMQReader(new_host.m_address, new_host.m_zmqPort, m_params.m_socks5Proxy, this);
|
||||
m_zmqLastActive = seconds_since_epoch();
|
||||
m_ZMQReader = new_reader;
|
||||
}
|
||||
@@ -2906,7 +2872,7 @@ void p2pool::reconnect_to_host()
|
||||
|
||||
int p2pool::run()
|
||||
{
|
||||
if (!m_params->valid()) {
|
||||
if (!m_params.valid()) {
|
||||
LOGERR(1, "Invalid or missing command line. Try \"p2pool --help\".");
|
||||
return 1;
|
||||
}
|
||||
@@ -2917,8 +2883,8 @@ int p2pool::run()
|
||||
}
|
||||
|
||||
#ifdef WITH_TLS
|
||||
if (!m_params->m_tlsCert.empty() && !m_params->m_tlsCertKey.empty()) {
|
||||
if (!ServerTls::load_from_files(m_params->m_tlsCert.c_str(), m_params->m_tlsCertKey.c_str())) {
|
||||
if (!m_params.m_tlsCert.empty() && !m_params.m_tlsCertKey.empty()) {
|
||||
if (!ServerTls::load_from_files(m_params.m_tlsCert.c_str(), m_params.m_tlsCertKey.c_str())) {
|
||||
LOGERR(1, "Failed to load TLS files");
|
||||
return 1;
|
||||
}
|
||||
|
||||
+4
-4
@@ -40,7 +40,7 @@ struct PoolBlock;
|
||||
class p2pool : public MinerCallbackHandler, public nocopy_nomove
|
||||
{
|
||||
public:
|
||||
explicit p2pool(const std::vector<std::vector<std::string>>& args);
|
||||
explicit p2pool(const Params& params);
|
||||
~p2pool() override;
|
||||
|
||||
int run();
|
||||
@@ -48,14 +48,14 @@ public:
|
||||
bool stopped() const { return m_stopped; }
|
||||
void stop();
|
||||
|
||||
const Params& params() const { return *m_params; }
|
||||
const Params& params() const { return m_params; }
|
||||
bool in_donation_mode(uint64_t height);
|
||||
BlockTemplate& block_template() { return *m_blockTemplate; }
|
||||
SideChain& side_chain() { return *m_sideChain; }
|
||||
|
||||
FORCEINLINE const Params::Host& current_host() const
|
||||
{
|
||||
const std::vector<Params::Host>& v = m_params->m_hosts;
|
||||
const std::vector<Params::Host>& v = m_params.m_hosts;
|
||||
return v[m_currentHostIndex % v.size()];
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ private:
|
||||
|
||||
std::atomic<bool> m_stopped;
|
||||
|
||||
const Params* m_params;
|
||||
const Params& m_params;
|
||||
std::vector<double> m_hostPing;
|
||||
|
||||
std::atomic<uint32_t> m_currentHostIndex;
|
||||
|
||||
Reference in New Issue
Block a user