Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 209e235

Browse files
author
Antonio Juarez
committed
Add proper big transaction handling
1 parent 76bb193 commit 209e235

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/cryptonote_core/tx_pool.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated
2222

23+
#define TRANSACTION_SIZE_LIMIT (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE)
24+
2325
namespace cryptonote {
2426
//---------------------------------------------------------------------------------
2527
tx_memory_pool::tx_memory_pool(blockchain_storage& bchs): m_blockchain(bchs) {
@@ -52,6 +54,12 @@ namespace cryptonote {
5254
return false;
5355
}
5456

57+
if (!kept_by_block && blob_size >= TRANSACTION_SIZE_LIMIT) {
58+
LOG_ERROR("transaction is too big: " << blob_size << " bytes, maximum size: " << TRANSACTION_SIZE_LIMIT);
59+
tvc.m_verifivation_failed = true;
60+
return false;
61+
}
62+
5563
//check key images for transaction if it is not kept by block
5664
if (!kept_by_block) {
5765
if (have_tx_keyimges_as_spent(tx)) {
@@ -340,6 +348,16 @@ namespace cryptonote {
340348
m_transactions.clear();
341349
m_spent_key_images.clear();
342350
}
351+
352+
for (auto it = m_transactions.begin(); it != m_transactions.end(); ) {
353+
auto it2 = it++;
354+
if (it2->second.blob_size >= TRANSACTION_SIZE_LIMIT) {
355+
LOG_PRINT_L0("Transaction " << get_transaction_hash(it2->second.tx) << " is too big (" << it2->second.blob_size << " bytes), removing it from pool");
356+
remove_transaction_keyimages(it2->second.tx);
357+
m_transactions.erase(it2);
358+
}
359+
}
360+
343361
// Ignore deserialization error
344362
return true;
345363
}

src/wallet/wallet2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace tools
102102
void store();
103103
cryptonote::account_base& get_account(){return m_account;}
104104

105-
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);
105+
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);
106106
bool deinit();
107107

108108
void stop() { m_run.store(false, std::memory_order_relaxed); }

0 commit comments

Comments
 (0)