From 4607939ab64f8720542c12f2522b41bbf9c39c3b Mon Sep 17 00:00:00 2001 From: Some Random Crypto Guy Date: Thu, 16 May 2024 22:29:32 +0100 Subject: [PATCH] fixed unlock time info displayed for mined blocks; added tx_type to get_return_address() call - needed for F point on transfers; bumped version --- src/blockchain_db/lmdb/db_lmdb.cpp | 2 +- src/cryptonote_core/cryptonote_tx_utils.cpp | 28 +++++++++++++++++++-- src/version.cpp.in | 2 +- src/wallet/wallet2.cpp | 2 ++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index b48e61f..9f1bb80 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -924,7 +924,7 @@ void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t l ybi.block_height = m_height; ybi.slippage_total_this_block = slippage_total; ybi.locked_coins_this_block = yield_total; - ybi.locked_coins_tally = ybi_prev.locked_coins_tally - ybi_matured.locked_coins_tally + yield_total; + ybi.locked_coins_tally = ybi_prev.locked_coins_tally - ybi_matured.locked_coins_this_block + yield_total; ybi.network_health_percentage = 100; // Put the YBI into the table diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index 5dc40b1..84cc859 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -641,6 +641,7 @@ namespace cryptonote } //--------------------------------------------------------------- bool get_return_address(const size_t tx_version, // needed in case we change implementation down the line + const cryptonote::transaction_type& tx_type, // needed because TRANSFER needs to use F point instead of return_address and TX pubkey const crypto::ec_scalar& uniqueness, const cryptonote::account_keys &sender_account_keys, // needed to calculate pretty much anything const crypto::public_key &P_change, // one-time public key from CONVERT/YIELD change @@ -999,6 +1000,7 @@ namespace cryptonote uint64_t summary_outs_money = 0; //fill outputs size_t output_index = 0; + size_t change_index = 0; for(const tx_destination_entry& dst_entr: destinations) { CHECK_AND_ASSERT_MES(dst_entr.amount > 0 || tx.version > 1, false, "Destination with wrong amount: " << dst_entr.amount); @@ -1020,6 +1022,11 @@ namespace cryptonote continue; } } + + // Check to see if this is the change output + if (dst_entr.is_change) { + change_index = output_index; + } // Get the uniqueness for this TX CHECK_AND_ASSERT_MES(!tx.vin.empty(), false, "tx.vin[] is empty"); @@ -1061,7 +1068,7 @@ namespace cryptonote CHECK_AND_ASSERT_MES(P_change != crypto::null_pkey, false, "Internal error - not found TX change output for CONVERT tx"); // Now generate the return address and TX pubkey - CHECK_AND_ASSERT_MES(get_return_address(tx.version, uniqueness, sender_account_keys, P_change, txkey_pub, tx.return_address, tx.return_pubkey, hwdev), false, "Failed to get protocol destination address"); + CHECK_AND_ASSERT_MES(get_return_address(tx.version, tx.type, uniqueness, sender_account_keys, P_change, txkey_pub, tx.return_address, tx.return_pubkey, hwdev), false, "Failed to get protocol destination address"); } else if (tx_type == cryptonote::transaction_type::YIELD) { @@ -1079,7 +1086,24 @@ namespace cryptonote CHECK_AND_ASSERT_MES(P_change != crypto::null_pkey, false, "Internal error - not found TX change output for YIELD tx"); // Now generate the return address and TX pubkey - CHECK_AND_ASSERT_MES(get_return_address(tx.version, uniqueness, sender_account_keys, P_change, txkey_pub, tx.return_address, tx.return_pubkey, hwdev), false, "Failed to get protocol destination address"); + CHECK_AND_ASSERT_MES(get_return_address(tx.version, tx.type, uniqueness, sender_account_keys, P_change, txkey_pub, tx.return_address, tx.return_pubkey, hwdev), false, "Failed to get protocol destination address"); + } else if (tx_type == cryptonote::transaction_type::TRANSFER) { + + // Get the uniqueness for this TX + CHECK_AND_ASSERT_MES(!tx.vin.empty(), false, "tx.vin[] is empty"); + CHECK_AND_ASSERT_MES(tx.vin[0].type() == typeid(cryptonote::txin_to_key), false, "incorrect tx.vin[0] type for TRANSFER TX"); + crypto::key_image k_image = boost::get(tx.vin[0]).k_image; + ec_scalar uniqueness; + CHECK_AND_ASSERT_MES(calculate_uniqueness(tx.type, k_image, 0, 0, uniqueness), false, "Failed to calculate uniqueness for the transaction"); + + // Get the output public key for the change output + crypto::public_key P_change = crypto::null_pkey; + CHECK_AND_ASSERT_MES(tx.vout.size() == 2, false, "Internal error - incorrect number of outputs (!=2) for TRANSFER tx"); + CHECK_AND_ASSERT_MES(cryptonote::get_output_public_key(tx.vout[change_index], P_change), false, "Internal error - failed to get TX change output public key"); + CHECK_AND_ASSERT_MES(P_change != crypto::null_pkey, false, "Internal error - not found TX change output for TRANSFER tx"); + + // Now generate the return address and TX pubkey + CHECK_AND_ASSERT_MES(get_return_address(tx.version, tx.type, uniqueness, sender_account_keys, P_change, txkey_pub, tx.return_address, tx.return_pubkey, hwdev), false, "Failed to get protocol destination address"); } LOG_PRINT_L2("tx pubkey: " << txkey_pub); diff --git a/src/version.cpp.in b/src/version.cpp.in index f80281f..03ceaaf 100644 --- a/src/version.cpp.in +++ b/src/version.cpp.in @@ -1,5 +1,5 @@ #define DEF_SALVIUM_VERSION_TAG "7f6b8da" -#define DEF_SALVIUM_VERSION "0.0.2" +#define DEF_SALVIUM_VERSION "0.0.3" #define DEF_MONERO_VERSION_TAG "@VERSIONTAG@" #define DEF_MONERO_VERSION "0.18.2.2" #define DEF_MONERO_RELEASE_NAME "Zero" diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d0c36c1..83079cb 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -6311,6 +6311,8 @@ std::map>> wallet2:: uint64_t unlock_height = td.m_block_height + std::max(CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS); if (td.m_tx.unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER && td.m_tx.unlock_time > unlock_height) unlock_height = td.m_tx.unlock_time; + if (td.m_tx.type == cryptonote::transaction_type::MINER) + unlock_height = td.m_block_height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW; uint64_t unlock_time = td.m_tx.unlock_time >= CRYPTONOTE_MAX_BLOCK_NUMBER ? td.m_tx.unlock_time : 0; blocks_to_unlock = unlock_height > blockchain_height ? unlock_height - blockchain_height : 0; time_to_unlock = unlock_time > now ? unlock_time - now : 0;