Skip to content

Commit

Permalink
tx_pool: remove HF4-incompatible txs on load
Browse files Browse the repository at this point in the history
  • Loading branch information
sowle committed Mar 21, 2024
1 parent 921b447 commit e11ee0f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/currency_core/currency_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ namespace currency
r = m_blockchain_storage.init(m_config_folder, vm);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");

m_mempool.remove_incompatible_txs();

r = m_miner.init(vm);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize miner");

Expand Down
21 changes: 21 additions & 0 deletions src/currency_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,27 @@ namespace currency
return true;
}
//---------------------------------------------------------------------------------
void tx_memory_pool::remove_incompatible_txs()
{
std::vector<crypto::hash> invalid_tx_ids;

m_db_transactions.enumerate_items([&](uint64_t i, const crypto::hash& h, const tx_details &tx_entry)
{
if (!m_blockchain.validate_tx_for_hardfork_specific_terms(tx_entry.tx, h))
invalid_tx_ids.push_back(h);
return true;
});

for(const auto& id : invalid_tx_ids)
{
transaction tx{};
size_t blob_size = 0;
uint64_t fee = 0;
take_tx(id, tx, blob_size, fee);
LOG_PRINT_L0("tx " << id << " was incompatible with the hardfork rules and removed");
}
}
//---------------------------------------------------------------------------------
bool tx_memory_pool::load_keyimages_cache()
{
CRITICAL_REGION_LOCAL(m_key_images_lock);
Expand Down
2 changes: 2 additions & 0 deletions src/currency_core/tx_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ namespace currency

bool remove_stuck_transactions(); // made public to be called from coretests

void remove_incompatible_txs(); // made public to be called after the BCS is loaded and hardfork info is ready

private:
bool on_tx_add(crypto::hash tx_id, const transaction& tx, bool kept_by_block);
bool on_tx_remove(const crypto::hash &tx_id, const transaction& tx, bool kept_by_block);
Expand Down
2 changes: 1 addition & 1 deletion src/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
#define PROJECT_REVISION "0"
#define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION

#define PROJECT_VERSION_BUILD_NO 280
#define PROJECT_VERSION_BUILD_NO 282
#define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO)
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"

0 comments on commit e11ee0f

Please sign in to comment.