Fix crash at start with loglevel 5 and clean up debug logging

This commit is contained in:
Matt Hess
2026-02-19 17:26:21 +00:00
parent 6efab82426
commit 867047f897
2 changed files with 3 additions and 105 deletions
+1 -103
View File
@@ -399,11 +399,6 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
return;
}
// DEBUG: Show share/reward assignment
for (size_t i = 0; i < m_shares.size(); ++i) {
LOGINFO(5, "BlockTemplate share[" << i << "]: spend_key=" << m_shares[i].m_wallet->spend_public_key() << " weight=" << m_shares[i].m_weight << " reward=" << m_rewards[i]);
}
auto get_reward_amounts_weight = [this]() {
return std::accumulate(m_rewards.begin(), m_rewards.end(), 0ULL,
[](uint64_t a, uint64_t b)
@@ -641,18 +636,6 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
m_minerTxSize = m_minerTx.size();
m_blockTemplateBlob.insert(m_blockTemplateBlob.end(), m_minerTx.begin(), m_minerTx.end());
// DEBUG: Show ALL of m_minerTx
LOGINFO(6, "DEBUG: FULL m_minerTx (" << m_minerTx.size() << " bytes):");
std::string full_tx_hex;
full_tx_hex.reserve(m_minerTx.size() * 2);
for (size_t i = 0; i < m_minerTx.size(); ++i) {
char buf[3];
snprintf(buf, sizeof(buf), "%02x", m_minerTx[i]);
full_tx_hex.append(buf);
}
LOGINFO(6, full_tx_hex);
LOGINFO(6, "DEBUG: major_version = " << data.major_version << ", checking if >= 10");
// Protocol tx for Salvium Carrot v1+
// First, calculate and store the miner TX hash
@@ -672,8 +655,6 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
m_transactionHashes.reserve(HASH_SIZE * 2 + mempool_txs.size());
m_transactionHashes.insert(m_transactionHashes.end(), miner_tx_hash.h, miner_tx_hash.h + HASH_SIZE);
LOGINFO(5, "Stored miner TX hash at position 0: " << miner_tx_hash);
// Write protocol tx to blob (for sidechain consensus)
m_protocolTxOffsetInTemplate = m_blockTemplateBlob.size();
if (m_poolBlockTemplate->m_sidechainHeight >= SIDECHAIN_PROTOCOL_TX_HARDFORK_HEIGHT && data.protocol_tx_loaded && !data.protocol_tx_blob.empty()) {
@@ -805,7 +786,6 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
m_fullDataBlob = m_blockTemplateBlob;
m_fullDataBlob.insert(m_fullDataBlob.end(), sidechain_data.begin(), sidechain_data.end());
LOGINFO(6, "blob size = " << m_fullDataBlob.size());
m_poolBlockTemplate->m_sidechainId = calc_sidechain_hash(0);
{
@@ -815,9 +795,6 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
}
if (pool_block_debug()) {
LOGINFO(5, "DEBUG: pool_block_debug() is TRUE - executing debug block");
const size_t merkle_root_offset = m_extraNonceOffsetInTemplate + m_poolBlockTemplate->m_extraNonceSize + 2 + m_poolBlockTemplate->m_merkleTreeDataSize;
memcpy(m_blockTemplateBlob.data() + merkle_root_offset, m_poolBlockTemplate->m_merkleRoot.h, HASH_SIZE);
@@ -873,17 +850,6 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, const
calc_merkle_tree_main_branch();
// DEBUG: Log block template structure
LOGINFO(5, "DEBUG P2POOL TEMPLATE (" << m_blockTemplateBlob.size() << " bytes)");
std::string hex;
hex.reserve(400);
for (size_t i = 0; i < std::min<size_t>(200, m_blockTemplateBlob.size()); ++i) {
char buf[3];
snprintf(buf, 3, "%02x", m_blockTemplateBlob[i]);
hex += buf;
}
LOGINFO(5, "P2POOL FIRST 200 BYTES: " << hex);
LOGINFO(3, "final reward = " << log::Gray() << log::SALAmount(final_reward) << log::NoColor() <<
", weight = " << log::Gray() << final_weight << log::NoColor() <<
", outputs = " << log::Gray() << m_poolBlockTemplate->m_outputAmounts.size() << log::NoColor() <<
@@ -1034,7 +1000,6 @@ void BlockTemplate::select_mempool_transactions(const Mempool& mempool)
}
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) {
m_mempoolTxs.clear();
@@ -1248,7 +1213,6 @@ int BlockTemplate::create_miner_tx(const MinerData& data, const std::vector<Mine
}
// TX_EXTRA - per-output D_e for Janus protection
LOGINFO(5, "DEBUG: Carrot extra - major_version=" << data.major_version << ", dry_run=" << static_cast<int>(dry_run) << ", num_outputs=" << num_outputs);
m_minerTxExtra.clear();
m_poolBlockTemplate->m_additionalPubKeys.clear();
@@ -1387,14 +1351,6 @@ hash BlockTemplate::calc_miner_tx_hash(uint32_t extra_nonce) const
const uint8_t* data = m_blockTemplateBlob.data() + m_minerTxOffsetInTemplate;
const size_t prefix_size = m_minerTxPrefixSize;
const size_t base_rct_size = m_minerTxSize - prefix_size;
LOGINFO(5, "DEBUG: minerTxOffsetInTemplate=" << m_minerTxOffsetInTemplate << ", m_minerTxSize=" << m_minerTxSize);
LOGINFO(5, "DEBUG: First 20 bytes of miner tx in template:");
char hex_buf[128] = {0};
for (size_t i = 0; i < 20 && i < m_minerTxSize; ++i) {
snprintf(hex_buf + i*2, 3, "%02x", data[i]);
}
LOGINFO(5, static_cast<const char*>(hex_buf));
// Pre-Carrot: original logic with patching
const size_t extra_nonce_offset = m_extraNonceOffsetInTemplate - m_minerTxOffsetInTemplate;
@@ -1422,25 +1378,6 @@ hash BlockTemplate::calc_miner_tx_hash(uint32_t extra_nonce) const
const size_t N = m_minerTxKeccakStateInputLength;
const bool b = N && (N <= extra_nonce_offset) && (N < prefix_size) && (prefix_size - N <= sizeof(tx_buf));
LOGINFO(6, "DEBUG: extra_nonce=" << extra_nonce << ", extra_nonce_offset=" << extra_nonce_offset << ", merkle_root_offset=" << merkle_root_offset);
// DEBUG: Log what we're actually hashing
std::vector<uint8_t> debug_prefix(prefix_size);
for (size_t i = 0; i < prefix_size; ++i) {
uint32_t k = static_cast<uint32_t>(i - extra_nonce_offset);
if (k < EXTRA_NONCE_SIZE) {
debug_prefix[i] = extra_nonce_buf[k];
} else {
k = static_cast<uint32_t>(i - merkle_root_offset);
if (k < HASH_SIZE) {
debug_prefix[i] = merge_mining_root.h[k];
} else {
debug_prefix[i] = data[i];
}
}
}
LOGINFO(6, "DEBUG: Hashing prefix (" << prefix_size << " bytes): " << log::hex_buf(debug_prefix.data(), std::min(size_t(120), prefix_size)));
// Slow path: O(N)
if (!b || pool_block_debug())
{
@@ -1490,24 +1427,6 @@ hash BlockTemplate::calc_miner_tx_hash(uint32_t extra_nonce) const
hash result;
keccak(hashes, sizeof(hashes), result.h);
// Debug: log the component hashes
char prefix_hash_hex[65] = {0};
char base_rct_hash_hex[65] = {0};
char prunable_hash_hex[65] = {0};
char final_hash_hex[65] = {0};
for (int i = 0; i < 32; ++i) {
snprintf(prefix_hash_hex + static_cast<size_t>(i) * 2, 3, "%02x", hashes[i]);
snprintf(base_rct_hash_hex + static_cast<size_t>(i) * 2, 3, "%02x", hashes[32 + i]);
snprintf(prunable_hash_hex + static_cast<size_t>(i) * 2, 3, "%02x", hashes[64 + i]);
snprintf(final_hash_hex + static_cast<size_t>(i) * 2, 3, "%02x", result.h[i]);
}
LOGINFO(5, "Miner TX hash components:");
LOGINFO(5, " Prefix hash: " << static_cast<const char*>(prefix_hash_hex));
LOGINFO(5, " Base RCT hash: " << static_cast<const char*>(base_rct_hash_hex));
LOGINFO(5, " Prunable hash: " << static_cast<const char*>(prunable_hash_hex));
LOGINFO(5, " Final TX hash: " << static_cast<const char*>(final_hash_hex));
LOGINFO(5, " Prefix size: " << prefix_size << ", Base RCT size: " << base_rct_size << ", Total TX size: " << m_minerTxSize);
return result;
}
@@ -1520,9 +1439,6 @@ void BlockTemplate::calc_merkle_tree_main_branch()
}
const uint8_t* h = m_transactionHashes.data();
if (count == 2) {
hash protocol_hash;
memcpy(protocol_hash.h, h + HASH_SIZE, HASH_SIZE);
LOGINFO(5, "Merkle branch protocol tx hash: " << protocol_hash);
m_merkleTreeMainBranch.insert(m_merkleTreeMainBranch.end(), h + HASH_SIZE, h + HASH_SIZE * 2);
}
else {
@@ -1558,18 +1474,6 @@ void BlockTemplate::calc_merkle_tree_main_branch()
m_merkleTreeMainBranch.insert(m_merkleTreeMainBranch.end(), ints.data() + HASH_SIZE, ints.data() + HASH_SIZE * 2);
}
// DEBUG: Log the calculated merkle root
if (m_majorVersion >= 10) {
hash merkle_root;
// The merkle root is the hash of (miner_hash + last_branch_element)
uint8_t buf[HASH_SIZE * 2];
memcpy(buf, m_transactionHashes.data(), HASH_SIZE);
if (!m_merkleTreeMainBranch.empty()) {
memcpy(buf + HASH_SIZE, m_merkleTreeMainBranch.data() + m_merkleTreeMainBranch.size() - HASH_SIZE, HASH_SIZE);
keccak(buf, sizeof(buf), merkle_root.h);
LOGINFO(6, "Calculated merkle root: " << merkle_root);
}
}
}
bool BlockTemplate::get_difficulties(const uint32_t template_id, uint64_t& height, uint64_t& sidechain_height, difficulty_type& mainchain_difficulty, difficulty_type& aux_diff, difficulty_type& sidechain_difficulty) const
@@ -1658,10 +1562,7 @@ uint32_t BlockTemplate::get_hashing_blob_nolock(uint32_t extra_nonce, uint8_t* b
}
root_hash merkle_root;
merkle_hash(hashes, merkle_root);
LOGINFO(6, " m_transactionHashes size: " << m_transactionHashes.size() << " num_hashes: " << num_hashes);
LOGINFO(6, " Result merkle root: " << static_cast<const hash&>(merkle_root));
memcpy(p, merkle_root.h, HASH_SIZE);
memcpy(p, merkle_root.h, HASH_SIZE);
p += HASH_SIZE;
// Total number of transactions in this block (including the miner tx)
@@ -1669,9 +1570,6 @@ uint32_t BlockTemplate::get_hashing_blob_nolock(uint32_t extra_nonce, uint8_t* b
const uint64_t tx_count_in_header = m_numTransactionHashes + (m_majorVersion >= 10 ? 2 : 1);
writeVarint(tx_count_in_header, [&p](uint8_t b) { *(p++) = b; });
// DEBUG: Show what hashing blob we're creating
LOGINFO(6, "DEBUG get_hashing_blob result (" << static_cast<uint32_t>(p - blob) << " bytes): " << log::hex_buf(blob, std::min(size_t(76), static_cast<size_t>(p - blob))));
return static_cast<uint32_t>(p - blob);
}
+2 -2
View File
@@ -407,10 +407,10 @@ int main(int argc, char* argv[])
// 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();
const p2pool::Params params = params_file.empty() ? get_params(argc, argv) : get_params(params_file);
printf("Reticulating splines...\n");
p2pool::init_crypto_cache();