From d25099a23a4214171a180c2f0baa25f02e453c0d Mon Sep 17 00:00:00 2001 From: _xxfedexx_ Date: Fri, 17 Feb 2023 22:03:49 +0100 Subject: [PATCH 1/2] P2Pool and Solo-Mining only --- src/cryptonote_basic/cryptonote_basic.h | 4 +- .../cryptonote_boost_serialization.h | 3 + src/cryptonote_basic/miner.cpp | 5 +- src/cryptonote_config.h | 4 + src/cryptonote_core/blockchain.cpp | 74 ++++++++++++------- src/rpc/core_rpc_server.cpp | 4 +- src/rpc/daemon_handler.cpp | 4 +- 7 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h index 215903a0c..bf91b7c43 100644 --- a/src/cryptonote_basic/cryptonote_basic.h +++ b/src/cryptonote_basic/cryptonote_basic.h @@ -473,7 +473,9 @@ namespace cryptonote if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { FIELD(signature) - FIELD(vote) + if (major_version < HF_VERSION_P2POOL) { + FIELD(vote) + } } END_SERIALIZE() }; diff --git a/src/cryptonote_basic/cryptonote_boost_serialization.h b/src/cryptonote_basic/cryptonote_boost_serialization.h index 6d2b7e55b..5d0150ee0 100644 --- a/src/cryptonote_basic/cryptonote_boost_serialization.h +++ b/src/cryptonote_basic/cryptonote_boost_serialization.h @@ -199,6 +199,9 @@ namespace boost if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { a & b.signature; + if (b.major_version < HF_VERSION_P2POOL) { + FIELD(vote) + } a & b.vote; } //------------------ diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index 74b787500..187df4b4a 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -627,7 +627,10 @@ namespace cryptonote crypto::generate_signature(sig_data, eph_pub_key, eph_secret_key, signature); // amend signature to block header before PoW hashing b.signature = signature; - b.vote = m_int_vote; + + if (b.major_version < HF_VERSION_P2POOL) { + b.vote = m_int_vote; + } } crypto::hash h; diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 821a36f65..4856f5628 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -198,6 +198,10 @@ #define HF_VERSION_VIEW_TAGS 20 #define HF_VERSION_2021_SCALING 20 #define HF_VERSION_BLOCK_HEADER_MINER_SIG 18 +#define HF_VERSION_P2POOL 20 + +#define MIN_MINER_OUTPUTS 5 +#define MIN_MINER_AMOUNT_FACTOR 500 #define PER_KB_FEE_QUANTIZATION_DECIMALS 8 #define CRYPTONOTE_SCALING_2021_FEE_ROUNDING_PLACES 2 diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index f4513b69f..18ec68bb2 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1414,34 +1414,42 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height, // Miner Block Header Signing if (hf_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { - // sanity checks - if (b.miner_tx.vout.size() != 1) + // block has been P2Pool mined, no signature required + if (hf_version >= HF_VERSION_P2POOL && b.miner_tx.vout.size() >= MIN_MINER_OUTPUTS) { - MWARNING("Only 1 output in miner transaction allowed"); - return false; - } - if (b.miner_tx.vout[0].target.type() != typeid(txout_to_key)) - { - MWARNING("Wrong txout type"); - return false; - } - if (b.vote > 2) - { - MWARNING("Vote integer must be either 0, 1, or 2"); - return false; - } - // keccak hash block header data and check miner signature - // if signature is invalid, reject block - crypto::hash sig_data = get_sig_data(b); - crypto::signature signature = b.signature; - crypto::public_key eph_pub_key = boost::get(b.miner_tx.vout[0].target).key; - if (!crypto::check_signature(sig_data, eph_pub_key, signature)) - { - MWARNING("Miner signature is invalid"); - return false; + LOG_PRINT_L1("Transaction meets MIN_MINER_OUTPUTS") } else { - LOG_PRINT_L1("Miner signature is good"); - LOG_PRINT_L1("Vote: " << b.vote); + // sanity checks + if (b.miner_tx.vout.size() != 1) + { + MWARNING("Only 1 output in miner transaction allowed"); + return false; + } + if (b.miner_tx.vout[0].target.type() != typeid(txout_to_key)) + { + MWARNING("Wrong txout type"); + return false; + } + if (hf_version < HF_VERSION_P2POOL && b.vote > 2) + { + MWARNING("Vote integer must be either 0, 1, or 2"); + return false; + } + // keccak hash block header data and check miner signature + // if signature is invalid, reject block + crypto::hash sig_data = get_sig_data(b); + crypto::signature signature = b.signature; + crypto::public_key eph_pub_key = boost::get(b.miner_tx.vout[0].target).key; + if (!crypto::check_signature(sig_data, eph_pub_key, signature)) + { + MWARNING("Miner signature is invalid"); + return false; + } else { + LOG_PRINT_L1("Miner signature is good"); + if (hf_version < HF_VERSION_P2POOL) { + LOG_PRINT_L1("Vote: " << b.vote); + } + } } } @@ -1546,6 +1554,20 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl partial_block_reward = true; base_reward = money_in_use - fee; } + + // check that each output has minimal amount of WOW + if (version >= HF_VERSION_P2POOL) { + uint64_t min_miner_amount = base_reward / MIN_MINER_AMOUNT_FACTOR; + for (auto &o: b.miner_tx.vout) + { + if (o.amount+1 < min_miner_amount) + { + MERROR_VER("Each output must have at least " << print_money(min_miner_amount) << " block reward"); + return false; + } + } + } + return true; } //------------------------------------------------------------------ diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 4d50839fe..aff13c9bd 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -2204,7 +2204,9 @@ namespace cryptonote if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { b.signature = {}; - b.vote = 0; + if (b.major_version < HF_VERSION_P2POOL) { + b.vote = 0; + } } crypto::hash seed_hash = crypto::null_hash; if (b.major_version >= RX_BLOCK_VERSION && !epee::string_tools::hex_to_pod(template_res.seed_hash, seed_hash)) diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp index 2acc66bd6..004cc844e 100644 --- a/src/rpc/daemon_handler.cpp +++ b/src/rpc/daemon_handler.cpp @@ -898,7 +898,9 @@ namespace rpc if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) { header.signature = b.signature; - header.vote = b.vote; + if (b.major_version < HF_VERSION_P2POOL) { + header.vote = b.vote; + } } header.prev_id = b.prev_id; From 7e4aa48f9058f3de0adba49a6527d3cafb04287c Mon Sep 17 00:00:00 2001 From: _xxfedexx_ Date: Fri, 17 Feb 2023 22:05:02 +0100 Subject: [PATCH 2/2] fix typo --- src/cryptonote_basic/cryptonote_boost_serialization.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cryptonote_basic/cryptonote_boost_serialization.h b/src/cryptonote_basic/cryptonote_boost_serialization.h index 5d0150ee0..d7b67599d 100644 --- a/src/cryptonote_basic/cryptonote_boost_serialization.h +++ b/src/cryptonote_basic/cryptonote_boost_serialization.h @@ -200,9 +200,8 @@ namespace boost { a & b.signature; if (b.major_version < HF_VERSION_P2POOL) { - FIELD(vote) + a & b.vote; } - a & b.vote; } //------------------ a & b.miner_tx;