mirror of
https://github.com/monero-project/monero.git
synced 2026-02-01 09:15:16 +01:00
tx_pool: speed up take_tx for transactions from blocks
This happens for every historical tx when syncing, and the unnecessary parsing is actually showing up on profile. Since these are kept cached for just one block, this does not increase memory usage after syncing.
This commit is contained in:
@@ -247,6 +247,8 @@ namespace cryptonote
|
|||||||
memset(meta.padding, 0, sizeof(meta.padding));
|
memset(meta.padding, 0, sizeof(meta.padding));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (kept_by_block)
|
||||||
|
m_parsed_tx_cache.insert(std::make_pair(id, tx));
|
||||||
CRITICAL_REGION_LOCAL1(m_blockchain);
|
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||||
LockedTXN lock(m_blockchain);
|
LockedTXN lock(m_blockchain);
|
||||||
m_blockchain.add_txpool_tx(id, blob, meta);
|
m_blockchain.add_txpool_tx(id, blob, meta);
|
||||||
@@ -288,6 +290,8 @@ namespace cryptonote
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (kept_by_block)
|
||||||
|
m_parsed_tx_cache.insert(std::make_pair(id, tx));
|
||||||
CRITICAL_REGION_LOCAL1(m_blockchain);
|
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||||
LockedTXN lock(m_blockchain);
|
LockedTXN lock(m_blockchain);
|
||||||
m_blockchain.remove_txpool_tx(id);
|
m_blockchain.remove_txpool_tx(id);
|
||||||
@@ -468,7 +472,12 @@ namespace cryptonote
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(id);
|
cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(id);
|
||||||
if (!parse_and_validate_tx_from_blob(txblob, tx))
|
auto ci = m_parsed_tx_cache.find(id);
|
||||||
|
if (ci != m_parsed_tx_cache.end())
|
||||||
|
{
|
||||||
|
tx = ci->second;
|
||||||
|
}
|
||||||
|
else if (!parse_and_validate_tx_from_blob(txblob, tx))
|
||||||
{
|
{
|
||||||
MERROR("Failed to parse tx from txpool");
|
MERROR("Failed to parse tx from txpool");
|
||||||
return false;
|
return false;
|
||||||
@@ -911,6 +920,7 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
m_input_cache.clear();
|
m_input_cache.clear();
|
||||||
|
m_parsed_tx_cache.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
@@ -918,6 +928,7 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||||
m_input_cache.clear();
|
m_input_cache.clear();
|
||||||
|
m_parsed_tx_cache.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -584,6 +584,8 @@ private:
|
|||||||
size_t m_txpool_weight;
|
size_t m_txpool_weight;
|
||||||
|
|
||||||
mutable std::unordered_map<crypto::hash, std::tuple<bool, tx_verification_context, uint64_t, crypto::hash>> m_input_cache;
|
mutable std::unordered_map<crypto::hash, std::tuple<bool, tx_verification_context, uint64_t, crypto::hash>> m_input_cache;
|
||||||
|
|
||||||
|
std::unordered_map<crypto::hash, transaction> m_parsed_tx_cache;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user