aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-03-25 19:00:08 +0200
committerRiccardo Spagni <ric@spagni.net>2016-03-25 19:00:08 +0200
commit1559c71ef221f09e345618442dd5dafb46b0c975 (patch)
tree22d11e34d61de9c4eb8157188f9ec0ebc31aa245
parentMerge pull request #762 (diff)
parentblockchain: for v3, require miner tx to have well behaved outs (diff)
downloadmonero-1559c71ef221f09e345618442dd5dafb46b0c975.tar.xz
Merge pull request #763
b852766 blockchain: for v3, require miner tx to have well behaved outs (moneromooo-monero) 97638b1 core: fix miner tx block reward with fees (moneromooo-monero)
-rw-r--r--src/cryptonote_core/blockchain.cpp13
-rw-r--r--src/cryptonote_core/blockchain.h3
-rw-r--r--src/cryptonote_core/cryptonote_format_utils.cpp15
3 files changed, 20 insertions, 11 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 2f42e1db5..0f6afe740 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -948,7 +948,7 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height)
}
//------------------------------------------------------------------
// This function validates the miner transaction reward
-bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, bool &partial_block_reward)
+bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, bool &partial_block_reward, uint8_t version)
{
LOG_PRINT_L3("Blockchain::" << __func__);
//validate reward
@@ -957,6 +957,15 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
money_in_use += o.amount;
partial_block_reward = false;
+ if (version >= 3) {
+ for (auto &o: b.miner_tx.vout) {
+ if (!is_valid_decomposed_amount(o.amount)) {
+ LOG_PRINT_L1("miner tx output " << print_money(o.amount) << " is not a valid decomposed amount");
+ return false;
+ }
+ }
+ }
+
std::vector<size_t> last_blocks_sizes;
get_last_n_blocks_sizes(last_blocks_sizes, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (!get_block_reward(epee::misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward, get_current_hard_fork_version()))
@@ -2698,7 +2707,7 @@ leave:
TIME_MEASURE_START(vmt);
uint64_t base_reward = 0;
uint64_t already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
- if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins, bvc.m_partial_block_reward))
+ if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins, bvc.m_partial_block_reward, m_hardfork->get_current_version()))
{
LOG_PRINT_L1("Block with id: " << id << " has incorrect miner transaction");
bvc.m_verifivation_failed = true;
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 94def1aa9..393faef2a 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -980,10 +980,11 @@ namespace cryptonote
* @param base_reward return-by-reference the new block's generated coins
* @param already_generated_coins the amount of currency generated prior to this block
* @param partial_block_reward return-by-reference true if miner accepted only partial reward
+ * @param version hard fork version for that transaction
*
* @return false if anything is found wrong with the miner transaction, otherwise true
*/
- bool validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, bool &partial_block_reward);
+ bool validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, bool &partial_block_reward, uint8_t version);
/**
* @brief reverts the blockchain to its previous state following a failed switch
diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp
index 253e568b5..3c1acd8a9 100644
--- a/src/cryptonote_core/cryptonote_format_utils.cpp
+++ b/src/cryptonote_core/cryptonote_format_utils.cpp
@@ -126,20 +126,19 @@ namespace cryptonote
return false;
}
- // from hard fork 2, we cut out the low significant digits. This makes the tx smaller, and
- // keeps the paid amount almost the same. The unpaid remainder gets pushed back to the
- // emission schedule
- if (hard_fork_version >= 2)
- {
- block_reward = block_reward - block_reward % ::config::BASE_REWARD_CLAMP_THRESHOLD;
- }
-
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
LOG_PRINT_L1("Creating block template: reward " << block_reward <<
", fee " << fee)
#endif
block_reward += fee;
+ // from hard fork 2, we cut out the low significant digits. This makes the tx smaller, and
+ // keeps the paid amount almost the same. The unpaid remainder gets pushed back to the
+ // emission schedule
+ if (hard_fork_version >= 2) {
+ block_reward = block_reward - block_reward % ::config::BASE_REWARD_CLAMP_THRESHOLD;
+ }
+
std::vector<uint64_t> out_amounts;
decompose_amount_into_digits(block_reward, hard_fork_version >= 2 ? 0 : ::config::DEFAULT_DUST_THRESHOLD,
[&out_amounts](uint64_t a_chunk) { out_amounts.push_back(a_chunk); },