From 213cb4f85c5cabc8aad2a167f5257c8a53c1531b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 23 Sep 2022 23:19:44 +0200 Subject: [PATCH 01/49] implemented proper versioning for binary serialization --- src/currency_core/currency_basic.h | 21 ++++ src/serialization/serialization.h | 24 ++++- tests/unit_tests/serialization.cpp | 163 +++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+), 1 deletion(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 375dd6e6..af113532 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -687,6 +687,27 @@ namespace currency + struct asset_descriptor_base + { + uint64_t total_max_supply = 0; + uint64_t current_supply = 0; + uint8_t decimal_point = 12; + std::string ticker; + std::string full_name; + crypto::public_key owner = currency::null_pkey; + + BEGIN_VERSIONED_SERIALIZE() + FIELD(total_max_supply) + FIELD(current_supply) + FIELD(decimal_point) + FIELD(ticker) + FIELD(full_name) + FIELD(owner) + END_SERIALIZE() + }; + + + struct extra_padding { std::vector buff; //stub diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index b3b54e23..6e16b498 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -61,7 +61,7 @@ inline bool do_serialize(Archive &ar, T &v) #define VARIANT_TAG(A, T, Tg) \ template struct variant_serialization_traits, T> { static inline typename A::variant_tag_type get_tag() { return Tg; } } #define BEGIN_SERIALIZE() \ - template class Archive> bool do_serialize(Archive &_ser_ar) { + template class Archive> bool do_serialize(Archive &_ser_ar) {uint8_t s_current_version = 0; uint8_t s_version = 0; #define BEGIN_SERIALIZE_OBJECT() \ template class Archive> bool do_serialize(Archive &_ser_ar) { _ser_ar.begin_object(); bool _ser_res = do_serialize_object(_ser_ar); _ser_ar.end_object(); return _ser_res; } \ template class Archive> bool do_serialize_object(Archive &_ser_ar){ @@ -98,6 +98,28 @@ do { \ if (!_ser_ar.stream().good()) return false; \ } while (0); +#define VERSION() \ +do { \ + _ser_ar.tag("VERSION"); \ + if (!_ser_ar.stream().good()){break;} \ + _ser_ar.serialize_varint(s_version); \ + if (!_ser_ar.stream().good()) return false; \ + if(s_version > s_current_version) return false; \ +} while (0); + +#define CURRENT_VERSION(v) \ +do { \ + s_current_version = v; \ + if (_ser_ar.is_saving_arch()) { s_version = v; } \ +} while (0); + + + +#define BEGIN_VERSIONED_SERIALIZE() \ + BEGIN_SERIALIZE() \ + VERSION() + + #define DEFINE_SERIALIZATION_VERSION(v) inline static uint32_t get_serialization_version() { return v; } diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index e2aa25db..2ad3a6f4 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -740,3 +740,166 @@ TEST(Serialization, serializes_transacion_versions) validate_tx_serialisation(tx); } + +struct A +{ + std::string one; + std::string two; + std::vector vector_one; + + BEGIN_SERIALIZE() + FIELD(one) + FIELD(two) + FIELD(vector_one) + END_SERIALIZE() +}; + +struct A_v1 : public A +{ + std::vector vector_two; + + + BEGIN_SERIALIZE() + CURRENT_VERSION(1) + FIELD(one) + FIELD(two) + FIELD(vector_one) + VERSION() + if (s_version < 1) return true; + FIELD(vector_two) + END_SERIALIZE() +}; + +struct A_v2 : public A_v1 +{ + std::vector vector_3; + std::vector vector_4; + + + BEGIN_SERIALIZE() + CURRENT_VERSION(2) + FIELD(one) + FIELD(two) + FIELD(vector_one) + VERSION() + if (s_version < 1) return true; + FIELD(vector_two) + if (s_version < 2) return true; + FIELD(vector_3) + FIELD(vector_4) + END_SERIALIZE() +}; + +struct A_v3 : public A_v2 +{ + std::vector vector_5; + + BEGIN_SERIALIZE() + CURRENT_VERSION(3) + FIELD(one) + FIELD(two) + FIELD(vector_one) + VERSION() + if (s_version < 1) return true; + FIELD(vector_two) + if (s_version < 2) return true; + FIELD(vector_3) + FIELD(vector_4) + if (s_version < 3) return true; + FIELD(vector_4) + END_SERIALIZE() +}; + +inline bool operator==(const A& lhs, const A& rhs) +{ + if ((lhs.one != rhs.one || lhs.two != rhs.two || lhs.vector_one != rhs.vector_one)) + { + return false; + } + return true; +} + +inline bool operator==(const A_v1& lhs, const A_v1& rhs) +{ + if (!(static_cast(lhs) == static_cast(rhs))) + return false; + if ((lhs.vector_two != rhs.vector_two)) + { + return false; + } + return true; +} + +inline bool operator==(const A_v2& lhs, const A_v2& rhs) +{ + if (!(static_cast(lhs) == static_cast(rhs))) + return false; + if ((lhs.vector_3 != rhs.vector_3)) + { + return false; + } + return true; +} + +inline bool operator==(const A_v3& lhs, const A_v3& rhs) +{ + if (!(static_cast(lhs) == static_cast(rhs))) + return false; + if ((lhs.vector_5 != rhs.vector_5)) + { + return false; + } + return true; +} + +template +bool perform_test_ser_vers(second& f) +{ + string blob; + first s_s = AUTO_VAL_INIT(s_s); + if (!serialization::dump_binary(f, blob)) + return false; + if (!serialization::parse_binary(blob, s_s)) + return false; + + + if (!(f == static_cast(s_s))) + { + return false; + } + return true; +} + +TEST(Serialization, versioning2) +{ + A_v3 a_3; + a_3.one = "one"; + a_3.two = "two"; + a_3.vector_one.push_back(a_3.one); + a_3.vector_one.push_back(a_3.two); + a_3.vector_two = a_3.vector_one; + a_3.vector_5 = a_3.vector_4 = a_3.vector_3 = a_3.vector_two; + + A_v2 a_2(a_3); + A_v1 a_1(a_3); + A a(a_3); + + bool r = perform_test_ser_vers(a); + ASSERT_TRUE(r); + r = perform_test_ser_vers(a); + ASSERT_TRUE(r); + r = perform_test_ser_vers(a); + ASSERT_TRUE(r); + + r = perform_test_ser_vers(a_1); + ASSERT_TRUE(r); + r = perform_test_ser_vers(a_1); + ASSERT_TRUE(r); + + r = perform_test_ser_vers(a_2); + ASSERT_TRUE(r); + + r = perform_test_ser_vers(a_3); + ASSERT_TRUE(r); + +} \ No newline at end of file From 43c0c7944dabef6940090a6efd47475c231767be Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 26 Sep 2022 21:57:24 +0200 Subject: [PATCH 02/49] inital code for submiting asset descriptor --- src/currency_core/currency_basic.h | 45 ++++++++++++++++++++++++++++-- src/wallet/wallet2.cpp | 18 ++++++++++++ src/wallet/wallet2.h | 3 +- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index af113532..77f7dee9 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -703,10 +703,48 @@ namespace currency FIELD(ticker) FIELD(full_name) FIELD(owner) - END_SERIALIZE() + END_SERIALIZE() + + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(total_max_supply) + BOOST_SERIALIZE(current_supply) + BOOST_SERIALIZE(decimal_point) + BOOST_SERIALIZE(ticker) + BOOST_SERIALIZE(full_name) + BOOST_SERIALIZE(owner) + END_BOOST_SERIALIZATION() }; +#define ASSET_DESCRIPTOR_OPERATION_UNDEFINED 0 +#define ASSET_DESCRIPTOR_OPERATION_REGISTER 1 +#define ASSET_DESCRIPTOR_OPERATION_UPDATE 2 + + + struct asset_descriptor_operation + { + uint8_t operation_type = ASSET_DESCRIPTOR_OPERATION_UNDEFINED; + std::vector proof; + asset_descriptor_base descriptor; + + + BEGIN_VERSIONED_SERIALIZE() + FIELD(operation_type) + FIELD(proof) + FIELD(descriptor) + END_SERIALIZE() + + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(operation_type) + BOOST_SERIALIZE(proof) + BOOST_SERIALIZE(descriptor) + END_BOOST_SERIALIZATION() + }; + + + struct extra_padding { @@ -775,7 +813,7 @@ namespace currency typedef boost::mpl::vector24< tx_service_attachment, tx_comment, tx_payer_old, tx_receiver_old, tx_derivation_hint, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry_old, extra_user_data, extra_padding, etc_tx_flags16_t, etc_tx_details_unlock_time2, - tx_payer, tx_receiver, extra_alias_entry, zarcanum_tx_data_v1, zarcanum_outs_range_proof, zc_balance_proof + tx_payer, tx_receiver, extra_alias_entry, zarcanum_tx_data_v1, zarcanum_outs_range_proof, zc_balance_proof, asset_descriptor_operation > all_payload_types; typedef boost::make_variant_over::type payload_items_v; @@ -1102,6 +1140,9 @@ SET_VARIANT_TAGS(currency::zc_balance_proof, 46, "zc_balance_proof"); SET_VARIANT_TAGS(currency::open_asset_id, 47, "asset_id"); +SET_VARIANT_TAGS(currency::asset_descriptor_operation, 48, "asset_descriptor_base"); + + #undef SET_VARIANT_TAGS diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 4aa78072..cf8ad1b7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4121,6 +4121,24 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren destinations.push_back(tx_dest_alias_reward); transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); +} +//---------------------------------------------------------------------------------------------------- +void wallet2::publish_new_asset(const asset_descriptor_base& asset_info, const std::vector& destinations) +{ + asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); + asset_reg_info.descriptor = asset_info; + asset_reg_info.operation_type = ASSET_DESCRIPTOR_OPERATION_REGISTER; + + + std::vector destinations_local = destinations; + std::vector extra; + std::vector attachments; + + extra.push_back(asset_reg_info); + + transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); + + } //---------------------------------------------------------------------------------------------------- void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f75b1e98..c6837a08 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -551,7 +551,8 @@ namespace tools void request_alias_registration(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward, const crypto::secret_key& authority_key = currency::null_skey); void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); bool check_available_sources(std::list& amounts); - + + void publish_new_asset(const asset_descriptor_base& asset_info, const std::vector& destinations); bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size); From a718895fd7dccc00d7e9f2821d739bf9f948e597 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 27 Sep 2022 20:13:49 +0200 Subject: [PATCH 03/49] Asset id context in wallet: basic implementations --- src/crypto/crypto-sugar.h | 9 ++++ src/currency_core/crypto_config.h | 4 ++ src/currency_core/currency_basic.h | 5 +- src/currency_core/currency_config.h | 2 +- src/currency_core/currency_format_utils.cpp | 29 ++++++++++ src/currency_core/currency_format_utils.h | 9 ++++ src/wallet/wallet2.cpp | 59 +++++++++++++++++---- src/wallet/wallet2.h | 19 ++++++- 8 files changed, 122 insertions(+), 14 deletions(-) diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index 280a8f79..3d2e0457 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -1153,6 +1153,15 @@ namespace crypto return hs_calculator.calc_hash(); } + static scalar_t hs(const char(&str32)[32], const crypto::key_derivation& derivation, uint64_t index) + { + hs_t hs_calculator(3); + hs_calculator.add_32_chars(str32); + hs_calculator.add_pub_key(reinterpret_cast(derivation)); + hs_calculator.add_scalar(index); + return hs_calculator.calc_hash(); + } + static point_t hp(const point_t& p) { point_t result; diff --git a/src/currency_core/crypto_config.h b/src/currency_core/crypto_config.h index 06eaa3e8..4203f4bb 100644 --- a/src/currency_core/crypto_config.h +++ b/src/currency_core/crypto_config.h @@ -6,6 +6,7 @@ // hash domain separation strings, 32 bytes long (31 chars + \0) // + #define CRYPTO_HDS_OUT_AMOUNT_MASK "ZANO_HDS_OUT_AMOUNT_MASK_______" #define CRYPTO_HDS_OUT_BLINDING_MASK "ZANO_HDS_OUT_BLINDING_MASK_____" #define CRYPTO_HDS_OUT_CONCEALING_POINT "ZANO_HDS_OUT_CONCEALING_POINT__" @@ -22,3 +23,6 @@ #define CRYPTO_HDS_ZARCANUM_LAST_POW_HASH "ZANO_HDS_ZARCANUM_LAST_POW_HASH" #define CRYPTO_HDS_ZARCANUM_SECRET_Q "ZANO_HDS_ZARCANUM_SECRET_Q_____" + +#define CRYPTO_HDS_ASSET_CONTROL_KEY "ZANO_HDS_ASSET_CONTROL_KEY_____" +#define CRYPTO_HDS_ASSET_ID "ZANO_HDS_ASSET_ID______________" diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 77f7dee9..1ed699e6 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -719,7 +719,8 @@ namespace currency #define ASSET_DESCRIPTOR_OPERATION_UNDEFINED 0 #define ASSET_DESCRIPTOR_OPERATION_REGISTER 1 -#define ASSET_DESCRIPTOR_OPERATION_UPDATE 2 +#define ASSET_DESCRIPTOR_OPERATION_EMMIT 2 +#define ASSET_DESCRIPTOR_OPERATION_UPDATE 3 struct asset_descriptor_operation @@ -810,7 +811,7 @@ namespace currency END_SERIALIZE() }; - typedef boost::mpl::vector24< + typedef boost::mpl::vector25< tx_service_attachment, tx_comment, tx_payer_old, tx_receiver_old, tx_derivation_hint, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry_old, extra_user_data, extra_padding, etc_tx_flags16_t, etc_tx_details_unlock_time2, tx_payer, tx_receiver, extra_alias_entry, zarcanum_tx_data_v1, zarcanum_outs_range_proof, zc_balance_proof, asset_descriptor_operation diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index c6246d79..c87f8541 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -231,7 +231,7 @@ #define BC_OFFERS_CURRENCY_MARKET_FILENAME "market.bin" #ifndef TESTNET -#define WALLET_FILE_SERIALIZATION_VERSION 153 +#define WALLET_FILE_SERIALIZATION_VERSION 154 #else #define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+69) #endif diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 3292ab8c..d6b870e1 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -807,6 +807,17 @@ namespace currency return derive_public_key_from_target_address(destination_addr, tx_sec_key, index, out_eph_public_key, derivation); } //--------------------------------------------------------------- + bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::public_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index) + { + crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); + bool r = crypto::generate_key_derivation(src_pub_key, src_sec_key, derivation); + CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << src_pub_key << ", " << src_sec_key << ")"); + scalar_t sec_key = crypto::hash_helper_t::hs(hs_domain, derivation, index); + derived_sec_key = sec_key.as_secret_key(); + derived_pub_key = (sec_key * crypto::c_point_G).to_public_key(); + return true; + } + //--------------------------------------------------------------- // derivation = 8 * tx_sec_key * destination_addr.view_public_key // out_eph_public_key = destination_addr.spend_public_key + Hs(derivation, index) * G bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key, crypto::key_derivation& derivation) @@ -1970,6 +1981,18 @@ namespace currency } } + + if (tx.version > TRANSACTION_VERSION_PRE_HF4) + { + asset_descriptor_operation ado = AUTO_VAL_INIT(ado); + if (get_type_in_variant_container(tx.extra, ado)) + { + crypto::secret_key stub = AUTO_VAL_INIT(stub); + bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, ado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); + CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); + } + } + //sort inputs and mapping if it's zarcanum hardfork if (tx.version > TRANSACTION_VERSION_PRE_HF4) { @@ -3313,6 +3336,12 @@ namespace currency tv.type = "zc_balance_proof"; return true; } + template + bool operator()(const t_type& t_t) + { + tv.type = typeid(t_t).name(); + return true; + } }; //------------------------------------------------------------------ template diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 0e0da357..51cf782a 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -315,6 +315,8 @@ namespace currency bool generate_key_image_helper(const account_keys& ack, const crypto::public_key& tx_public_key, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki); bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key, crypto::key_derivation& derivation); bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key); + bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::public_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index = 0); + std::string short_hash_str(const crypto::hash& h); bool is_mixattr_applicable_for_fake_outs_counter(uint8_t mix_attr, uint64_t fake_attr_count); bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t current_blockchain_size, uint64_t current_time); @@ -536,6 +538,13 @@ namespace currency return print_fixed_decimal_point(amount, CURRENCY_DISPLAY_DECIMAL_POINT); } //--------------------------------------------------------------- + + template + std::string print_asset_money(t_number amount, size_t decimal_point) + { + return print_fixed_decimal_point(amount, decimal_point); + } + //--------------------------------------------------------------- template bool alias_rpc_details_to_alias_info(const alias_rpc_details_t& ard, currency::extra_alias_entry& ai) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index cf8ad1b7..51638b1e 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -752,6 +752,48 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t } } + if (ptc.tx_money_spent_in_ins) + { + //check if there are asset_registration that belong to this wallet + asset_descriptor_operation ado = AUTO_VAL_INIT(ado); + if (get_type_in_variant_container(tx.extra, ado)) + { + if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) + { + crypto::public_key self_check = AUTO_VAL_INIT(self_check); + crypto::secret_key asset_control_key = AUTO_VAL_INIT(asset_control_key); + bool r = derive_key_pair_from_key_pair(tx_pub_key, m_account.get_keys().spend_secret_key, asset_control_key, self_check, CRYPTO_HDS_ASSET_CONTROL_KEY); + if (!r) + { + //not critical error, continue to work + LOG_ERROR("Failed to derive_key_pair_from_key_pair for asset_descriptor_operation in tx " << get_transaction_hash(tx)); + }else + { + if (self_check != ado.descriptor.owner) + { + //still not critical error + LOG_ERROR("Public key from asset_descriptor_operation(" << ado.descriptor.owner << ") not much with derived public key(" << self_check << "), for tx" << get_transaction_hash(tx)); + } + else + { + wallet_own_asset_context& asset_context = m_own_asset_descriptors[hash_helper_t::hs(CRYPTO_HDS_ASSET_ID, ado.descriptor.owner), 0]; + asset_context.asset_descriptor = ado.descriptor; + std::stringstream ss; + ss << "New Asset Registered:" + << ENDL << "Name: " << asset_context.asset_descriptor.full_name + << ENDL << "Ticker: " << asset_context.asset_descriptor.ticker + << ENDL << "Total Max Supply: " << print_asset_money(asset_context.asset_descriptor.total_max_supply, asset_context.asset_descriptor.decimal_point) + << ENDL << "Current Supply: " << print_asset_money(asset_context.asset_descriptor.current_supply, asset_context.asset_descriptor.decimal_point) + << ENDL << "DecimalPoint: " << asset_context.asset_descriptor.decimal_point; + + WLT_LOG_MAGENTA(ss.str() << , LOG_LEVEL_0); + if (m_wcallback) + m_wcallback->on_message(i_wallet2_callback::ms_yellow, ss.str()); + } + } + } + } + } if (ptc.tx_money_spent_in_ins) {//this actually is transfer transaction, notify about spend @@ -4123,22 +4165,19 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); } //---------------------------------------------------------------------------------------------------- -void wallet2::publish_new_asset(const asset_descriptor_base& asset_info, const std::vector& destinations) +void wallet2::publish_new_asset(const asset_descriptor_base& asset_info/*, const std::vector& destinations*/, currency::transaction& result_tx) { asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; asset_reg_info.operation_type = ASSET_DESCRIPTOR_OPERATION_REGISTER; + construct_tx_param ctp = get_default_construct_tx_param(); + //ctp.dsts = destinations; + ctp.extra.push_back(asset_reg_info); - std::vector destinations_local = destinations; - std::vector extra; - std::vector attachments; - - extra.push_back(asset_reg_info); - - transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); - - + finalized_tx ft = AUTO_VAL_INIT(ft); + this->transfer(ctp, ft, true, nullptr); + result_tx = ft.tx; } //---------------------------------------------------------------------------------------------------- void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index c6837a08..130b8ca3 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -506,6 +506,17 @@ namespace tools }; + struct wallet_own_asset_context + { + asset_descriptor_base asset_descriptor; + crypto::secret_key control_key; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(asset_descriptor) + BOOST_SERIALIZE(control_key) + END_BOOST_SERIALIZATION() + }; + void assign_account(const currency::account_base& acc); void generate(const std::wstring& path, const std::string& password, bool auditable_wallet); void restore(const std::wstring& path, const std::string& pass, const std::string& seed_or_tracking_seed, bool tracking_wallet, const std::string& seed_password); @@ -552,7 +563,7 @@ namespace tools void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); bool check_available_sources(std::list& amounts); - void publish_new_asset(const asset_descriptor_base& asset_info, const std::vector& destinations); + void publish_new_asset(const asset_descriptor_base& asset_info/*, const std::vector& destinations*/, currency::transaction& result_tx); bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size); @@ -804,6 +815,10 @@ namespace tools a & m_active_htlcs; a & m_active_htlcs_txid; + if (ver < 154) + return; + + a & m_own_asset_descriptors; } void wipeout_extra_if_needed(std::vector& transfer_history); @@ -1084,6 +1099,7 @@ private: std::unordered_map m_unconfirmed_txs; std::unordered_set m_unconfirmed_multisig_transfers; std::unordered_map m_tx_keys; + std::unordered_map m_own_asset_descriptors; std::multimap m_htlcs; //map [expired_if_more_then] -> height of expiration amount_gindex_to_transfer_id_container m_active_htlcs; // map [amount; gindex] -> transfer index @@ -1115,6 +1131,7 @@ private: } // namespace tools BOOST_CLASS_VERSION(tools::wallet2, WALLET_FILE_SERIALIZATION_VERSION) + BOOST_CLASS_VERSION(tools::wallet_public::wallet_transfer_info, 11) BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 3) BOOST_CLASS_VERSION(tools::wallet2::transfer_details_base, 2) From 1fd6e08e5cd9081a2a3becd17b154310569bbff4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 28 Sep 2022 22:06:07 +0200 Subject: [PATCH 04/49] initial code for introducing asset descriptor for wallet --- src/crypto/crypto-sugar.h | 3 +-- src/currency_core/currency_format_utils.cpp | 4 ++-- src/currency_core/currency_format_utils.h | 2 +- .../currency_format_utils_abstract.h | 20 +++++++++++++++++++ src/wallet/wallet2.cpp | 7 ++++--- src/wallet/wallet2.h | 4 ++-- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index 3d2e0457..572e09d5 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -1200,7 +1200,6 @@ namespace crypto { // hs won't touch memory if size is 0, so it's safe return hash_helper_t::hs(data(), sizeof(scalar_t) * size()); - } - + } } // namespace crypto diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index d6b870e1..d0e5c424 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -807,12 +807,12 @@ namespace currency return derive_public_key_from_target_address(destination_addr, tx_sec_key, index, out_eph_public_key, derivation); } //--------------------------------------------------------------- - bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::public_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index) + bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::secret_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index) { crypto::key_derivation derivation = AUTO_VAL_INIT(derivation); bool r = crypto::generate_key_derivation(src_pub_key, src_sec_key, derivation); CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << src_pub_key << ", " << src_sec_key << ")"); - scalar_t sec_key = crypto::hash_helper_t::hs(hs_domain, derivation, index); + crypto::scalar_t sec_key = crypto::hash_helper_t::hs(hs_domain, derivation, index); derived_sec_key = sec_key.as_secret_key(); derived_pub_key = (sec_key * crypto::c_point_G).to_public_key(); return true; diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 51cf782a..ac5e1ef7 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -315,7 +315,7 @@ namespace currency bool generate_key_image_helper(const account_keys& ack, const crypto::public_key& tx_public_key, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki); bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key, crypto::key_derivation& derivation); bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key); - bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::public_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index = 0); + bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::secret_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index = 0); std::string short_hash_str(const crypto::hash& h); bool is_mixattr_applicable_for_fake_outs_counter(uint8_t mix_attr, uint64_t fake_attr_count); diff --git a/src/currency_core/currency_format_utils_abstract.h b/src/currency_core/currency_format_utils_abstract.h index addfd80a..b26e906f 100644 --- a/src/currency_core/currency_format_utils_abstract.h +++ b/src/currency_core/currency_format_utils_abstract.h @@ -353,6 +353,26 @@ namespace currency size_t get_object_blobsize(const transaction& t, uint64_t prefix_blob_size); + inline + void put_t_to_buff(std::string& buff) + {} + + template + void put_t_to_buff(std::string& buff, const T& var1, Types&... var2) + { + static_assert(std::is_pod::value, "T must be a POD type."); + buff.append((const char*)&var1, sizeof(var1)); + put_t_to_buff(buff, var2...); + } + + template + crypto::hash get_hash_from_POD_objects(Types&... var1) + { + std::string buff; + put_t_to_buff(buff, var1...); + return crypto::cn_fast_hash(buff.data(), buff.size()); + } + #define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val) \ CHECK_AND_ASSERT_MES(variant_var.type() == typeid(specific_type), fail_return_val, "wrong variant type: " << variant_var.type().name() << ", expected " << typeid(specific_type).name()); \ diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 51638b1e..9462b9dc 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -776,7 +776,8 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t } else { - wallet_own_asset_context& asset_context = m_own_asset_descriptors[hash_helper_t::hs(CRYPTO_HDS_ASSET_ID, ado.descriptor.owner), 0]; + + wallet_own_asset_context& asset_context = m_own_asset_descriptors[get_hash_from_POD_objects(CRYPTO_HDS_ASSET_ID, ado.descriptor.owner)]; asset_context.asset_descriptor = ado.descriptor; std::stringstream ss; ss << "New Asset Registered:" @@ -786,7 +787,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t << ENDL << "Current Supply: " << print_asset_money(asset_context.asset_descriptor.current_supply, asset_context.asset_descriptor.decimal_point) << ENDL << "DecimalPoint: " << asset_context.asset_descriptor.decimal_point; - WLT_LOG_MAGENTA(ss.str() << , LOG_LEVEL_0); + WLT_LOG_MAGENTA(ss.str(), LOG_LEVEL_0); if (m_wcallback) m_wcallback->on_message(i_wallet2_callback::ms_yellow, ss.str()); } @@ -4165,7 +4166,7 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); } //---------------------------------------------------------------------------------------------------- -void wallet2::publish_new_asset(const asset_descriptor_base& asset_info/*, const std::vector& destinations*/, currency::transaction& result_tx) +void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx) { asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 130b8ca3..27acfc69 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -508,7 +508,7 @@ namespace tools struct wallet_own_asset_context { - asset_descriptor_base asset_descriptor; + currency::asset_descriptor_base asset_descriptor; crypto::secret_key control_key; BEGIN_BOOST_SERIALIZATION() @@ -563,7 +563,7 @@ namespace tools void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); bool check_available_sources(std::list& amounts); - void publish_new_asset(const asset_descriptor_base& asset_info/*, const std::vector& destinations*/, currency::transaction& result_tx); + void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx); bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size); From 7d8259f58c9d8d391a85b87dd9bef7dc280551ef Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Sep 2022 19:18:05 +0200 Subject: [PATCH 05/49] added code for handling chain detachment(reorg) --- src/currency_core/currency_format_utils.cpp | 40 ++++++++++++++------- src/wallet/wallet2.cpp | 13 +++++-- src/wallet/wallet2.h | 2 ++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index d0e5c424..34ba13b0 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1711,6 +1711,13 @@ namespace currency return true; } + + crypto::hash get_asset_id_from_descriptor(const asset_descriptor_base& adb) + { + return get_hash_from_POD_objects(CRYPTO_HDS_ASSET_ID, adb.owner); + } + + bool construct_tx(const account_keys& sender_account_keys, const finalize_tx_param& ftp, finalized_tx& result) { const std::vector& sources = ftp.sources; @@ -1797,6 +1804,19 @@ namespace currency //std::vector zc_sources; //std::vector NLSAG_sources; + crypto::hash asset_id_for_destinations = currency::null_hash; + if (tx.version > TRANSACTION_VERSION_PRE_HF4) + { + asset_descriptor_operation ado = AUTO_VAL_INIT(ado); + if (get_type_in_variant_container(tx.extra, ado)) + { + crypto::secret_key stub = AUTO_VAL_INIT(stub); + bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, ado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); + CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); + //also assign this asset id to destinations + asset_id_for_destinations = get_asset_id_from_descriptor(ado.descriptor); + } + } std::vector in_contexts; @@ -1927,6 +1947,14 @@ namespace currency // "Shuffle" outs std::vector shuffled_dsts(destinations); + if (asset_id_for_destinations != currency::null_hash) + { + //must be asset publication + for (auto& item : shuffled_dsts) + { + item.asset_id = asset_id_for_destinations; + } + } if (shuffle) std::sort(shuffled_dsts.begin(), shuffled_dsts.end(), [](const tx_destination_entry& de1, const tx_destination_entry& de2) { return de1.amount < de2.amount; }); @@ -1981,18 +2009,6 @@ namespace currency } } - - if (tx.version > TRANSACTION_VERSION_PRE_HF4) - { - asset_descriptor_operation ado = AUTO_VAL_INIT(ado); - if (get_type_in_variant_container(tx.extra, ado)) - { - crypto::secret_key stub = AUTO_VAL_INIT(stub); - bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, ado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); - CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); - } - } - //sort inputs and mapping if it's zarcanum hardfork if (tx.version > TRANSACTION_VERSION_PRE_HF4) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9462b9dc..b95a535c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -775,10 +775,10 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t LOG_ERROR("Public key from asset_descriptor_operation(" << ado.descriptor.owner << ") not much with derived public key(" << self_check << "), for tx" << get_transaction_hash(tx)); } else - { - + { wallet_own_asset_context& asset_context = m_own_asset_descriptors[get_hash_from_POD_objects(CRYPTO_HDS_ASSET_ID, ado.descriptor.owner)]; asset_context.asset_descriptor = ado.descriptor; + asset_context.height = height; std::stringstream ss; ss << "New Asset Registered:" << ENDL << "Name: " << asset_context.asset_descriptor.full_name @@ -2550,6 +2550,15 @@ void wallet2::detach_blockchain(uint64_t including_height) ++it; } + //asset descriptors + for (auto it = m_own_asset_descriptors.begin(); it != m_own_asset_descriptors.end(); ) + { + if (including_height <= it->second.height) + it = m_own_asset_descriptors.erase(it); + else + ++it; + } + WLT_LOG_L0("Detached blockchain on height " << including_height << ", transfers detached " << transfers_detached << ", blocks detached " << blocks_detached); } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 27acfc69..2d45cc8c 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -510,10 +510,12 @@ namespace tools { currency::asset_descriptor_base asset_descriptor; crypto::secret_key control_key; + uint64_t height = 0; BEGIN_BOOST_SERIALIZATION() BOOST_SERIALIZE(asset_descriptor) BOOST_SERIALIZE(control_key) + BOOST_SERIALIZE(height) END_BOOST_SERIALIZATION() }; From c61149f4805e4d8513a6039e336242d564559bc3 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 29 Sep 2022 23:44:00 +0200 Subject: [PATCH 06/49] added put/pop asset info to core --- src/currency_core/blockchain_storage.cpp | 71 +++++++++++++++++++++ src/currency_core/blockchain_storage.h | 8 +++ src/currency_core/currency_basic.h | 8 ++- src/currency_core/currency_format_utils.cpp | 10 ++- src/currency_core/currency_format_utils.h | 1 + src/currency_core/dispatch_core_events.h | 1 + 6 files changed, 90 insertions(+), 9 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index aefd7a0e..ba711c66 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -59,6 +59,7 @@ using namespace currency; #define BLOCKCHAIN_STORAGE_CONTAINER_ADDR_TO_ALIAS "addr_to_alias" #define BLOCKCHAIN_STORAGE_CONTAINER_TX_FEE_MEDIAN "median_fee2" #define BLOCKCHAIN_STORAGE_CONTAINER_GINDEX_INCS "gindex_increments" +#define BLOCKCHAIN_STORAGE_CONTAINER_ASSETS "assets" #define BLOCKCHAIN_STORAGE_OPTIONS_ID_CURRENT_BLOCK_CUMUL_SZ_LIMIT 0 #define BLOCKCHAIN_STORAGE_OPTIONS_ID_CURRENT_PRUNED_RS_HEIGHT 1 @@ -95,6 +96,7 @@ blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) :m_db(nullptr, m m_db_multisig_outs(m_db), m_db_solo_options(m_db), m_db_aliases(m_db), + m_db_assets(m_db), m_db_addr_to_alias(m_db), m_read_lock(m_rw_lock), m_db_current_block_cumul_sz_limit(BLOCKCHAIN_STORAGE_OPTIONS_ID_CURRENT_BLOCK_CUMUL_SZ_LIMIT, m_db_solo_options), @@ -297,6 +299,7 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro m_db_multisig_outs.set_cache_size(cache_size); m_db_solo_options.set_cache_size(cache_size); m_db_aliases.set_cache_size(cache_size); + m_db_assets.set_cache_size(cache_size); m_db_addr_to_alias.set_cache_size(cache_size); } @@ -414,6 +417,7 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro m_db_multisig_outs.deinit(); m_db_solo_options.deinit(); m_db_aliases.deinit(); + m_db_assets.deinit(); m_db_addr_to_alias.deinit(); m_db_per_block_gindex_incs.deinit(); m_db.close(); @@ -660,6 +664,7 @@ bool blockchain_storage::clear() m_db_outputs.clear(); m_db_multisig_outs.clear(); m_db_aliases.clear(); + m_db_assets.clear(); m_db_addr_to_alias.clear(); m_db_per_block_gindex_incs.clear(); m_pos_targetdata_cache.clear(); @@ -1546,6 +1551,7 @@ void blockchain_storage::reset_db_cache() const m_db_solo_options.clear_cache(); m_db_multisig_outs.clear_cache(); m_db_aliases.clear_cache(); + m_db_assets.clear_cache(); m_db_addr_to_alias.clear_cache(); } @@ -2953,6 +2959,7 @@ void blockchain_storage::print_db_cache_perfeormance_data() const DB_CONTAINER_PERF_DATA_ENTRY(m_db_multisig_outs) << ENDL DB_CONTAINER_PERF_DATA_ENTRY(m_db_solo_options) << ENDL DB_CONTAINER_PERF_DATA_ENTRY(m_db_aliases) << ENDL + DB_CONTAINER_PERF_DATA_ENTRY(m_db_assets) << ENDL DB_CONTAINER_PERF_DATA_ENTRY(m_db_addr_to_alias) << ENDL //DB_CONTAINER_PERF_DATA_ENTRY(m_db_per_block_gindex_incs) << ENDL //DB_CONTAINER_PERF_DATA_ENTRY(m_tx_fee_median) << ENDL @@ -3518,6 +3525,27 @@ uint64_t blockchain_storage::get_aliases_count() const return m_db_aliases.size(); } //------------------------------------------------------------------ +bool blockchain_storage::get_asset_info(const crypto::hash& asset_id, asset_descriptor_base& info)const +{ + CRITICAL_REGION_LOCAL(m_read_lock); + auto as_ptr = m_db_assets.find(asset_id); + if (as_ptr) + { + if (as_ptr->size()) + { + info = as_ptr->back(); + return true; + } + } + return false; +} +//------------------------------------------------------------------ +uint64_t blockchain_storage::get_assets_count() const +{ + CRITICAL_REGION_LOCAL(m_read_lock); + return m_db_assets.size(); +} +//------------------------------------------------------------------ std::string blockchain_storage::get_alias_by_address(const account_public_address& addr)const { auto alias_ptr = m_db_addr_to_alias.find(addr); @@ -3700,6 +3728,49 @@ bool blockchain_storage::put_alias_info(const transaction & tx, extra_alias_entr return true; } //------------------------------------------------------------------ +bool blockchain_storage::pop_asset_info(const crypto::hash& asset_id) +{ + CRITICAL_REGION_LOCAL(m_read_lock); + + auto asset_history_ptr = m_db_assets.find(asset_id); + CHECK_AND_ASSERT_MES(asset_history_ptr && asset_history_ptr->size(), false, "empty name list in pop_asset_info"); + + assets_container::t_value_type local_asset_hist = *asset_history_ptr; + local_asset_hist.pop_back(); + if (local_asset_hist.size()) + m_db_aliases.set(asset_id, local_asset_hist); + else + m_db_aliases.erase(asset_id); + + LOG_PRINT_MAGENTA("[ASSET_POP]: " << asset_id << ": " << (!local_asset_hist.empty() ? "(prev)" : "(erased)"), LOG_LEVEL_1); + return true; +} +//------------------------------------------------------------------ +bool blockchain_storage::put_asset_info(const transaction & tx, asset_descriptor_operation & ado) +{ + CRITICAL_REGION_LOCAL(m_read_lock); + if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) + { + crypto::hash asset_id = get_asset_id_from_descriptor(ado.descriptor); + auto asset_history_ptr = m_db_aliases.find(asset_id); + CHECK_AND_ASSERT_MES(!asset_history_ptr, false, "Asset id already existing"); + assets_container::t_value_type local_asset_history = AUTO_VAL_INIT(local_asset_history); + local_asset_history.push_back(ado.descriptor); + m_db_assets.set(asset_id, local_asset_history); + LOG_PRINT_MAGENTA("[ASSET_REGISTERED]: " << asset_id << ": " << ado.descriptor.full_name, LOG_LEVEL_1); + //TODO: + //rise_core_event(CORE_EVENT_ADD_ASSET, alias_info_to_rpc_alias_info(ai)); + + } + else + { + //TODO: implement other operations + CHECK_AND_ASSERT_THROW(false, "not implemented yet"); + } + + return true; +} +//------------------------------------------------------------------ void blockchain_storage::set_event_handler(i_core_event_handler* event_handler) const { if (event_handler == nullptr) diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 15d027bb..92ab3049 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -288,6 +288,8 @@ namespace currency uint64_t get_aliases_count()const; uint64_t get_block_h_older_then(uint64_t timestamp) const; bool validate_tx_service_attachmens_in_services(const tx_service_attachment& a, size_t i, const transaction& tx)const; + bool get_asset_info(const crypto::hash& asset_id, asset_descriptor_base& info)const; + uint64_t get_assets_count() const; bool check_tx_input(const transaction& tx, size_t in_index, const txin_to_key& txin, const crypto::hash& tx_prefix_hash, uint64_t& max_related_block_height, uint64_t& source_max_unlock_time_for_pos_coinbase)const; bool check_tx_input(const transaction& tx, size_t in_index, const txin_multisig& txin, const crypto::hash& tx_prefix_hash, uint64_t& max_related_block_height)const; bool check_tx_input(const transaction& tx, size_t in_index, const txin_htlc& txin, const crypto::hash& tx_prefix_hash, uint64_t& max_related_block_height)const; @@ -486,6 +488,9 @@ namespace currency typedef tools::db::cached_key_value_accessor multisig_outs_container;// ms out id => ms_output_entry typedef tools::db::cached_key_value_accessor solo_options_container; typedef tools::db::basic_key_value_accessor per_block_gindex_increments_container; // height => [(amount, gindex_increment), ...] + + typedef tools::db::cached_key_value_accessor, true, false> assets_container; + //----------------------------------------- @@ -527,6 +532,7 @@ namespace currency address_to_aliases_container m_db_addr_to_alias; per_block_gindex_increments_container m_db_per_block_gindex_incs; + assets_container m_db_assets; @@ -645,6 +651,8 @@ namespace currency bool unprocess_blockchain_tx_attachments(const transaction& tx, uint64_t h, uint64_t timestamp); bool pop_alias_info(const extra_alias_entry& ai); bool put_alias_info(const transaction& tx, extra_alias_entry& ai); + bool pop_asset_info(const crypto::hash& asset_id); + bool put_asset_info(const transaction & tx, asset_descriptor_operation & ado); void fill_addr_to_alias_dict(); //bool resync_spent_tx_flags(); bool prune_ring_signatures_and_attachments_if_need(); diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 074d0dd3..ae103568 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -725,15 +725,17 @@ namespace currency struct asset_descriptor_operation { - uint8_t operation_type = ASSET_DESCRIPTOR_OPERATION_UNDEFINED; - std::vector proof; - asset_descriptor_base descriptor; + uint8_t operation_type = ASSET_DESCRIPTOR_OPERATION_UNDEFINED; + std::vector proof; + asset_descriptor_base descriptor; + std::vector asset_id; //questionable regarding form of optional fields BEGIN_VERSIONED_SERIALIZE() FIELD(operation_type) FIELD(proof) FIELD(descriptor) + FIELD(asset_id) END_SERIALIZE() diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 90bd203a..e69415d0 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1797,9 +1797,8 @@ namespace currency tx.extra.insert(tx.extra.end(), extra_local.begin(), extra_local.end()); } -// //first: separate zarcanum inputs and regular one - //std::vector zc_sources; - //std::vector NLSAG_sources; + + uint64_t summary_inputs_money = 0; crypto::hash asset_id_for_destinations = currency::null_hash; if (tx.version > TRANSACTION_VERSION_PRE_HF4) @@ -1812,6 +1811,8 @@ namespace currency CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); //also assign this asset id to destinations asset_id_for_destinations = get_asset_id_from_descriptor(ado.descriptor); + //TODO: temporary + summary_inputs_money += ado.descriptor.current_supply; } } @@ -1824,7 +1825,6 @@ namespace currency size_t current_index = 0; inputs_mapping.resize(sources.size()); size_t input_starter_index = tx.vin.size(); - uint64_t summary_inputs_money = 0; //fill inputs NLSAG and Zarcanum for (const tx_source_entry& src_entr : sources) { @@ -2055,8 +2055,6 @@ namespace currency if (tx.attachment.size()) add_attachments_info_to_extra(tx.extra, tx.attachment); } - - // // generate ring signatures // diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index b5f535ba..17e5e251 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -288,6 +288,7 @@ namespace currency uint64_t get_tx_version(uint64_t h, const hard_forks_descriptor& hfd); bool construct_tx(const account_keys& sender_account_keys, const finalize_tx_param& param, finalized_tx& result); + crypto::hash get_asset_id_from_descriptor(const asset_descriptor_base& adb); bool sign_multisig_input_in_tx(currency::transaction& tx, size_t ms_input_index, const currency::account_keys& keys, const currency::transaction& source_tx, bool *p_is_input_fully_signed = nullptr); diff --git a/src/currency_core/dispatch_core_events.h b/src/currency_core/dispatch_core_events.h index dadff8b1..19d3df40 100644 --- a/src/currency_core/dispatch_core_events.h +++ b/src/currency_core/dispatch_core_events.h @@ -17,6 +17,7 @@ #define CORE_EVENT_ADD_ALIAS "CORE_EVENT_ADD_ALIAS" #define CORE_EVENT_UPDATE_ALIAS "CORE_EVENT_UPDATE_ALIAS" #define CORE_EVENT_BLOCK_ADDED "CORE_EVENT_BLOCK_ADDED" +#define CORE_EVENT_ADD_ASSET "CORE_EVENT_ADD_ASSET" namespace currency From 5ab9a2b9743d202db05f3d10335ba51ee5aab372 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 30 Sep 2022 21:23:06 +0200 Subject: [PATCH 07/49] fixed compilation issues regarding asset_descriptors --- src/currency_core/blockchain_storage.cpp | 32 +++++++++++++++++---- src/currency_core/blockchain_storage.h | 2 +- src/currency_core/currency_basic.h | 2 ++ src/currency_core/currency_format_utils.cpp | 22 ++++++++++++-- src/currency_core/currency_format_utils.h | 1 + src/wallet/wallet2.cpp | 6 ++-- 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index ba711c66..e805b0cb 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3501,6 +3501,22 @@ bool blockchain_storage::unprocess_blockchain_tx_extra(const transaction& tx) r = pop_alias_info(ei.m_alias); CHECK_AND_ASSERT_MES(r, false, "failed to pop_alias_info"); } + + if (ei.m_asset_operation.operation_type != ASSET_DESCRIPTOR_OPERATION_UNDEFINED) + { + crypto::hash asset_id = currency::null_hash; + if (ei.m_asset_operation.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) + { + asset_id = get_asset_id_from_descriptor(ei.m_asset_operation.descriptor); + } + else + { + CHECK_AND_ASSERT_MES(ei.m_asset_operation.asset_id.size() == 1, false, "Unexpected asset_id in operation"); + asset_id = ei.m_asset_operation.asset_id.back(); + } + r = pop_asset_info(asset_id); + CHECK_AND_ASSERT_MES(r, false, "failed to pop_alias_info"); + } return true; } //------------------------------------------------------------------ @@ -3533,7 +3549,7 @@ bool blockchain_storage::get_asset_info(const crypto::hash& asset_id, asset_desc { if (as_ptr->size()) { - info = as_ptr->back(); + info = as_ptr->back().descriptor; return true; } } @@ -3738,9 +3754,9 @@ bool blockchain_storage::pop_asset_info(const crypto::hash& asset_id) assets_container::t_value_type local_asset_hist = *asset_history_ptr; local_asset_hist.pop_back(); if (local_asset_hist.size()) - m_db_aliases.set(asset_id, local_asset_hist); + m_db_assets.set(asset_id, local_asset_hist); else - m_db_aliases.erase(asset_id); + m_db_assets.erase(asset_id); LOG_PRINT_MAGENTA("[ASSET_POP]: " << asset_id << ": " << (!local_asset_hist.empty() ? "(prev)" : "(erased)"), LOG_LEVEL_1); return true; @@ -3752,10 +3768,10 @@ bool blockchain_storage::put_asset_info(const transaction & tx, asset_descriptor if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) { crypto::hash asset_id = get_asset_id_from_descriptor(ado.descriptor); - auto asset_history_ptr = m_db_aliases.find(asset_id); + auto asset_history_ptr = m_db_assets.find(asset_id); CHECK_AND_ASSERT_MES(!asset_history_ptr, false, "Asset id already existing"); assets_container::t_value_type local_asset_history = AUTO_VAL_INIT(local_asset_history); - local_asset_history.push_back(ado.descriptor); + local_asset_history.push_back(ado); m_db_assets.set(asset_id, local_asset_history); LOG_PRINT_MAGENTA("[ASSET_REGISTERED]: " << asset_id << ": " << ado.descriptor.full_name, LOG_LEVEL_1); //TODO: @@ -3860,6 +3876,12 @@ bool blockchain_storage::process_blockchain_tx_extra(const transaction& tx) r = put_alias_info(tx, ei.m_alias); CHECK_AND_ASSERT_MES(r, false, "failed to put_alias_info"); } + if (ei.m_asset_operation.operation_type != ASSET_DESCRIPTOR_OPERATION_UNDEFINED) + { + r = put_asset_info(tx, ei.m_asset_operation); + CHECK_AND_ASSERT_MES(r, false, "failed to put_asset_info"); + } + return true; } //------------------------------------------------------------------ diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 92ab3049..14f74a4a 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -489,7 +489,7 @@ namespace currency typedef tools::db::cached_key_value_accessor solo_options_container; typedef tools::db::basic_key_value_accessor per_block_gindex_increments_container; // height => [(amount, gindex_increment), ...] - typedef tools::db::cached_key_value_accessor, true, false> assets_container; + typedef tools::db::cached_key_value_accessor, true, false> assets_container; //----------------------------------------- diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index ae103568..1faaf62f 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -53,6 +53,8 @@ namespace currency const static crypto::key_derivation null_derivation = AUTO_VAL_INIT(null_derivation); const static crypto::hash gdefault_genesis = epee::string_tools::hex_to_pod("CC608F59F8080E2FBFE3C8C80EB6E6A953D47CF2D6AEBD345BADA3A1CAB99852"); + const static crypto::hash ffff_hash = epee::string_tools::hex_to_pod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + typedef std::string payment_id_t; diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index e69415d0..c40d41be 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -346,8 +346,16 @@ namespace currency { if (tx.version > TRANSACTION_VERSION_PRE_HF4) { + //@#@ TODO: This is just a temporary code + uint64_t assets_emmited = 0; + asset_descriptor_operation ado = AUTO_VAL_INIT(ado); + if (get_type_in_variant_container(tx.extra, ado) && ado.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER) + { + assets_emmited += ado.descriptor.current_supply; + } + size_t zc_inputs_count = 0; - uint64_t bare_inputs_sum = additional_inputs_amount_and_fees_for_mining_tx; + uint64_t bare_inputs_sum = additional_inputs_amount_and_fees_for_mining_tx + assets_emmited; for(auto& vin : tx.vin) { VARIANT_SWITCH_BEGIN(vin); @@ -671,6 +679,7 @@ namespace currency mutable bool was_attachment; mutable bool was_userdata; mutable bool was_alias; + mutable bool was_asset; tx_extra_info& rei; const transaction& rtx; @@ -701,6 +710,12 @@ namespace currency rei.m_alias = ae; return true; } + bool operator()(const asset_descriptor_operation & ado) const + { + ENSURE_ONETIME(was_asset, "asset"); + rei.m_asset_operation = ado; + return true; + } bool operator()(const extra_alias_entry_old& ae) const { return operator()(static_cast(ae)); @@ -1949,7 +1964,10 @@ namespace currency //must be asset publication for (auto& item : shuffled_dsts) { - item.asset_id = asset_id_for_destinations; + if (item.asset_id == currency::ffff_hash) + { + item.asset_id = asset_id_for_destinations; + } } } if (shuffle) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 17e5e251..639ae636 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -70,6 +70,7 @@ namespace currency extra_alias_entry m_alias; std::string m_user_data_blob; extra_attachment_info m_attachment_info; + asset_descriptor_operation m_asset_operation; }; //--------------------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 97f9f9e2..6a78f757 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4180,9 +4180,8 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; asset_reg_info.operation_type = ASSET_DESCRIPTOR_OPERATION_REGISTER; - construct_tx_param ctp = get_default_construct_tx_param(); - //ctp.dsts = destinations; + ctp.dsts = destinations; ctp.extra.push_back(asset_reg_info); finalized_tx ft = AUTO_VAL_INIT(ft); @@ -4988,6 +4987,9 @@ assets_selection_context wallet2::get_needed_money(uint64_t fee, const std::vect amounts_map[currency::null_hash].needed_amount = fee; BOOST_FOREACH(auto& dt, dsts) { + if(dt.asset_id == currency::ffff_hash) + continue; //this destination for emmition only + THROW_IF_TRUE_WALLET_EX(0 == dt.amount, error::zero_destination); uint64_t money_to_add = dt.amount; if (dt.amount_to_provide) From 51d8c855407a5c2d536d4b87f422dc74022d977e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 3 Oct 2022 22:03:54 +0200 Subject: [PATCH 08/49] added core test for multiasset(never tried yet) --- src/currency_core/blockchain_storage.cpp | 1 - src/currency_core/currency_format_utils.cpp | 19 ++++++---- .../currency_format_utils_abstract.h | 36 +++++++++++++++---- src/wallet/wallet2.cpp | 7 +++- src/wallet/wallet2.h | 2 +- 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index e805b0cb..202983f1 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3776,7 +3776,6 @@ bool blockchain_storage::put_asset_info(const transaction & tx, asset_descriptor LOG_PRINT_MAGENTA("[ASSET_REGISTERED]: " << asset_id << ": " << ado.descriptor.full_name, LOG_LEVEL_1); //TODO: //rise_core_event(CORE_EVENT_ADD_ASSET, alias_info_to_rpc_alias_info(ai)); - } else { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index c40d41be..d04df21f 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1816,18 +1816,19 @@ namespace currency uint64_t summary_inputs_money = 0; crypto::hash asset_id_for_destinations = currency::null_hash; + asset_descriptor_operation* pado = nullptr; if (tx.version > TRANSACTION_VERSION_PRE_HF4) { - asset_descriptor_operation ado = AUTO_VAL_INIT(ado); - if (get_type_in_variant_container(tx.extra, ado)) + pado = get_type_in_variant_container(tx.extra); + if (pado) { crypto::secret_key stub = AUTO_VAL_INIT(stub); - bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, ado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); + bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, pado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); //also assign this asset id to destinations - asset_id_for_destinations = get_asset_id_from_descriptor(ado.descriptor); + asset_id_for_destinations = get_asset_id_from_descriptor(pado.descriptor); //TODO: temporary - summary_inputs_money += ado.descriptor.current_supply; + summary_inputs_money += pado.descriptor.current_supply; } } @@ -1957,19 +1958,25 @@ namespace currency tx.vin.push_back(ins_zc); }*/ - // "Shuffle" outs std::vector shuffled_dsts(destinations); if (asset_id_for_destinations != currency::null_hash) { + uint64_t amount_of_assets = 0; //must be asset publication for (auto& item : shuffled_dsts) { if (item.asset_id == currency::ffff_hash) { item.asset_id = asset_id_for_destinations; + amount_of_assets += item.amount; } } + CHECK_AND_ASSERT_MES(pado, false, "pado is null ??"); + pado->descriptor.current_supply = amount_of_assets; } + + + // "Shuffle" outs if (shuffle) std::sort(shuffled_dsts.begin(), shuffled_dsts.end(), [](const tx_destination_entry& de1, const tx_destination_entry& de2) { return de1.amount < de2.amount; }); diff --git a/src/currency_core/currency_format_utils_abstract.h b/src/currency_core/currency_format_utils_abstract.h index b26e906f..56fe20de 100644 --- a/src/currency_core/currency_format_utils_abstract.h +++ b/src/currency_core/currency_format_utils_abstract.h @@ -96,17 +96,41 @@ namespace currency template bool get_type_in_variant_container(variant_t_container& av, specific_type_t& a) { - for (auto& ai : av) + const specific_type_t* pa = get_type_in_variant_container(av); + if (pa) { - if (ai.type() == typeid(specific_type_t)) - { - a = boost::get(ai); - return true; - } + a = *pa; + return true; } return false; } //--------------------------------------------------------------- + //--------------------------------------------------------------- + template + specific_type_t* get_type_in_variant_container(variant_t_container& av) + { + for (auto& ai : av) + { + if (ai.type() == typeid(specific_type_t)) + { + return &boost::get(ai); + } + } + return nullptr; + } + //--------------------------------------------------------------- + template + specific_type_t& get_type_in_variant_container_by_ref(variant_t_container& av) + { + for (auto& ai : av) + { + if (ai.type() == typeid(specific_type_t)) + { + return boost::get(ai); + } + } + ASSERT_MES_AND_THROW("Objec not found"); + } // if cb returns true, it means "continue", false -- means "stop" template bool process_type_in_variant_container(const variant_container_t& av, callback_t& cb, bool return_value_if_none_found = true) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6a78f757..5d1dfc89 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4175,7 +4175,7 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren transfer(destinations, 0, 0, fee, extra, attachments, get_current_split_strategy(), tx_dust_policy(DEFAULT_DUST_THRESHOLD), res_tx, CURRENCY_TO_KEY_OUT_RELAXED, false); } //---------------------------------------------------------------------------------------------------- -void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx) +void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::hash& asset_id) { asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; @@ -4187,6 +4187,11 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf finalized_tx ft = AUTO_VAL_INIT(ft); this->transfer(ctp, ft, true, nullptr); result_tx = ft.tx; + //get generated asset id + currency::asset_descriptor_operation ado = AUTO_VAL_INIT(ado); + bool r = get_type_in_variant_container(result_tx.extra, ado); + CHECK_AND_ASSERT_THROW_MES(r, "Failed find asset info in tx"); + asset_id = get_asset_id_from_descriptor(ado.descriptor); } //---------------------------------------------------------------------------------------------------- void wallet2::request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 2d45cc8c..7c50704f 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -565,7 +565,7 @@ namespace tools void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); bool check_available_sources(std::list& amounts); - void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx); + void publish_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::hash& asset_id); bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size); From 5f607acda2c9af3e463b044b2c3964ecdefe75b5 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 3 Oct 2022 22:29:35 +0200 Subject: [PATCH 09/49] fixed few errors --- src/currency_core/currency_format_utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index d04df21f..569082bf 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1823,12 +1823,12 @@ namespace currency if (pado) { crypto::secret_key stub = AUTO_VAL_INIT(stub); - bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, pado.descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); + bool r = derive_key_pair_from_key_pair(sender_account_keys.account_address.spend_public_key, one_time_secret_key, stub, pado->descriptor.owner, CRYPTO_HDS_ASSET_CONTROL_KEY); CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); //also assign this asset id to destinations - asset_id_for_destinations = get_asset_id_from_descriptor(pado.descriptor); + asset_id_for_destinations = get_asset_id_from_descriptor(pado->descriptor); //TODO: temporary - summary_inputs_money += pado.descriptor.current_supply; + summary_inputs_money += pado->descriptor.current_supply; } } From d864d43aab498ab5e5305cb862ed24aec7e54c74 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 4 Oct 2022 16:29:24 +0200 Subject: [PATCH 10/49] fixes over tests --- src/currency_core/currency_format_utils.cpp | 4 +- tests/core_tests/chaingen_main.cpp | 2 + tests/core_tests/chaingen_tests_list.h | 1 + tests/core_tests/multiassets_test.cpp | 110 ++++++++++++++++++++ tests/core_tests/multiassets_test.h | 16 +++ tests/unit_tests/proxy_to_coretests.cpp | 12 +++ 6 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 tests/core_tests/multiassets_test.cpp create mode 100644 tests/core_tests/multiassets_test.h create mode 100644 tests/unit_tests/proxy_to_coretests.cpp diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 569082bf..9f149027 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1827,8 +1827,6 @@ namespace currency CHECK_AND_ASSERT_MES(r, false, "Failed to derive_public_key_from_tx_and_account_pub_key()"); //also assign this asset id to destinations asset_id_for_destinations = get_asset_id_from_descriptor(pado->descriptor); - //TODO: temporary - summary_inputs_money += pado->descriptor.current_supply; } } @@ -1973,6 +1971,8 @@ namespace currency } CHECK_AND_ASSERT_MES(pado, false, "pado is null ??"); pado->descriptor.current_supply = amount_of_assets; + //TODO: temporary + summary_inputs_money += amount_of_assets; } diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 12a0de86..e20bceea 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1060,6 +1060,8 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(isolate_auditable_and_proof); GENERATE_AND_PLAY(zarcanum_basic_test); + GENERATE_AND_PLAY(multiassets_basic_test); + // GENERATE_AND_PLAY(gen_block_reward); diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h index c4eac1be..cf3fbb7d 100644 --- a/tests/core_tests/chaingen_tests_list.h +++ b/tests/core_tests/chaingen_tests_list.h @@ -41,3 +41,4 @@ #include "atomic_tests.h" #include "isolate_auditable_and_proof.h" #include "zarcanum_test.h" +#include "multiassets_test.h" diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp new file mode 100644 index 00000000..edecf951 --- /dev/null +++ b/tests/core_tests/multiassets_test.cpp @@ -0,0 +1,110 @@ +// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chaingen.h" +#include "multiassets_test.h" +#include "wallet_test_core_proxy.h" + +#include "random_helper.h" + +#define AMOUNT_TO_TRANSFER_MULTIASSETS_BASIC (TESTS_DEFAULT_FEE) + +#define AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC 500000000000000000 + + + +using namespace currency; + +//------------------------------------------------------------------------------ +multiassets_basic_test::multiassets_basic_test() +{ + REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); + REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); + + m_hardforks.set_hardfork_height(1, 1); + m_hardforks.set_hardfork_height(2, 1); + m_hardforks.set_hardfork_height(3, 1); + m_hardforks.set_hardfork_height(4, 1); +} + +bool multiassets_basic_test::generate(std::vector& events) const +{ + m_accounts.resize(MINER_ACC_IDX+1); + account_base& miner_acc = m_accounts[MINER_ACC_IDX]; + miner_acc.generate(); + + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); + DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks + set_hard_fork_heights_to_generator(generator); + //TODO: Need to make sure REWIND_BLOCKS_N and other coretests codebase are capable of following hardfork4 rules + //in this test hardfork4 moment moved to runtime section + REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); + + DO_CALLBACK(events, "c1"); + + return true; +} + +bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + bool r = false; + std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX); + account_base alice_acc; + alice_acc.generate(); + std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, alice_acc); + + miner_wlt->refresh(); + + asset_descriptor_base adb = AUTO_VAL_INIT(adb); + adb.total_max_supply = 1000000000000000000; //1M coins + adb.full_name = "Test coins"; + adb.ticker = "TCT"; + adb.decimal_point = 12; + + std::vector destinations(2); + destinations[0].addr.push_back(miner_wlt->get_account().get_public_address()); + destinations[0].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; + destinations[0].asset_id = currency::ffff_hash; + destinations[1].addr.push_back(alice_wlt->get_account().get_public_address()); + destinations[1].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; + destinations[1].asset_id = currency::ffff_hash; + + currency::transaction tx = AUTO_VAL_INIT(tx); + crypto::hash asset_id = currency::null_hash; + miner_wlt->publish_new_asset(adb, destinations, tx, asset_id); + + //pass over hardfork + r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + + miner_wlt->refresh(); + alice_wlt->refresh(); + uint64_t mined = 0; + std::unordered_map balances; + miner_wlt->balance(balances, mined); + + auto it_asset = balances.find(asset_id); + auto it_native = balances.find(currency::null_hash); + + + CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native->second.total == 0, false, "Failed to find needed asset in result balances"); + + + balances.clear(); + alice_wlt->balance(balances, mined); + + it_asset = balances.find(asset_id); + it_native = balances.find(currency::null_hash); + + CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native->second.total == 0, false, "Failed to find needed asset in result balances"); + + + return true; +} diff --git a/tests/core_tests/multiassets_test.h b/tests/core_tests/multiassets_test.h new file mode 100644 index 00000000..46889ef8 --- /dev/null +++ b/tests/core_tests/multiassets_test.h @@ -0,0 +1,16 @@ +// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once +#include "chaingen.h" +#include "wallet_tests_basic.h" + + +struct multiassets_basic_test : public wallet_test +{ + multiassets_basic_test(); + bool generate(std::vector& events) const; + bool c1(currency::core& c, size_t ev_index, const std::vector& events); +}; diff --git a/tests/unit_tests/proxy_to_coretests.cpp b/tests/unit_tests/proxy_to_coretests.cpp new file mode 100644 index 00000000..219fab7a --- /dev/null +++ b/tests/unit_tests/proxy_to_coretests.cpp @@ -0,0 +1,12 @@ +// Copyright (c) 2012-2022 The Zano project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "gtest/gtest.h" + +#include "common/util.h" +#include "p2p/net_peerlist.h" +#include "core_tests/chaingen.h" + + +//TODO \ No newline at end of file From ca4556a8046274f13ceabdb4a6ba6d9330bc52fd Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 4 Oct 2022 22:00:30 +0200 Subject: [PATCH 11/49] Minor fixes --- src/currency_core/currency_format_utils.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 549ff3c5..39dcc0fd 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -665,20 +665,18 @@ namespace currency //--------------------------------------------------------------- struct tx_extra_handler : public boost::static_visitor { - mutable bool was_padding; //let the padding goes only at the end - mutable bool was_pubkey; - mutable bool was_attachment; - mutable bool was_userdata; - mutable bool was_alias; - mutable bool was_asset; + mutable bool was_padding = false; //let the padding goes only at the end + mutable bool was_pubkey = false; + mutable bool was_attachment = false; + mutable bool was_userdata = false; + mutable bool was_alias = false; + mutable bool was_asset = false; tx_extra_info& rei; const transaction& rtx; tx_extra_handler(tx_extra_info& ei, const transaction& tx) :rei(ei), rtx(tx) - { - was_padding = was_pubkey = was_attachment = was_userdata = was_alias = false; - } + {} #define ENSURE_ONETIME(varname, entry_name) CHECK_AND_ASSERT_MES(varname == false, false, "double entry in tx_extra: " entry_name); varname = true; From 8e0cf0f142ce0031d7ca64939cc9632dbfb8e6cf Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 4 Oct 2022 23:13:02 +0200 Subject: [PATCH 12/49] fixed storage bug over assets container --- src/common/db_backend_lmdb.cpp | 4 ++++ src/currency_core/blockchain_storage.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/common/db_backend_lmdb.cpp b/src/common/db_backend_lmdb.cpp index 6dfb1eea..75e60ce4 100644 --- a/src/common/db_backend_lmdb.cpp +++ b/src/common/db_backend_lmdb.cpp @@ -291,6 +291,10 @@ namespace tools if (res == MDB_NOTFOUND) return false; + if (res != MDB_SUCCESS) + { + return false; + } CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_get, h: " << h << ", ks: " << ks); res_buff.assign((const char*)data.mv_data, data.mv_size); diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 1f9b8f41..ace87e70 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -281,6 +281,8 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro CHECK_AND_ASSERT_MES(res, false, "Unable to init db container"); res = m_db_aliases.init(BLOCKCHAIN_STORAGE_CONTAINER_ALIASES); CHECK_AND_ASSERT_MES(res, false, "Unable to init db container"); + res = m_db_assets.init(BLOCKCHAIN_STORAGE_CONTAINER_ASSETS); + CHECK_AND_ASSERT_MES(res, false, "Unable to init db container"); res = m_db_addr_to_alias.init(BLOCKCHAIN_STORAGE_CONTAINER_ADDR_TO_ALIAS); CHECK_AND_ASSERT_MES(res, false, "Unable to init db container"); res = m_db_per_block_gindex_incs.init(BLOCKCHAIN_STORAGE_CONTAINER_GINDEX_INCS); From 319f295984d185f43b79d103f5a3611ec88a0a83 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 5 Oct 2022 21:31:21 +0200 Subject: [PATCH 13/49] fixed multiasset test --- src/currency_core/currency_basic.h | 2 ++ tests/core_tests/multiassets_test.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 1faaf62f..ea09da90 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -412,6 +412,7 @@ namespace currency FIELD(amount_commitment) FIELD(encrypted_amount) FIELD(mix_attr) + FIELD(etc_details) END_SERIALIZE() BEGIN_BOOST_SERIALIZATION() @@ -420,6 +421,7 @@ namespace currency BOOST_SERIALIZE(amount_commitment) BOOST_SERIALIZE(encrypted_amount) BOOST_SERIALIZE(mix_attr) + BOOST_SERIALIZE(etc_details) END_BOOST_SERIALIZATION() }; diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index edecf951..3f65b4c0 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -74,6 +74,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v currency::transaction tx = AUTO_VAL_INIT(tx); crypto::hash asset_id = currency::null_hash; miner_wlt->publish_new_asset(adb, destinations, tx, asset_id); + LOG_PRINT_L0("Published new asset: " << asset_id << ", tx_id: " << currency::get_transaction_hash(tx)); //pass over hardfork r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); @@ -92,7 +93,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); - CHECK_AND_ASSERT_MES(it_native->second.total == 0, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native->second.total == 17517226000000000000, false, "Failed to find needed asset in result balances"); balances.clear(); @@ -101,10 +102,11 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v it_asset = balances.find(asset_id); it_native = balances.find(currency::null_hash); - CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native == balances.end(), false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); - CHECK_AND_ASSERT_MES(it_native->second.total == 0, false, "Failed to find needed asset in result balances"); - + + //TODO: add transfer of tokens return true; } From 8a549244077a74ea53454875cf3dd5f31417648f Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 6 Oct 2022 22:59:00 +0200 Subject: [PATCH 14/49] multiple fixes over wallet and math(credits to @sowle) --- src/currency_core/currency_format_utils.cpp | 12 +++---- src/wallet/wallet2.cpp | 16 ++++++--- src/wallet/wallet2.h | 6 ++-- tests/core_tests/multiassets_test.cpp | 39 ++++++++++++++++++--- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 741a26db..1da3cf01 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1599,7 +1599,7 @@ namespace currency }; //-------------------------------------------------------------------------------- bool generate_ZC_sig(const crypto::hash& tx_hash_for_signature, size_t input_index, const tx_source_entry& se, const input_generation_context_data& in_context, - const account_keys& sender_account_keys, const crypto::scalar_t& blinding_masks_sum, const uint64_t tx_flags, crypto::scalar_t& local_blinding_masks_sum, transaction& tx) + const account_keys& sender_account_keys, const crypto::scalar_t& blinding_masks_sum, const uint64_t tx_flags, crypto::scalar_t& local_blinding_masks_sum, transaction& tx, bool last_output) { bool watch_only_mode = sender_account_keys.spend_secret_key == null_skey; CHECK_AND_ASSERT_MES(se.is_zarcanum(), false, "sources contains a non-zarcanum input"); @@ -1621,7 +1621,7 @@ namespace currency #endif crypto::scalar_t blinding_mask = 0; - if ((tx_flags & TX_FLAG_SIGNATURE_MODE_SEPARATE) == 0 || se.separately_signed_tx_complete) + if ((last_output && (tx_flags & TX_FLAG_SIGNATURE_MODE_SEPARATE) == 0) || se.separately_signed_tx_complete) { // either normal tx or the last signature of consolidated tx -- in both cases we need to calculate non-random blinding mask for pseudo output commitment blinding_mask = blinding_masks_sum + local_blinding_masks_sum; @@ -1946,11 +1946,10 @@ namespace currency { tx.vin.push_back(ins_zc); }*/ - + uint64_t amount_of_assets = 0; std::vector shuffled_dsts(destinations); if (asset_id_for_destinations != currency::null_hash) { - uint64_t amount_of_assets = 0; //must be asset publication for (auto& item : shuffled_dsts) { @@ -2048,7 +2047,7 @@ namespace currency if (!has_zc_inputs) { - r = generate_tx_balance_proof(tx, blinding_masks_sum); + r = generate_tx_balance_proof(tx, blinding_masks_sum, amount_of_assets); CHECK_AND_ASSERT_MES(r, false, "generate_tx_balance_proof failed"); } } @@ -2094,7 +2093,8 @@ namespace currency { // ZC // blinding_masks_sum is supposed to be sum(mask of all tx output) - sum(masks of all pseudo out commitments) - r = generate_ZC_sig(tx_hash_for_signature, i + input_starter_index, source_entry, in_contexts[i], sender_account_keys, blinding_masks_sum, flags, local_blinding_masks_sum, tx); + r = generate_ZC_sig(tx_hash_for_signature, i + input_starter_index, source_entry, in_contexts[i], sender_account_keys, blinding_masks_sum, flags, + local_blinding_masks_sum, tx, i + 1 == sources.size()); CHECK_AND_ASSERT_MES(r, false, "generate_ZC_sigs failed"); } else diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 014ed1ff..41f620a2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1877,7 +1877,7 @@ detail::split_strategy_id_t wallet2::get_current_split_strategy() return tools::detail::ssi_void; } // -void wallet2::transfer(uint64_t amount, const currency::account_public_address& acc, currency::transaction& result_tx) +void wallet2::transfer(uint64_t amount, const currency::account_public_address& acc, currency::transaction& result_tx, const crypto::hash& asset_id) { std::vector extra; std::vector attachments; @@ -1886,13 +1886,14 @@ void wallet2::transfer(uint64_t amount, const currency::account_public_address& dst.resize(1); dst.back().addr.push_back(acc); dst.back().amount = amount; + dst.back().asset_id = asset_id; this->transfer(dst, 0, 0, TX_DEFAULT_FEE, extra, attachments, get_current_split_strategy(), tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), result_tx); } //---------------------------------------------------------------------------------------------------- -void wallet2::transfer(uint64_t amount, const currency::account_public_address& acc) +void wallet2::transfer(uint64_t amount, const currency::account_public_address& acc, const crypto::hash& asset_id) { transaction result_tx = AUTO_VAL_INIT(result_tx); - this->transfer(amount, acc, result_tx); + this->transfer(amount, acc, result_tx, asset_id); } //---------------------------------------------------------------------------------------------------- void wallet2::reset_creation_time(uint64_t timestamp) @@ -5664,7 +5665,14 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money, change_dts.asset_id = asset_id; } WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(found_money >= needed_money, "needed_money==" << needed_money << " < found_money==" << found_money); - + if (asset_id != currency::null_hash) + { + if (change_dts.amount) + { + final_detinations.push_back(change_dts); + } + return; + } uint64_t dust = 0; bool r = detail::apply_split_strategy_by_id(destination_split_strategy_id, dsts, change_dts, dust_policy.dust_threshold, final_detinations, dust, WALLET_MAX_ALLOWED_OUTPUT_AMOUNT); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 83da27e9..1435df27 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -241,7 +241,7 @@ namespace tools const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) { - splitted_dsts = dsts; + splitted_dsts.insert(splitted_dsts.end(), dsts.begin(), dsts.end()); if (change_dst.amount > 0) splitted_dsts.push_back(change_dst); } @@ -578,8 +578,8 @@ namespace tools uint64_t unlocked_balance() const; - void transfer(uint64_t amount, const currency::account_public_address& acc); - void transfer(uint64_t amount, const currency::account_public_address& acc, currency::transaction& result_tx); + void transfer(uint64_t amount, const currency::account_public_address& acc, const crypto::hash& asset_id = currency::null_hash); + void transfer(uint64_t amount, const currency::account_public_address& acc, currency::transaction& result_tx, const crypto::hash& asset_id = currency::null_hash); void transfer(const std::vector& dsts, size_t fake_outputs_count, diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 3f65b4c0..d9d300b7 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -20,6 +20,10 @@ using namespace currency; //------------------------------------------------------------------------------ multiassets_basic_test::multiassets_basic_test() { + // TODO: remove the following line + static uint64_t ts = 1; + random_state_test_restorer::reset_random(ts); + REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); @@ -35,12 +39,13 @@ bool multiassets_basic_test::generate(std::vector& events) con account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); - MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); + uint64_t ts = 145000000; + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks set_hard_fork_heights_to_generator(generator); //TODO: Need to make sure REWIND_BLOCKS_N and other coretests codebase are capable of following hardfork4 rules //in this test hardfork4 moment moved to runtime section - REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); + REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); DO_CALLBACK(events, "c1"); @@ -51,10 +56,11 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v { bool r = false; std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX); + miner_wlt->get_account().set_createtime(0); account_base alice_acc; alice_acc.generate(); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, alice_acc); - + alice_wlt->get_account().set_createtime(0); miner_wlt->refresh(); asset_descriptor_base adb = AUTO_VAL_INIT(adb); @@ -106,7 +112,32 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v CHECK_AND_ASSERT_MES(it_native == balances.end(), false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); - //TODO: add transfer of tokens + miner_wlt->transfer(AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC/2, alice_wlt->get_account().get_public_address(), asset_id); + //pass over hardfork + r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + + alice_wlt->refresh(); + balances.clear(); + alice_wlt->balance(balances, mined); + + it_asset = balances.find(asset_id); + + CHECK_AND_ASSERT_MES(it_asset != balances.end(), false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC + AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC/2, false, "Failed to find needed asset in result balances"); + + try { + + miner_wlt->transfer(AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC / 2, alice_wlt->get_account().get_public_address(), asset_id); + //pass over hardfork + CHECK_AND_ASSERT_MES(false, false, "Transfer with 0 Zano worked(fail)"); + } + catch (...) + { + + } + + return true; } From b3daf9aa08ffaa9c29e5802d9e8c594a112cfef1 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 7 Oct 2022 21:44:43 +0200 Subject: [PATCH 15/49] fixed bug in constract_tx regarding inputs mapping --- src/currency_core/currency_format_utils.cpp | 14 ++++++++------ tests/core_tests/chaingen_main.cpp | 2 +- tests/core_tests/multiassets_test.cpp | 9 +++++---- tests/core_tests/multiassets_test.h | 2 ++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 1da3cf01..4726c405 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -2082,10 +2082,12 @@ namespace currency //size_t in_context_index = 0; crypto::scalar_t local_blinding_masks_sum = 0; // ZC only r = false; - for (size_t i = 0; i != sources.size(); i++) + for (size_t i_ = 0; i_ != sources.size(); i_++) { - const tx_source_entry& source_entry = sources[inputs_mapping[i]]; - crypto::hash tx_hash_for_signature = prepare_prefix_hash_for_sign(tx, i + input_starter_index, tx_prefix_hash); + size_t i_mapped = inputs_mapping[i_]; + + const tx_source_entry& source_entry = sources[i_mapped]; + crypto::hash tx_hash_for_signature = prepare_prefix_hash_for_sign(tx, i_ + input_starter_index, tx_prefix_hash); CHECK_AND_ASSERT_MES(tx_hash_for_signature != null_hash, false, "prepare_prefix_hash_for_sign failed"); std::stringstream ss_ring_s; @@ -2093,14 +2095,14 @@ namespace currency { // ZC // blinding_masks_sum is supposed to be sum(mask of all tx output) - sum(masks of all pseudo out commitments) - r = generate_ZC_sig(tx_hash_for_signature, i + input_starter_index, source_entry, in_contexts[i], sender_account_keys, blinding_masks_sum, flags, - local_blinding_masks_sum, tx, i + 1 == sources.size()); + r = generate_ZC_sig(tx_hash_for_signature, i_ + input_starter_index, source_entry, in_contexts[i_mapped], sender_account_keys, blinding_masks_sum, flags, + local_blinding_masks_sum, tx, i_ + 1 == sources.size()); CHECK_AND_ASSERT_MES(r, false, "generate_ZC_sigs failed"); } else { // NLSAG - r = generate_NLSAG_sig(tx_hash_for_signature, tx_prefix_hash, i + input_starter_index, source_entry, sender_account_keys, in_contexts[i], txkey, flags, tx, &ss_ring_s); + r = generate_NLSAG_sig(tx_hash_for_signature, tx_prefix_hash, i_ + input_starter_index, source_entry, sender_account_keys, in_contexts[i_mapped], txkey, flags, tx, &ss_ring_s); CHECK_AND_ASSERT_MES(r, false, "generate_NLSAG_sig failed"); } diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index e20bceea..64c68ac1 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1061,7 +1061,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(zarcanum_basic_test); GENERATE_AND_PLAY(multiassets_basic_test); - + // GENERATE_AND_PLAY(gen_block_reward); diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index d9d300b7..333c714c 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -16,13 +16,14 @@ using namespace currency; - +uint64_t multiassets_basic_test::ts_starter = 0; //------------------------------------------------------------------------------ multiassets_basic_test::multiassets_basic_test() { // TODO: remove the following line - static uint64_t ts = 1; - random_state_test_restorer::reset_random(ts); + + //LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); + //random_state_test_restorer::reset_random(ts_starter); REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); @@ -134,7 +135,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v } catch (...) { - + return true; } diff --git a/tests/core_tests/multiassets_test.h b/tests/core_tests/multiassets_test.h index 46889ef8..74e17bf6 100644 --- a/tests/core_tests/multiassets_test.h +++ b/tests/core_tests/multiassets_test.h @@ -10,7 +10,9 @@ struct multiassets_basic_test : public wallet_test { + static uint64_t ts_starter; multiassets_basic_test(); bool generate(std::vector& events) const; bool c1(currency::core& c, size_t ev_index, const std::vector& events); }; + From 4d9e6d41a2c7119c2e1a49173dc47efd061c0721 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 7 Oct 2022 22:16:42 +0200 Subject: [PATCH 16/49] fix for linux build --- .../currency_format_utils_abstract.h | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/currency_core/currency_format_utils_abstract.h b/src/currency_core/currency_format_utils_abstract.h index 36efd213..fd23136b 100644 --- a/src/currency_core/currency_format_utils_abstract.h +++ b/src/currency_core/currency_format_utils_abstract.h @@ -91,6 +91,19 @@ namespace currency ++result; } return result; + } + //--------------------------------------------------------------- + template + specific_type_t* get_type_in_variant_container(variant_t_container& av) + { + for (auto& ai : av) + { + if (ai.type() == typeid(specific_type_t)) + { + return &boost::get(ai); + } + } + return nullptr; } //--------------------------------------------------------------- template @@ -107,19 +120,6 @@ namespace currency //--------------------------------------------------------------- //--------------------------------------------------------------- template - specific_type_t* get_type_in_variant_container(variant_t_container& av) - { - for (auto& ai : av) - { - if (ai.type() == typeid(specific_type_t)) - { - return &boost::get(ai); - } - } - return nullptr; - } - //--------------------------------------------------------------- - template specific_type_t& get_type_in_variant_container_by_ref(variant_t_container& av) { for (auto& ai : av) From 09a1ddf97b892d8caea6f56854922d034aa46c89 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 7 Oct 2022 22:45:52 +0200 Subject: [PATCH 17/49] removed unused includes --- tests/unit_tests/proxy_to_coretests.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit_tests/proxy_to_coretests.cpp b/tests/unit_tests/proxy_to_coretests.cpp index 219fab7a..df09b253 100644 --- a/tests/unit_tests/proxy_to_coretests.cpp +++ b/tests/unit_tests/proxy_to_coretests.cpp @@ -4,9 +4,9 @@ #include "gtest/gtest.h" -#include "common/util.h" -#include "p2p/net_peerlist.h" -#include "core_tests/chaingen.h" +//#include "common/util.h" +//#include "p2p/net_peerlist.h" +//#include "core_tests/chaingen.h" //TODO \ No newline at end of file From 033ec29d606b22068c49a18a233fb47ac83e2873 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 10 Oct 2022 14:46:56 +0200 Subject: [PATCH 18/49] attempt to fix unit_tests Serialization:versioning2 --- tests/unit_tests/serialization.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 2ad3a6f4..43df9c0e 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -806,7 +806,7 @@ struct A_v3 : public A_v2 FIELD(vector_3) FIELD(vector_4) if (s_version < 3) return true; - FIELD(vector_4) + FIELD(vector_5) END_SERIALIZE() }; From 19f0f0bbf07a50ed803b14848c3d6672593e648b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 10 Oct 2022 20:46:06 +0200 Subject: [PATCH 19/49] fixed but with sequence points --- src/currency_core/currency_format_utils.cpp | 4 ++-- tests/core_tests/chaingen_main.cpp | 8 +++++++- tests/core_tests/multiassets_test.cpp | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 4726c405..3c630e5d 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1580,7 +1580,6 @@ namespace currency ftp.tx_outs_attr = tx_outs_attr; ftp.shuffle = shuffle; ftp.flags = flags; - ftp.tx_version; finalized_tx ft = AUTO_VAL_INIT(ft); ft.tx = tx; @@ -1832,7 +1831,8 @@ namespace currency //fill inputs NLSAG and Zarcanum for (const tx_source_entry& src_entr : sources) { - inputs_mapping[current_index] = current_index++; + inputs_mapping[current_index] = current_index; + current_index++; in_contexts.push_back(input_generation_context_data()); if(src_entr.is_multisig()) {//multisig input diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 64c68ac1..3c98be09 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1060,7 +1060,13 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(isolate_auditable_and_proof); GENERATE_AND_PLAY(zarcanum_basic_test); - GENERATE_AND_PLAY(multiassets_basic_test); + + stop_on_first_fail = true; + for (uint64_t i = 0; i != 30; i++) + { + multiassets_basic_test::ts_starter = i; + GENERATE_AND_PLAY(multiassets_basic_test); + } diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 333c714c..f4de2b3a 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -22,8 +22,8 @@ multiassets_basic_test::multiassets_basic_test() { // TODO: remove the following line - //LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); - //random_state_test_restorer::reset_random(ts_starter); + LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); + random_state_test_restorer::reset_random(ts_starter); REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); From 2098bdc8695c9b7e5afc97bacc2ae1aa98c37d30 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 10 Oct 2022 20:47:41 +0200 Subject: [PATCH 20/49] removed cycle for enumerating random on multiassets_basic_test --- tests/core_tests/chaingen_main.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 3c98be09..ec9b4c46 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1061,12 +1061,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(zarcanum_basic_test); - stop_on_first_fail = true; - for (uint64_t i = 0; i != 30; i++) - { - multiassets_basic_test::ts_starter = i; - GENERATE_AND_PLAY(multiassets_basic_test); - } + GENERATE_AND_PLAY(multiassets_basic_test); From 4fa2afa87e7f6385f953e1067f37ec26af0584db Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 12:02:48 +0200 Subject: [PATCH 21/49] remopved random deterministic setup --- tests/core_tests/multiassets_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index f4de2b3a..333c714c 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -22,8 +22,8 @@ multiassets_basic_test::multiassets_basic_test() { // TODO: remove the following line - LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); - random_state_test_restorer::reset_random(ts_starter); + //LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); + //random_state_test_restorer::reset_random(ts_starter); REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); From f1a7c25fa36fe3ff43d212929c1bc9ae43bcd72d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 13:44:59 +0200 Subject: [PATCH 22/49] fixed warnings on linux --- contrib/epee/include/net/net_utils_base.h | 2 ++ src/crypto/crypto-sugar.h | 3 +++ src/currency_core/currency_format_utils_abstract.h | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h index 1ef06777..8b474516 100644 --- a/contrib/epee/include/net/net_utils_base.h +++ b/contrib/epee/include/net/net_utils_base.h @@ -79,6 +79,8 @@ namespace net_utils m_started(time(NULL)) {} + connection_context_base(const connection_context_base& a) = default; + connection_context_base& operator=(const connection_context_base& a) { set_details(a.m_connection_id, a.m_remote_ip, a.m_remote_port, a.m_is_income); diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index 68e05fce..f9e626a6 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -844,8 +844,11 @@ namespace crypto // zeroes all elements void zero() { + PUSH_GCC_WARNINGS() + DISABLE_GCC_AND_CLANG_WARNING(class-memaccess) size_t size_bytes = sizeof(scalar_t) * size(); memset(data(), 0, size_bytes); + POP_GCC_WARNINGS() } // invert all elements in-place efficiently: 4*N muptiplications + 1 inversion diff --git a/src/currency_core/currency_format_utils_abstract.h b/src/currency_core/currency_format_utils_abstract.h index fd23136b..dece4b0f 100644 --- a/src/currency_core/currency_format_utils_abstract.h +++ b/src/currency_core/currency_format_utils_abstract.h @@ -193,7 +193,7 @@ namespace currency } //--------------------------------------------------------------- inline - const bool get_key_image_from_txin_v(const txin_v& in_v, crypto::key_image& result) noexcept + bool get_key_image_from_txin_v(const txin_v& in_v, crypto::key_image& result) noexcept { try { @@ -218,6 +218,7 @@ namespace currency catch(...) { // should never go here, just precaution + return false; } return false; From 8c90dc40325aa1ad1cc5f7e0b2dd87f75468705b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 14:53:30 +0200 Subject: [PATCH 23/49] removed parentheses --- src/crypto/crypto-sugar.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index f9e626a6..7fb39548 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -844,11 +844,11 @@ namespace crypto // zeroes all elements void zero() { - PUSH_GCC_WARNINGS() + PUSH_GCC_WARNINGS DISABLE_GCC_AND_CLANG_WARNING(class-memaccess) size_t size_bytes = sizeof(scalar_t) * size(); memset(data(), 0, size_bytes); - POP_GCC_WARNINGS() + POP_GCC_WARNINGS } // invert all elements in-place efficiently: 4*N muptiplications + 1 inversion From cfafa1e73d74802d05a233d25d1275f7cb1c479c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 15:54:44 +0200 Subject: [PATCH 24/49] disabled unknown pragmas for backward comp --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f55455d..32d5ccfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ else() else() set(ARCH_FLAG "-march=${ARCH}") endif() - set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return -Wno-comment") + set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return -Wno-comment -Wcomment -Wno-unknown-pragmas") # if(NOT APPLE) # set(WARNINGS "${WARNINGS} -Werror") # endif() From 2927edf16adf2e230c9100ef4e3ffd7f65df9176 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 16:05:48 +0200 Subject: [PATCH 25/49] removed multiple warnings over gcc/clang compilers --- CMakeLists.txt | 4 ++-- src/crypto/bitcoin/sha256.cpp | 5 ++++- src/crypto/clsag.cpp | 2 +- src/wallet/wallet_errors.h | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32d5ccfc..64bc5c99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ else() else() set(ARCH_FLAG "-march=${ARCH}") endif() - set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return -Wno-comment -Wcomment -Wno-unknown-pragmas") + set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return -Wno-comment -Wcomment -Wno-unknown-pragmas -Wno-pragmas") # if(NOT APPLE) # set(WARNINGS "${WARNINGS} -Werror") # endif() @@ -135,7 +135,7 @@ else() else() set(APPLE_FLAG "") endif() - set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wstrict-prototypes") + set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wstrict-prototypes -Wcomment") set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers") try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/utils/test-static-assert.c" COMPILE_DEFINITIONS "-std=c++14") if(STATIC_ASSERT_RES) diff --git a/src/crypto/bitcoin/sha256.cpp b/src/crypto/bitcoin/sha256.cpp index 56266951..caf8a85d 100644 --- a/src/crypto/bitcoin/sha256.cpp +++ b/src/crypto/bitcoin/sha256.cpp @@ -462,6 +462,9 @@ namespace TransformD64Type TransformD64_4way = nullptr; TransformD64Type TransformD64_8way = nullptr; + PUSH_GCC_WARNINGS + DISABLE_GCC_AND_CLANG_WARNING(unused-function) + bool SelfTest() { // Input state (equal to the initial SHA256 state) static const uint32_t init[8] = { @@ -626,7 +629,7 @@ std::string SHA256AutoDetect() assert(SelfTest()); return ret; } - +POP_GCC_WARNINGS ////// SHA-256 CSHA256::CSHA256() : bytes(0) diff --git a/src/crypto/clsag.cpp b/src/crypto/clsag.cpp index a1b28dcb..80eb7982 100644 --- a/src/crypto/clsag.cpp +++ b/src/crypto/clsag.cpp @@ -14,7 +14,7 @@ namespace crypto #define DBG_VAL_PRINT(x) (void(0)) // std::cout << #x ": " << x << std::endl #define DBG_PRINT(x) (void(0)) // std::cout << x << std::endl - static std::ostream &operator <<(std::ostream &o, const crypto::hash &v) { return o << pod_to_hex(v); } + //static std::ostream &operator <<(std::ostream &o, const crypto::hash &v) { return o << pod_to_hex(v); } bool generate_CLSAG_GG(const hash& m, const std::vector& ring, const point_t& pseudo_out_amount_commitment, const key_image& ki, const scalar_t& secret_x, const scalar_t& secret_f, uint64_t secret_index, CLSAG_GG_signature& sig) diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 8c820551..9aed4074 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -757,4 +757,5 @@ if (cond) ss << mess; \ LOG_ERROR("THROW EXCEPTION: wallet_common_error"); \ tools::error::throw_wallet_ex(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ss.str()); \ - } \ No newline at end of file + } + From db5564ac1eb80f41482ef800ef92b644bf9cbd93 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 16:17:12 +0200 Subject: [PATCH 26/49] explicit namespace for print_money in wallet --- src/crypto/bitcoin/sha256.cpp | 2 +- src/wallet/wallet2.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/bitcoin/sha256.cpp b/src/crypto/bitcoin/sha256.cpp index caf8a85d..20c994f3 100644 --- a/src/crypto/bitcoin/sha256.cpp +++ b/src/crypto/bitcoin/sha256.cpp @@ -7,7 +7,7 @@ #include #include - +#include "warnings.h" //#include #if defined(__x86_64__) || defined(__amd64__) || defined(__i386__) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 1435df27..5d0f02a6 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1312,7 +1312,7 @@ namespace tools ptc.is_derived_from_coinbase = true; else ptc.is_derived_from_coinbase = false; - WLT_LOG_L0("Spent key out, transfer #" << tr_index << ", amount: " << print_money(td.amount()) << ", with tx: " << get_transaction_hash(tx) << ", at height " << ptc.height << + WLT_LOG_L0("Spent key out, transfer #" << tr_index << ", amount: " << currency::print_money(td.amount()) << ", with tx: " << get_transaction_hash(tx) << ", at height " << ptc.height << "; flags: " << flags_before << " -> " << td.m_flags); ptc.mtd.spent_indices.push_back(ptc.i); remove_transfer_from_expiration_list(tr_index); From 425166ff49ea78bf7797c711cb7c21d7516f822a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 16:21:03 +0200 Subject: [PATCH 27/49] disabled warnings for comments --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64bc5c99..af96caf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ else() else() set(ARCH_FLAG "-march=${ARCH}") endif() - set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return -Wno-comment -Wcomment -Wno-unknown-pragmas -Wno-pragmas") + set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-aggregate-return -Wno-comment -Wno-unknown-pragmas -Wno-pragmas") # if(NOT APPLE) # set(WARNINGS "${WARNINGS} -Werror") # endif() @@ -135,7 +135,7 @@ else() else() set(APPLE_FLAG "") endif() - set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wstrict-prototypes -Wcomment") + set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wstrict-prototypes -Wno-comment") set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers") try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/utils/test-static-assert.c" COMPILE_DEFINITIONS "-std=c++14") if(STATIC_ASSERT_RES) From ce7438265db3dae2c3810872888d0586e0d52a36 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 20:19:24 +0200 Subject: [PATCH 28/49] added default initialization --- src/currency_core/currency_basic.h | 6 +++--- tests/core_tests/chaingen_pch.cpp | 1 - tests/core_tests/multiassets_test.cpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index ea09da90..43a5749a 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -443,7 +443,7 @@ namespace currency struct zc_outs_range_proof { crypto::bpp_signature_serialized bpp; - uint8_t outputs_count; // how many outputs are included in the proof + uint8_t outputs_count = 0; // how many outputs are included in the proof BEGIN_SERIALIZE_OBJECT() FIELD(bpp) @@ -459,7 +459,7 @@ namespace currency // Zarcanum-aware CLSAG signature struct ZC_sig { - crypto::public_key pseudo_out_amount_commitment; // premultiplied by 1/8 + crypto::public_key pseudo_out_amount_commitment = null_pkey; // premultiplied by 1/8 crypto::CLSAG_GG_signature_serialized clsags_gg; BEGIN_SERIALIZE_OBJECT() @@ -475,7 +475,7 @@ namespace currency struct zc_balance_proof { - crypto::signature s; + crypto::signature s = null_sig; BEGIN_SERIALIZE_OBJECT() FIELD(s) diff --git a/tests/core_tests/chaingen_pch.cpp b/tests/core_tests/chaingen_pch.cpp index 11878762..4f86d7c7 100644 --- a/tests/core_tests/chaingen_pch.cpp +++ b/tests/core_tests/chaingen_pch.cpp @@ -1,5 +1,4 @@ // Copyright (c) 2022 Zano Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#pragma once #include "chaingen.h" diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 333c714c..64e501a8 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -100,7 +100,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v CHECK_AND_ASSERT_MES(it_asset != balances.end() && it_native != balances.end(), false, "Failed to find needed asset in result balances"); CHECK_AND_ASSERT_MES(it_asset->second.total == AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC, false, "Failed to find needed asset in result balances"); - CHECK_AND_ASSERT_MES(it_native->second.total == 17517226000000000000, false, "Failed to find needed asset in result balances"); + CHECK_AND_ASSERT_MES(it_native->second.total == uint64_t(17517226)*COIN, false, "Failed to find needed asset in result balances"); balances.clear(); From cdd7c1e735dd3725c4dcb56550de176104b636d9 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 20:53:36 +0200 Subject: [PATCH 29/49] warnings suppress --- src/crypto/crypto-sugar.h | 3 +-- src/currency_core/offers_service_basics.h | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index 7fb39548..4aa576fd 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -141,8 +141,7 @@ namespace crypto crypto::secret_key m_sk; }; - scalar_t() - {} + scalar_t() = default; // won't check scalar range validity (< L) scalar_t(uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3) diff --git a/src/currency_core/offers_service_basics.h b/src/currency_core/offers_service_basics.h index 809bf88b..1dffe367 100644 --- a/src/currency_core/offers_service_basics.h +++ b/src/currency_core/offers_service_basics.h @@ -19,9 +19,9 @@ namespace bc_services { //fields filled in UI - uint8_t offer_type; // OFFER_TYPE_PRIMARY_TO_TARGET(SELL ORDER) - 0, OFFER_TYPE_TARGET_TO_PRIMARY(BUY ORDER) - 1 etc. - uint64_t amount_primary; // amount of the currency - uint64_t amount_target; // amount of other currency or goods + uint8_t offer_type = 0; // OFFER_TYPE_PRIMARY_TO_TARGET(SELL ORDER) - 0, OFFER_TYPE_TARGET_TO_PRIMARY(BUY ORDER) - 1 etc. + uint64_t amount_primary = 0; // amount of the currency + uint64_t amount_target = 0; // amount of other currency or goods std::string bonus; // std::string target; // [] currency / goods std::string primary; // currency for goods @@ -33,7 +33,7 @@ namespace bc_services std::string deal_option; // []full amount, by parts std::string category; // [] std::string preview_url; // [] - uint8_t expiration_time; // n-days + uint8_t expiration_time = 0; // n-days //----------------- BEGIN_KV_SERIALIZE_MAP() From 00d4ae9828345b0b5a200b1f8d9e5b0780221d63 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 21:17:05 +0200 Subject: [PATCH 30/49] set deterministic rand to find bug in multiasset_test --- contrib/epee/include/misc_log_ex.h | 2 +- tests/core_tests/chaingen_main.cpp | 6 +++++- tests/core_tests/multiassets_test.cpp | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 107238b8..c9a96148 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -1261,7 +1261,7 @@ namespace log_space enabled_channels_local.insert(ch_name); genabled_channels.swap(enabled_channels_local); #ifndef ANDROID_BUILD - std::cout << "log channel '" << ch_name << "' enabled" << std::endl; + //std::cout << "log channel '" << ch_name << "' enabled" << std::endl; #endif } diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index ec9b4c46..f4457002 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1061,7 +1061,11 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(zarcanum_basic_test); - GENERATE_AND_PLAY(multiassets_basic_test); + for (size_t i = 0; i != 100; i++) + { + multiassets_basic_test::ts_starter = i; + GENERATE_AND_PLAY(multiassets_basic_test); + } diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 64e501a8..078ed32b 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -22,8 +22,8 @@ multiassets_basic_test::multiassets_basic_test() { // TODO: remove the following line - //LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); - //random_state_test_restorer::reset_random(ts_starter); + LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); + random_state_test_restorer::reset_random(ts_starter); REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); From 0441b8021658188b25e330daab049eab5dd6bdc6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 21:26:27 +0200 Subject: [PATCH 31/49] set stop_on_first_fail to stop on fail --- tests/core_tests/chaingen_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index f4457002..ba13d999 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1061,6 +1061,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(zarcanum_basic_test); + stop_on_first_fail = true; for (size_t i = 0; i != 100; i++) { multiassets_basic_test::ts_starter = i; From fcfdf3e8efc66311a52aa64c4387e63ab482b347 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Oct 2022 23:27:33 +0200 Subject: [PATCH 32/49] disabled random fix --- tests/core_tests/chaingen_main.cpp | 10 +++++----- tests/core_tests/multiassets_test.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index ba13d999..246d4c74 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1061,12 +1061,12 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(zarcanum_basic_test); - stop_on_first_fail = true; - for (size_t i = 0; i != 100; i++) - { - multiassets_basic_test::ts_starter = i; + //stop_on_first_fail = true; + //for (size_t i = 0; i != 100; i++) + //{ + // multiassets_basic_test::ts_starter = i; GENERATE_AND_PLAY(multiassets_basic_test); - } + //} diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 078ed32b..64e501a8 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -22,8 +22,8 @@ multiassets_basic_test::multiassets_basic_test() { // TODO: remove the following line - LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); - random_state_test_restorer::reset_random(ts_starter); + //LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); + //random_state_test_restorer::reset_random(ts_starter); REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); From d3b2ca0e3a4d3b52ca61c6aa969cdf9646dfba63 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 12:10:48 +0200 Subject: [PATCH 33/49] more warnings cleanup --- contrib/epee/include/warnings.h | 4 ++++ src/common/variant_helper.h | 6 +++--- src/currency_core/currency_format_utils.cpp | 2 -- src/serialization/serialization.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/contrib/epee/include/warnings.h b/contrib/epee/include/warnings.h index bbdcd9fe..433372fc 100644 --- a/contrib/epee/include/warnings.h +++ b/contrib/epee/include/warnings.h @@ -12,9 +12,13 @@ #define DISABLE_GCC_WARNING(w) #define DISABLE_CLANG_WARNING(w) #define DISABLE_GCC_AND_CLANG_WARNING(w) +#define ATTRIBUTE_UNUSED #else + +#define ATTRIBUTE_UNUSED __attribute__((unused)) + #include #define PUSH_VS_WARNINGS diff --git a/src/common/variant_helper.h b/src/common/variant_helper.h index f0439db2..7fcf996b 100644 --- a/src/common/variant_helper.h +++ b/src/common/variant_helper.h @@ -4,9 +4,9 @@ #pragma once -#define VARIANT_SWITCH_BEGIN(v_type_obj) {auto & local_reference_eokcmeokmeokcm = v_type_obj; if(false) {; -#define VARIANT_CASE_CONST(v_type, typed_name) } else if(local_reference_eokcmeokmeokcm.type() == typeid(v_type)) { const v_type& typed_name = boost::get(local_reference_eokcmeokmeokcm); -#define VARIANT_CASE(v_type, typed_name) } else if(local_reference_eokcmeokmeokcm.type() == typeid(v_type)) { v_type& typed_name = boost::get(local_reference_eokcmeokmeokcm); +#define VARIANT_SWITCH_BEGIN(v_type_obj) {auto & local_reference_eokcmeokmeokcm ATTRIBUTE_UNUSED = v_type_obj; if(false) {; +#define VARIANT_CASE_CONST(v_type, typed_name) } else if(local_reference_eokcmeokmeokcm.type() == typeid(v_type)) { const v_type& typed_name ATTRIBUTE_UNUSED = boost::get(local_reference_eokcmeokmeokcm); +#define VARIANT_CASE(v_type, typed_name) } else if(local_reference_eokcmeokmeokcm.type() == typeid(v_type)) { v_type& typed_name ATTRIBUTE_UNUSED = boost::get(local_reference_eokcmeokmeokcm); #define VARIANT_CASE_TV(v_type) VARIANT_CASE(v_type, tv) #define VARIANT_CASE_OTHER() } else { #define VARIANT_CASE_THROW_ON_OTHER() } else { ASSERT_MES_AND_THROW("Unknown type in switch statemet: " << local_reference_eokcmeokmeokcm.type().name()); diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 3c630e5d..36de2bbd 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1737,8 +1737,6 @@ namespace currency result.ftp = ftp; CHECK_AND_ASSERT_MES(destinations.size() <= CURRENCY_TX_MAX_ALLOWED_OUTS, false, "Too many outs (" << destinations.size() << ")! Tx can't be constructed."); - bool watch_only_mode = sender_account_keys.spend_secret_key == null_skey; - bool append_mode = false; if (flags&TX_FLAG_SIGNATURE_MODE_SEPARATE && tx.vin.size()) append_mode = true; diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index 6e16b498..5b5383b1 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -61,7 +61,7 @@ inline bool do_serialize(Archive &ar, T &v) #define VARIANT_TAG(A, T, Tg) \ template struct variant_serialization_traits, T> { static inline typename A::variant_tag_type get_tag() { return Tg; } } #define BEGIN_SERIALIZE() \ - template class Archive> bool do_serialize(Archive &_ser_ar) {uint8_t s_current_version = 0; uint8_t s_version = 0; + template class Archive> bool do_serialize(Archive &_ser_ar) {uint8_t s_current_version ATTRIBUTE_UNUSED = 0; uint8_t s_version ATTRIBUTE_UNUSED = 0; #define BEGIN_SERIALIZE_OBJECT() \ template class Archive> bool do_serialize(Archive &_ser_ar) { _ser_ar.begin_object(); bool _ser_res = do_serialize_object(_ser_ar); _ser_ar.end_object(); return _ser_res; } \ template class Archive> bool do_serialize_object(Archive &_ser_ar){ From df596d799df3ffa05107078bdcdc1d046e5b3514 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 12:19:51 +0200 Subject: [PATCH 34/49] fixed warnings in core tests --- tests/core_tests/chaingen.cpp | 1 - tests/core_tests/checkpoints_tests.cpp | 2 +- tests/core_tests/escrow_wallet_tests.cpp | 4 ++-- tests/core_tests/hard_fork_1.cpp | 4 ++-- tests/core_tests/hard_fork_2.cpp | 8 ++++---- tests/core_tests/wallet_tests.cpp | 3 --- tests/core_tests/zarcanum_test.cpp | 2 +- 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 94ce0211..1ad68d41 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -1003,7 +1003,6 @@ bool init_output_indices(map_output_idx_t& outs, map_output_t& outs_mine, const { for (const block& blk : blockchain) { - volatile uint64_t height = get_block_height(blk); std::vector vtx; vtx.push_back(&blk.miner_tx); diff --git a/tests/core_tests/checkpoints_tests.cpp b/tests/core_tests/checkpoints_tests.cpp index 918615c9..3e7b0b76 100644 --- a/tests/core_tests/checkpoints_tests.cpp +++ b/tests/core_tests/checkpoints_tests.cpp @@ -927,7 +927,7 @@ bool gen_checkpoints_set_after_switching_to_altchain::generate(std::vector& events) const REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); m_alice_bob_start_amount = MK_TEST_COINS(200); - uint64_t amount_chunks = 10; + //uint64_t amount_chunks = 10; m_alice_bob_start_chunk_amount = m_alice_bob_start_amount / 10; transaction tx_0 = AUTO_VAL_INIT(tx_0); @@ -3159,7 +3159,7 @@ bool escrow_balance::generate(std::vector& events) const bool escrow_balance::c1(currency::core& c, size_t ev_index, const std::vector& events) { - bool r = false, stub_bool = false; + bool r = false; CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); diff --git a/tests/core_tests/hard_fork_1.cpp b/tests/core_tests/hard_fork_1.cpp index ab49fb94..9134c831 100644 --- a/tests/core_tests/hard_fork_1.cpp +++ b/tests/core_tests/hard_fork_1.cpp @@ -186,7 +186,7 @@ bool hard_fork_1_unlock_time_2_in_coinbase::generate(std::vector& { // Test idea: make sure chain switches without PoS before and after hardfork - bool r = false; + //bool r = false; GENERATE_ACCOUNT(miner_acc); GENERATE_ACCOUNT(alice_acc); MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index fbe68459..f61ff753 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -76,7 +76,7 @@ bool hard_fork_2_tx_payer_in_wallet::generate(std::vector& eve bool hard_fork_2_tx_payer_in_wallet::c1(currency::core& c, size_t ev_index, const std::vector& events) { - bool r = false, stub_bool = false; + bool r = false; CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_accounts[MINER_ACC_IDX]); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); @@ -324,7 +324,7 @@ bool hard_fork_2_tx_receiver_in_wallet::generate(std::vector& bool hard_fork_2_tx_receiver_in_wallet::c1(currency::core& c, size_t ev_index, const std::vector& events) { - bool r = false, stub_bool = false; + bool r = false; CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_accounts[MINER_ACC_IDX]); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); @@ -468,7 +468,7 @@ bool hard_fork_2_tx_extra_alias_entry_in_wallet::generate(std::vector& events) { - bool r = false, stub_bool = false; + bool r = false; CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_accounts[MINER_ACC_IDX]); @@ -670,7 +670,7 @@ bool hard_fork_2_auditable_addresses_basics::generate(std::vector& events) { - bool r = false, stub_bool = false; + bool r = false; CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); std::shared_ptr bob_wlt = init_playtime_test_wallet(events, c, m_accounts[BOB_ACC_IDX]); diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index ae2620bc..3d891568 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -3290,7 +3290,6 @@ bool wallet_unconfimed_tx_balance::generate(std::vector& event bool wallet_unconfimed_tx_balance::c1(currency::core& c, size_t ev_index, const std::vector& events) { - bool r = false; std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(100), false, UINT64_MAX, MK_TEST_COINS(100)), false, ""); @@ -3505,7 +3504,6 @@ wallet_watch_only_and_chain_switch::wallet_watch_only_and_chain_switch() bool wallet_watch_only_and_chain_switch::generate(std::vector& events) const { - bool r = false; m_accounts.resize(TOTAL_ACCS_COUNT); account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); @@ -3602,7 +3600,6 @@ wallet_spend_form_auditable_and_track::wallet_spend_form_auditable_and_track() bool wallet_spend_form_auditable_and_track::generate(std::vector& events) const { - bool r = false; m_accounts.resize(TOTAL_ACCS_COUNT); account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); diff --git a/tests/core_tests/zarcanum_test.cpp b/tests/core_tests/zarcanum_test.cpp index 73760667..a6b74490 100644 --- a/tests/core_tests/zarcanum_test.cpp +++ b/tests/core_tests/zarcanum_test.cpp @@ -86,7 +86,7 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect //miner_wlt->refresh(); alice_wlt->refresh(); - uint64_t unlocked = 0; + //uint64_t unlocked = 0; //uint64_t balance = alice_wlt->balance(unlocked); CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", transfer_amount * 4, UINT64_MAX, transfer_amount * 4), false, ""); From ff730a1bc4877c95bcdab86c22cb3ad2f5b78ab2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 12:24:26 +0200 Subject: [PATCH 35/49] moved tor to latest version --- contrib/tor-connect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/tor-connect b/contrib/tor-connect index 2e7176dc..13f47143 160000 --- a/contrib/tor-connect +++ b/contrib/tor-connect @@ -1 +1 @@ -Subproject commit 2e7176dcea611c1933bec4133591e3f1885b8b37 +Subproject commit 13f47143c0dcb8c12cfa293efc9d6d57ad3d1e37 From 760ee3aa2881d2c7af87e654aaaa4a3a1e74048c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 13:01:16 +0200 Subject: [PATCH 36/49] last warnings removed from coretests --- tests/core_tests/hard_fork_2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index f61ff753..5935968a 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -909,7 +909,7 @@ bool hard_fork_2_awo_wallets_basic_test::c1(currency::core& c, size static const std::wstring bob_wo_restored_filename(L"bob_wo_restored_wallet"); static const std::wstring bob_non_auditable_filename(L"bob_non_auditable_wallet"); - bool r = false, stub_bool = false; + bool r = false; CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); @@ -1181,7 +1181,7 @@ bool hard_fork_2_alias_update_using_old_tx::generate(std::vector bool hard_fork_2_alias_update_using_old_tx::c1(currency::core& c, size_t ev_index, const std::vector& events) { - bool r = false, stub_bool = false; + bool r = false; CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX); From 289cbf62f7d40dc7669b0aa8f2ac9f535afb9e26 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 14:29:07 +0200 Subject: [PATCH 37/49] deterministic random enabled --- tests/core_tests/chaingen_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 246d4c74..a2fe7736 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1064,7 +1064,7 @@ int main(int argc, char* argv[]) //stop_on_first_fail = true; //for (size_t i = 0; i != 100; i++) //{ - // multiassets_basic_test::ts_starter = i; + multiassets_basic_test::ts_starter = 0; GENERATE_AND_PLAY(multiassets_basic_test); //} From cebad7aab3d3df5655db181acf0e04b059f52fd2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 17:01:58 +0200 Subject: [PATCH 38/49] deterministic random enabled2 --- tests/core_tests/multiassets_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 64e501a8..078ed32b 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -22,8 +22,8 @@ multiassets_basic_test::multiassets_basic_test() { // TODO: remove the following line - //LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); - //random_state_test_restorer::reset_random(ts_starter); + LOG_PRINT_MAGENTA("STARTER TS: " << ts_starter, LOG_LEVEL_0); + random_state_test_restorer::reset_random(ts_starter); REGISTER_CALLBACK_METHOD(multiassets_basic_test, configure_core); REGISTER_CALLBACK_METHOD(multiassets_basic_test, c1); From 64ff2cb641df4bca333cc42f00ffbec68075d167 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 18:55:50 +0200 Subject: [PATCH 39/49] added more logs to multiasset test debug --- src/currency_core/currency_format_utils.cpp | 3 +++ src/wallet/wallet_errors.h | 1 + 2 files changed, 4 insertions(+) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 36de2bbd..3261306f 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1948,9 +1948,11 @@ namespace currency std::vector shuffled_dsts(destinations); if (asset_id_for_destinations != currency::null_hash) { + LOG_PRINT_MAGENTA("[Asset descriptor operation]: shuffled_dsts.size()=" << shuffled_dsts.size(), LOG_LEVEL_0); //must be asset publication for (auto& item : shuffled_dsts) { + LOG_PRINT_MAGENTA("[Asset descriptor operation]: item.asset_id: " << item.asset_id << ", amount: " << item.amount, LOG_LEVEL_0); if (item.asset_id == currency::ffff_hash) { item.asset_id = asset_id_for_destinations; @@ -1961,6 +1963,7 @@ namespace currency pado->descriptor.current_supply = amount_of_assets; //TODO: temporary summary_inputs_money += amount_of_assets; + LOG_PRINT_MAGENTA("[Asset descripto operation]: amount_of_assets: " << amount_of_assets << ", summary_inputs_money: " << summary_inputs_money, LOG_LEVEL_0); } diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 9aed4074..e45eafb6 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -463,6 +463,7 @@ namespace tools ss << currency::get_account_address_as_str(a) << ";"; } ss << " anount: " << currency::print_money(dst.amount); + ss << " asset_id: " << dst.asset_id; } ss << "\nunlock_time: " << m_unlock_time; From 9f26c3563087696da83bd003dc07dc3b04f51b55 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 20:03:42 +0200 Subject: [PATCH 40/49] added more logs to multiasset test debug 2 --- .../currency_format_utils_transactions.h | 1 + src/wallet/wallet2.cpp | 11 +++++++++++ tests/core_tests/multiassets_test.cpp | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index 0c8a9e8c..21b01a39 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -110,6 +110,7 @@ namespace currency FIELD(amount_to_provide) FIELD(unlock_time) FIELD(htlc_options) + FIELD(asset_id) END_SERIALIZE() }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 41f620a2..0eb474a5 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4185,6 +4185,10 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf ctp.dsts = destinations; ctp.extra.push_back(asset_reg_info); + //&&&&& + LOG_PRINT_MAGENTA("ctp.dsts[0].asset_id:" << ctp.dsts[0].asset_id << ", ctp.dsts[1].asset_id:" << ctp.dsts[1].asset_id); + + finalized_tx ft = AUTO_VAL_INIT(ft); this->transfer(ctp, ft, true, nullptr); result_tx = ft.tx; @@ -5747,6 +5751,13 @@ void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx prepare_tx_destinations(needed_money_map, static_cast(ctp.split_strategy_id), ctp.dust_policy, ctp.dsts, ftp.prepared_destinations); TIME_MEASURE_FINISH_MS(prepare_tx_destinations_time); + //&&&&& + for (const auto d : ftp.prepared_destinations) + { + LOG_PRINT_MAGENTA("[prepare_tx_destinations] amount:" << d.amoumt << ", asset_id:" << d.asset_id); + } + + if (ctp.mark_tx_as_complete && !ftp.sources.empty()) ftp.sources.back().separately_signed_tx_complete = true; diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 078ed32b..2c66ac7c 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -77,6 +77,10 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v destinations[1].addr.push_back(alice_wlt->get_account().get_public_address()); destinations[1].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; destinations[1].asset_id = currency::ffff_hash; + + LOG_PRINT_MAGENTA("destinations[0].asset_id:" << destinations[0].asset_id); + LOG_PRINT_MAGENTA("destinations[1].asset_id:" << destinations[1].asset_id); + LOG_PRINT_MAGENTA("currency::ffff_hash:" << currency::ffff_hash); currency::transaction tx = AUTO_VAL_INIT(tx); crypto::hash asset_id = currency::null_hash; From 5b4d41b1ed0c519a5755241163c61621598ad602 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 20:05:45 +0200 Subject: [PATCH 41/49] fixed bug with compilation --- src/wallet/wallet2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0eb474a5..7e0a8db2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4186,7 +4186,7 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf ctp.extra.push_back(asset_reg_info); //&&&&& - LOG_PRINT_MAGENTA("ctp.dsts[0].asset_id:" << ctp.dsts[0].asset_id << ", ctp.dsts[1].asset_id:" << ctp.dsts[1].asset_id); + LOG_PRINT_MAGENTA("ctp.dsts[0].asset_id:" << ctp.dsts[0].asset_id << ", ctp.dsts[1].asset_id:" << ctp.dsts[1].asset_id, LOG_LEVEL_0); finalized_tx ft = AUTO_VAL_INIT(ft); @@ -5754,7 +5754,7 @@ void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx //&&&&& for (const auto d : ftp.prepared_destinations) { - LOG_PRINT_MAGENTA("[prepare_tx_destinations] amount:" << d.amoumt << ", asset_id:" << d.asset_id); + LOG_PRINT_MAGENTA("[prepare_tx_destinations] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); } From c5972c006af91577093e1e742499ebbe9f552d64 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 20:09:56 +0200 Subject: [PATCH 42/49] added missing argument to macro in multiasset test --- tests/core_tests/multiassets_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 2c66ac7c..8bc70f08 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -78,9 +78,9 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v destinations[1].amount = AMOUNT_ASSETS_TO_TRANSFER_MULTIASSETS_BASIC; destinations[1].asset_id = currency::ffff_hash; - LOG_PRINT_MAGENTA("destinations[0].asset_id:" << destinations[0].asset_id); - LOG_PRINT_MAGENTA("destinations[1].asset_id:" << destinations[1].asset_id); - LOG_PRINT_MAGENTA("currency::ffff_hash:" << currency::ffff_hash); + LOG_PRINT_MAGENTA("destinations[0].asset_id:" << destinations[0].asset_id, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("destinations[1].asset_id:" << destinations[1].asset_id, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("currency::ffff_hash:" << currency::ffff_hash, LOG_LEVEL_0); currency::transaction tx = AUTO_VAL_INIT(tx); crypto::hash asset_id = currency::null_hash; From 218d2735c578b7b005665f56d4dc0890432fa15b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 21:36:13 +0200 Subject: [PATCH 43/49] more logs, more logs, more logs --- src/wallet/wallet2.cpp | 35 +++++++++++++++++++++++++++++++++-- src/wallet/wallet2.h | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7e0a8db2..7d094d86 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5661,6 +5661,9 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money, const std::vector& dsts, std::vector& final_detinations, const crypto::hash& asset_id) { + //&&&&& + LOG_PRINT_MAGENTA("[-->prepare_tx_destinations[asset_id="<< asset_id <<"]] needed_money " << needed_money, LOG_LEVEL_0); + currency::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts); if (needed_money < found_money) { @@ -5678,11 +5681,28 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money, return; } + //&&&&& + //LOG_PRINT_MAGENTA("[--prepare_tx_destinations[asset_id=" << asset_id << "]] needed_money " << needed_money, LOG_LEVEL_0); + + //&&&&& + for (const auto& d : dsts) + { + LOG_PRINT_MAGENTA("[--prepare_tx_destinations::before split] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); + } + uint64_t dust = 0; bool r = detail::apply_split_strategy_by_id(destination_split_strategy_id, dsts, change_dts, dust_policy.dust_threshold, final_detinations, dust, WALLET_MAX_ALLOWED_OUTPUT_AMOUNT); WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(r, "invalid split strategy id: " << destination_split_strategy_id); WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(dust_policy.dust_threshold >= dust, "invalid dust value: dust = " << dust << ", dust_threshold = " << dust_policy.dust_threshold); + //&&&&& + for (const auto& d : final_detinations) + { + LOG_PRINT_MAGENTA("[--prepare_tx_destinations::after split] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); + } + + + //@#@ #ifdef _DEBUG if (final_detinations.size() > 10) @@ -5747,14 +5767,25 @@ void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx } TIME_MEASURE_FINISH_MS(prepare_tx_sources_time); + //&&&&& + for (const auto& d : ctp.dsts) + { + LOG_PRINT_MAGENTA("[pre-prepare_tx_destinations] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); + } + //&&&&& + for (const auto& d : needed_money_map) + { + LOG_PRINT_MAGENTA("[pre-prepare_tx_destinations] needed_money_map key: " << d.first << ", needed amount: " << d.second.needed_amount, LOG_LEVEL_0); + } + TIME_MEASURE_START_MS(prepare_tx_destinations_time); prepare_tx_destinations(needed_money_map, static_cast(ctp.split_strategy_id), ctp.dust_policy, ctp.dsts, ftp.prepared_destinations); TIME_MEASURE_FINISH_MS(prepare_tx_destinations_time); //&&&&& - for (const auto d : ftp.prepared_destinations) + for (const auto& d : ftp.prepared_destinations) { - LOG_PRINT_MAGENTA("[prepare_tx_destinations] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); + LOG_PRINT_MAGENTA("[post-prepare_tx_destinations] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 5d0f02a6..f05d6d8a 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -252,6 +252,9 @@ namespace tools const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) { + //&&&&& + LOG_PRINT_MAGENTA("[--apply_split_strategy_by_id, split strtegy_id: " << id, LOG_LEVEL_0); + switch (id) { case ssi_digit: From affdff7a3decfcbcc07d1191da214aeb7b6f3e9b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 22:57:09 +0200 Subject: [PATCH 44/49] pre-fix for the problem with asset_id --- src/currency_core/currency_format_utils_transactions.h | 1 + src/wallet/wallet2.h | 4 ++-- tests/core_tests/chaingen_main.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index 21b01a39..643a5f66 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -100,6 +100,7 @@ namespace currency tx_destination_entry() = default; tx_destination_entry(uint64_t a, const account_public_address& ad) : amount(a), addr(1, ad) {} + tx_destination_entry(uint64_t a, const account_public_address& ad, const crypto::hash& aid) : amount(a), addr(1, ad), asset_id(aid) {} tx_destination_entry(uint64_t a, const account_public_address& ad, uint64_t ut) : amount(a), addr(1, ad), unlock_time(ut) {} tx_destination_entry(uint64_t a, const std::list& addr) : amount(a), addr(addr), minimum_sigs(addr.size()) {} diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f05d6d8a..8a60b752 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -184,8 +184,8 @@ namespace tools else { currency::decompose_amount_into_digits(de.amount, dust_threshold, - [&](uint64_t chunk) { splitted_dsts.push_back(currency::tx_destination_entry(chunk, de.addr)); }, - [&](uint64_t a_dust) { splitted_dsts.push_back(currency::tx_destination_entry(a_dust, de.addr)); }, max_output_allowed); + [&](uint64_t chunk) { splitted_dsts.push_back(currency::tx_destination_entry(chunk, de.addr, de.asset_id)); }, + [&](uint64_t a_dust) { splitted_dsts.push_back(currency::tx_destination_entry(a_dust, de.addr, de.asset_id)); }, max_output_allowed); } } diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index a2fe7736..b0638233 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -912,7 +912,7 @@ int main(int argc, char* argv[]) // GENERATE_AND_PLAY(pos_wallet_minting_same_amount_diff_outs); // Long test! Takes ~10 hours to simulate 6000 blocks on 2015 middle-end computer //GENERATE_AND_PLAY(pos_emission_test); // Long test! by demand only GENERATE_AND_PLAY(pos_wallet_big_block_test); - GENERATE_AND_PLAY(block_template_against_txs_size); + //GENERATE_AND_PLAY(block_template_against_txs_size); // Long test! by demand only GENERATE_AND_PLAY(pos_altblocks_validation); // alternative blocks and generic chain-switching tests From b3b57ae5349ad6bd0c49daf36098b32df0f47072 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 23:01:17 +0200 Subject: [PATCH 45/49] one more constructor overload --- src/currency_core/currency_format_utils_transactions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index 643a5f66..6eb9ddd1 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -102,7 +102,7 @@ namespace currency tx_destination_entry(uint64_t a, const account_public_address& ad) : amount(a), addr(1, ad) {} tx_destination_entry(uint64_t a, const account_public_address& ad, const crypto::hash& aid) : amount(a), addr(1, ad), asset_id(aid) {} tx_destination_entry(uint64_t a, const account_public_address& ad, uint64_t ut) : amount(a), addr(1, ad), unlock_time(ut) {} - tx_destination_entry(uint64_t a, const std::list& addr) : amount(a), addr(addr), minimum_sigs(addr.size()) {} + tx_destination_entry(uint64_t a, const std::list& addr, const crypto::hash& aid) : amount(a), addr(addr), minimum_sigs(addr.size()), asset_id(aid) {} BEGIN_SERIALIZE_OBJECT() FIELD(amount) From 0b97855eeb7001f16140b239e0246b726af06efb Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 23:05:25 +0200 Subject: [PATCH 46/49] one more constructor overload: and fixed --- src/currency_core/currency_format_utils_transactions.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index 6eb9ddd1..c38c9cc4 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -102,8 +102,10 @@ namespace currency tx_destination_entry(uint64_t a, const account_public_address& ad) : amount(a), addr(1, ad) {} tx_destination_entry(uint64_t a, const account_public_address& ad, const crypto::hash& aid) : amount(a), addr(1, ad), asset_id(aid) {} tx_destination_entry(uint64_t a, const account_public_address& ad, uint64_t ut) : amount(a), addr(1, ad), unlock_time(ut) {} + tx_destination_entry(uint64_t a, const std::list& addr) : amount(a), addr(addr), minimum_sigs(addr.size()){} tx_destination_entry(uint64_t a, const std::list& addr, const crypto::hash& aid) : amount(a), addr(addr), minimum_sigs(addr.size()), asset_id(aid) {} + BEGIN_SERIALIZE_OBJECT() FIELD(amount) FIELD(addr) From 38b5ef3748d9836a8b01a9caabb6b91b8868f280 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 23:38:48 +0200 Subject: [PATCH 47/49] removed debug logs --- src/currency_core/currency_format_utils.cpp | 3 -- src/wallet/wallet2.cpp | 50 --------------------- 2 files changed, 53 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 3261306f..36de2bbd 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1948,11 +1948,9 @@ namespace currency std::vector shuffled_dsts(destinations); if (asset_id_for_destinations != currency::null_hash) { - LOG_PRINT_MAGENTA("[Asset descriptor operation]: shuffled_dsts.size()=" << shuffled_dsts.size(), LOG_LEVEL_0); //must be asset publication for (auto& item : shuffled_dsts) { - LOG_PRINT_MAGENTA("[Asset descriptor operation]: item.asset_id: " << item.asset_id << ", amount: " << item.amount, LOG_LEVEL_0); if (item.asset_id == currency::ffff_hash) { item.asset_id = asset_id_for_destinations; @@ -1963,7 +1961,6 @@ namespace currency pado->descriptor.current_supply = amount_of_assets; //TODO: temporary summary_inputs_money += amount_of_assets; - LOG_PRINT_MAGENTA("[Asset descripto operation]: amount_of_assets: " << amount_of_assets << ", summary_inputs_money: " << summary_inputs_money, LOG_LEVEL_0); } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7d094d86..6f60deb9 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4185,10 +4185,6 @@ void wallet2::publish_new_asset(const currency::asset_descriptor_base& asset_inf ctp.dsts = destinations; ctp.extra.push_back(asset_reg_info); - //&&&&& - LOG_PRINT_MAGENTA("ctp.dsts[0].asset_id:" << ctp.dsts[0].asset_id << ", ctp.dsts[1].asset_id:" << ctp.dsts[1].asset_id, LOG_LEVEL_0); - - finalized_tx ft = AUTO_VAL_INIT(ft); this->transfer(ctp, ft, true, nullptr); result_tx = ft.tx; @@ -5661,9 +5657,6 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money, const std::vector& dsts, std::vector& final_detinations, const crypto::hash& asset_id) { - //&&&&& - LOG_PRINT_MAGENTA("[-->prepare_tx_destinations[asset_id="<< asset_id <<"]] needed_money " << needed_money, LOG_LEVEL_0); - currency::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts); if (needed_money < found_money) { @@ -5681,37 +5674,11 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money, return; } - //&&&&& - //LOG_PRINT_MAGENTA("[--prepare_tx_destinations[asset_id=" << asset_id << "]] needed_money " << needed_money, LOG_LEVEL_0); - - //&&&&& - for (const auto& d : dsts) - { - LOG_PRINT_MAGENTA("[--prepare_tx_destinations::before split] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); - } - uint64_t dust = 0; bool r = detail::apply_split_strategy_by_id(destination_split_strategy_id, dsts, change_dts, dust_policy.dust_threshold, final_detinations, dust, WALLET_MAX_ALLOWED_OUTPUT_AMOUNT); WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(r, "invalid split strategy id: " << destination_split_strategy_id); WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(dust_policy.dust_threshold >= dust, "invalid dust value: dust = " << dust << ", dust_threshold = " << dust_policy.dust_threshold); - //&&&&& - for (const auto& d : final_detinations) - { - LOG_PRINT_MAGENTA("[--prepare_tx_destinations::after split] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); - } - - - - //@#@ -#ifdef _DEBUG - if (final_detinations.size() > 10) - { - WLT_LOG_L0("final_detinations.size()=" << final_detinations.size()); - } -#endif - //@#@ - if (0 != dust && !dust_policy.add_to_fee) { final_detinations.push_back(currency::tx_destination_entry(dust, dust_policy.addr_for_dust)); @@ -5767,27 +5734,10 @@ void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx } TIME_MEASURE_FINISH_MS(prepare_tx_sources_time); - //&&&&& - for (const auto& d : ctp.dsts) - { - LOG_PRINT_MAGENTA("[pre-prepare_tx_destinations] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); - } - //&&&&& - for (const auto& d : needed_money_map) - { - LOG_PRINT_MAGENTA("[pre-prepare_tx_destinations] needed_money_map key: " << d.first << ", needed amount: " << d.second.needed_amount, LOG_LEVEL_0); - } - TIME_MEASURE_START_MS(prepare_tx_destinations_time); prepare_tx_destinations(needed_money_map, static_cast(ctp.split_strategy_id), ctp.dust_policy, ctp.dsts, ftp.prepared_destinations); TIME_MEASURE_FINISH_MS(prepare_tx_destinations_time); - //&&&&& - for (const auto& d : ftp.prepared_destinations) - { - LOG_PRINT_MAGENTA("[post-prepare_tx_destinations] amount:" << d.amount << ", asset_id:" << d.asset_id, LOG_LEVEL_0); - } - if (ctp.mark_tx_as_complete && !ftp.sources.empty()) ftp.sources.back().separately_signed_tx_complete = true; From d4166ffa5d9a159817e598aa51a6667213cc86e6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Oct 2022 23:40:38 +0200 Subject: [PATCH 48/49] Fixed DUMBEST bug of this year!(absolute champion) --- src/wallet/wallet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6f60deb9..377ca986 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5881,7 +5881,7 @@ construct_tx_param wallet2::get_default_construct_tx_param_inital() } const construct_tx_param& wallet2::get_default_construct_tx_param() { - static construct_tx_param ctp = get_default_construct_tx_param_inital(); + construct_tx_param ctp = get_default_construct_tx_param_inital(); return ctp; } //---------------------------------------------------------------------------------------------------- From bc95391e93a91e52c7388033f04e01e0c833a512 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Oct 2022 00:07:40 +0200 Subject: [PATCH 49/49] removed link to local object(really bad day) --- src/wallet/wallet2.cpp | 5 ++--- src/wallet/wallet2.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a9aa6c6b..468c15e5 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5880,10 +5880,9 @@ construct_tx_param wallet2::get_default_construct_tx_param_inital() ctp.shuffle = 0; return ctp; } -const construct_tx_param& wallet2::get_default_construct_tx_param() +construct_tx_param wallet2::get_default_construct_tx_param() { - construct_tx_param ctp = get_default_construct_tx_param_inital(); - return ctp; + return get_default_construct_tx_param_inital(); } //---------------------------------------------------------------------------------------------------- bool wallet2::store_unsigned_tx_to_file_and_reserve_transfers(const currency::finalize_tx_param& ftp, const std::string& filename, std::string* p_unsigned_tx_blob_str /* = nullptr */) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 1de32a3e..a630312e 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1006,7 +1006,7 @@ private: template bool process_input_t(const input_t& in_t, wallet2::process_transaction_context& ptc, const currency::transaction& tx); - const construct_tx_param& get_default_construct_tx_param(); + construct_tx_param get_default_construct_tx_param(); uint64_t get_tx_expiration_median() const;