Merge pull request #4 from bitmonero-project/upstream

mining bug fixed
This commit is contained in:
amjuarez 2014-04-21 13:03:04 +00:00
commit 3f29e75b56
2 changed files with 15 additions and 48 deletions

View file

@ -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);
}
}

View file

@ -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;
}
if (!is_transaction_ready_to_go(tx.second) || have_key_images(k_images, tx.second.tx))
continue;
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);
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;
}
}
for (size_t i = 0; i < best_position; i++) {
if (txs[i]) {
bl.tx_hashes.push_back(txs[i]->first);
}
}
return true;