Skip to content

Commit c0e536c

Browse files
committed
src: fix rpc limit issue with introduction of size limit
1 parent a1dc85c commit c0e536c

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/cryptonote_core/cryptonote_core.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,9 +1724,9 @@ namespace cryptonote
17241724
return true;
17251725
}
17261726
//-----------------------------------------------------------------------------------------------
1727-
bool core::get_pool_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& txs, bool include_sensitive_txes) const
1727+
bool core::get_pool_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& txs, bool include_sensitive_txes, size_t limit_size) const
17281728
{
1729-
return m_mempool.get_transactions_info(txids, txs, include_sensitive_txes);
1729+
return m_mempool.get_transactions_info(txids, txs, include_sensitive_txes, limit_size);
17301730
}
17311731
//-----------------------------------------------------------------------------------------------
17321732
bool core::get_pool_transactions(std::vector<transaction>& txs, bool include_sensitive_data) const
@@ -1741,9 +1741,9 @@ namespace cryptonote
17411741
return true;
17421742
}
17431743
//-----------------------------------------------------------------------------------------------
1744-
bool core::get_pool_info(time_t start_time, bool include_sensitive_txes, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental) const
1744+
bool core::get_pool_info(time_t start_time, bool include_sensitive_txes, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental, size_t limit_size) const
17451745
{
1746-
return m_mempool.get_pool_info(start_time, include_sensitive_txes, max_tx_count, added_txs, remaining_added_txids, removed_txs, incremental);
1746+
return m_mempool.get_pool_info(start_time, include_sensitive_txes, max_tx_count, added_txs, remaining_added_txids, removed_txs, incremental, limit_size);
17471747
}
17481748
//-----------------------------------------------------------------------------------------------
17491749
bool core::get_pool_transaction_stats(struct txpool_stats& stats, bool include_sensitive_data) const

src/cryptonote_core/cryptonote_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ namespace cryptonote
514514
*
515515
* @note see tx_memory_pool::get_pool_transactions_info
516516
*/
517-
bool get_pool_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& txs, bool include_sensitive_txes = false) const;
517+
bool get_pool_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& txs, bool include_sensitive_txes = false, size_t limit_size = 0) const;
518518

519519
/**
520520
* @copydoc tx_memory_pool::get_pool_info
@@ -523,7 +523,7 @@ namespace cryptonote
523523
*
524524
* @note see tx_memory_pool::get_pool_info
525525
*/
526-
bool get_pool_info(time_t start_time, bool include_sensitive_txes, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental) const;
526+
bool get_pool_info(time_t start_time, bool include_sensitive_txes, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental, size_t limit_size = 0) const;
527527

528528
/**
529529
* @copydoc tx_memory_pool::get_transactions

src/cryptonote_core/tx_pool.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,19 +694,21 @@ namespace cryptonote
694694
return true;
695695
}
696696
//------------------------------------------------------------------
697-
bool tx_memory_pool::get_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_details>>& txs, bool include_sensitive) const
697+
bool tx_memory_pool::get_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_details>>& txs, bool include_sensitive, size_t limit_size) const
698698
{
699699
CRITICAL_REGION_LOCAL(m_transactions_lock);
700700
CRITICAL_REGION_LOCAL1(m_blockchain);
701701

702702
txs.clear();
703+
size_t size = 0;
703704

704705
for (const auto &it: txids)
705706
{
706707
tx_details details;
707708
bool success = get_transaction_info(it, details, include_sensitive, true/*include_blob*/);
708-
if (success)
709+
if (success && (!limit_size || (size + details.blob_size < limit_size)))
709710
{
711+
size += details.blob_size;
710712
txs.push_back(std::make_pair(it, std::move(details)));
711713
}
712714
}
@@ -985,7 +987,7 @@ namespace cryptonote
985987
}, false, category);
986988
}
987989
//------------------------------------------------------------------
988-
bool tx_memory_pool::get_pool_info(time_t start_time, bool include_sensitive, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental) const
990+
bool tx_memory_pool::get_pool_info(time_t start_time, bool include_sensitive, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental, size_t limit_size) const
989991
{
990992
CRITICAL_REGION_LOCAL(m_transactions_lock);
991993
CRITICAL_REGION_LOCAL1(m_blockchain);
@@ -1029,7 +1031,7 @@ namespace cryptonote
10291031
remaining_added_txids = std::vector<crypto::hash>(txids.begin() + max_tx_count, txids.end());
10301032
txids.erase(txids.begin() + max_tx_count, txids.end());
10311033
}
1032-
get_transactions_info(txids, added_txs, include_sensitive);
1034+
get_transactions_info(txids, added_txs, include_sensitive, limit_size);
10331035
return true;
10341036
}
10351037

@@ -1039,7 +1041,7 @@ namespace cryptonote
10391041
if (pit.second >= start_time)
10401042
txids.push_back(pit.first);
10411043
}
1042-
get_transactions_info(txids, added_txs, include_sensitive);
1044+
get_transactions_info(txids, added_txs, include_sensitive, limit_size);
10431045
if (added_txs.size() > max_tx_count)
10441046
{
10451047
remaining_added_txids.reserve(added_txs.size() - max_tx_count);

src/cryptonote_core/tx_pool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ namespace cryptonote
465465
/**
466466
* @brief get information about multiple transactions
467467
*/
468-
bool get_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_details>>& txs, bool include_sensitive_data = false) const;
468+
bool get_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_details>>& txs, bool include_sensitive_data = false, size_t limit_size = 0) const;
469469

470470
/**
471471
* @brief get transactions not in the passed set
@@ -477,7 +477,7 @@ namespace cryptonote
477477
*
478478
* @return true on success, false on error
479479
*/
480-
bool get_pool_info(time_t start_time, bool include_sensitive, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental) const;
480+
bool get_pool_info(time_t start_time, bool include_sensitive, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental, size_t limit_size = 0) const;
481481

482482
private:
483483

src/rpc/core_rpc_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ namespace cryptonote
661661

662662
bool incremental;
663663
std::vector<std::pair<crypto::hash, tx_memory_pool::tx_details>> added_pool_txs;
664-
bool success = m_core.get_pool_info((time_t)req.pool_info_since, allow_sensitive, max_tx_count, added_pool_txs, res.remaining_added_pool_txids, res.removed_pool_txids, incremental);
664+
bool success = m_core.get_pool_info((time_t)req.pool_info_since, allow_sensitive, max_tx_count, added_pool_txs, res.remaining_added_pool_txids, res.removed_pool_txids, incremental, LEVIN_DEFAULT_MAX_PACKET_SIZE * 0.9);
665665
if (success)
666666
{
667667
res.added_pool_txs.clear();

0 commit comments

Comments
 (0)