From 5c92920619349e5874b29ac5fa9b77e8a613b019 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sat, 18 Sep 2021 10:03:06 +0200 Subject: [PATCH] Default log level 3 Also refactored default port numbers --- src/log.cpp | 2 +- src/main.cpp | 6 +++++- src/p2p_server.cpp | 16 +++++++++------- src/p2p_server.h | 1 + src/p2pool.cpp | 9 +++++---- src/params.cpp | 22 ++++++++++++++++++++++ src/params.h | 4 ++-- src/side_chain.cpp | 28 ++++++++++++++-------------- src/stratum_server.cpp | 2 +- src/stratum_server.h | 1 + src/util.cpp | 2 +- src/zmq_reader.cpp | 2 +- 12 files changed, 63 insertions(+), 32 deletions(-) diff --git a/src/log.cpp b/src/log.cpp index d358d3a..7746f8a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -27,7 +27,7 @@ namespace p2pool { namespace log { -int GLOBAL_LOG_LEVEL = 4; +int GLOBAL_LOG_LEVEL = 3; #ifndef P2POOL_LOG_DISABLE diff --git a/src/main.cpp b/src/main.cpp index c176f08..69ea41f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,8 @@ #include "common.h" #include "p2pool.h" +#include "stratum_server.h" +#include "p2p_server.h" static void usage() { @@ -35,12 +37,14 @@ static void usage() "--data-api Path to the p2pool JSON data (use it in tandem with an external web-server)\n" "--help Show this help message\n\n" "Example command line:\n\n" - "%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum [::]:3333,0.0.0.0:3333 --p2p [::]:37889,0.0.0.0:37889\n\n", + "%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n", #ifdef _WIN32 "p2pool.exe" #else "./p2pool" #endif + , p2pool::DEFAULT_STRATUM_PORT + , p2pool::DEFAULT_P2P_PORT ); } diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 87b418c..19e4f2c 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -34,7 +34,6 @@ static const char* seed_nodes[] = { static constexpr int DEFAULT_BACKLOG = 16; static constexpr uint64_t DEFAULT_BAN_TIME = 600; -static constexpr int DEFAULT_LISTEN_PORT = 37889; #include "tcp_server.inl" @@ -334,6 +333,8 @@ void P2PServer::load_peer_list() // Load peers from seed nodes if we're on the default sidechain if (m_pool->side_chain().is_default()) { + const int p2p_port = DEFAULT_P2P_PORT; + for (size_t i = 0; i < array_size(seed_nodes); ++i) { LOGINFO(4, "loading peers from " << seed_nodes[i]); @@ -355,13 +356,13 @@ void P2PServer::load_peer_list() if (r->ai_family == AF_INET6) { addr_str = inet_ntop(AF_INET6, &reinterpret_cast(r->ai_addr)->sin6_addr, addr_str_buf, sizeof(addr_str_buf)); if (addr_str) { - s << '[' << addr_str << "]:" << DEFAULT_LISTEN_PORT << '\0'; + s << '[' << addr_str << "]:" << p2p_port << '\0'; } } else { addr_str = inet_ntop(AF_INET, &reinterpret_cast(r->ai_addr)->sin_addr, addr_str_buf, sizeof(addr_str_buf)); if (addr_str) { - s << addr_str << ':' << DEFAULT_LISTEN_PORT << '\0'; + s << addr_str << ':' << p2p_port << '\0'; } } @@ -376,7 +377,7 @@ void P2PServer::load_peer_list() freeaddrinfo(result); } else { - LOGWARN(4, "getaddrinfo failed for " << seed_nodes[i] << ": " << gai_strerror(err)); + LOGWARN(3, "getaddrinfo failed for " << seed_nodes[i] << ": " << gai_strerror(err)); } } } @@ -497,12 +498,12 @@ void P2PServer::remove_peer_from_list(const raw_ip& ip) void P2PServer::broadcast(const PoolBlock& block) { if (block.m_txinGenHeight + 2 < m_pool->miner_data().height) { - LOGWARN(4, "Trying to broadcast a stale block " << block.m_sidechainId << " (mainchain height " << block.m_txinGenHeight << ", current height is " << m_pool->miner_data().height << ')'); + LOGWARN(3, "Trying to broadcast a stale block " << block.m_sidechainId << " (mainchain height " << block.m_txinGenHeight << ", current height is " << m_pool->miner_data().height << ')'); return; } if (block.m_txinGenHeight > m_pool->miner_data().height + 2) { - LOGWARN(4, "Trying to broadcast a block " << block.m_sidechainId << " ahead on mainchain (mainchain height " << block.m_txinGenHeight << ", current height is " << m_pool->miner_data().height << ')'); + LOGWARN(3, "Trying to broadcast a block " << block.m_sidechainId << " ahead on mainchain (mainchain height " << block.m_txinGenHeight << ", current height is " << m_pool->miner_data().height << ')'); return; } @@ -1436,7 +1437,8 @@ bool P2PServer::P2PClient::on_block_broadcast(const uint8_t* buf, uint32_t size) } else if (peer_height > our_height) { if (peer_height >= our_height + 2) { - LOGWARN(4, "peer " << static_cast(m_addrString) << " is ahead on mainchain (height " << peer_height << ", your height " << our_height << "). Is your monerod stuck or lagging?"); + const int level = (peer_height >= our_height + 3) ? 3 : 4; + LOGWARN(level , "peer " << static_cast(m_addrString) << " is ahead on mainchain (height " << peer_height << ", your height " << our_height << "). Is your monerod stuck or lagging?"); } } else { diff --git a/src/p2p_server.h b/src/p2p_server.h index 11d8621..0ef5482 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -29,6 +29,7 @@ class BlockCache; static constexpr size_t P2P_BUF_SIZE = 128 * 1024; static constexpr size_t PEER_LIST_RESPONSE_MAX_PEERS = 16; +static constexpr int DEFAULT_P2P_PORT = 37889; class P2PServer : public TCPServer { diff --git a/src/p2pool.cpp b/src/p2pool.cpp index dd1d234..c2a76c7 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -418,7 +418,7 @@ void p2pool::submit_block() const } if (is_external) { - LOGWARN(4, "submit_block (external blob): daemon returned error: " << (error_msg ? error_msg : "unknown error")); + LOGWARN(3, "submit_block (external blob): daemon returned error: " << (error_msg ? error_msg : "unknown error")); } else { LOGERR(0, "submit_block: daemon returned error: '" << (error_msg ? error_msg : "unknown error") << "', template id = " << template_id << ", nonce = " << nonce << ", extra_nonce = " << extra_nonce); @@ -442,7 +442,7 @@ void p2pool::submit_block() const { if (size > 0) { if (is_external) { - LOGWARN(4, "submit_block (external blob): RPC request failed, error " << log::const_buf(data, size)); + LOGWARN(3, "submit_block (external blob): RPC request failed, error " << log::const_buf(data, size)); } else { LOGERR(0, "submit_block (external blob): RPC request failed, error " << log::const_buf(data, size)); @@ -1036,11 +1036,12 @@ void p2pool::api_update_stats_mod() } const uint64_t round_hashes = total_hashes.lo - last_block_total_hashes.lo; + const int stratum_port = DEFAULT_STRATUM_PORT; m_api->set(p2pool_api::Category::GLOBAL, "stats_mod", - [&mainnet_tip, last_block_found_time, &last_block_found_buf, last_block_found_height, miners, hashrate, round_hashes](log::Stream& s) + [&mainnet_tip, last_block_found_time, &last_block_found_buf, last_block_found_height, miners, hashrate, round_hashes, stratum_port](log::Stream& s) { - s << "{\"config\":{\"ports\":[{\"port\":3333,\"tls\":false}],\"fee\":0,\"minPaymentThreshold\":400000000},\"network\":{\"height\":" + s << "{\"config\":{\"ports\":[{\"port\":" << stratum_port << ",\"tls\":false}],\"fee\":0,\"minPaymentThreshold\":400000000},\"network\":{\"height\":" << mainnet_tip.height << "},\"pool\":{\"stats\":{\"lastBlockFound\":\"" << last_block_found_time << "000\"},\"blocks\":[\"" << static_cast(last_block_found_buf) << static_cast(last_block_found_buf) + HASH_SIZE * 2 - 4 << ':' diff --git a/src/params.cpp b/src/params.cpp index 14cbf51..7e0eb7f 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -17,6 +17,8 @@ #include "common.h" #include "params.h" +#include "stratum_server.h" +#include "p2p_server.h" namespace p2pool { @@ -68,6 +70,26 @@ Params::Params(int argc, char* argv[]) m_apiPath = argv[++i]; } } + + if (m_stratumAddresses.empty()) { + const int stratum_port = DEFAULT_STRATUM_PORT; + + char buf[log::Stream::BUF_SIZE + 1]; + log::Stream s(buf); + s << "[::]:" << stratum_port << ",0.0.0.0:" << stratum_port << '\0'; + + m_stratumAddresses = buf; + } + + if (m_p2pAddresses.empty()) { + const int p2p_port = DEFAULT_P2P_PORT; + + char buf[log::Stream::BUF_SIZE + 1]; + log::Stream s(buf); + s << "[::]:" << p2p_port << ",0.0.0.0:" << p2p_port << '\0'; + + m_p2pAddresses = buf; + } } bool Params::ok() const diff --git a/src/params.h b/src/params.h index 4f2c5a2..b38c299 100644 --- a/src/params.h +++ b/src/params.h @@ -32,8 +32,8 @@ struct Params uint32_t m_zmqPort = 18083; bool m_lightMode = false; Wallet m_wallet{ nullptr }; - std::string m_stratumAddresses{ "[::]:3333,0.0.0.0:3333" }; - std::string m_p2pAddresses{ "[::]:37889,0.0.0.0:37889" }; + std::string m_stratumAddresses; + std::string m_p2pAddresses; std::string m_p2pPeerList; std::string m_config; std::string m_apiPath; diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 5355ef9..5f24022 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -51,6 +51,10 @@ static_assert(1 <= UNCLE_BLOCK_DEPTH && UNCLE_BLOCK_DEPTH <= 10, "Invalid UNCLE_ namespace p2pool { +static constexpr uint8_t default_consensus_id[HASH_SIZE] = { + 34,175,126,231,181,11,104,146,227,153,218,107,44,108,68,39,178,81,4,212,169,4,142,0,177,110,157,240,68,7,249,24 +}; + SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name) : m_pool(pool) , m_networkType(type) @@ -91,9 +95,9 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name) constexpr char default_config[] = "mainnet\0" "default\0" "\0" "10\0" "100000\0" "2160\0" "20\0"; + // Hardcoded default consensus ID if (memcmp(buf, default_config, sizeof(default_config) - 1) == 0) { - // Hardcoded default consensus ID - m_consensusId.assign({ 34,175,126,231,181,11,104,146,227,153,218,107,44,108,68,39,178,81,4,212,169,4,142,0,177,110,157,240,68,7,249,24 }); + m_consensusId.assign(default_consensus_id, default_consensus_id + HASH_SIZE); } else { const randomx_flags flags = randomx_get_flags(); @@ -270,8 +274,8 @@ bool SideChain::get_shares(PoolBlock* tip, std::vector& shares) cons for (const hash& uncle_id : cur->m_uncles) { auto it = m_blocksById.find(uncle_id); if (it == m_blocksById.end()) { - LOGWARN(4, "get_shares: can't find uncle block at height = " << cur->m_sidechainHeight << ", id = " << uncle_id); - LOGWARN(4, "get_shares: can't calculate shares for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); + LOGWARN(3, "get_shares: can't find uncle block at height = " << cur->m_sidechainHeight << ", id = " << uncle_id); + LOGWARN(3, "get_shares: can't calculate shares for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); return false; } @@ -307,8 +311,8 @@ bool SideChain::get_shares(PoolBlock* tip, std::vector& shares) cons auto it = m_blocksById.find(cur->m_parent); if (it == m_blocksById.end()) { - LOGWARN(4, "get_shares: can't find parent block at height = " << cur->m_sidechainHeight - 1 << ", id = " << cur->m_parent); - LOGWARN(4, "get_shares: can't calculate shares for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); + LOGWARN(3, "get_shares: can't find parent block at height = " << cur->m_sidechainHeight - 1 << ", id = " << cur->m_parent); + LOGWARN(3, "get_shares: can't calculate shares for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); return false; } @@ -746,10 +750,6 @@ time_t SideChain::last_updated() const bool SideChain::is_default() const { - constexpr uint8_t default_consensus_id[HASH_SIZE] = { - 34,175,126,231,181,11,104,146,227,153,218,107,44,108,68,39,178,81,4,212,169,4,142,0,177,110,157,240,68,7,249,24 - }; - return (memcmp(m_consensusId.data(), default_consensus_id, HASH_SIZE) == 0); } @@ -806,8 +806,8 @@ bool SideChain::get_difficulty(PoolBlock* tip, std::vector& diff for (const hash& uncle_id : cur->m_uncles) { auto it = m_blocksById.find(uncle_id); if (it == m_blocksById.end()) { - LOGWARN(4, "get_difficulty: can't find uncle block at height = " << cur->m_sidechainHeight << ", id = " << uncle_id); - LOGWARN(4, "get_difficulty: can't calculate diff for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); + LOGWARN(3, "get_difficulty: can't find uncle block at height = " << cur->m_sidechainHeight << ", id = " << uncle_id); + LOGWARN(3, "get_difficulty: can't calculate diff for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); return false; } @@ -830,8 +830,8 @@ bool SideChain::get_difficulty(PoolBlock* tip, std::vector& diff auto it = m_blocksById.find(cur->m_parent); if (it == m_blocksById.end()) { - LOGWARN(4, "get_difficulty: can't find parent block at height = " << cur->m_sidechainHeight - 1 << ", id = " << cur->m_parent); - LOGWARN(4, "get_difficulty: can't calculate diff for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); + LOGWARN(3, "get_difficulty: can't find parent block at height = " << cur->m_sidechainHeight - 1 << ", id = " << cur->m_parent); + LOGWARN(3, "get_difficulty: can't calculate diff for block at height = " << tip->m_sidechainHeight << ", id = " << tip->m_sidechainId << ", mainchain height = " << tip->m_txinGenHeight); return false; } diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index 30166df..8bda6d5 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -606,7 +606,7 @@ void StratumServer::on_share_found(uv_work_t* req) hash pow_hash; if (!pool->calculate_hash(blob, blob_size, seed_hash, pow_hash)) { - LOGWARN(4, "client " << static_cast(client->m_addrString) << " couldn't check share PoW"); + LOGWARN(3, "client " << static_cast(client->m_addrString) << " couldn't check share PoW"); share->m_result = SubmittedShare::Result::COULDNT_CHECK_POW; return; } diff --git a/src/stratum_server.h b/src/stratum_server.h index 0e38523..e825695 100644 --- a/src/stratum_server.h +++ b/src/stratum_server.h @@ -27,6 +27,7 @@ class p2pool; class BlockTemplate; static constexpr size_t STRATUM_BUF_SIZE = log::Stream::BUF_SIZE + 1; +static constexpr int DEFAULT_STRATUM_PORT = 3333; class StratumServer : public TCPServer { diff --git a/src/util.cpp b/src/util.cpp index b1105c0..84c0282 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -356,7 +356,7 @@ bool resolve_host(std::string& host, bool& is_v6) freeaddrinfo(r); } else { - LOGWARN(4, "getaddrinfo failed for " << host << ": " << gai_strerror(err)); + LOGWARN(3, "getaddrinfo failed for " << host << ": " << gai_strerror(err)); return false; } diff --git a/src/zmq_reader.cpp b/src/zmq_reader.cpp index 6753be2..0a52025 100644 --- a/src/zmq_reader.cpp +++ b/src/zmq_reader.cpp @@ -257,7 +257,7 @@ void ZMQReader::parse(char* data, size_t size) } } else { - LOGWARN(4, "json-full-chain_main outputs not found"); + LOGWARN(1, "json-full-chain_main outputs not found"); } auto inputs = inputs_it->value.GetArray();