mirror of
https://github.com/monero-project/monero.git
synced 2024-12-13 20:06:32 +02:00
core: bound the amount of entries in bad tx semantics cache
This is to prevent unbounded memory use. Since I don't think there is a container that has quick insert, quick lookup, and automatic FIFO, I use two and swap every N, clearing the oldest one.
This commit is contained in:
parent
240054a7f8
commit
9effa55311
@ -60,6 +60,8 @@ DISABLE_VS_WARNINGS(4355)
|
|||||||
|
|
||||||
#define MERROR_VER(x) MCERROR("verify", x)
|
#define MERROR_VER(x) MCERROR("verify", x)
|
||||||
|
|
||||||
|
#define BAD_SEMANTICS_TXES_MAX_SIZE 100
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -496,11 +498,14 @@ namespace cryptonote
|
|||||||
}
|
}
|
||||||
//std::cout << "!"<< tx.vin.size() << std::endl;
|
//std::cout << "!"<< tx.vin.size() << std::endl;
|
||||||
|
|
||||||
if (bad_semantics_txes.find(tx_hash) != bad_semantics_txes.end())
|
for (int idx = 0; idx < 2; ++idx)
|
||||||
{
|
{
|
||||||
LOG_PRINT_L1("Transaction already seen with bad semantics, rejected");
|
if (bad_semantics_txes[idx].find(tx_hash) != bad_semantics_txes[idx].end())
|
||||||
tvc.m_verifivation_failed = true;
|
{
|
||||||
return false;
|
LOG_PRINT_L1("Transaction already seen with bad semantics, rejected");
|
||||||
|
tvc.m_verifivation_failed = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
|
uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
|
||||||
@ -551,8 +556,13 @@ namespace cryptonote
|
|||||||
if(!check_tx_semantic(tx, keeped_by_block))
|
if(!check_tx_semantic(tx, keeped_by_block))
|
||||||
{
|
{
|
||||||
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to check tx " << tx_hash << " semantic, rejected");
|
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to check tx " << tx_hash << " semantic, rejected");
|
||||||
bad_semantics_txes.insert(tx_hash);
|
|
||||||
tvc.m_verifivation_failed = true;
|
tvc.m_verifivation_failed = true;
|
||||||
|
bad_semantics_txes[0].insert(tx_hash);
|
||||||
|
if (bad_semantics_txes[0].size() >= BAD_SEMANTICS_TXES_MAX_SIZE)
|
||||||
|
{
|
||||||
|
std::swap(bad_semantics_txes[0], bad_semantics_txes[1]);
|
||||||
|
bad_semantics_txes[0].clear();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -836,7 +836,7 @@ namespace cryptonote
|
|||||||
|
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
|
|
||||||
std::unordered_set<crypto::hash> bad_semantics_txes;
|
std::unordered_set<crypto::hash> bad_semantics_txes[2];
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
UPDATES_DISABLED,
|
UPDATES_DISABLED,
|
||||||
|
Loading…
Reference in New Issue
Block a user