aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/tx_pool.cpp
diff options
context:
space:
mode:
authorthankful_for_today <my email>2014-04-20 00:53:40 +0400
committerthankful_for_today <my email>2014-04-20 00:53:40 +0400
commit0fd82c910b8e4cbf0b3940d6e42f2e992287582d (patch)
treece65c67d26b006d305f00abb04486fddb3484eaf /src/cryptonote_core/tx_pool.cpp
parentmistake in README fixed (diff)
downloadmonero-0fd82c910b8e4cbf0b3940d6e42f2e992287582d.tar.xz
mining bug fixed
Diffstat (limited to 'src/cryptonote_core/tx_pool.cpp')
-rw-r--r--src/cryptonote_core/tx_pool.cpp57
1 files changed, 12 insertions, 45 deletions
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;