diff options
author | thankful_for_today <my email> | 2014-04-20 00:53:40 +0400 |
---|---|---|
committer | thankful_for_today <my email> | 2014-04-20 00:53:40 +0400 |
commit | 0fd82c910b8e4cbf0b3940d6e42f2e992287582d (patch) | |
tree | ce65c67d26b006d305f00abb04486fddb3484eaf /src/cryptonote_core | |
parent | mistake in README fixed (diff) | |
download | monero-0fd82c910b8e4cbf0b3940d6e42f2e992287582d.tar.xz |
mining bug fixed
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/blockchain_storage.cpp | 4 | ||||
-rw-r--r-- | src/cryptonote_core/tx_pool.cpp | 57 |
2 files changed, 14 insertions, 47 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index cef988c40..c1b9619f2 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -572,7 +572,7 @@ bool blockchain_storage::create_block_template(block& b, const account_public_ad diffic = get_difficulty_for_next_block(); CHECK_AND_ASSERT_MES(diffic, false, "difficulty owverhead."); - median_size = m_current_block_cumul_sz_limit; + median_size = m_current_block_cumul_sz_limit / 2; already_generated_coins = m_blocks.back().already_generated_coins; CRITICAL_REGION_END(); @@ -1603,4 +1603,4 @@ bool blockchain_storage::add_new_block(const block& bl_, block_verification_cont } return handle_block_to_main_chain(bl, id, bvc); -}
\ No newline at end of file +} diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 6cd33a2d7..24e5752ad 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -348,60 +348,27 @@ namespace cryptonote return ss.str(); } //--------------------------------------------------------------------------------- - bool tx_memory_pool::fill_block_template(block &bl, size_t median_size, uint64_t already_generated_coins, size_t &total_size, uint64_t &fee) { - typedef transactions_container::value_type txv; + bool tx_memory_pool::fill_block_template(block &bl, size_t median_size, uint64_t already_generated_coins, size_t &total_size, uint64_t &fee) + { CRITICAL_REGION_LOCAL(m_transactions_lock); - std::vector<txv *> txs(m_transactions.size()); - std::transform(m_transactions.begin(), m_transactions.end(), txs.begin(), [](txv &a) -> txv * { return &a; }); - std::sort(txs.begin(), txs.end(), [](txv *a, txv *b) -> bool { - uint64_t a_hi, a_lo = mul128(a->second.fee, b->second.blob_size, &a_hi); - uint64_t b_hi, b_lo = mul128(b->second.fee, a->second.blob_size, &b_hi); - return a_hi > b_hi || (a_hi == b_hi && a_lo > b_lo); - }); - - size_t current_size = 0; - uint64_t current_fee = 0; - uint64_t best_money; - if (!get_block_reward(median_size, CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE, already_generated_coins, best_money)) { - LOG_ERROR("Block with just a miner transaction is already too large!"); - return false; - } - size_t best_position = 0; total_size = 0; fee = 0; + size_t max_total_size = 2 * median_size - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE; std::unordered_set<crypto::key_image> k_images; - - for (size_t i = 0; i < txs.size(); i++) { - txv &tx(*txs[i]); - - if(!is_transaction_ready_to_go(tx.second) || have_key_images(k_images, tx.second.tx)) { - txs[i] = NULL; + BOOST_FOREACH(transactions_container::value_type& tx, m_transactions) + { + if (max_total_size < total_size + tx.second.blob_size) continue; - } - append_key_images(k_images, tx.second.tx); - current_size += tx.second.blob_size; - current_fee += tx.second.fee; - - uint64_t current_reward; - if (!get_block_reward(median_size, current_size + CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE, already_generated_coins, current_reward)) { - break; - } - - if (best_money < current_reward + current_fee) { - best_money = current_reward + current_fee; - best_position = i + 1; - total_size = current_size; - fee = current_fee; - } - } + if (!is_transaction_ready_to_go(tx.second) || have_key_images(k_images, tx.second.tx)) + continue; - for (size_t i = 0; i < best_position; i++) { - if (txs[i]) { - bl.tx_hashes.push_back(txs[i]->first); - } + bl.tx_hashes.push_back(tx.first); + total_size += tx.second.blob_size; + fee += tx.second.fee; + append_key_images(k_images, tx.second.tx); } return true; |