Skip to content

Commit

Permalink
chore: add transaction packet size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankovi committed Feb 3, 2025
1 parent 8737b8b commit 810c8a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions libraries/common/include/common/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ constexpr uint32_t kDagExpiryLevelLimit = 1000;
constexpr uint32_t kDagBlockMaxTips = 16;

const uint32_t kMaxTransactionsInPacket{500};
const uint32_t kMaxTransactionsSizeInPacket{500000};
const uint32_t kMaxHashesInPacket{5000};

const uint32_t kPeriodicEventsThreadCount{2};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ TransactionPacketHandler::transactionsToSendToPeer(std::shared_ptr<TaraxaPeer> p
bool trx_max_reached = false;
auto account_iterator = account_start_index;
std::pair<SharedTransactions, std::vector<trx_hash_t>> result;
uint64_t trx_data_size = 0;
// Next peer should continue after the last account of the current peer
uint32_t next_peer_account_index = (account_start_index + 1) % accounts_size;

Expand All @@ -100,11 +101,13 @@ TransactionPacketHandler::transactionsToSendToPeer(std::shared_ptr<TaraxaPeer> p
}
} else {
result.first.push_back(trx);
if (result.first.size() == kMaxTransactionsInPacket) {
trx_data_size += trx->getData().size();
if (result.first.size() == kMaxTransactionsInPacket || trx_data_size > kMaxTransactionsSizeInPacket) {
// Max number of transactions reached, save next_peer_account_index for next peer to continue to avoid
// sending same transactions to multiple peers
trx_max_reached = true;
next_peer_account_index = (account_iterator + 1) % accounts_size;
trx_data_size = 0;
}
}
}
Expand Down

0 comments on commit 810c8a3

Please sign in to comment.