Add proper big transaction handling

This commit is contained in:
Antonio Juarez 2014-06-29 03:39:24 +04:00
parent 76bb193b05
commit 209e2356f5
2 changed files with 19 additions and 1 deletions

View file

@ -20,6 +20,8 @@
DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated
#define TRANSACTION_SIZE_LIMIT (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE)
namespace cryptonote { namespace cryptonote {
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
tx_memory_pool::tx_memory_pool(blockchain_storage& bchs): m_blockchain(bchs) { tx_memory_pool::tx_memory_pool(blockchain_storage& bchs): m_blockchain(bchs) {
@ -52,6 +54,12 @@ namespace cryptonote {
return false; return false;
} }
if (!kept_by_block && blob_size >= TRANSACTION_SIZE_LIMIT) {
LOG_ERROR("transaction is too big: " << blob_size << " bytes, maximum size: " << TRANSACTION_SIZE_LIMIT);
tvc.m_verifivation_failed = true;
return false;
}
//check key images for transaction if it is not kept by block //check key images for transaction if it is not kept by block
if (!kept_by_block) { if (!kept_by_block) {
if (have_tx_keyimges_as_spent(tx)) { if (have_tx_keyimges_as_spent(tx)) {
@ -340,6 +348,16 @@ namespace cryptonote {
m_transactions.clear(); m_transactions.clear();
m_spent_key_images.clear(); m_spent_key_images.clear();
} }
for (auto it = m_transactions.begin(); it != m_transactions.end(); ) {
auto it2 = it++;
if (it2->second.blob_size >= TRANSACTION_SIZE_LIMIT) {
LOG_PRINT_L0("Transaction " << get_transaction_hash(it2->second.tx) << " is too big (" << it2->second.blob_size << " bytes), removing it from pool");
remove_transaction_keyimages(it2->second.tx);
m_transactions.erase(it2);
}
}
// Ignore deserialization error // Ignore deserialization error
return true; return true;
} }

View file

@ -102,7 +102,7 @@ namespace tools
void store(); void store();
cryptonote::account_base& get_account(){return m_account;} cryptonote::account_base& get_account(){return m_account;}
void init(const std::string& daemon_address = "http://localhost:8080", uint64_t upper_transaction_size_limit = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE*2 - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); void init(const std::string& daemon_address = "http://localhost:8080", uint64_t upper_transaction_size_limit = ((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
bool deinit(); bool deinit();
void stop() { m_run.store(false, std::memory_order_relaxed); } void stop() { m_run.store(false, std::memory_order_relaxed); }