CI: revised clang-tidy list of checks

This commit is contained in:
SChernykh
2025-09-25 18:46:22 +02:00
parent 26357f44ec
commit 0184a3139c
36 changed files with 146 additions and 157 deletions
+1 -1
View File
@@ -37,4 +37,4 @@ jobs:
- name: Run clang-tidy
run: |
cd src
clang-tidy-21 *.cpp -p ../build -checks=-clang-diagnostic-undefined-internal,-clang-analyzer-optin.performance.Padding,-clang-diagnostic-nan-infinity-disabled -warnings-as-errors=* -header-filter=^[^\.]
clang-tidy-21 *.cpp -p ../build -checks=bugprone-*,clang-analyzer-*,llvm-*,cppcoreguidelines-pro-type-cstyle-cast,cppcoreguidelines-rvalue-reference-param-not-moved,hicpp-use-emplace,hicpp-use-override,-bugprone-easily-swappable-parameters,-bugprone-empty-catch,-llvm-include-order -warnings-as-errors=* -header-filter=^[^\./]
+4 -4
View File
@@ -44,16 +44,16 @@ struct BlockCache::Impl : public nocopy_nomove
return;
}
int result = lseek(m_fd, static_cast<off_t>(CACHE_SIZE) - 1, SEEK_SET);
if (result == -1) {
auto result1 = lseek(m_fd, static_cast<off_t>(CACHE_SIZE) - 1, SEEK_SET);
if (result1 == -1) {
LOGERR(1, "lseek failed");
close(m_fd);
m_fd = -1;
return;
}
result = write(m_fd, "", 1);
if (result != 1) {
auto result2 = write(m_fd, "", 1);
if (result2 != 1) {
LOGERR(1, "write failed");
close(m_fd);
m_fd = -1;
+1 -1
View File
@@ -865,7 +865,7 @@ void BlockTemplate::select_mempool_transactions(const Mempool& mempool)
k += r / 34359738368ULL;
}
const size_t max_transactions = (MAX_BLOCK_SIZE > k) ? ((MAX_BLOCK_SIZE - k) / HASH_SIZE) : 0;
const uint32_t max_transactions = static_cast<uint32_t>((MAX_BLOCK_SIZE > k) ? ((MAX_BLOCK_SIZE - k) / HASH_SIZE) : 0);
LOGINFO(6, max_transactions << " transactions can be taken with current block size limit");
if (max_transactions == 0) {
+2 -2
View File
@@ -91,7 +91,7 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
rng.discard(10000);
for (int i = 0; i < 10; ++i) {
if (start_listening(false, "127.0.0.1", 49152 + (rng() % 16384))) {
if (start_listening(false, "127.0.0.1", 49152 + static_cast<int>(rng() % 16384))) {
break;
}
}
@@ -293,7 +293,7 @@ static void do_status(p2pool *m_pool, const char * /* args */)
static void do_loglevel(p2pool * /* m_pool */, const char *args)
{
int level = strtol(args, nullptr, 10);
int level = static_cast<int>(strtol(args, nullptr, 10));
level = std::min(std::max(level, 0), log::MAX_GLOBAL_LOG_LEVEL);
log::GLOBAL_LOG_LEVEL = level;
LOGINFO(0, "log level set to " << level);
+4 -4
View File
@@ -66,7 +66,7 @@ private:
static RandomBytes* randomBytes = nullptr;
}
} // namespace
static FORCEINLINE bool less32(const uint8_t* k0, const uint8_t* k1)
{
@@ -390,7 +390,7 @@ private:
m_viewTags1[i] = k; \
return; \
} \
else if (t == k) { \
if (t == k) { \
return; \
} \
} while (0)
@@ -481,12 +481,12 @@ void init_crypto_cache()
void destroy_crypto_cache()
{
{
auto p = randomBytes;
auto* p = randomBytes;
randomBytes = nullptr;
delete p;
}
{
auto p = cache;
auto* p = cache;
cache = nullptr;
delete p;
}
+1 -1
View File
@@ -126,7 +126,7 @@ CurlContext::CurlContext(const std::string& address, int port, const std::string
m_req.clear();
}
else {
s << "/json_rpc\0";
s << "/json_rpc" << '\0';
}
m_url = buf;
+16 -16
View File
@@ -50,12 +50,12 @@ NOINLINE void keccakf_plain(std::array<uint64_t, 25>& st)
bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
#define THETA(i) { \
const uint64_t t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); \
st[i + 0 ] ^= t; \
st[i + 5] ^= t; \
st[i + 10] ^= t; \
st[i + 15] ^= t; \
st[i + 20] ^= t; \
const uint64_t t = bc[((i) + 4) % 5] ^ ROTL64(bc[((i) + 1) % 5], 1); \
st[(i) + 0 ] ^= t; \
st[(i) + 5] ^= t; \
st[(i) + 10] ^= t; \
st[(i) + 15] ^= t; \
st[(i) + 20] ^= t; \
}
THETA(0);
@@ -93,16 +93,16 @@ NOINLINE void keccakf_plain(std::array<uint64_t, 25>& st)
// Chi
#define CHI(j) { \
const uint64_t st0 = st[j ]; \
const uint64_t st1 = st[j + 1]; \
const uint64_t st2 = st[j + 2]; \
const uint64_t st3 = st[j + 3]; \
const uint64_t st4 = st[j + 4]; \
st[j ] ^= ~st1 & st2; \
st[j + 1] ^= ~st2 & st3; \
st[j + 2] ^= ~st3 & st4; \
st[j + 3] ^= ~st4 & st0; \
st[j + 4] ^= ~st0 & st1; \
const uint64_t st0 = st[(j) ]; \
const uint64_t st1 = st[(j) + 1]; \
const uint64_t st2 = st[(j) + 2]; \
const uint64_t st3 = st[(j) + 3]; \
const uint64_t st4 = st[(j) + 4]; \
st[(j) ] ^= ~st1 & st2; \
st[(j) + 1] ^= ~st2 & st3; \
st[(j) + 2] ^= ~st3 & st4; \
st[(j) + 3] ^= ~st4 & st0; \
st[(j) + 4] ^= ~st0 & st1; \
}
CHI( 0);
+16 -16
View File
@@ -43,12 +43,12 @@ NOINLINE void keccakf_bmi(std::array<uint64_t, 25>& st)
bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
#define THETA(i) { \
const uint64_t t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); \
st[i + 0 ] ^= t; \
st[i + 5] ^= t; \
st[i + 10] ^= t; \
st[i + 15] ^= t; \
st[i + 20] ^= t; \
const uint64_t t = bc[((i) + 4) % 5] ^ ROTL64(bc[((i) + 1) % 5], 1); \
st[(i) + 0 ] ^= t; \
st[(i) + 5] ^= t; \
st[(i) + 10] ^= t; \
st[(i) + 15] ^= t; \
st[(i) + 20] ^= t; \
}
THETA(0);
@@ -86,16 +86,16 @@ NOINLINE void keccakf_bmi(std::array<uint64_t, 25>& st)
// Chi
#define CHI(j) { \
const uint64_t st0 = st[j ]; \
const uint64_t st1 = st[j + 1]; \
const uint64_t st2 = st[j + 2]; \
const uint64_t st3 = st[j + 3]; \
const uint64_t st4 = st[j + 4]; \
st[j ] ^= _andn_u64(st1, st2); \
st[j + 1] ^= _andn_u64(st2, st3); \
st[j + 2] ^= _andn_u64(st3, st4); \
st[j + 3] ^= _andn_u64(st4, st0); \
st[j + 4] ^= _andn_u64(st0, st1); \
const uint64_t st0 = st[(j) ]; \
const uint64_t st1 = st[(j) + 1]; \
const uint64_t st2 = st[(j) + 2]; \
const uint64_t st3 = st[(j) + 3]; \
const uint64_t st4 = st[(j) + 4]; \
st[(j) ] ^= _andn_u64(st1, st2); \
st[(j) + 1] ^= _andn_u64(st2, st3); \
st[(j) + 2] ^= _andn_u64(st3, st4); \
st[(j) + 3] ^= _andn_u64(st4, st0); \
st[(j) + 4] ^= _andn_u64(st0, st1); \
}
CHI(0);
+4 -4
View File
@@ -211,7 +211,7 @@ public:
#endif
// Mark that everything is written into this log slot
p[0] = buf[0] + 1;
p[0] = static_cast<char>(buf[0] + 1);
// Signal the worker thread
uv_cond_signal(&m_cond);
@@ -453,7 +453,7 @@ static FORCEINLINE void writeCurrentTime(Stream& s)
s.setNumberWidth(2);
s << (t.tm_year + 1900) << '-' << (t.tm_mon + 1) << '-' << t.tm_mday << ' ' << t.tm_hour << ':' << t.tm_min << ':' << t.tm_sec << '.';
const int32_t mcs = time_point_cast<microseconds>(now).time_since_epoch().count() % 1000000;
const int32_t mcs = static_cast<int32_t>(time_point_cast<microseconds>(now).time_since_epoch().count() % 1000000);
s.setNumberWidth(4);
s << (mcs / 100);
@@ -474,8 +474,8 @@ NOINLINE Writer::Writer(Severity severity) : Stream(m_stackBuf)
NOINLINE Writer::~Writer()
{
const uint32_t size = static_cast<uint32_t>(m_pos + 1);
m_buf[1] = static_cast<uint8_t>(size & 255);
m_buf[2] = static_cast<uint8_t>(size >> 8);
m_buf[1] = static_cast<char>(static_cast<uint8_t>(size & 255));
m_buf[2] = static_cast<char>(static_cast<uint8_t>(size >> 8));
m_buf[m_pos] = '\n';
#ifndef P2POOL_LOG_DISABLE
worker->write(m_buf, size);
+1 -1
View File
@@ -207,7 +207,7 @@ int p2pool_test()
constexpr char expected_hash[] = "3b5ecc2bb14f467161a04fe476b541194fba82dbbbfc7c320961f922a0294dee";
if (memcmp(buf, expected_hash, RANDOMX_HASH_SIZE * 2) != 0) {
if (memcmp(buf, expected_hash, static_cast<int>(RANDOMX_HASH_SIZE * 2)) != 0) {
printf("Invalid hash calculated: expected %s, got %s\n", expected_hash, buf);
return 1;
}
+1 -1
View File
@@ -395,5 +395,5 @@ char* strdup_hook(const char* s) noexcept
#endif
}
}
} // namespace p2pool
#endif
+2 -1
View File
@@ -41,7 +41,7 @@ void Mempool::add(const TxMempoolData& tx)
}
}
void Mempool::swap(std::vector<TxMempoolData>& transactions)
void Mempool::swap_transactions(std::vector<TxMempoolData>& transactions)
{
const uint64_t cur_time = seconds_since_epoch();
@@ -59,6 +59,7 @@ void Mempool::swap(std::vector<TxMempoolData>& transactions)
}
m_transactions.clear();
m_transactions.reserve(transactions.size());
for (TxMempoolData& data : transactions) {
m_transactions.emplace(data.id, data);
+1 -1
View File
@@ -32,7 +32,7 @@ public:
~Mempool();
void add(const TxMempoolData& tx);
void swap(std::vector<TxMempoolData>& transactions);
void swap_transactions(std::vector<TxMempoolData>& transactions);
size_t size() const
{
-3
View File
@@ -34,12 +34,9 @@ IMergeMiningClient* IMergeMiningClient::create(p2pool* pool, const std::string&
if (host.find(MergeMiningClientTari::TARI_PREFIX) == 0) {
return new MergeMiningClientTari(pool, host, wallet);
}
else
#endif
{
return new MergeMiningClientJSON_RPC(pool, host, wallet);
}
}
catch (...) {
LOGERR(1, "Failed to create merge mining client for " << host);
}
+3 -5
View File
@@ -44,10 +44,10 @@ MergeMiningClientJSON_RPC::MergeMiningClientJSON_RPC(p2pool* pool, const std::st
const size_t k = host.find_last_of(':');
if (k != std::string::npos) {
m_host = host.substr(0, k);
m_port = std::stoul(host.substr(k + 1), nullptr, 10);
m_port = static_cast<int32_t>(std::stol(host.substr(k + 1), nullptr, 10));
}
if (m_host.empty() || (m_port == 0) || (m_port >= 65536)) {
if (m_host.empty() || (m_port <= 0) || (m_port >= 65536)) {
LOGERR(1, "Invalid host " << host);
throw std::exception();
}
@@ -390,13 +390,11 @@ bool MergeMiningClientJSON_RPC::parse_merge_mining_submit_solution(const char* d
if (error_result.IsString()) {
return err(error_result.GetString());
}
else if (error_result.IsObject() && error_result.HasMember("message") && error_result["message"].IsString()) {
if (error_result.IsObject() && error_result.HasMember("message") && error_result["message"].IsString()) {
return err(error_result["message"].GetString());
}
else {
return err("an unknown error occurred");
}
}
if (!doc.HasMember("result")) {
return err("\"result\" field not found");
+1 -1
View File
@@ -52,7 +52,7 @@ private:
bool parse_merge_mining_submit_solution(const char* data, size_t size) const;
std::string m_host;
uint32_t m_port;
int32_t m_port;
mutable uv_rwlock_t m_lock;
ChainParameters m_chainParams;
+5 -6
View File
@@ -303,12 +303,11 @@ void MergeMiningClientTari::on_external_block(const PoolBlock& block)
LOGINFO(4, "External aux job solution found, but it's for another miner");
return;
}
else {
LOGINFO(4, "External aux job solution found, but it's stale");
chain_params.aux_hash = data;
chain_params.aux_diff = diff;
}
}
else {
m_previousAuxHashesFoundIndex = std::numeric_limits<uint32_t>::max();
}
@@ -512,10 +511,10 @@ void MergeMiningClientTari::submit_solution(const std::vector<uint8_t>& coinbase
data.append(reinterpret_cast<const char*>(keccak_state.data()), sizeof(keccak_state));
// coinbase_tx_hasher.offset
data.append(1, static_cast<uint8_t>(offset));
data.append(1, static_cast<char>(static_cast<uint8_t>(offset)));
// coinbase_tx_hasher.rate
data.append(1, static_cast<uint8_t>(KeccakParams::HASH_DATA_AREA));
data.append(1, static_cast<char>(static_cast<uint8_t>(KeccakParams::HASH_DATA_AREA)));
// coinbase_tx_hasher.mode
data.append(1, 1);
@@ -527,7 +526,7 @@ void MergeMiningClientTari::submit_solution(const std::vector<uint8_t>& coinbase
// aux_chain_merkle_proof
data.append(1, static_cast<char>(merkle_proof.size()));
data.append(reinterpret_cast<const char*>(merkle_proof.data()), merkle_proof.size() * HASH_SIZE);
writeVarint(merkle_proof_path, [&data](uint8_t value) { data.append(1, value); });
writeVarint(merkle_proof_path, [&data](uint8_t value) { data.append(1, static_cast<char>(value)); });
pow->set_pow_data(data);
}
@@ -865,7 +864,7 @@ bool MergeMiningClientTari::TariServer::start()
std::mt19937_64 rng(rd());
for (size_t i = 0; i < 10; ++i) {
if (start_listening(false, "127.0.0.1", 49152 + (rng() % 16384))) {
if (start_listening(false, "127.0.0.1", 49152 + static_cast<int>((rng() % 16384)))) {
break;
}
}
+2 -1
View File
@@ -153,7 +153,8 @@ bool get_merkle_proof(const std::vector<std::vector<hash>>& tree, const hash& h,
if (count == 1) {
return true;
}
else if (count == 2) {
if (count == 2) {
proof.emplace_back(hashes[index ^ 1]);
path = index & 1;
}
+2 -2
View File
@@ -867,7 +867,7 @@ P2PServer::Broadcast::Broadcast(const PoolBlock& block, const PoolBlock* parent)
data->compact_blob.reserve(data->pruned_blob.capacity() + (N - 1));
// Copy pruned_blob without the transaction list
data->compact_blob.assign(data->pruned_blob.begin(), data->pruned_blob.end() - (N - 1) * HASH_SIZE);
data->compact_blob.assign(data->pruned_blob.begin(), data->pruned_blob.end() - static_cast<uint32_t>((N - 1) * HASH_SIZE));
// Process transaction hashes one by one
size_t num_found = 0;
@@ -1602,7 +1602,7 @@ void P2PServer::clean_aux_job_messages()
for (auto it = m_auxJobMessages.begin(); it != m_auxJobMessages.end();) {
// Delete old messages only after 3x the timeout to give some leeway for system clock adjustments
if (cur_time > it->second + AUX_JOB_TIMEOUT * 3) {
if (cur_time > it->second + static_cast<uint64_t>(AUX_JOB_TIMEOUT * 3)) {
it = m_auxJobMessages.erase(it);
}
else {
+10 -10
View File
@@ -290,12 +290,12 @@ p2pool::~p2pool()
delete m_params;
{
auto p = bkg_jobs_tracker;
auto* p = bkg_jobs_tracker;
bkg_jobs_tracker = nullptr;
delete p;
}
{
auto p = PoolBlock::s_precalculatedSharesLock;
auto* p = PoolBlock::s_precalculatedSharesLock;
PoolBlock::s_precalculatedSharesLock = nullptr;
delete p;
}
@@ -422,7 +422,7 @@ void p2pool::handle_miner_data(MinerData& data)
m_mempool->swap(data.tx_backlog);
}
#else
m_mempool->swap(data.tx_backlog);
m_mempool->swap_transactions(data.tx_backlog);
#endif
{
@@ -545,7 +545,7 @@ void p2pool::get_missing_heights()
char buf[log::Stream::BUF_SIZE + 1] = {};
log::Stream s(buf);
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_header_by_height\",\"params\":{\"height\":" << h << "}}\0";
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_header_by_height\",\"params\":{\"height\":" << h << "}}" << '\0';
const Params::Host& host = current_host();
@@ -1269,7 +1269,7 @@ void p2pool::download_block_headers1(uint64_t current_height)
const Params::Host& host = current_host();
s.m_pos = 0;
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_header_by_height\",\"params\":{\"height\":" << prev_seed_height << "}}\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,
[this, prev_seed_height, current_height](const char* data, size_t size, double) {
@@ -1302,7 +1302,7 @@ void p2pool::download_block_headers2(uint64_t current_height)
const Params::Host& host = current_host();
s.m_pos = 0;
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"get_block_header_by_height\",\"params\":{\"height\":" << seed_height << "}}\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,
[this, seed_height, current_height](const char* data, size_t size, double) {
@@ -1338,7 +1338,7 @@ void p2pool::download_block_headers3(uint64_t start_height, uint64_t current_hei
const uint64_t next_height = start_height + RESTRICTED_BLOCK_HEADER_RANGE;
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";
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,
[this, start_height, next_height, current_height](const char* data, size_t size, double) {
@@ -1371,7 +1371,7 @@ void p2pool::download_block_headers4(uint64_t start_height, uint64_t current_hei
const Params::Host& host = current_host();
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";
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,
[this, start_height, current_height, host](const char* data, size_t size, double)
@@ -1863,7 +1863,7 @@ uint32_t p2pool::parse_block_headers_range(const char* data, size_t size)
auto headers = it2->value.GetArray();
uint64_t min_height = std::numeric_limits<uint64_t>::max();
uint64_t max_height = 0;
for (auto i = headers.begin(); i != headers.end(); ++i) {
for (auto* i = headers.begin(); i != headers.end(); ++i) {
if (!i->IsObject()) {
continue;
}
@@ -2093,7 +2093,7 @@ void p2pool::api_update_block_found(const ChainMain* data, const PoolBlock* bloc
if (data) {
m_foundBlocks.emplace_back(cur_time, data->height, data->id, diff, total_hashes);
}
found_blocks.assign(m_foundBlocks.end() - std::min<size_t>(m_foundBlocks.size(), 51), m_foundBlocks.end());
found_blocks.assign(m_foundBlocks.end() - std::min<int>(static_cast<int>(m_foundBlocks.size()), 51), m_foundBlocks.end());
}
m_api->set(p2pool_api::Category::POOL, "blocks",
+1 -1
View File
@@ -106,7 +106,7 @@ void p2pool_api::on_stop()
uv_close(reinterpret_cast<uv_handle_t*>(&m_dumpToFileAsync), nullptr);
}
void p2pool_api::dump_to_file_async_internal(Category category, const char* filename, Callback<void, log::Stream&>::Base&& callback)
void p2pool_api::dump_to_file_async_internal(Category category, const char* filename, const Callback<void, log::Stream&>::Base& callback)
{
std::vector<char> buf(1024);
log::Stream s(buf.data(), buf.size());
+1 -1
View File
@@ -54,7 +54,7 @@ private:
std::vector<char> buf;
};
void dump_to_file_async_internal(Category category, const char* filename, Callback<void, log::Stream&>::Base&& callback);
void dump_to_file_async_internal(Category category, const char* filename, const Callback<void, log::Stream&>::Base& callback);
void dump_to_file();
static void on_fs_open(uv_fs_t* req);
static void on_fs_write(uv_fs_t* req);
+11 -11
View File
@@ -38,7 +38,7 @@ Params::Params(int argc, char* const argv[])
const char* address = argv[++i];
if (m_hosts.empty()) {
m_hosts.emplace_back(Host());
m_hosts.emplace_back();
m_hosts.back().m_address = address;
}
else {
@@ -51,19 +51,19 @@ Params::Params(int argc, char* const argv[])
if ((strcmp(argv[i], "--rpc-port") == 0) && (i + 1 < argc)) {
if (m_hosts.empty()) {
m_hosts.emplace_back(Host());
m_hosts.emplace_back();
}
m_hosts.back().m_rpcPort = std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 65535UL);
m_hosts.back().m_rpcPort = static_cast<int32_t>(std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 65535UL));
ok = true;
}
if ((strcmp(argv[i], "--zmq-port") == 0) && (i + 1 < argc)) {
if (m_hosts.empty()) {
m_hosts.emplace_back(Host());
m_hosts.emplace_back();
}
m_hosts.back().m_zmqPort = std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 65535UL);
m_hosts.back().m_zmqPort = static_cast<int32_t>(std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 65535UL));
ok = true;
}
@@ -103,7 +103,7 @@ Params::Params(int argc, char* const argv[])
}
if ((strcmp(argv[i], "--loglevel") == 0) && (i + 1 < argc)) {
const int level = std::min(std::max<int>(strtol(argv[++i], nullptr, 10), 0), log::MAX_GLOBAL_LOG_LEVEL);
const int level = std::min(std::max<int>(static_cast<int>(strtol(argv[++i], nullptr, 10)), 0), log::MAX_GLOBAL_LOG_LEVEL);
log::GLOBAL_LOG_LEVEL = level;
ok = true;
}
@@ -178,7 +178,7 @@ Params::Params(int argc, char* const argv[])
if ((strcmp(argv[i], "--rpc-login") == 0) && (i + 1 < argc)) {
if (m_hosts.empty()) {
m_hosts.emplace_back(Host());
m_hosts.emplace_back();
}
m_hosts.back().m_rpcLogin = argv[++i];
@@ -188,7 +188,7 @@ Params::Params(int argc, char* const argv[])
#ifdef WITH_TLS
if (strcmp(argv[i], "--rpc-ssl") == 0) {
if (m_hosts.empty()) {
m_hosts.emplace_back(Host());
m_hosts.emplace_back();
}
m_hosts.back().m_rpcSSL = true;
@@ -197,7 +197,7 @@ Params::Params(int argc, char* const argv[])
if ((strcmp(argv[i], "--rpc-ssl-fingerprint") == 0) && (i + 1 < argc)) {
if (m_hosts.empty()) {
m_hosts.emplace_back(Host());
m_hosts.emplace_back();
}
m_hosts.back().m_rpcSSL_Fingerprint = argv[++i];
@@ -217,7 +217,7 @@ Params::Params(int argc, char* const argv[])
}
if ((strcmp(argv[i], "--p2p-external-port") == 0) && (i + 1 < argc)) {
m_p2pExternalPort = std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 65535UL);
m_p2pExternalPort = static_cast<int32_t>(std::min(std::max(strtoul(argv[++i], nullptr, 10), 1UL), 65535UL));
ok = true;
}
@@ -290,7 +290,7 @@ Params::Params(int argc, char* const argv[])
m_hosts.erase(std::remove_if(m_hosts.begin(), m_hosts.end(), invalid_host), m_hosts.end());
if (m_hosts.empty()) {
m_hosts.emplace_back(Host());
m_hosts.emplace_back();
}
if (m_stratumAddresses.empty()) {
+4 -4
View File
@@ -33,7 +33,7 @@ struct Params
{
Host() : m_address("127.0.0.1"), m_rpcPort(18081), m_zmqPort(18083), m_rpcSSL(false) {}
Host(const char* address, uint32_t rpcPort, uint32_t zmqPort, const char* rpcLogin)
Host(const char* address, int32_t rpcPort, int32_t zmqPort, const char* rpcLogin)
: m_address(address)
, m_rpcPort(rpcPort)
, m_zmqPort(zmqPort)
@@ -46,8 +46,8 @@ struct Params
bool init_display_name(const Params& p);
std::string m_address;
uint32_t m_rpcPort;
uint32_t m_zmqPort;
int32_t m_rpcPort;
int32_t m_zmqPort;
std::string m_rpcLogin;
@@ -99,7 +99,7 @@ struct Params
bool m_autoDiff = true;
std::string m_socks5Proxy;
bool m_dns = true;
uint32_t m_p2pExternalPort = 0;
int32_t m_p2pExternalPort = 0;
#ifdef WITH_UPNP
bool m_upnp = true;
bool m_upnpStratum = false;
+2 -2
View File
@@ -71,7 +71,7 @@ RandomX_Hasher::RandomX_Hasher(p2pool* pool)
PANIC_STOP();
}
}
memory_allocated += RANDOMX_ARGON_MEMORY * 1024;
memory_allocated += static_cast<uint64_t>(RANDOMX_ARGON_MEMORY * 1024);
}
uv_rwlock_init_checked(&m_datasetLock);
@@ -456,7 +456,7 @@ bool RandomX_Hasher_RPC::calculate(const void* data_ptr, size_t size, uint64_t h
s << "{\"jsonrpc\":\"2.0\",\"id\":\"0\",\"method\":\"calc_pow\",\"params\":{\"major_version\":" << major_version <<
",\"height\":" << height <<
",\"block_blob\":\"" << log::hex_buf(data, size) << '"' <<
",\"seed_hash\":\"\"}}\0";
",\"seed_hash\":\"\"}}" << '\0';
std::atomic<int> result{ 0 };
std::atomic<bool> done{ false };
+7 -9
View File
@@ -161,7 +161,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
rx_vec_i128* scratchpad_ptr = scratchpad;
rx_vec_i128* cache_ptr = scratchpad_end;
for (uint64_t i = scratchpad_size, n = RANDOMX_ARGON_MEMORY * 1024 / sizeof(rx_vec_i128); i < n; ++i) {
for (uint64_t i = scratchpad_size, n = static_cast<uint64_t>(RANDOMX_ARGON_MEMORY * 1024) / sizeof(rx_vec_i128); i < n; ++i) {
*scratchpad_ptr = rx_xor_vec_i128(*scratchpad_ptr, *cache_ptr);
++cache_ptr;
++scratchpad_ptr;
@@ -523,7 +523,7 @@ void SideChain::cleanup_incoming_blocks()
// Forget seen blocks that were added more than 10 minutes ago
for (auto i = m_incomingBlocks.begin(); i != m_incomingBlocks.end();) {
if (cur_time < i->second + 10 * 60) {
if (cur_time < i->second + 10ul * 60ul) {
++i;
}
else {
@@ -1165,9 +1165,9 @@ uint64_t SideChain::miner_count()
MutexLock lock(m_seenWalletsLock);
// Every 5 minutes, delete wallets that weren't seen for more than 72 hours
if (m_seenWalletsLastPruneTime + 5 * 60 <= cur_time) {
if (m_seenWalletsLastPruneTime + 5ul * 60ul <= cur_time) {
for (auto it = m_seenWallets.begin(); it != m_seenWallets.end();) {
if (it->second + 72 * 60 * 60 < cur_time) {
if (it->second + 72ul * 60ul * 60ul < cur_time) {
it = m_seenWallets.erase(it);
}
else {
@@ -1314,10 +1314,10 @@ bool SideChain::get_difficulty(const PoolBlock* tip, std::vector<DifficultyData>
const uint64_t index1 = cut_size - 1;
const uint64_t index2 = difficultyData.size() - cut_size;
std::nth_element(tmpTimestamps.begin(), tmpTimestamps.begin() + index1, tmpTimestamps.end());
std::nth_element(tmpTimestamps.begin(), tmpTimestamps.begin() + static_cast<int32_t>(index1), tmpTimestamps.end());
const uint64_t timestamp1 = oldest_timestamp + tmpTimestamps[index1];
std::nth_element(tmpTimestamps.begin(), tmpTimestamps.begin() + index2, tmpTimestamps.end());
std::nth_element(tmpTimestamps.begin(), tmpTimestamps.begin() + static_cast<int32_t>(index2), tmpTimestamps.end());
const uint64_t timestamp2 = oldest_timestamp + tmpTimestamps[index2];
// Make a reasonable assumption that each block has higher timestamp, so delta_t can't be less than delta_index
@@ -2047,10 +2047,8 @@ void SideChain::update_depths(PoolBlock* block)
LOGWARN(3, "Block " << block->m_sidechainId << ": m_sidechainHeight is inconsistent with child's m_sidechainHeight.");
return;
}
else {
update_depth(block, child->m_depth + 1);
}
}
if (std::find(child->m_uncles.begin(), child->m_uncles.end(), block->m_sidechainId) != child->m_uncles.end()) {
update_depth(block, child->m_depth + i);
@@ -2090,7 +2088,7 @@ void SideChain::update_depths(PoolBlock* block)
LOGWARN(3, "Block " << block->m_sidechainId << ": m_sidechainHeight is inconsistent with child's m_sidechainHeight.");
return;
}
else if (block->m_depth > 0) {
if (block->m_depth > 0) {
update_depth(child, block->m_depth - 1);
}
}
+7 -11
View File
@@ -362,7 +362,7 @@ bool StratumServer::on_submit(StratumClient* client, uint32_t id, const char* jo
for (int i = static_cast<int>(sizeof(uint32_t)) - 1; i >= 0; --i) {
uint32_t d[2];
if (!from_hex(nonce_str[i * 2], d[0]) || !from_hex(nonce_str[i * 2 + 1], d[1])) {
if (!from_hex(nonce_str[i * 2 + 0], d[0]) || !from_hex(nonce_str[i * 2 + 1], d[1])) {
LOGWARN(4, "client " << static_cast<char*>(client->m_addrString) << " invalid params ('nonce' is not a hex integer)");
return false;
}
@@ -373,7 +373,7 @@ bool StratumServer::on_submit(StratumClient* client, uint32_t id, const char* jo
for (size_t i = 0; i < HASH_SIZE; ++i) {
uint32_t d[2];
if (!from_hex(result_str[i * 2], d[0]) || !from_hex(result_str[i * 2 + 1], d[1])) {
if (!from_hex(result_str[i * 2 + 0], d[0]) || !from_hex(result_str[i * 2 + 1], d[1])) {
LOGWARN(4, "client " << static_cast<char*>(client->m_addrString) << " invalid params ('result' is not a hex value)");
return false;
}
@@ -684,8 +684,6 @@ void StratumServer::print_stratum_status() const
}
// Compresses 64-bit hashes value into 16-bit value (5 bits for shift, 11 bits for data)
namespace {
enum HashValue : uint64_t {
bits = 11,
mask = (1 << bits) - 1,
@@ -714,8 +712,6 @@ static FORCEINLINE uint16_t hash_compress(uint64_t h)
return static_cast<uint16_t>((shift << HashValue::bits) | (h >> shift));
}
}
void StratumServer::update_auto_diff(StratumClient* client, const uint64_t timestamp, const uint64_t hashes)
{
const uint16_t hashes_compressed = hash_compress(hashes);
@@ -928,15 +924,15 @@ void StratumServer::update_hashrate_data(uint64_t hashes, uint64_t timestamp)
data[m_hashrateDataHead] = { timestamp, m_cumulativeHashes };
}
while (data[m_hashrateDataTail_15m].m_timestamp + 15 * 60 < timestamp) {
while (data[m_hashrateDataTail_15m].m_timestamp + 15ul * 60ul < timestamp) {
m_hashrateDataTail_15m = (m_hashrateDataTail_15m + 1) % N;
}
while (data[m_hashrateDataTail_1h].m_timestamp + 60 * 60 < timestamp) {
while (data[m_hashrateDataTail_1h].m_timestamp + 60ul * 60ul < timestamp) {
m_hashrateDataTail_1h = (m_hashrateDataTail_1h + 1) % N;
}
while (data[m_hashrateDataTail_24h].m_timestamp + 60 * 60 * 24 < timestamp) {
while (data[m_hashrateDataTail_24h].m_timestamp + 60ul * 60ul * 24ul < timestamp) {
m_hashrateDataTail_24h = (m_hashrateDataTail_24h + 1) % N;
}
}
@@ -1348,11 +1344,11 @@ bool StratumServer::StratumClient::process_request(char* data, uint32_t size)
LOGINFO(6, "incoming login from " << log::Gray() << static_cast<char*>(m_addrString));
return process_login(doc, id.GetUint());
}
else if (strcmp(s, "submit") == 0) {
if (strcmp(s, "submit") == 0) {
LOGINFO(6, "incoming share from " << log::Gray() << static_cast<char*>(m_addrString));
return process_submit(doc, id.GetUint());
}
else if (strcmp(s, "keepalived") == 0) {
if (strcmp(s, "keepalived") == 0) {
LOGINFO(6, "incoming keepalive from " << log::Gray() << static_cast<char*>(m_addrString));
return true;
}
+5 -6
View File
@@ -97,7 +97,7 @@ TCPServer::~TCPServer()
delete m_connectedClientsList;
}
void TCPServer::parse_address_list_internal(const std::string& address_list, Callback<void, bool, const std::string&, const std::string&, int>::Base&& callback)
void TCPServer::parse_address_list_internal(const std::string& address_list, const Callback<void, bool, const std::string&, const std::string&, int>::Base& callback)
{
if (address_list.empty()) {
return;
@@ -128,7 +128,7 @@ void TCPServer::parse_address_list_internal(const std::string& address_list, Cal
const uint32_t port = std::stoul(address.substr(k2 + 1), nullptr, 10);
if ((port > 0) && (port < 65536)) {
callback(is_v6, address, ip, port);
callback(is_v6, address, ip, static_cast<int>(port));
}
else {
error_invalid_ip(address);
@@ -420,10 +420,8 @@ bool TCPServer::connect_to_peer(Client* client)
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), on_connection_error);
return false;
}
else {
LOGINFO(5, "connecting to " << log::Gray() << static_cast<const char*>(client->m_addrString));
}
LOGINFO(5, "connecting to " << log::Gray() << static_cast<const char*>(client->m_addrString));
return true;
}
@@ -538,7 +536,7 @@ void TCPServer::print_bans()
}
}
bool TCPServer::send_internal(Client* client, Callback<size_t, uint8_t*, size_t>::Base&& callback, bool raw)
bool TCPServer::send_internal(Client* client, const Callback<size_t, uint8_t*, size_t>::Base& callback, bool raw)
{
check_event_loop_thread(__func__);
@@ -627,6 +625,7 @@ void TCPServer::loop(void* data)
if (n < sizeof(buf)) {
// Set the thread name as is
memcpy(buf, log_category_prefix, n);
buf[n] = '\0';
}
else {
// Thread name is too long, use the "first 7 characters - last 7 characters" format
+2 -2
View File
@@ -152,7 +152,7 @@ private:
void on_new_client(uv_stream_t* server);
void on_new_client(uv_stream_t* server, Client* client);
[[nodiscard]] bool send_internal(Client* client, Callback<size_t, uint8_t*, size_t>::Base&& callback, bool raw);
[[nodiscard]] bool send_internal(Client* client, const Callback<size_t, uint8_t*, size_t>::Base& callback, bool raw);
allocate_client_callback m_allocateNewClient;
@@ -173,7 +173,7 @@ protected:
static void loop(void* data);
static void parse_address_list_internal(const std::string& address_list, Callback<void, bool, const std::string&, const std::string&, int>::Base&& callback);
static void parse_address_list_internal(const std::string& address_list, const Callback<void, bool, const std::string&, const std::string&, int>::Base& callback);
void start_listening(const std::string& listen_addresses, bool upnp);
bool start_listening(bool is_v6, const std::string& ip, int port, std::string address = std::string());
+4 -3
View File
@@ -225,7 +225,7 @@ bool ServerTls::init()
return true;
}
bool ServerTls::on_read_internal(const char* data, uint32_t size, ReadCallback::Base&& read_callback, WriteCallback::Base&& write_callback)
bool ServerTls::on_read_internal(const char* data, uint32_t size, const ReadCallback::Base& read_callback, const WriteCallback::Base& write_callback)
{
SSL* ssl = m_ssl.get();
if (!ssl) {
@@ -270,7 +270,8 @@ bool ServerTls::on_read_internal(const char* data, uint32_t size, ReadCallback::
// Continue handshake, nothing to read yet
return true;
}
else if (result == 1) {
if (result == 1) {
// Handshake finished, skip to "SSL_read" further down
}
else {
@@ -291,7 +292,7 @@ bool ServerTls::on_read_internal(const char* data, uint32_t size, ReadCallback::
return true;
}
bool ServerTls::on_write_internal(const uint8_t* data, size_t size, WriteCallback::Base&& write_callback)
bool ServerTls::on_write_internal(const uint8_t* data, size_t size, const WriteCallback::Base& write_callback)
{
SSL* ssl = m_ssl.get();
if (!ssl) {
+2 -2
View File
@@ -61,8 +61,8 @@ private:
typedef Callback<bool, char*, uint32_t> ReadCallback;
typedef Callback<bool, const uint8_t*, size_t> WriteCallback;
[[nodiscard]] bool on_read_internal(const char* data, uint32_t size, ReadCallback::Base&& read_callback, WriteCallback::Base&& write_callback);
[[nodiscard]] bool on_write_internal(const uint8_t* data, size_t size, WriteCallback::Base&& write_callback);
[[nodiscard]] bool on_read_internal(const char* data, uint32_t size, const ReadCallback::Base& read_callback, const WriteCallback::Base& write_callback);
[[nodiscard]] bool on_write_internal(const uint8_t* data, size_t size, const WriteCallback::Base& write_callback);
private:
bssl::UniquePtr<SSL> m_ssl;
+2 -3
View File
@@ -569,7 +569,7 @@ bool resolve_host(std::string& host, bool& is_v6)
return true;
}
bool get_dns_txt_records_base(const std::string& host, Callback<void, const char*, size_t>::Base&& callback)
bool get_dns_txt_records_base(const std::string& host, const Callback<void, const char*, size_t>::Base& callback)
{
if (disable_resolve_host) {
LOGERR(1, "get_dns_txt_records was called with DNS disabled for host " << host);
@@ -849,11 +849,10 @@ int add_portmapping(int external_port, int internal_port)
LOGWARN(1, "UPNP_DeletePortMapping returned error " << result);
return 0;
}
else {
LOGINFO(1, "UPnP: Deleted mapping for external port " << external_port);
result = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, eport, iport, local_addr, "P2Pool", "TCP", nullptr, nullptr);
}
}
if (result) {
LOGWARN(1, "UPNP_AddPortMapping returned error " << result);
+3 -3
View File
@@ -357,14 +357,14 @@ struct Callback
struct Base
{
virtual ~Base() {}
virtual R operator()(Args...) = 0;
virtual R operator()(Args...) const = 0;
};
template<typename T>
struct Derived : public Base
{
explicit FORCEINLINE Derived(T&& cb) : m_cb(std::move(cb)) {}
R operator()(Args... args) override { return m_cb(args...); }
R operator()(Args... args) const override { return m_cb(args...); }
private:
Derived& operator=(Derived&&) = delete;
@@ -372,7 +372,7 @@ struct Callback
};
};
bool get_dns_txt_records_base(const std::string& host, Callback<void, const char*, size_t>::Base&& callback);
bool get_dns_txt_records_base(const std::string& host, const Callback<void, const char*, size_t>::Base& callback);
template<typename T>
FORCEINLINE bool get_dns_txt_records(const std::string& host, T&& callback) { return get_dns_txt_records_base(host, Callback<void, const char*, size_t>::Derived<T>(std::move(callback))); }
+6 -6
View File
@@ -61,8 +61,8 @@ struct ReverseAlphabet
result.num_symbols = 0;
for (size_t i = 0; i < alphabet_size; ++i) {
if (result.data[static_cast<int>(alphabet[i])] < 0) {
result.data[static_cast<int>(alphabet[i])] = static_cast<int8_t>(i);
if (result.data[static_cast<uint8_t>(alphabet[i])] < 0) {
result.data[static_cast<uint8_t>(alphabet[i])] = static_cast<int8_t>(i);
++result.num_symbols;
}
}
@@ -75,7 +75,7 @@ constexpr ReverseAlphabet rev_alphabet = ReverseAlphabet::init();
static_assert(rev_alphabet.num_symbols == 58, "Check alphabet");
}
} // namespace
namespace p2pool {
@@ -125,7 +125,7 @@ bool Wallet::decode(const char* address)
uint64_t order = 1;
for (int j = ((i < num_full_blocks) ? block_sizes.back() : last_block_size) - 1; j >= 0; --j) {
const int digit = rev_alphabet.data[static_cast<int>(address[j])];
const int8_t digit = rev_alphabet.data[static_cast<uint8_t>(address[j])];
if (digit < 0) {
return false;
}
@@ -142,7 +142,7 @@ bool Wallet::decode(const char* address)
address += block_sizes.back();
for (int j = ((i < num_full_blocks) ? sizeof(num) : last_block_size_index) - 1; j >= 0; --j) {
for (int j = static_cast<int>((i < num_full_blocks) ? sizeof(num) : last_block_size_index) - 1; j >= 0; --j) {
data[data_index++] = static_cast<uint8_t>(num >> (j * 8));
}
}
@@ -231,7 +231,7 @@ void Wallet::encode(char (&buf)[ADDRESS_LENGTH]) const
n = (n << 8) | data[i * sizeof(uint64_t) + j];
}
for (int j = ((i < num_full_blocks) ? block_sizes.back() : last_block_size) - 1; j >= 0; --j) {
const int digit = n % alphabet_size;
const int digit = static_cast<int>(n % alphabet_size);
n /= alphabet_size;
buf[i * block_sizes.back() + j] = alphabet[digit];
}
+3 -3
View File
@@ -347,7 +347,7 @@ static std::vector<uint8_t> construct_monero_block_blob(rapidjson::Value* value,
writeVarint(arr.Size(), blob);
for (auto i = arr.begin(); i != arr.end(); ++i) {
for (auto* i = arr.begin(); i != arr.end(); ++i) {
auto amount = i->FindMember("amount");
if ((amount == i->MemberEnd()) || !amount->value.IsUint64()) {
LOGWARN(3, "construct_monero_block_blob: amount not found or is not UInt64");
@@ -409,7 +409,7 @@ static std::vector<uint8_t> construct_monero_block_blob(rapidjson::Value* value,
writeVarint(arr2.Size(), blob);
out_transaction_hashes.reserve(arr2.Size());
for (auto i = arr2.begin(); i != arr2.end(); ++i) {
for (auto* i = arr2.begin(); i != arr2.end(); ++i) {
if (!i->IsString()) {
LOGWARN(3, "construct_monero_block_blob: tx_hash is not a string");
return empty_blob;
@@ -528,7 +528,7 @@ void ZMQReader::parse(char* data, size_t size)
std::vector<std::vector<uint8_t>> blobs;
blobs.reserve(arr.Size());
for (auto i = arr.begin(); i != arr.end(); ++i) {
for (auto* i = arr.begin(); i != arr.end(); ++i) {
std::vector<hash> tx_hashes;
blobs.emplace_back(construct_monero_block_blob(i, tx_hashes));
+1 -1
View File
@@ -141,7 +141,7 @@ TEST(block_template, update)
tx.weight = 1500;
transactions.push_back(tx);
}
mempool.swap(transactions);
mempool.swap_transactions(transactions);
ASSERT_EQ(mempool.size(), 10);
data.aux_chains.emplace_back(H("01f0cf665bd4cd31cbb2b2470236389c483522b350335e10a4a5dca34cb85990"), H("d9de1cfba7cdbd47f12f77addcb39b24c1ae7a16c35372bf28d6aee5d7579ee6"), difficulty_type(1000000));