From 5d6fa03f119ab205795d7e29478c30dcbea3f4fb Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 1 Sep 2021 10:43:10 +0200 Subject: [PATCH] Show all Monero block rewards in log --- .gitignore | 2 +- src/block_template.cpp | 10 +++++----- src/common.h | 3 ++- src/p2pool.cpp | 7 +++++-- src/zmq_reader.cpp | 33 ++++++++++++++++++++++++++------- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 9ef9604..ddeae70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ build - +logs diff --git a/src/block_template.cpp b/src/block_template.cpp index c21e65a..e6eb4d1 100644 --- a/src/block_template.cpp +++ b/src/block_template.cpp @@ -221,9 +221,9 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet const uint64_t max_reward = base_reward + total_tx_fees; - LOGINFO(3, "base reward = " << log::Gray() << base_reward << log::NoColor() << + LOGINFO(3, "base reward = " << log::Gray() << log::XMRAmount(base_reward) << log::NoColor() << ", mempool: " << log::Gray() << m_mempoolTxs.size() << log::NoColor() << - " transactions, fees = " << log::Gray() << total_tx_fees << log::NoColor() << + " transactions, fees = " << log::Gray() << log::XMRAmount(total_tx_fees) << log::NoColor() << ", weight = " << log::Gray() << total_tx_weight); m_blockHeader.clear(); @@ -384,11 +384,11 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet } #if TEST_MEMPOOL_PICKING_ALGORITHM - LOGINFO(3, "final_reward = " << final_reward << ", transactions = " << m_numTransactionHashes << ", final_weight = " << final_weight); + LOGINFO(3, "final_reward = " << log::XMRAmount(final_reward) << ", transactions = " << m_numTransactionHashes << ", final_weight = " << final_weight); uint64_t final_reward2; fill_optimal_knapsack(data, base_reward, miner_tx_weight, final_reward2, final_fees, final_weight); - LOGINFO(3, "best_reward = " << final_reward2 << ", transactions = " << m_numTransactionHashes << ", final_weight = " << final_weight); + LOGINFO(3, "best_reward = " << log::XMRAmount(final_reward2) << ", transactions = " << m_numTransactionHashes << ", final_weight = " << final_weight); if (final_reward2 < final_reward) { LOGERR(1, "fill_optimal_knapsack has a bug, found solution is not optimal. Fix it!"); } @@ -487,7 +487,7 @@ void BlockTemplate::update(const MinerData& data, const Mempool& mempool, Wallet calc_merkle_tree_main_branch(); - LOGINFO(3, "final reward = " << log::Gray() << final_reward << log::NoColor() << + LOGINFO(3, "final reward = " << log::Gray() << log::XMRAmount(final_reward) << log::NoColor() << ", weight = " << log::Gray() << final_weight << log::NoColor() << ", outputs = " << log::Gray() << m_poolBlockTemplate->m_outputs.size() << log::NoColor() << ", " << log::Gray() << m_numTransactionHashes << log::NoColor() << diff --git a/src/common.h b/src/common.h index b5fd167..91cddfc 100644 --- a/src/common.h +++ b/src/common.h @@ -254,10 +254,11 @@ struct MinerData struct ChainMain { - FORCEINLINE ChainMain() : height(0), timestamp(0), id() {} + FORCEINLINE ChainMain() : height(0), timestamp(0), reward(0), id() {} uint64_t height; uint64_t timestamp; + uint64_t reward; hash id; }; diff --git a/src/p2pool.cpp b/src/p2pool.cpp index f4a2369..2fcff19 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -178,8 +178,9 @@ void p2pool::handle_miner_data(MinerData& data) c.height = data.height - 1; c.id = data.prev_id; - // timestamp is unknown here + // timestamp and reward is unknown here c.timestamp = 0; + c.reward = 0; m_mainchainByHash[c.id] = c; } @@ -230,6 +231,7 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra) ChainMain& c = m_mainchainByHeight[data.height]; c.height = data.height; c.timestamp = data.timestamp; + c.reward = data.reward; // data.id not filled in here, but c.id should be available. Copy it to data.id for logging data.id = c.id; @@ -256,7 +258,8 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra) LOGINFO(2, "new main chain block: height = " << log::Gray() << data.height << log::NoColor() << ", id = " << log::LightBlue() << data.id << log::NoColor() << - ", timestamp = " << log::Gray() << data.timestamp); + ", timestamp = " << log::Gray() << data.timestamp << log::NoColor() << + ", reward = " << log::Gray() << log::XMRAmount(data.reward)); if (!sidechain_id.empty() && side_chain().has_block(sidechain_id)) { LOGINFO(0, log::LightGreen() << "BLOCK FOUND: main chain block at height " << data.height << " was mined by this p2pool" << BLOCK_FOUND); diff --git a/src/zmq_reader.cpp b/src/zmq_reader.cpp index 12452da..7a90496 100644 --- a/src/zmq_reader.cpp +++ b/src/zmq_reader.cpp @@ -219,42 +219,61 @@ void ZMQReader::parse(char* data, size_t size) auto arr = doc.GetArray(); for (Value* i = arr.begin(); i != arr.end(); ++i) { if (!PARSE(*i, m_chainmainData, timestamp)) { - LOGWARN(1, "json-full-chain_main array element failed to parse, skipping it"); + LOGWARN(1, "json-full-chain_main timestamp failed to parse, skipping it"); continue; } auto it = i->FindMember("miner_tx"); if ((it == i->MemberEnd()) || !it->value.IsObject()) { - LOGWARN(1, "json-full-chain_main array element failed to parse, skipping it"); + LOGWARN(1, "json-full-chain_main miner_tx not found, skipping it"); continue; } auto extra_it = it->value.FindMember("extra"); if ((extra_it == it->value.MemberEnd()) || !extra_it->value.IsString()) { - LOGWARN(1, "json-full-chain_main array element failed to parse, skipping it"); + LOGWARN(1, "json-full-chain_main extra not found, skipping it"); continue; } auto inputs_it = it->value.FindMember("inputs"); if ((inputs_it == it->value.MemberEnd()) || !inputs_it->value.IsArray()) { - LOGWARN(1, "json-full-chain_main array element failed to parse, skipping it"); + LOGWARN(1, "json-full-chain_main inputs not found, skipping it"); continue; } + // Get block reward from miner_tx outputs + m_chainmainData.reward = 0; + + auto outputs_it = it->value.FindMember("outputs"); + if ((outputs_it != it->value.MemberEnd()) && outputs_it->value.IsArray()) { + auto outputs = outputs_it->value.GetArray(); + for (SizeType j = 0, n = outputs.Size(); j < n; ++j) { + if (outputs[j].IsObject()) { + auto amount_it = outputs[j].FindMember("amount"); + if (amount_it != outputs[j].MemberEnd() && amount_it->value.IsUint64()) { + m_chainmainData.reward += amount_it->value.GetUint64(); + } + } + } + } + else { + LOGWARN(4, "json-full-chain_main outputs not found"); + } + auto inputs = inputs_it->value.GetArray(); if ((inputs.Size() == 0) || !inputs[0].IsObject()) { - LOGWARN(1, "json-full-chain_main array element failed to parse, skipping it"); + LOGWARN(1, "json-full-chain_main inputs is not an array, skipping it"); continue; } it = inputs[0].FindMember("gen"); if ((it == inputs[0].MemberEnd()) || !it->value.IsObject()) { - LOGWARN(1, "json-full-chain_main array element failed to parse, skipping it"); + LOGWARN(1, "json-full-chain_main gen not found, skipping it"); continue; } if (!PARSE(it->value, m_chainmainData, height)) { - LOGWARN(1, "json-full-chain_main array element failed to parse, skipping it"); + LOGWARN(1, "json-full-chain_main height not found, skipping it"); continue; }