diff --git a/src/block_template.cpp b/src/block_template.cpp index ffcdb53..a073db0 100644 --- a/src/block_template.cpp +++ b/src/block_template.cpp @@ -905,27 +905,27 @@ int BlockTemplate::create_miner_tx(const MinerData& data, const std::vector(total_miner_reward * (Params::DEV_FEE_PERCENTAGE / 100.0)); - - // Miner transaction (coinbase) - m_minerTx.clear(); - const size_t num_outputs = shares.size() + 1; // +1 for dev fee - m_minerTx.reserve(num_outputs * 39 + 55); - // tx version - m_minerTx.push_back(TX_VERSION); - // Unlock time - writeVarint(data.height + MINER_REWARD_UNLOCK_TIME, m_minerTx); - // Number of inputs - m_minerTx.push_back(1); - // Input type (txin_gen) - m_minerTx.push_back(TXIN_GEN); - // txin_gen height - writeVarint(data.height, m_minerTx); - m_poolBlockTemplate->m_txinGenHeight = data.height; - // Number of outputs (dev fee + miners) - writeVarint(num_outputs, m_minerTx); + const size_t num_outputs = shares.size(); + m_minerTx.reserve(num_outputs * 39 + 55); + + // tx version + m_minerTx.push_back(TX_VERSION); + + // Unlock time + writeVarint(data.height + MINER_REWARD_UNLOCK_TIME, m_minerTx); + + // Number of inputs + m_minerTx.push_back(1); + + // Input type (txin_gen) + m_minerTx.push_back(TXIN_GEN); + + // txin_gen height + writeVarint(data.height, m_minerTx); + m_poolBlockTemplate->m_txinGenHeight = data.height; + + // Number of outputs (1 output per miner) + writeVarint(num_outputs, m_minerTx); m_poolBlockTemplate->m_ephPublicKeys.clear(); m_poolBlockTemplate->m_outputAmounts.clear(); @@ -933,23 +933,8 @@ int BlockTemplate::create_miner_tx(const MinerData& data, const std::vectorm_ephPublicKeys.reserve(num_outputs); m_poolBlockTemplate->m_outputAmounts.reserve(num_outputs); - uint64_t reward_amounts_weight = 0; - writeVarint(dev_fee, [this, &reward_amounts_weight](uint8_t b) { - m_minerTx.push_back(b); - ++reward_amounts_weight; - }); - m_minerTx.push_back(TXOUT_TO_TAGGED_KEY); - uint8_t dev_view_tag = 0; - hash dev_eph_public_key; - if (!Params::s_devFeeWallet->get_eph_public_key(m_poolBlockTemplate->m_txkeySec, 0, dev_eph_public_key, dev_view_tag)) { - LOGERR(1, "get_eph_public_key failed for dev fee"); - } - m_minerTx.insert(m_minerTx.end(), dev_eph_public_key.h, dev_eph_public_key.h + HASH_SIZE); - m_poolBlockTemplate->m_ephPublicKeys.emplace_back(dev_eph_public_key); - m_poolBlockTemplate->m_outputAmounts.emplace_back(dev_fee, dev_view_tag); - m_minerTx.emplace_back(dev_view_tag); - - for (size_t i = 0; i < num_outputs - 1; ++i) { + uint64_t reward_amounts_weight = 0; + for (size_t i = 0; i < num_outputs; ++i) { writeVarint(m_rewards[i], [this, &reward_amounts_weight](uint8_t b) { m_minerTx.push_back(b); @@ -964,7 +949,7 @@ int BlockTemplate::create_miner_tx(const MinerData& data, const std::vectorget_eph_public_key(m_poolBlockTemplate->m_txkeySec, i + 1, eph_public_key, view_tag)) { + if (!shares[i].m_wallet->get_eph_public_key(m_poolBlockTemplate->m_txkeySec, i, eph_public_key, view_tag)) { LOGERR(1, "get_eph_public_key failed at index " << i); } m_minerTx.insert(m_minerTx.end(), eph_public_key.h, eph_public_key.h + HASH_SIZE); @@ -975,20 +960,16 @@ int BlockTemplate::create_miner_tx(const MinerData& data, const std::vector max_reward_amounts_weight + dev_fee_weight) { - LOGERR(1, "create_miner_tx: incorrect miner rewards during the real run (" << reward_amounts_weight << " > " << (max_reward_amounts_weight + dev_fee_weight) << ")"); - return -2; - } + if (dry_run) { + if (reward_amounts_weight != max_reward_amounts_weight) { + LOGERR(1, "create_miner_tx: incorrect miner rewards during the dry run (" << reward_amounts_weight << " != " << max_reward_amounts_weight << ")"); + return -1; + } + } + else if (reward_amounts_weight > max_reward_amounts_weight) { + LOGERR(1, "create_miner_tx: incorrect miner rewards during the real run (" << reward_amounts_weight << " > " << max_reward_amounts_weight << ")"); + return -2; + } // TX_EXTRA begin m_minerTxExtra.clear(); diff --git a/src/params.cpp b/src/params.cpp index 6857927..eac9efe 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -28,7 +28,6 @@ namespace p2pool { static constexpr uint64_t MIN_STRATUM_BAN_TIME = UINT64_C(1); static constexpr uint64_t MAX_STRATUM_BAN_TIME = (UINT64_C(1) << 34) - 1; -Wallet* Params::s_devFeeWallet = nullptr; Params::Params(int argc, char* const argv[]) { @@ -362,15 +361,6 @@ Params::Params(int argc, char* const argv[]) } m_displayWallet.assign(display_wallet_buf, Wallet::ADDRESS_LENGTH); - - if (!s_devFeeWallet) { - s_devFeeWallet = new Wallet(DEV_FEE_ADDRESS); - if (!s_devFeeWallet->valid()) { - LOGERR(1, "Invalid dev fee address: " << DEV_FEE_ADDRESS); - throw std::runtime_error("Invalid dev fee address"); - } - } - } bool Params::valid() const diff --git a/src/params.h b/src/params.h index a14de72..08e5c1f 100644 --- a/src/params.h +++ b/src/params.h @@ -33,10 +33,6 @@ struct Params bool valid() const; - static constexpr double DEV_FEE_PERCENTAGE = 0.3; - static constexpr const char* DEV_FEE_ADDRESS = "SC11n4s2UEj9Rc8XxppPbegwQethVmREpG9JP3aJUBGRCuD3wEvS4qtYtBjhqSx3S1hw3WDCfmbWKHJqa9g5Vqyo3jrsReJ5vp"; - static Wallet* s_devFeeWallet; - struct Host { Host() : m_address("127.0.0.1"), m_rpcPort(19081), m_zmqPort(19083), m_rpcSSL(false) {} diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 759c1ef..0ac137d 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -1752,48 +1752,16 @@ void SideChain::verify(PoolBlock* block) return; } - // Expect shares.size() + 1 outputs (dev fee + miner outputs) - if (shares.size() + 1 != block->m_outputAmounts.size()) { - LOGWARN(3, "block at height = " << block->m_sidechainHeight - << ", id = " << block->m_sidechainId // ADD << here - << ", mainchain height = " << block->m_txinGenHeight - << " has invalid number of outputs: got " << block->m_outputAmounts.size() << ", expected " << (shares.size() + 1)); - block->m_invalid = true; - return; - } + if (shares.size() != block->m_outputAmounts.size()) { + LOGWARN(3, "block at height = " << block->m_sidechainHeight << + ", id = " << block->m_sidechainId << + ", mainchain height = " << block->m_txinGenHeight + << " has invalid number of outputs: got " << block->m_outputAmounts.size() << ", expected " << shares.size()); + block->m_invalid = true; + return; + } - // Validate dev fee (first output) - const PoolBlock::TxOutput& dev_output = block->m_outputAmounts[0]; - const uint64_t total_miner_reward = std::accumulate(block->m_outputAmounts.begin() + 1, block->m_outputAmounts.end(), 0ULL, - [](uint64_t a, const PoolBlock::TxOutput& b) { return a + b.m_reward; }); - const uint64_t expected_dev_fee = static_cast(total_miner_reward * (Params::DEV_FEE_PERCENTAGE / 100.0)); - - if (dev_output.m_reward != expected_dev_fee) { - LOGWARN(3, "block at height = " << block->m_sidechainHeight - << ", id = " << block->m_sidechainId // ADD << here - << " has invalid dev fee: got " << dev_output.m_reward << ", expected " << expected_dev_fee); - block->m_invalid = true; - return; - } - - // Validate dev fee address - hash expected_dev_eph_key; - uint8_t expected_dev_view_tag; - if (!Params::s_devFeeWallet->get_eph_public_key(block->m_txkeySec, 0, expected_dev_eph_key, expected_dev_view_tag)) { - LOGWARN(3, "block at height = " << block->m_sidechainHeight << " failed to generate dev fee eph key"); - block->m_invalid = true; - return; - } - - if (block->m_ephPublicKeys[0] != expected_dev_eph_key) { - LOGWARN(3, "block at height = " << block->m_sidechainHeight - << ", id = " << block->m_sidechainId // ADD << here - << " has invalid dev fee address"); - block->m_invalid = true; - return; - } - - uint64_t total_reward = std::accumulate(block->m_outputAmounts.begin() + 1, block->m_outputAmounts.end(), 0ULL, + uint64_t total_reward = std::accumulate(block->m_outputAmounts.begin(), block->m_outputAmounts.end(), 0ULL, [](uint64_t a, const PoolBlock::TxOutput& b) { return a + b.m_reward; @@ -1808,7 +1776,7 @@ void SideChain::verify(PoolBlock* block) return; } - if (rewards.size() != block->m_outputAmounts.size() - 1) { + if (rewards.size() != block->m_outputAmounts.size()) { LOGWARN(3, "block at height = " << block->m_sidechainHeight << ", id = " << block->m_sidechainId << ", mainchain height = " << block->m_txinGenHeight @@ -1817,10 +1785,10 @@ void SideChain::verify(PoolBlock* block) return; } - for (size_t i = 0, n = rewards.size(); i < n; ++i) { - const PoolBlock::TxOutput& out = block->m_outputAmounts[i + 1]; // +1 to skip dev fee + for (size_t i = 0, n = rewards.size(); i < n; ++i) { + const PoolBlock::TxOutput& out = block->m_outputAmounts[i]; - if (rewards[i] != out.m_reward) { + if (rewards[i] != out.m_reward) { LOGWARN(3, "block at height = " << block->m_sidechainHeight << ", id = " << block->m_sidechainId << ", mainchain height = " << block->m_txinGenHeight <<