From a288150e97198a10ff3042e426c3b0c7f309883b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 9 Jul 2019 19:22:57 +0200 Subject: [PATCH] set spent flag --- src/currency_core/blockchain_storage.cpp | 68 +++++++++- src/currency_core/blockchain_storage.h | 7 + src/daemon/daemon_commands_handler.h | 159 ++++++++++++----------- 3 files changed, 151 insertions(+), 83 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index e7012315..e3e3865c 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -304,6 +304,10 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro if(!m_db_blocks.back()->bl.timestamp) timestamp_diff = m_core_runtime_config.get_core_time() - 1341378000; + m_db.begin_transaction(); + set_lost_tx_unmixable(); + m_db.commit_transaction(); + LOG_PRINT_GREEN("Blockchain initialized. (v:" << m_db_storage_major_compatibility_version << ") last block: " << m_db_blocks.size() - 1 << ENDL << "genesis: " << get_block_hash(m_db_blocks[0]->bl) << ENDL << "last block: " << m_db_blocks.size() - 1 << ", " << misc_utils::get_time_interval_string(timestamp_diff) << " time ago" << ENDL @@ -311,10 +315,49 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro << "current pow difficulty: " << get_next_diff_conditional(false) << ENDL << "total transactions: " << m_db_transactions.size(), LOG_LEVEL_0); - return true; } + +//------------------------------------------------------------------ +bool blockchain_storage::set_lost_tx_unmixable_for_height(uint64_t height) +{ + if (height == 75738) + return set_lost_tx_unmixable(); + return true; +} +//------------------------------------------------------------------ +bool blockchain_storage::set_lost_tx_unmixable() +{ + if (m_db_blocks.size() > 75738) + { + crypto::hash tx_id_1 = epee::string_tools::parse_tpod_from_hex_string("c2a2229d614e7c026433efbcfdbd0be1f68d9b419220336df3e2c209f5d57314"); + crypto::hash tx_id_2 = epee::string_tools::parse_tpod_from_hex_string("647f936c6ffbd136f5c95d9a90ad554bdb4c01541c6eb5755ad40b984d80da67"); + + auto tx_ptr_1 = m_db_transactions.find(tx_id_1); + CHECK_AND_ASSERT_MES(tx_ptr_1, false, "Internal error: filed to find lost tx"); + transaction_chain_entry tx1_local_entry(*tx_ptr_1); + for (size_t i = 0; i != tx1_local_entry.m_spent_flags.size(); i++) + { + tx1_local_entry.m_spent_flags[i] = true; + } + m_db_transactions.set(tx_id_1, tx1_local_entry); + + auto tx_ptr_2 = m_db_transactions.find(tx_id_2); + transaction_chain_entry tx2_local_entry(*tx_ptr_2); + CHECK_AND_ASSERT_MES(tx_ptr_1, false, "Internal error: filed to find lost tx"); + for (size_t i = 0; i != tx2_local_entry.m_spent_flags.size(); i++) + { + tx2_local_entry.m_spent_flags[i] = true; + } + m_db_transactions.set(tx_id_2, tx2_local_entry); + } + return true; +} +//------------------------------------------------------------------ +void blockchain_storage::patch_out_if_needed(txout_to_key& out, const crypto::hash& tx_id, uint64_t n) const +{ +} //------------------------------------------------------------------ void blockchain_storage::initialize_db_solo_options_values() { @@ -1578,7 +1621,19 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto:: { //block orphaned bvc.m_marked_as_orphaned = true; - LOG_PRINT_RED_L0("Block recognized as orphaned and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height); + + if (m_invalid_blocks.count(id) != 0) + { + LOG_PRINT_RED_L0("Block recognized as blacklisted (parent " << b.prev_id << " is in blacklist) and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height); + } + else if (m_invalid_blocks.count(b.prev_id) != 0) + { + LOG_PRINT_RED_L0("Block recognized as orphaned (parent " << b.prev_id << " is in blacklist) and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height); + } + else + { + LOG_PRINT_RED_L0("Block recognized as orphaned and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height); + } } CHECK_AND_ASSERT_MES(validate_blockchain_prev_links(), false, "EPIC FAIL!"); @@ -3458,10 +3513,11 @@ bool blockchain_storage::print_tx_outputs_lookup(const crypto::hash& tx_id)const //amount -> index -> [{tx_id, rind_count}] std::map > > > usage_stat; - + std::stringstream strm_tx; CHECK_AND_ASSERT_MES(tx_ptr->tx.vout.size() == tx_ptr->m_global_output_indexes.size(), false, "Internal error: output size missmatch"); for (uint64_t i = 0; i!= tx_ptr->tx.vout.size();i++) { + strm_tx << "[" << i << "]: " << print_money(tx_ptr->tx.vout[i].amount) << ENDL; if (tx_ptr->tx.vout[i].target.type() != typeid(currency::txout_to_key)) continue; @@ -3513,7 +3569,7 @@ bool blockchain_storage::print_tx_outputs_lookup(const crypto::hash& tx_id)const } } - LOG_PRINT_L0("Results: " << ENDL << ss.str()); + LOG_PRINT_L0("Results: " << ENDL << strm_tx.str() << ENDL << ss.str()); return true; } @@ -4619,6 +4675,10 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt powpos_str_entry << "PoW:\t" << proof_hash; timestamp_str_entry << ", block ts: " << bei.bl.timestamp << " (diff: " << std::showpos << ts_diff << "s)"; } + //explanation of this code will be provided later with public announce + set_lost_tx_unmixable_for_height(bei.height); + + LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED " << (is_pos_bl ? "[PoS]" : "[PoW]") << " Sq: " << sequence_factor << ENDL << "id:\t" << id << timestamp_str_entry.str() << ENDL << powpos_str_entry.str() diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index db65c420..8c387253 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -525,6 +525,9 @@ namespace currency bool init_tx_fee_median(); bool update_tx_fee_median(); void initialize_db_solo_options_values(); + bool set_lost_tx_unmixable(); + bool set_lost_tx_unmixable_for_height(uint64_t height); + void patch_out_if_needed(txout_to_key& out, const crypto::hash& tx_id, uint64_t n)const ; bool switch_to_alternative_blockchain(alt_chain_type& alt_chain); void purge_alt_block_txs_hashs(const block& b); void add_alt_block_txs_hashs(const block& b); @@ -691,7 +694,11 @@ namespace currency TIME_MEASURE_FINISH_PD(tx_check_inputs_loop_scan_outputkeys_loop_find_tx); CHECKED_GET_SPECIFIC_VARIANT(tx_ptr->tx.vout[n].target, const txout_to_key, outtk, false); + //explanation of this code will be provided later with public announce + patch_out_if_needed(const_cast(outtk), tx_id, n); + + CHECK_AND_ASSERT_MES(tx_in_to_key.key_offsets.size() >= 1, false, "internal error: tx input has empty key_offsets"); // should never happen as input correctness must be handled by the caller bool mixattr_ok = is_mixattr_applicable_for_fake_outs_counter(outtk.mix_attr, tx_in_to_key.key_offsets.size() - 1); CHECK_AND_ASSERT_MES(mixattr_ok, false, "tx output #" << output_index << " violates mixin restrictions: mix_attr = " << static_cast(outtk.mix_attr) << ", key_offsets.size = " << tx_in_to_key.key_offsets.size()); diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 39cb39f6..ac057703 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -38,7 +38,7 @@ public: //m_cmd_binder.set_handler("print_bci", boost::bind(&daemon_commands_handler::print_bci, this, _1)); m_cmd_binder.set_handler("print_bc_outs", boost::bind(&daemon_commands_handler::print_bc_outs, this, _1)); m_cmd_binder.set_handler("print_market", boost::bind(&daemon_commands_handler::print_market, this, _1)); - m_cmd_binder.set_handler("print_bc_outs_stat", boost::bind(&daemon_commands_handler::print_bc_outs_stat, this, _1)); + m_cmd_binder.set_handler("print_bc_outs_stat", boost::bind(&daemon_commands_handler::print_bc_outs_stat, this, _1)); m_cmd_binder.set_handler("print_block", boost::bind(&daemon_commands_handler::print_block, this, _1), "Print block, print_block | "); m_cmd_binder.set_handler("print_block_info", boost::bind(&daemon_commands_handler::print_block_info, this, _1), "Print block info, print_block | "); m_cmd_binder.set_handler("print_tx", boost::bind(&daemon_commands_handler::print_tx, this, _1), "Print transaction, print_tx "); @@ -85,17 +85,17 @@ public: private: -// //-------------------------------------------------------------------------------- -// std::string get_commands_str() -// { -// return m_cmd_binder.get_usage(); -// } -// //-------------------------------------------------------------------------------- -// bool help(const std::vector& /*args*/) -// { -// std::cout << get_commands_str() << ENDL; -// return true; -// } + // //-------------------------------------------------------------------------------- + // std::string get_commands_str() + // { + // return m_cmd_binder.get_usage(); + // } + // //-------------------------------------------------------------------------------- + // bool help(const std::vector& /*args*/) + // { + // std::cout << get_commands_str() << ENDL; + // return true; + // } //-------------------------------------------------------------------------------- bool print_pl(const std::vector& args) { @@ -166,23 +166,24 @@ private: { m_srv.get_payload_object().get_core().get_blockchain_storage().reset_db_cache(); return true; - } + } bool clear_altblocks(const std::vector& args) { m_srv.get_payload_object().get_core().get_blockchain_storage().clear_altblocks(); return true; } - + //-------------------------------------------------------------------------------- bool show_hr(const std::vector& args) { - if(!m_srv.get_payload_object().get_core().get_miner().is_mining()) - { - std::cout << "Mining is not started. You need start mining before you can see hash rate." << ENDL; - } else - { - m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(true); - } + if (!m_srv.get_payload_object().get_core().get_miner().is_mining()) + { + std::cout << "Mining is not started. You need start mining before you can see hash rate." << ENDL; + } + else + { + m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(true); + } return true; } //-------------------------------------------------------------------------------- @@ -194,7 +195,7 @@ private: //-------------------------------------------------------------------------------- bool print_bc_outs(const std::vector& args) { - if(args.size() != 1) + if (args.size() != 1) { std::cout << "need file path as parameter" << ENDL; return true; @@ -220,25 +221,25 @@ private: //-------------------------------------------------------------------------------- bool print_cn(const std::vector& args) { - m_srv.get_payload_object().log_connections(); - return true; + m_srv.get_payload_object().log_connections(); + return true; } //-------------------------------------------------------------------------------- bool print_bc(const std::vector& args) { - if(!args.size()) + if (!args.size()) { std::cout << "need block index parameter" << ENDL; return false; } uint64_t start_index = 0; uint64_t end_block_parametr = m_srv.get_payload_object().get_core().get_current_blockchain_size(); - if(!string_tools::get_xtype_from_string(start_index, args[0])) + if (!string_tools::get_xtype_from_string(start_index, args[0])) { std::cout << "wrong starter block index parameter" << ENDL; return false; } - if(args.size() >1 && !string_tools::get_xtype_from_string(end_block_parametr, args[1])) + if (args.size() > 1 && !string_tools::get_xtype_from_string(end_block_parametr, args[1])) { std::cout << "wrong end block index parameter" << ENDL; return false; @@ -274,7 +275,7 @@ private: { m_srv.get_payload_object().get_core().get_blockchain_storage().print_db_cache_perfeormance_data(); return true; - } + } //-------------------------------------------------------------------------------- bool search_by_id(const std::vector& args) { @@ -287,7 +288,7 @@ private: crypto::hash id = currency::null_hash; if (!parse_hash256(args[0], id)) { - std::cout << "specified ID parameter '"<< args[0] << "' is wrong" << ENDL; + std::cout << "specified ID parameter '" << args[0] << "' is wrong" << ENDL; return false; } std::list res_list; @@ -373,7 +374,7 @@ private: 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; } @@ -416,43 +417,43 @@ private: //-------------------------------------------------------------------------------- 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)"); + // 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)"); + // 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; } //-------------------------------------------------------------------------------- @@ -522,7 +523,7 @@ private: if (r) { // currency::block& block = bei.bl; - LOG_PRINT_GREEN("------------------ block_id: " << bei.id << " ------------------" << ENDL << epee::serialization::store_t_to_json(bei) , LOG_LEVEL_0); + LOG_PRINT_GREEN("------------------ block_id: " << bei.id << " ------------------" << ENDL << epee::serialization::store_t_to_json(bei), LOG_LEVEL_0); } else { @@ -551,7 +552,7 @@ private: if (r) { -// currency::block& block = bei.bl; + // currency::block& block = bei.bl; LOG_PRINT_GREEN("------------------ block_id: " << get_block_hash(bei.bl) << " ------------------" << ENDL << currency::obj_to_json_str(bei), LOG_LEVEL_0); m_srv.get_payload_object().get_core().get_blockchain_storage().calc_tx_cummulative_blob(bei.bl); } @@ -623,11 +624,11 @@ private: return true; } -// std::vector tx_ids; -// tx_ids.push_back(tx_hash); -// std::list txs; -// std::list missed_ids; -// m_srv.get_payload_object().get_core().get_transactions(tx_ids, txs, missed_ids); + // std::vector tx_ids; + // tx_ids.push_back(tx_hash); + // std::list txs; + // std::list missed_ids; + // m_srv.get_payload_object().get_core().get_transactions(tx_ids, txs, missed_ids); currency::transaction_chain_entry tx_entry = AUTO_VAL_INIT(tx_entry); @@ -655,10 +656,10 @@ private: for (auto at : tx.attachment) { if (at.type() == typeid(currency::tx_service_attachment)) - { + { const currency::tx_service_attachment& sa = boost::get(at); ss << "++++++++++++++++++++++++++++++++ " << ENDL; - ss << "[SERVICE_ATTACHMENT]: ID = \'" << sa.service_id << "\', INSTRUCTION: \'" << sa.instruction << "\'" << ENDL; + ss << "[SERVICE_ATTACHMENT]: ID = \'" << sa.service_id << "\', INSTRUCTION: \'" << sa.instruction << "\'" << ENDL; if (!(sa.flags&TX_SERVICE_ATTACHMENT_ENCRYPT_BODY)) { @@ -696,7 +697,7 @@ private: return true; } - + //-------------------------------------------------------------------------------- bool print_pool(const std::vector& args) { @@ -711,20 +712,20 @@ private: } //-------------------------------------------------------------------------------- bool start_mining(const std::vector& args) { - if(!args.size()) + if (!args.size()) { std::cout << "Please, specify wallet address to mine for: start_mining [threads=1]" << std::endl; return true; } currency::account_public_address adr; - if(!currency::get_account_address_from_str(adr, args.front())) + if (!currency::get_account_address_from_str(adr, args.front())) { std::cout << "target account address has wrong format" << std::endl; return true; } size_t threads_count = 1; - if(args.size() > 1) + if (args.size() > 1) { bool ok = string_tools::get_xtype_from_string(threads_count, args[1]); threads_count = (ok && 0 < threads_count) ? threads_count : 1; @@ -771,7 +772,7 @@ private: else ss << " "; ss << std::setw(10) << std::left << pow_diffs[i].second; - + ss << " "; ss << std::setw(6) << std::left << pos_diffs[i].first; if (i == 0) @@ -791,9 +792,9 @@ private: LOG_PRINT_L0(ENDL << epee::deadlock_guard_singleton::get_dlg_state()); return true; } - - + + }; -POP_WARNINGS +POP_WARNINGS \ No newline at end of file