From 7f851205a0495ae9c33c7b91562d6bd85d96dc9a Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 16 Mar 2024 14:57:25 +0100 Subject: [PATCH] tx_pool: add post-HF4 txs are now being check for balance proof. Core test hard_fork_4_consolidated_txs changed accordingly --- src/currency_core/tx_pool.cpp | 12 +++++++++++- src/currency_core/tx_pool.h | 3 ++- tests/core_tests/hard_fork_4.cpp | 24 ++++++++++++++---------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/currency_core/tx_pool.cpp b/src/currency_core/tx_pool.cpp index 94a69124..3f133932 100644 --- a/src/currency_core/tx_pool.cpp +++ b/src/currency_core/tx_pool.cpp @@ -224,6 +224,14 @@ namespace currency } TIME_MEASURE_FINISH_PD(check_inputs_time); + TIME_MEASURE_START_PD(check_post_hf4_balance); + if (tx.version > TRANSACTION_VERSION_PRE_HF4) + { + r = check_tx_balance(tx, id); + CHECK_AND_ASSERT_MES_CUSTOM(r, false, { tvc.m_verification_failed = true; }, "post-HF4 tx: balance proof is invalid"); + } + TIME_MEASURE_FINISH_PD(check_post_hf4_balance); + do_insert_transaction(tx, id, blob_size, kept_by_block, tx_fee, ch_inp_res ? max_used_block_id : null_hash, ch_inp_res ? max_used_block_height : 0); TIME_MEASURE_FINISH_PD(tx_processing_time); @@ -240,9 +248,11 @@ namespace currency << "/" << m_performance_data.validate_alias_time.get_last_val() << "/" << m_performance_data.check_keyimages_ws_ms_time.get_last_val() << "/" << m_performance_data.check_inputs_time.get_last_val() + << "/b"<< m_performance_data.check_post_hf4_balance.get_last_val() << "/" << m_performance_data.begin_tx_time.get_last_val() << "/" << m_performance_data.update_db_time.get_last_val() - << "/" << m_performance_data.db_commit_time.get_last_val() << ")" ); + << "/" << m_performance_data.db_commit_time.get_last_val() + << ")"); return true; } diff --git a/src/currency_core/tx_pool.h b/src/currency_core/tx_pool.h index 4ede52a2..df604f59 100644 --- a/src/currency_core/tx_pool.h +++ b/src/currency_core/tx_pool.h @@ -77,7 +77,8 @@ namespace currency epee::math_helper::average check_inputs_time; epee::math_helper::average begin_tx_time; epee::math_helper::average update_db_time; - epee::math_helper::average db_commit_time; + epee::math_helper::average db_commit_time; + epee::math_helper::average check_post_hf4_balance; }; typedef std::unordered_map> key_image_cache; diff --git a/tests/core_tests/hard_fork_4.cpp b/tests/core_tests/hard_fork_4.cpp index 8652a846..e5b4d6b4 100644 --- a/tests/core_tests/hard_fork_4.cpp +++ b/tests/core_tests/hard_fork_4.cpp @@ -134,18 +134,22 @@ bool hard_fork_4_consolidated_txs::generate(std::vector& event CHECK_AND_ASSERT_MES(dhc == destinations.size(), false, "unexpected derivation hints count: " << dhc); // partially completed tx_1 shouldn't be accepted - if (m_post_hf4_zarcanum) - { - ADD_CUSTOM_EVENT(events, tx_1); - DO_CALLBACK(events, "mark_invalid_block"); - MAKE_NEXT_BLOCK_TX1(events, blk_2a, blk_1r, miner_acc, tx_1); - } - else - { + + // now we added a balance check to tx_memory_pool::add_tx() for post-HF4 txs, so the behaviour is the same -- partially completed consolidated tx won't be added to the pool -- sowle + // (subject to change in future) + + //if (m_post_hf4_zarcanum) + //{ + // ADD_CUSTOM_EVENT(events, tx_1); + // DO_CALLBACK(events, "mark_invalid_block"); + // MAKE_NEXT_BLOCK_TX1(events, blk_2a, blk_1r, miner_acc, tx_1); + // DO_CALLBACK(events, "clear_tx_pool"); + //} + //else + //{ DO_CALLBACK(events, "mark_invalid_tx"); ADD_CUSTOM_EVENT(events, tx_1); - } - DO_CALLBACK(events, "clear_tx_pool"); + //} }