From 09dc88ba39924d41697cbaa105f0c84b52594206 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 2 Feb 2024 16:04:09 +0100 Subject: [PATCH] network reset + some changes in genesis for testnet(which didn't work after all) --- src/connectivity_tool/conn_tool.cpp | 5 +- src/currency_core/currency_config.h | 2 +- src/currency_core/currency_format_utils.cpp | 76 +++++++++++---------- src/currency_core/currency_format_utils.h | 4 +- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index b4364d04..710692bd 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -407,8 +407,11 @@ bool generate_genesis(const std::string& path_config, uint64_t premine_split_amo ss.str(""); ss.clear(); + const account_public_address dummy_address = AUTO_VAL_INIT(dummy_address); + std::cout << ENDL << "PROOF PHRASE: " << gcp.proof_string << ENDL; - // construct_miner_tx(0, 0, 0, 0, 0, destinations, bl.miner_tx, TRANSACTION_VERSION_PRE_HF4, gcp.proof_string, CURRENCY_MINER_TX_MAX_OUTS); <-- temporarily commented out; this overload needs to be re-implemented -- sowle + uint64_t block_reward_without_fee = 0; + construct_miner_tx(0, 0, 0, 0, 0, dummy_address, dummy_address, bl.miner_tx, block_reward_without_fee, TRANSACTION_VERSION_PRE_HF4, gcp.proof_string, CURRENCY_MINER_TX_MAX_OUTS, false, pos_entry(), nullptr, nullptr, destinations); currency::blobdata txb = tx_to_blob(bl.miner_tx); //self validate block diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 4cc1406a..a622b08b 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -10,7 +10,7 @@ #ifndef TESTNET #define CURRENCY_FORMATION_VERSION 84 #else -#define CURRENCY_FORMATION_VERSION 90 +#define CURRENCY_FORMATION_VERSION 91 #endif #define CURRENCY_GENESIS_NONCE (CURRENCY_FORMATION_VERSION + 101011010121) //bender's nightmare diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 2111be68..5899af1e 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -367,9 +367,12 @@ namespace currency bool pos /* = false */, const pos_entry& pe /* = pos_entry() */, // only pe.stake_unlock_time and pe.stake_amount are used now, TODO: consider refactoring -- sowle tx_generation_context* ogc_ptr /* = nullptr */, - const keypair* tx_one_time_key_to_use /* = nullptr */ + const keypair* tx_one_time_key_to_use /* = nullptr */, + const std::vector& destinations_ /* = std::vector() */ ) { + std::vector destinations = destinations_; + bool r = false; if (!get_block_reward(pos, median_size, current_block_size, already_generated_coins, block_reward_without_fee, height)) @@ -379,45 +382,48 @@ namespace currency } uint64_t block_reward = block_reward_without_fee + fee; - // - // prepare destinations - // - // 1. split block_reward into out_amounts - std::vector out_amounts; - if (tx_version > TRANSACTION_VERSION_PRE_HF4) + if (!destinations.size()) { - // randomly split into CURRENCY_TX_MIN_ALLOWED_OUTS outputs for PoW block, or for PoS block only if the stakeholder address differs - // (otherwise for PoS miner tx there will be ONE output with amount = stake_amount + reward) - if (!pos || miner_address != stakeholder_address) - decompose_amount_randomly(block_reward, [&](uint64_t a){ out_amounts.push_back(a); }, CURRENCY_TX_MIN_ALLOWED_OUTS); - } - else - { - // non-hidden outs: split into digits - decompose_amount_into_digits(block_reward, DEFAULT_DUST_THRESHOLD, - [&out_amounts](uint64_t a_chunk) { out_amounts.push_back(a_chunk); }, - [&out_amounts](uint64_t a_dust) { out_amounts.push_back(a_dust); }); - CHECK_AND_ASSERT_MES(1 <= max_outs, false, "max_out must be non-zero"); - while (max_outs < out_amounts.size()) + // + // prepare destinations + // + // 1. split block_reward into out_amounts + std::vector out_amounts; + if (tx_version > TRANSACTION_VERSION_PRE_HF4) { - out_amounts[out_amounts.size() - 2] += out_amounts.back(); - out_amounts.resize(out_amounts.size() - 1); + // randomly split into CURRENCY_TX_MIN_ALLOWED_OUTS outputs for PoW block, or for PoS block only if the stakeholder address differs + // (otherwise for PoS miner tx there will be ONE output with amount = stake_amount + reward) + if (!pos || miner_address != stakeholder_address) + decompose_amount_randomly(block_reward, [&](uint64_t a) { out_amounts.push_back(a); }, CURRENCY_TX_MIN_ALLOWED_OUTS); } - } - // 2. construct destinations using out_amounts - std::vector destinations; - for (auto a : out_amounts) - { - tx_destination_entry de = AUTO_VAL_INIT(de); - de.addr.push_back(miner_address); - de.amount = a; - de.flags |= tx_destination_entry_flags::tdef_explicit_native_asset_id; // don't use asset id blinding as it's obvious which asset it is - if (pe.stake_unlock_time && pe.stake_unlock_time > height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW) + else { - //this means that block is creating after hardfork_1 and unlock_time is needed to set for every destination separately - de.unlock_time = height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW; + // non-hidden outs: split into digits + decompose_amount_into_digits(block_reward, DEFAULT_DUST_THRESHOLD, + [&out_amounts](uint64_t a_chunk) { out_amounts.push_back(a_chunk); }, + [&out_amounts](uint64_t a_dust) { out_amounts.push_back(a_dust); }); + CHECK_AND_ASSERT_MES(1 <= max_outs, false, "max_out must be non-zero"); + while (max_outs < out_amounts.size()) + { + out_amounts[out_amounts.size() - 2] += out_amounts.back(); + out_amounts.resize(out_amounts.size() - 1); + } + } + // 2. construct destinations using out_amounts + + for (auto a : out_amounts) + { + tx_destination_entry de = AUTO_VAL_INIT(de); + de.addr.push_back(miner_address); + de.amount = a; + de.flags |= tx_destination_entry_flags::tdef_explicit_native_asset_id; // don't use asset id blinding as it's obvious which asset it is + if (pe.stake_unlock_time && pe.stake_unlock_time > height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW) + { + //this means that block is creating after hardfork_1 and unlock_time is needed to set for every destination separately + de.unlock_time = height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW; + } + destinations.push_back(de); } - destinations.push_back(de); } if (pos) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index dd58c5ff..3493c6c6 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -280,7 +280,9 @@ namespace currency bool pos = false, const pos_entry& pe = pos_entry(), tx_generation_context* ogc_ptr = nullptr, - const keypair* tx_one_time_key_to_use = nullptr); + const keypair* tx_one_time_key_to_use = nullptr, + const std::vector& destinations = std::vector() + ); //--------------------------------------------------------------- uint64_t get_string_uint64_hash(const std::string& str); bool construct_tx_out(const tx_destination_entry& de, const crypto::secret_key& tx_sec_key, size_t output_index, transaction& tx, std::set& deriv_cache, const account_keys& self, crypto::scalar_t& asset_blinding_mask, crypto::scalar_t& amount_blinding_mask, crypto::point_t& blinded_asset_id, crypto::point_t& amount_commitment, finalized_tx& result, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);