From 18c35f22745cd932cbafaa22b78101e2f32e025c Mon Sep 17 00:00:00 2001 From: "crypro.zoidberg" Date: Thu, 25 Apr 2019 01:41:49 +0200 Subject: [PATCH] attempt to fix bug with unreturned key_images to tx_pool on reorganize --- src/currency_core/blockchain_storage.cpp | 3 + src/currency_core/currency_config.h | 2 +- src/currency_core/tx_pool.cpp | 11 +-- src/daemon/daemon_commands_handler.h | 98 ++++++++++++++++++++++++ src/simplewallet/simplewallet.cpp | 1 - 5 files changed, 108 insertions(+), 7 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 038e3264..a7fab028 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3459,7 +3459,10 @@ bool blockchain_storage::have_tx_keyimges_as_spent(const transaction &tx) const if (in.type() == typeid(txin_to_key)) { if (have_tx_keyimg_as_spent(boost::get(in).k_image)) + { return true; + } + } else if (in.type() == typeid(txin_multisig)) { diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 0eea1ebb..6766f9c6 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -46,7 +46,7 @@ #define BASE_REWARD_DUST_THRESHOLD ((uint64_t)1000000) // pow(10, 6) - change this will cause hard-fork! #define DEFAULT_DUST_THRESHOLD ((uint64_t)0)//((uint64_t)100000) // pow(10, 5) -#define TX_DEFAULT_FEE ((uint64_t)100000) // pow(10, 5) +#define TX_DEFAULT_FEE ((uint64_t)10000000000) // pow(10, 5) #define TX_MINIMUM_FEE ((uint64_t)100000) // pow(10, 5) // #define CURRENCY_FIXED_REWARD_ZONE_HEIGHT 300 // blocks will have fixed reward up to this height (including) diff --git a/src/currency_core/tx_pool.cpp b/src/currency_core/tx_pool.cpp index 817f2a55..0012f9df 100644 --- a/src/currency_core/tx_pool.cpp +++ b/src/currency_core/tx_pool.cpp @@ -777,16 +777,14 @@ namespace currency //--------------------------------------------------------------------------------- bool tx_memory_pool::on_tx_add(const transaction& tx, bool kept_by_block) { - if (!kept_by_block) - insert_key_images(tx, kept_by_block); // take into account only key images from txs that are not 'kept_by_block' + insert_key_images(tx, kept_by_block); insert_alias_info(tx); return true; } //--------------------------------------------------------------------------------- bool tx_memory_pool::on_tx_remove(const transaction& tx, bool kept_by_block) { - if (!kept_by_block) - remove_key_images(tx, kept_by_block); // take into account only key images from txs that are not 'kept_by_block' + remove_key_images(tx, kept_by_block); remove_alias_info(tx); return true; } @@ -944,8 +942,11 @@ namespace currency } } //if we here, transaction seems valid, but, anyway, check for key_images collisions with blockchain, just to be sure - if(m_blockchain.have_tx_keyimges_as_spent(txd.tx)) + if (m_blockchain.have_tx_keyimges_as_spent(txd.tx)) + { return false; + } + if (!check_tx_multisig_ins_and_outs(txd.tx, false)) return false; diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 46623a1e..6770d0f1 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -15,6 +15,7 @@ #include "crypto/hash.h" #include "warnings.h" #include "currency_core/bc_offers_service.h" +#include "serialization/binary_utils.h" PUSH_WARNINGS DISABLE_VS_WARNINGS(4100) @@ -64,6 +65,8 @@ public: m_cmd_binder.set_handler("rescan_aliases", boost::bind(&daemon_cmmands_handler::rescan_aliases, this, _1), "Debug function"); m_cmd_binder.set_handler("forecast_difficulty", boost::bind(&daemon_cmmands_handler::forecast_difficulty, this, _1), "Prints PoW and PoS difficulties for as many future blocks as possible based on current conditions"); m_cmd_binder.set_handler("print_deadlock_guard", boost::bind(&daemon_cmmands_handler::print_deadlock_guard, this, _1), "Print all threads which is blocked or involved in mutex ownership"); + m_cmd_binder.set_handler("print_block_from_hex_blob", boost::bind(&daemon_cmmands_handler::print_block_from_hex_blob, this, _1), "Unserialize block from hex binary data to json-like representation"); + m_cmd_binder.set_handler("print_tx_from_hex_blob", boost::bind(&daemon_cmmands_handler::print_tx_from_hex_blob, this, _1), "Unserialize transaction from hex binary data to json-like representation"); } bool start_handling() @@ -356,6 +359,101 @@ private: return true; } //-------------------------------------------------------------------------------- + template + bool print_t_from_hex_blob(const std::string& item_hex_blob) + { + std::string bin_buff; + bool res = epee::string_tools::parse_hexstr_to_binbuff(item_hex_blob, bin_buff); + CHECK_AND_ASSERT_MES(res, false, "failed to parse hex"); + + t_item item = AUTO_VAL_INIT(item); + + res = ::serialization::parse_binary(bin_buff, item); + CHECK_AND_ASSERT_MES(res, false, "failed to parse binary"); + + + LOG_PRINT_L0("OBJECT " << typeid(item).name() << ": " << ENDL << obj_to_json_str(item)); + return true; + } + //-------------------------------------------------------------------------------- + bool print_block_from_hex_blob(const std::vector& args) + { + if (!args.size()) + { + std::cout << "need block blob parameter" << ENDL; + return false; + } + + print_t_from_hex_blob(args[0]); + + LOG_PRINT_GREEN("Done", LOG_LEVEL_0); + return true; + } + //-------------------------------------------------------------------------------- + bool print_tx_from_hex_blob(const std::vector& args) + { + if (!args.size()) + { + std::cout << "need block blob parameter" << ENDL; + return false; + } + + print_t_from_hex_blob(args[0]); + + LOG_PRINT_GREEN("Done", LOG_LEVEL_0); + return true; + } + //-------------------------------------------------------------------------------- + struct tx_pool_exported_blobs + { + std::list all_txs_details; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(all_txs_details) + END_KV_SERIALIZE_MAP() + }; + //-------------------------------------------------------------------------------- + bool export_tx_pool_to_json(const std::vector& args) + { +// if (!args.size()) +// { +// std::cout << "need block blob parameter" << ENDL; +// return false; +// } +// tx_pool_exported_blobs tx_pool_json; +// m_srv.get_payload_object().get_core().get_tx_pool().get_all_transactions_details(tx_pool_json.all_txs_details); +// std::string pool_state = epee::serialization::store_t_to_json(tx_pool_json); +// CHECK_AND_ASSERT_THROW(pool_state.size(), false, "Unable to export pool"); +// +// bool r = file_io_utils::save_string_to_file(args[0], pool_state); +// CHECK_AND_ASSERT_THROW(r, false, "Unable to export pool"); +// LOG_PRINT_GREEN("Exported OK(" << tx_pool_json.all_txs_details.size() <<" transactions)"); + return true; + } + //-------------------------------------------------------------------------------- + bool import_tx_pool_to_json(const std::vector& args) + { +// if (!args.size()) +// { +// std::cout << "need block blob parameter" << ENDL; +// return false; +// } +// +// std::string buff; +// bool r = file_io_utils::load_file_to_string(args[0], buff); +// +// tx_pool_exported_blobs tx_pool_json; +// +// +// m_srv.get_payload_object().get_core().get_tx_pool().get_all_transactions_details(tx_pool_json.all_txs_details); +// std::string pool_state = epee::serialization::store_t_to_json(tx_pool_json); +// CHECK_AND_ASSERT_THROW(pool_state.size(), false, "Unable to export pool"); +// +// +// CHECK_AND_ASSERT_THROW(r, false, "Unable to export pool"); +// LOG_PRINT_GREEN("Exported OK(" << tx_pool_json.all_txs_details.size() << " transactions)"); + return true; + } + //-------------------------------------------------------------------------------- bool print_bci(const std::vector& args) { m_srv.get_payload_object().get_core().print_blockchain_index(); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index b885ea86..c78617aa 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -905,7 +905,6 @@ bool simple_wallet::get_transfer_info(const std::vector &args) { fail_msg_writer() << "failed to find transfer info by key_image"; return true; - } } std::string json_details = epee::serialization::store_t_to_json(td);