diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 9f306581f5f..25d3031b185 100755 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -4702,13 +4702,13 @@ void BlockchainLMDB::fixup(cryptonote::network_type nettype) if (is_hard_fork_at_least(nettype, cryptonote::network_version_17_POS, curr_height) && block_header_has_POS_components(get_block_header_from_height(curr_height))) { - diff = POS_FIXED_DIFFICULTY; // TARGET_BLOCK_TIME_V17 + diff = POS_FIXED_DIFFICULTY; // TARGET_BLOCK_TIME } else { diff = next_difficulty_v2(timestamps, difficulties, - tools::to_seconds(TARGET_BLOCK_TIME), //use OLD BLOCK_TIME + tools::to_seconds(TARGET_BLOCK_TIME_OLD), //use OLD BLOCK_TIME difficulty_mode(nettype, curr_height + 1)); } } diff --git a/src/cryptonote_basic/cryptonote_basic_impl.cpp b/src/cryptonote_basic/cryptonote_basic_impl.cpp index b774df289f6..48bd65f8d8e 100755 --- a/src/cryptonote_basic/cryptonote_basic_impl.cpp +++ b/src/cryptonote_basic/cryptonote_basic_impl.cpp @@ -119,8 +119,8 @@ namespace cryptonote { return result; } - bool get_base_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint64_t &reward_unpenalized, uint8_t version, uint64_t height) { - + bool get_base_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint64_t &reward_unpenalized, uint8_t version, uint64_t height) + { //premine reward if (height == 1) { @@ -128,13 +128,13 @@ namespace cryptonote { return true; } - if((height>=56500) && (version=56500) && (version= network_version_17_POS ? BLOCK_REWARD_HF17_POS : diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 7163d6d2b6f..6ac596fdaff 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -84,8 +84,14 @@ static_assert(STAKING_PORTIONS % 12 == 0, "Use a multiple of twelve, so that it #define DIFFICULTY_TARGET_V2 120 // seconds #define DIFFICULTY_TARGET_V1 60 // seconds - before first fork -constexpr auto TARGET_BLOCK_TIME = 2min; -constexpr auto TARGET_BLOCK_TIME_V17 = 30s; +constexpr auto TARGET_BLOCK_TIME_OLD = 2min; +constexpr uint64_t BLOCKS_PER_HOUR_OLD = 1h / TARGET_BLOCK_TIME_OLD; +constexpr uint64_t BLOCKS_PER_DAY_OLD = 24h / TARGET_BLOCK_TIME_OLD; + +constexpr auto TARGET_BLOCK_TIME = 30s; +constexpr uint64_t BLOCKS_PER_HOUR = 1h / TARGET_BLOCK_TIME; +constexpr uint64_t BLOCKS_PER_DAY = 24h / TARGET_BLOCK_TIME; + constexpr uint64_t DIFFICULTY_WINDOW = 59; constexpr uint64_t DIFFICULTY_BLOCKS_COUNT(bool before_hf16) { @@ -109,8 +115,8 @@ constexpr uint64_t DIFFICULTY_BLOCKS_COUNT(bool before_hf16) -#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 TARGET_BLOCK_TIME * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS -#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V3 TARGET_BLOCK_TIME_V17 * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS +#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 TARGET_BLOCK_TIME_OLD * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS +#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V3 TARGET_BLOCK_TIME * CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS #define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS 1 @@ -192,9 +198,6 @@ constexpr uint64_t DIFFICULTY_BLOCKS_COUNT(bool before_hf16) #define HASH_OF_HASHES_STEP 256 -#define VOTE_LIFETIME_HOURS 2 -#define MINIMUM_CREDIT_HOURS 2 - #define DEFAULT_TXPOOL_MAX_WEIGHT 648000000ull // 3 days at 300000, in bytes #define BULLETPROOF_MAX_OUTPUTS 16 @@ -204,10 +207,6 @@ constexpr uint64_t DIFFICULTY_BLOCKS_COUNT(bool before_hf16) #define CRYPTONOTE_PRUNING_TIP_BLOCKS 5500 // the smaller, the more space saved //#define CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED -constexpr uint64_t PRE_POS_BLOCKS_EXPECTED_IN_HOURS(int hours) { return (1h / TARGET_BLOCK_TIME) * hours; } -constexpr uint64_t PRE_POS_BLOCKS_EXPECTED_IN_DAYS(int days) { return PRE_POS_BLOCKS_EXPECTED_IN_HOURS(24) * days; } -constexpr uint64_t PRE_POS_BLOCKS_EXPECTED_IN_YEARS(int years) { return PRE_POS_BLOCKS_EXPECTED_IN_DAYS(365) * years; } - // New constants are intended to go here namespace config { @@ -243,7 +242,7 @@ namespace config inline constexpr std::string_view GENESIS_TX = "013c01ff0005978c390224a302c019c844f7141f35bf7f0fc5b02ada055e4ba897557b17ac6ccf88f0a2c09fab030276d443549feee11fe325048eeea083fcb7535312572d255ede1ecb58f84253b480e89226023b7d7c5e6eff4da699393abf12b6e3d04eae7909ae21932520fb3166b8575bb180cab5ee0102e93beb645ce7d5574d6a5ed5d9b8aadec7368342d08a7ca7b342a428353a10df80e497d01202b6e6844c1e9a478d0e4f7f34e455b26077a51f0005357aa19a49ca16eb373f622101f7c2a3a2ed7011b61998b1cd4f45b4d3c1daaa82908a10ca191342297eef1cf8"sv; inline constexpr uint32_t GENESIS_NONCE = 11011; - inline constexpr uint64_t GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS = PRE_POS_BLOCKS_EXPECTED_IN_DAYS(7);//Governance added from V17 + inline constexpr uint64_t GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS = 7 * BLOCKS_PER_DAY_OLD;//Governance added from V17 inline constexpr std::array GOVERNANCE_WALLET_ADDRESS = { "bxcguQiBhYaDW5wAdPLSwRHA6saX1nCEYUF89SPKZfBY1BENdLQWjti59aEtAEgrVZjnCJEVFoCDrG1DCoz2HeeN2pxhxL9xa"sv, // =cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * hours; } -constexpr uint64_t BLOCKS_EXPECTED_IN_DAYS(int days, uint8_t hf_version=17) { return BLOCKS_EXPECTED_IN_HOURS(24,hf_version) * days; } -constexpr uint64_t BLOCKS_EXPECTED_IN_YEARS(int years, uint8_t hf_version) { return BLOCKS_EXPECTED_IN_DAYS(365,hf_version) * years; } - -constexpr uint64_t BLOCKS_PER_CREDIT_EARNED = 30; \ No newline at end of file diff --git a/src/cryptonote_core/beldex_name_system.cpp b/src/cryptonote_core/beldex_name_system.cpp index 73d9e38658f..350e932b35e 100755 --- a/src/cryptonote_core/beldex_name_system.cpp +++ b/src/cryptonote_core/beldex_name_system.cpp @@ -645,28 +645,22 @@ std::vector all_mapping_types(uint8_t hf_version) { return result; } -std::optional expiry_blocks(cryptonote::network_type nettype, mapping_years map_years, uint8_t hf_version) +std::optional expiry_blocks(cryptonote::network_type nettype, mapping_years map_years) { std::optional result; - - // For testnet we shorten 1-, 2-, and 5-year renewals to 1/2/5 days with 1-day renewal. - const bool testnet_short = nettype == cryptonote::TESTNET; - - if (map_years == mapping_years::bns_1year) - result = BLOCKS_EXPECTED_IN_DAYS(1 * REGISTRATION_YEAR_DAYS,hf_version); - else if (map_years == mapping_years::bns_2years) - result = BLOCKS_EXPECTED_IN_DAYS(2 * REGISTRATION_YEAR_DAYS,hf_version); - else if (map_years == mapping_years::bns_5years) - result = BLOCKS_EXPECTED_IN_DAYS(5 * REGISTRATION_YEAR_DAYS,hf_version); - else if (map_years == mapping_years::bns_10years) - result = BLOCKS_EXPECTED_IN_DAYS(10 * REGISTRATION_YEAR_DAYS,hf_version); - - assert(result); - if (testnet_short) + result = BLOCKS_PER_DAY * REGISTRATION_YEAR_DAYS * ( + map_years == mapping_years::bns_1year ? 1 : + map_years == mapping_years::bns_2years ? 2 : + map_years == mapping_years::bns_5years ? 5 : + map_years == mapping_years::bns_10years ? 10 : 0); + + assert(result && *result); + + if (nettype == cryptonote::TESTNET) // For testnet we shorten 1/2/5/10 years renewals to 1/2/5 days. *result /= REGISTRATION_YEAR_DAYS; else if (nettype == cryptonote::FAKECHAIN) // For fakenet testing we shorten 1/2/5/10 years to 2/4/10/20 blocks - *result /= (BLOCKS_EXPECTED_IN_DAYS(((REGISTRATION_YEAR_DAYS) / 2),hf_version)); + *result /= (BLOCKS_PER_DAY * REGISTRATION_YEAR_DAYS / 2); return result; } @@ -1301,15 +1295,11 @@ bool validate_mapping_type(std::string_view mapping_type_str, uint8_t hf_version std::optional mapping_type_; if (tools::string_iequal(mapping, "bchat")) mapping_type_ = bns::mapping_type::bchat; - else if (hf_version >= cryptonote::network_version_17_POS) - { - if (tools::string_iequal(mapping, "belnet")) + else if (tools::string_iequal(mapping, "belnet")) mapping_type_ = bns::mapping_type::belnet; - else if (tools::string_iequal(mapping, "wallet")) + else if (tools::string_iequal(mapping, "wallet")) mapping_type_ = bns::mapping_type::wallet; - } - - if (!mapping_type_) + else { if (reason) *reason = "Unsupported BNS type \"" + std::string{mapping_type_str} + "\"; supported types are: bchat, belnet, wallet"; return false; @@ -1952,7 +1942,7 @@ std::optional add_or_get_owner_id(bns::name_system_db &bns_db, crypto:: // Build a query and bind values that will create a new row at the given height by copying the // current highest-height row values and/or updating the given update fields. using update_variant = std::variant; -std::pair> update_record_query(name_system_db& bns_db, uint64_t height, const cryptonote::tx_extra_beldex_name_system& entry, const crypto::hash& tx_hash,int8_t hf_version) +std::pair> update_record_query(name_system_db& bns_db, uint64_t height, const cryptonote::tx_extra_beldex_name_system& entry, const crypto::hash& tx_hash) { assert(entry.is_updating() || entry.is_renewing()); @@ -1972,7 +1962,7 @@ SELECT name_hash, ?, ?)"; if (entry.is_renewing()) { sql += ", expiration_height + ?, owner_id, backup_owner_id, encrypted_bchat_value, encrypted_wallet_value, encrypted_belnet_value"; - bind.emplace_back(expiry_blocks(bns_db.network_type(), entry.mapping_years, hf_version).value_or(0)); + bind.emplace_back(expiry_blocks(bns_db.network_type(), entry.mapping_years).value_or(0)); } else { @@ -2040,7 +2030,7 @@ SELECT name_hash, ?, ?)"; return result; } -bool add_bns_entry(bns::name_system_db &bns_db, uint64_t height, cryptonote::tx_extra_beldex_name_system const &entry, crypto::hash const &tx_hash,uint8_t hf_version) +bool add_bns_entry(bns::name_system_db &bns_db, uint64_t height, cryptonote::tx_extra_beldex_name_system const &entry, crypto::hash const &tx_hash) { // ----------------------------------------------------------------------------------------------- // New Mapping Insert or Completely Replace @@ -2067,7 +2057,7 @@ bool add_bns_entry(bns::name_system_db &bns_db, uint64_t height, cryptonote::tx_ } } - auto expiry = expiry_blocks(bns_db.network_type(), entry.mapping_years, hf_version); + auto expiry = expiry_blocks(bns_db.network_type(), entry.mapping_years); if (expiry) *expiry += height; if (!bns_db.save_mapping(tx_hash, entry, height, expiry, *owner_id, backup_owner_id)) { @@ -2080,7 +2070,7 @@ bool add_bns_entry(bns::name_system_db &bns_db, uint64_t height, cryptonote::tx_ // ----------------------------------------------------------------------------------------------- else { - auto [sql, bind] = update_record_query(bns_db, height, entry, tx_hash,hf_version); + auto [sql, bind] = update_record_query(bns_db, height, entry, tx_hash); if (sql.empty()) return false; // already MERROR'd @@ -2133,7 +2123,7 @@ bool name_system_db::add_block(const cryptonote::block &block, const std::vector } crypto::hash const &tx_hash = cryptonote::get_transaction_hash(tx); - if (!add_bns_entry(*this, height, entry, tx_hash,block.major_version)) + if (!add_bns_entry(*this, height, entry, tx_hash)) return false; bns_parsed_from_block = true; diff --git a/src/cryptonote_core/beldex_name_system.h b/src/cryptonote_core/beldex_name_system.h index 6a53d6fe25b..c4b414ccb05 100755 --- a/src/cryptonote_core/beldex_name_system.h +++ b/src/cryptonote_core/beldex_name_system.h @@ -157,7 +157,7 @@ constexpr std::string_view db_mapping_value(bns::mapping_type type) { } } // Returns the length of the given mapping type, in blocks, or std::nullopt if the mapping type never expires. -std::optional expiry_blocks(cryptonote::network_type nettype, mapping_years map_years, uint8_t hf_version); +std::optional expiry_blocks(cryptonote::network_type nettype, mapping_years map_years); // Returns *the* proper representation of a name_hash for querying the database, which is 44 base64 // characters (43 significant chars + a padding '='). External input values should always get diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 3e1d22f15bb..5821378bfc7 100755 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -650,7 +650,7 @@ void Blockchain::pop_blocks(uint64_t nblocks) bool stop_batch = m_db->batch_start(); uint8_t hf_version = get_network_version(); - uint64_t blocks_expected_in_hours = BLOCKS_EXPECTED_IN_HOURS(24,hf_version); + uint64_t blocks_expected_per_day = (hf_version>=cryptonote::network_version_17_POS) ? BLOCKS_PER_DAY : BLOCKS_PER_DAY_OLD ; try { const uint64_t blockchain_height = m_db->height(); @@ -663,7 +663,7 @@ void Blockchain::pop_blocks(uint64_t nblocks) tools::PerformanceTimer timer; for (int progress = 0; i < nblocks; ++i) { - if (nblocks >= blocks_expected_in_hours && (i != 0 && (i % blocks_per_update == 0))) + if (nblocks >= blocks_expected_per_day && (i != 0 && (i % blocks_per_update == 0))) { MGINFO("... popping blocks " << (++progress * PERCENT_PER_PROGRESS_UPDATE) << "% completed, height: " << (blockchain_height - i) << " (" << timer.seconds() << "s)"); timer.reset(); @@ -954,7 +954,7 @@ difficulty_type Blockchain::get_difficulty_for_next_block(bool POS) m_nettype, m_cache.m_timestamps, m_cache.m_difficulties, chain_height, m_cache.m_timestamps_and_difficulties_height); uint64_t diff = next_difficulty_v2(m_cache.m_timestamps, m_cache.m_difficulties, - tools::to_seconds((hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)), + tools::to_seconds((hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)), difficulty_mode(m_nettype, chain_height)); m_cache.m_timestamps_and_difficulties_height = chain_height; @@ -1219,7 +1219,7 @@ difficulty_type Blockchain::get_difficulty_for_alternative_chain(const std::list auto hf_version = cryptonote::get_network_version(m_nettype, height); return next_difficulty_v2(timestamps, cumulative_difficulties, - tools::to_seconds((hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)), + tools::to_seconds((hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)), difficulty_mode(m_nettype, height)); } //------------------------------------------------------------------ diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 3c36bb44ddb..0d3f7fb457e 100755 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -2474,7 +2474,7 @@ namespace cryptonote const auto hf_version = get_network_version(m_nettype, m_target_blockchain_height); - static double threshold = 1. / ((24h * 10) / (hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)); // one false positive every 10 days + static double threshold = 1. / ((24h * 10) / (hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)); // one false positive every 10 days static constexpr unsigned int max_blocks_checked = 150; const time_t now = time(NULL); @@ -2486,7 +2486,7 @@ namespace cryptonote unsigned int b = 0; const time_t time_boundary = now - static_cast(seconds[n]); for (time_t ts: timestamps) b += ts >= time_boundary; - const double p = probability(b, seconds[n] / tools::to_seconds((hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME))); + const double p = probability(b, seconds[n] / tools::to_seconds((hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD))); MDEBUG("blocks in the last " << seconds[n] / 60 << " minutes: " << b << " (probability " << p << ")"); if (p < threshold) { diff --git a/src/cryptonote_core/master_node_list.cpp b/src/cryptonote_core/master_node_list.cpp index 8c7b909f469..4912bb8f010 100755 --- a/src/cryptonote_core/master_node_list.cpp +++ b/src/cryptonote_core/master_node_list.cpp @@ -75,9 +75,9 @@ namespace master_nodes static uint64_t short_term_state_cull_height(uint8_t hf_version, uint64_t block_height) { - uint64_t state_change_tx_lifetime_in_blocks = BLOCKS_EXPECTED_IN_HOURS(2,hf_version); - size_t DEFAULT_SHORT_TERM_STATE_HISTORY = 6 * state_change_tx_lifetime_in_blocks; - + size_t constexpr DEFAULT_SHORT_TERM_STATE_HISTORY = 6 * STATE_CHANGE_TX_LIFETIME_IN_BLOCKS; + static_assert(DEFAULT_SHORT_TERM_STATE_HISTORY >= 12 * BLOCKS_PER_HOUR, // Arbitrary, but raises a compilation failure if it gets shortened. + "not enough short term state storage for blink quorum retrieval!"); uint64_t result = (block_height < DEFAULT_SHORT_TERM_STATE_HISTORY) ? 0 : block_height - DEFAULT_SHORT_TERM_STATE_HISTORY; return result; @@ -978,6 +978,9 @@ namespace master_nodes info.swarm_id = UNASSIGNED_SWARM_ID; info.last_ip_change_height = block_height; + if(hf_version >= cryptonote::network_version_18_bns) + info.recommission_credit = DECOMMISSION_INITIAL_CREDIT_V18; + for (size_t i = 0; i < contributor_args.addresses.size(); i++) { // Check for duplicates @@ -1614,8 +1617,8 @@ namespace master_nodes bool newest_block = m_blockchain.get_current_blockchain_height() == (block_height + 1); auto now = POS::clock::now().time_since_epoch(); - auto earliest_time = std::chrono::seconds(block.timestamp) - (block.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME); - auto latest_time = std::chrono::seconds(block.timestamp) + (block.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME); + auto earliest_time = std::chrono::seconds(block.timestamp) - (block.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD); + auto latest_time = std::chrono::seconds(block.timestamp) + (block.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD); if (newest_block && (now >= earliest_time && now <= latest_time)) { @@ -2138,7 +2141,6 @@ namespace master_nodes uint64_t cull_height = short_term_state_cull_height(hf_version, block_height); { auto end_it = m_transient.state_history.upper_bound(cull_height); - uint64_t vote_lifetime = BLOCKS_EXPECTED_IN_HOURS(VOTE_LIFETIME_HOURS,hf_version); for (auto it = m_transient.state_history.begin(); it != end_it; it++) { if (m_store_quorum_history) @@ -2146,7 +2148,7 @@ namespace master_nodes uint64_t next_long_term_state = ((it->height / STORE_LONG_TERM_STATE_INTERVAL) + 1) * STORE_LONG_TERM_STATE_INTERVAL; uint64_t dist_to_next_long_term_state = next_long_term_state - it->height; - bool need_quorum_for_future_states = (dist_to_next_long_term_state <= vote_lifetime + VOTE_OR_TX_VERIFY_HEIGHT_BUFFER); + bool need_quorum_for_future_states = (dist_to_next_long_term_state <= VOTE_LIFETIME + VOTE_OR_TX_VERIFY_HEIGHT_BUFFER); if ((it->height % STORE_LONG_TERM_STATE_INTERVAL) == 0 || need_quorum_for_future_states) { m_transient.state_added_to_archive = true; @@ -2692,8 +2694,7 @@ namespace master_nodes // first (vote_lifetime + VOTE_OR_TX_VERIFY_HEIGHT_BUFFER) states we only // store their quorums, such that the following states have quorum // information preceeding it. - uint64_t vote_lifetime = BLOCKS_EXPECTED_IN_HOURS(VOTE_LIFETIME_HOURS,hf_version); - uint64_t const max_short_term_height = short_term_state_cull_height(hf_version, (m_state.height - 1)) + vote_lifetime + VOTE_OR_TX_VERIFY_HEIGHT_BUFFER; + uint64_t const max_short_term_height = short_term_state_cull_height(hf_version, (m_state.height - 1)) + VOTE_LIFETIME + VOTE_OR_TX_VERIFY_HEIGHT_BUFFER; for (auto it = m_transient.state_history.begin(); it != m_transient.state_history.end() && it->height <= max_short_term_height; it++) @@ -3341,8 +3342,7 @@ namespace master_nodes auto was = info.recommission_credit; auto hf_version = mn_list->m_blockchain.get_network_version(); if (info.decommission_count <= info.is_decommissioned()) // Has never been decommissioned (or is currently in the first decommission), so add initial starting credit - - info.recommission_credit = BLOCKS_EXPECTED_IN_HOURS(MINIMUM_CREDIT_HOURS,hf_version); + info.recommission_credit = DECOMMISSION_INITIAL_CREDIT; else info.recommission_credit = 0; diff --git a/src/cryptonote_core/master_node_quorum_cop.cpp b/src/cryptonote_core/master_node_quorum_cop.cpp index 7edf6125dd1..dd1755991e2 100755 --- a/src/cryptonote_core/master_node_quorum_cop.cpp +++ b/src/cryptonote_core/master_node_quorum_cop.cpp @@ -309,8 +309,7 @@ namespace master_nodes LOG_PRINT_L3("Decommissioned master node " << quorum->workers[node_index] << " has no remaining credit; voting to deregister"); vote_for_state = new_state::deregister; // Credit ran out! } else { - int64_t decommission_minimum = BLOCKS_EXPECTED_IN_HOURS(2,hf_version); - if (credit >= decommission_minimum) { + if (credit >= DECOMMISSION_MINIMUM) { vote_for_state = new_state::decommission; LOG_PRINT_L3("Master node " << quorum->workers[node_index] @@ -320,7 +319,7 @@ namespace master_nodes LOG_PRINT_L3("Master node " << quorum->workers[node_index] << " has stopped passing required checks, but does not have sufficient earned credit (" - << credit << " blocks, " << decommission_minimum + << credit << " blocks, " << DECOMMISSION_MINIMUM << " required) to decommission; voting to deregister"); } } @@ -431,7 +430,6 @@ namespace master_nodes uint64_t const height = cryptonote::get_block_height(block); uint64_t const latest_height = std::max(m_core.get_current_blockchain_height(), m_core.get_target_blockchain_height()); - uint64_t VOTE_LIFETIME = BLOCKS_EXPECTED_IN_HOURS(VOTE_LIFETIME_HOURS,hf_version); if (latest_height < VOTE_LIFETIME) return; @@ -787,15 +785,12 @@ namespace master_nodes // Now we calculate the credit at last commission plus any credit earned from being up for `blocks_up` blocks since int64_t credit = info.recommission_credit; - if (blocks_up > 0) { - credit += blocks_up / BLOCKS_PER_CREDIT_EARNED; + credit += blocks_up * DECOMMISSION_CREDIT_PER_DAY / BLOCKS_PER_DAY; } - - int64_t decommission_max_credit = BLOCKS_EXPECTED_IN_HOURS(48,hf_version); - if (credit > decommission_max_credit) - credit = decommission_max_credit; // Cap the available decommission credit blocks if above the max + if (credit > DECOMMISSION_MAX_CREDIT) + credit = DECOMMISSION_MAX_CREDIT; // Cap the available decommission credit blocks if above the max // If currently decommissioned, remove any used credits used for the current downtime if (info.is_decommissioned()) diff --git a/src/cryptonote_core/master_node_rules.h b/src/cryptonote_core/master_node_rules.h index bf97cfc5c3e..94adf4879d9 100755 --- a/src/cryptonote_core/master_node_rules.h +++ b/src/cryptonote_core/master_node_rules.h @@ -31,8 +31,8 @@ namespace master_nodes { constexpr size_t POS_BLOCK_REQUIRED_SIGNATURES = 7; // A block must have exactly N signatures to be considered properly #endif - constexpr auto POS_MIN_TARGET_BLOCK_TIME = TARGET_BLOCK_TIME_V17 - 15s; - constexpr auto POS_MAX_TARGET_BLOCK_TIME = TARGET_BLOCK_TIME_V17 + 15s; + constexpr auto POS_MIN_TARGET_BLOCK_TIME = TARGET_BLOCK_TIME - 15s; + constexpr auto POS_MAX_TARGET_BLOCK_TIME = TARGET_BLOCK_TIME + 15s; constexpr size_t POS_QUORUM_SIZE = POS_QUORUM_NUM_VALIDATORS + 1 /*Leader*/; static_assert(POS_ROUND_TIME >= @@ -82,8 +82,14 @@ namespace master_nodes { // decommission time: the first quorum test after the credit expires determines whether the server // gets recommissioned or decommissioned). + inline constexpr int64_t DECOMMISSION_CREDIT_PER_DAY = BLOCKS_PER_DAY / 30; + inline constexpr int64_t DECOMMISSION_INITIAL_CREDIT = BLOCKS_PER_HOUR * 2; + inline constexpr int64_t DECOMMISSION_MAX_CREDIT = BLOCKS_PER_DAY * 2; + inline constexpr int64_t DECOMMISSION_MINIMUM = BLOCKS_PER_HOUR * 2; + inline constexpr int64_t DECOMMISSION_INITIAL_CREDIT_V18 = BLOCKS_PER_HOUR * 3; - + static_assert(DECOMMISSION_INITIAL_CREDIT <= DECOMMISSION_MAX_CREDIT, "Initial registration decommission credit cannot be larger than the maximum decommission credit"); + static_assert(DECOMMISSION_INITIAL_CREDIT_V18 <= DECOMMISSION_MAX_CREDIT, "Initial registration decommission credit cannot be larger than the maximum decommission credit"); // This determines how many credits a node gets when being recommissioned after being // decommissioned. It gets passed two values: the credit at the time the node was decomissioned, @@ -102,6 +108,29 @@ namespace master_nodes { return std::max(0, credit_at_decomm - 2*decomm_blocks); } + // Some sanity checks on the recommission credit value: + static_assert(RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, 0) <= DECOMMISSION_MAX_CREDIT, + "Max recommission credit should not be higher than DECOMMISSION_MAX_CREDIT"); + + // These are by no means exhaustive, but will at least catch simple mistakes + static_assert( + RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, DECOMMISSION_MAX_CREDIT) <= RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, DECOMMISSION_MAX_CREDIT/2) && + RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, DECOMMISSION_MAX_CREDIT/2) <= RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, 0) && + RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT/2, DECOMMISSION_MAX_CREDIT/2) <= RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT/2, 0), + "Recommission credit should be (weakly) decreasing in the length of decommissioning"); + static_assert( + RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT/2, 1) <= RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, 1) && + RECOMMISSION_CREDIT(0, 1) <= RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT/2, 1), + "Recommission credit should be (weakly) increasing in initial credit blocks"); + + // This one actually could be supported (i.e. you can have negative credit and half to crawl out + // of that hole), but the current code is entirely untested as to whether or not that actually + // works. + static_assert( + RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, 0) >= 0 && + RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, DECOMMISSION_MAX_CREDIT) >= 0 && + RECOMMISSION_CREDIT(DECOMMISSION_MAX_CREDIT, 2*DECOMMISSION_MAX_CREDIT) >= 0, // delayed recommission that overhangs your time + "Recommission credit should not be negative"); constexpr uint64_t CHECKPOINT_NUM_CHECKPOINTS_FOR_CHAIN_FINALITY = 2; // Number of consecutive checkpoints before, blocks preceeding the N checkpoints are locked in @@ -128,6 +157,7 @@ namespace master_nodes { // node on the network: temporary decommissioning, recommissioning, and permanent deregistration. constexpr size_t STATE_CHANGE_NTH_OF_THE_NETWORK_TO_TEST = 100; constexpr size_t STATE_CHANGE_MIN_NODES_TO_TEST = 50; + constexpr uint64_t VOTE_LIFETIME = BLOCKS_PER_HOUR * 2; // Small Stake prevented from unlocking stake until a certain number of blocks have passed constexpr uint64_t SMALL_CONTRIBUTOR_UNLOCK_TIMER = 2880 * 30; @@ -184,7 +214,7 @@ namespace master_nodes { constexpr size_t STEALING_SWARM_UPPER_PERCENTILE = 75; constexpr uint64_t KEY_IMAGE_AWAITING_UNLOCK_HEIGHT = 0; - + constexpr uint64_t STATE_CHANGE_TX_LIFETIME_IN_BLOCKS = VOTE_LIFETIME; // If we get an incoming vote of state change tx that is outside the acceptable range by this many // blocks then ignore it but don't trigger a connection drop; the sending side could be a couple @@ -235,11 +265,12 @@ namespace master_nodes { constexpr uint64_t staking_num_lock_blocks(cryptonote::network_type nettype,uint8_t hf_version) { + auto blocks_per_day = (hf_version>=cryptonote::network_version_17_POS) ? BLOCKS_PER_DAY : BLOCKS_PER_DAY_OLD ; switch (nettype) { case cryptonote::FAKECHAIN: return 30; - case cryptonote::TESTNET: return BLOCKS_EXPECTED_IN_DAYS(2,hf_version); - default: return BLOCKS_EXPECTED_IN_DAYS(30,hf_version); + case cryptonote::TESTNET: return 2 * blocks_per_day; + default: return 30 * blocks_per_day; } } diff --git a/src/cryptonote_core/master_node_voting.cpp b/src/cryptonote_core/master_node_voting.cpp index fd95d32da7e..32fabaeff58 100755 --- a/src/cryptonote_core/master_node_voting.cpp +++ b/src/cryptonote_core/master_node_voting.cpp @@ -179,16 +179,15 @@ namespace master_nodes tvc.m_verifivation_failed = true; return false; } - uint64_t state_change_tx_lifetime_in_blocks = BLOCKS_EXPECTED_IN_HOURS(2,hf_version); - if (latest_height >= state_change.block_height + state_change_tx_lifetime_in_blocks) + if (latest_height >= state_change.block_height + master_nodes::STATE_CHANGE_TX_LIFETIME_IN_BLOCKS) { LOG_PRINT_L1("Received state change tx for height: " << state_change.block_height << " and master node: " << state_change.master_node_index - << ", is older than: " << state_change_tx_lifetime_in_blocks + << ", is older than: " << master_nodes::STATE_CHANGE_TX_LIFETIME_IN_BLOCKS << " (current height: " << latest_height << ") " << "blocks and has been rejected."); vvc.m_invalid_block_height = true; - if (latest_height >= state_change.block_height + (state_change_tx_lifetime_in_blocks+ VOTE_OR_TX_VERIFY_HEIGHT_BUFFER)) + if (latest_height >= state_change.block_height + (master_nodes::STATE_CHANGE_TX_LIFETIME_IN_BLOCKS+ VOTE_OR_TX_VERIFY_HEIGHT_BUFFER)) tvc.m_verifivation_failed = true; return false; } @@ -426,11 +425,10 @@ namespace master_nodes { bool result = true; bool height_in_buffer = false; - uint64_t vote_lifetime = BLOCKS_EXPECTED_IN_HOURS(VOTE_LIFETIME_HOURS,hf_version); - if (latest_height > vote.block_height + vote_lifetime) + if (latest_height > vote.block_height + VOTE_LIFETIME) { - height_in_buffer = latest_height <= vote.block_height + (vote_lifetime + VOTE_OR_TX_VERIFY_HEIGHT_BUFFER); - LOG_PRINT_L1("Received vote for height: " << vote.block_height << ", is older than: " << vote_lifetime + height_in_buffer = latest_height <= vote.block_height + (VOTE_LIFETIME + VOTE_OR_TX_VERIFY_HEIGHT_BUFFER); + LOG_PRINT_L1("Received vote for height: " << vote.block_height << ", is older than: " << VOTE_LIFETIME << " blocks and has been rejected."); vvc.m_invalid_block_height = true; } @@ -605,9 +603,8 @@ namespace master_nodes #else constexpr uint64_t TIME_BETWEEN_RELAY = 60 * 2; #endif - uint64_t vote_lifetime = BLOCKS_EXPECTED_IN_HOURS(VOTE_LIFETIME_HOURS,hf_version); const uint64_t max_last_sent = static_cast(time(nullptr)) - TIME_BETWEEN_RELAY; - const uint64_t min_height = height > vote_lifetime ? height - vote_lifetime : 0; + const uint64_t min_height = height > VOTE_LIFETIME ? height - VOTE_LIFETIME : 0; std::vector result; @@ -694,8 +691,7 @@ namespace master_nodes void voting_pool::remove_expired_votes(uint64_t height,uint8_t hf_version) { std::unique_lock lock{m_lock}; - uint64_t vote_lifetime = BLOCKS_EXPECTED_IN_HOURS(VOTE_LIFETIME_HOURS,hf_version); - uint64_t min_height = (height < vote_lifetime) ? 0 : height - vote_lifetime; + uint64_t min_height = (height < VOTE_LIFETIME) ? 0 : height - VOTE_LIFETIME; cull_votes(m_obligations_pool, min_height, height); cull_votes(m_checkpoint_pool, min_height, height); } diff --git a/src/cryptonote_core/pos.cpp b/src/cryptonote_core/pos.cpp index ba8a4540886..70be8fb2c99 100755 --- a/src/cryptonote_core/pos.cpp +++ b/src/cryptonote_core/pos.cpp @@ -745,7 +745,7 @@ bool POS::get_round_timings(cryptonote::Blockchain const &blockchain, uint64_t b uint64_t const delta_height = block_height - cryptonote::get_block_height(POS_genesis_block); times.genesis_timestamp = POS::time_point(std::chrono::seconds(POS_genesis_block.timestamp)); times.prev_timestamp = POS::time_point(std::chrono::seconds(prev_timestamp)); - times.ideal_timestamp = POS::time_point(times.genesis_timestamp + (TARGET_BLOCK_TIME_V17 * delta_height)); //only for POS + times.ideal_timestamp = POS::time_point(times.genesis_timestamp + (TARGET_BLOCK_TIME * delta_height)); //only for POS #if 1 @@ -889,14 +889,14 @@ Yes +-----[Block can not be added to blockchain] - The ideal next block timestamp is determined by - G.Timestamp + (height * TARGET_BLOCK_TIME_v17) + G.Timestamp + (height * TARGET_BLOCK_TIME) Where 'G' is the base POS genesis block, i.e. the hardforking block activating POS (HF17). The actual next block timestamp is determined by - P.Timestamp + (TARGET_BLOCK_TIME_V17 ±15s) + P.Timestamp + (TARGET_BLOCK_TIME ±15s) Where 'P' is the previous block. The block time is adjusted ±15s depending on how close/far away the ideal block time is. diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index e621a1277bd..75aa3d52679 100755 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -473,19 +473,19 @@ namespace cryptonote if (hf17) { LOG_PRINT_CCONTEXT_L0("process_payload_sync_data hf17"); - std::chrono::seconds behindtime = 0 * TARGET_BLOCK_TIME; + std::chrono::seconds behindtime = 0 * TARGET_BLOCK_TIME_OLD; int64_t diff = static_cast(hshd.current_height) - static_cast(curr_height); uint64_t abs_diff = std::abs(diff); if (curr_height<*hf17){ LOG_PRINT_CCONTEXT_L0("process_payload_sync_data curr_height(*hf17) - static_cast(curr_height); - behindtime = old_diff * TARGET_BLOCK_TIME; + behindtime = old_diff * TARGET_BLOCK_TIME_OLD; uint64_t max_block_height = std::max(hshd.current_height, curr_height); - behindtime = behindtime + ((max_block_height - *hf17) * TARGET_BLOCK_TIME_V17); + behindtime = behindtime + ((max_block_height - *hf17) * TARGET_BLOCK_TIME); } else{ LOG_PRINT_CCONTEXT_L0("process_payload_sync_data curr_height>hf17"); - behindtime = (abs_diff * TARGET_BLOCK_TIME_V17); + behindtime = (abs_diff * TARGET_BLOCK_TIME); } MCLOG(is_inital ? el::Level::Info : el::Level::Debug, "global", context << "Sync data returned a new top block candidate: " << curr_height << " -> " << hshd.current_height << " [Your node is " << abs_diff << " blocks (" << tools::get_human_readable_timespan(behindtime) << " " diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index e5c7ff62865..94690702638 100755 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -1045,7 +1045,7 @@ bool rpc_command_executor::print_transaction_pool_stats() { else { uint64_t backlog = (res.pool_stats.bytes_total + full_reward_zone - 1) / full_reward_zone; - backlog_message = fmt::format("estimated {} block ({} minutes ) backlog", backlog, backlog * TARGET_BLOCK_TIME_V17 / 1min); + backlog_message = fmt::format("estimated {} block ({} minutes ) backlog", backlog, backlog * TARGET_BLOCK_TIME / 1min); } tools::msg_writer() << n_transactions << " tx(es), " << res.pool_stats.bytes_total << " bytes total (min " << res.pool_stats.bytes_min << ", max " << res.pool_stats.bytes_max << ", avg " << avg_bytes << ", median " << res.pool_stats.bytes_med << ")" << std::endl @@ -1389,7 +1389,7 @@ bool rpc_command_executor::alt_chain_info(const std::string &tip, size_t above, tools::msg_writer() << "Time span: " << tools::get_human_readable_timespan(std::chrono::seconds(dt)); cryptonote::difficulty_type start_difficulty = bhres.block_headers.back().difficulty; if (start_difficulty > 0) - tools::msg_writer() << "Approximated " << 100.f * tools::to_seconds(TARGET_BLOCK_TIME) * chain.length / dt << "% of network hash rate"; //old block time + tools::msg_writer() << "Approximated " << 100.f * tools::to_seconds(TARGET_BLOCK_TIME_OLD) * chain.length / dt << "% of network hash rate"; //old block time else tools::fail_msg_writer() << "Bad cumulative difficulty reported by dameon"; } @@ -1619,7 +1619,7 @@ static void append_printable_master_node_list_entry(cryptonote::network_type net else { uint64_t delta_height = (blockchain_height >= expiry_height) ? 0 : expiry_height - blockchain_height; - uint64_t expiry_epoch_time = now + (delta_height * tools::to_seconds(TARGET_BLOCK_TIME_V17)); + uint64_t expiry_epoch_time = now + (delta_height * tools::to_seconds(TARGET_BLOCK_TIME)); stream << expiry_height << " (in " << delta_height << ") blocks\n"; stream << indent2 << "Expiry Date (estimated): " << get_date_time(expiry_epoch_time) << " (" << get_human_time_ago(expiry_epoch_time, now) << ")\n"; } @@ -1740,11 +1740,10 @@ static void append_printable_master_node_list_entry(cryptonote::network_type net if (entry.active) { stream << indent2 << "Current Status: ACTIVE\n"; stream << indent2 << "Downtime Credits: " << entry.earned_downtime_blocks << " blocks" - << " (about " << to_string_rounded(entry.earned_downtime_blocks / (double) BLOCKS_EXPECTED_IN_HOURS(1,hf_version), 2) << " hours)"; + << " (about " << to_string_rounded(entry.earned_downtime_blocks / (double) BLOCKS_PER_HOUR, 2) << " hours)"; - int64_t decommission_minimum = BLOCKS_EXPECTED_IN_HOURS(MINIMUM_CREDIT_HOURS,hf_version); - if (entry.earned_downtime_blocks < decommission_minimum) - stream << " (Note: " << decommission_minimum << " blocks required to enable deregistration delay)"; + if (entry.earned_downtime_blocks < master_nodes::DECOMMISSION_MINIMUM) + stream << " (Note: " << master_nodes::DECOMMISSION_MINIMUM << " blocks required to enable deregistration delay)"; } else if (is_registered) { stream << indent2 << "Current Status: DECOMMISSIONED" ; if (entry.last_decommission_reason_consensus_all || entry.last_decommission_reason_consensus_any) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index a376243741d..3df28a2136e 100755 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -394,7 +394,7 @@ namespace cryptonote { namespace rpc { } res.difficulty = m_core.get_blockchain_storage().get_difficulty_for_next_block(next_block_is_POS); - res.target = tools::to_seconds((next_block_is_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)); + res.target = tools::to_seconds((next_block_is_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)); res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase res.tx_pool_size = m_core.get_pool().get_transactions_count(); if (context.admin) @@ -798,8 +798,8 @@ namespace cryptonote { namespace rpc { void operator()(const tx_extra_beldex_name_system& x) { auto& bns = entry.bns.emplace(); bns.version = x.version; - if (x.is_buying() || x.is_renewing()) - bns.blocks = bns::expiry_blocks(nettype, x.mapping_years, hf_version) ; + if ((x.is_buying() || x.is_renewing()) && (x.version == 1)) + bns.blocks = bns::expiry_blocks(nettype, x.mapping_years) ; if(x.version == 0) switch (x.type) { @@ -1310,7 +1310,7 @@ namespace cryptonote { namespace rpc { const miner& lMiner = m_core.get_miner(); res.active = lMiner.is_mining(); - res.block_target = tools::to_seconds(TARGET_BLOCK_TIME); // old_block_time + res.block_target = tools::to_seconds(TARGET_BLOCK_TIME_OLD); // old_block_time res.difficulty = m_core.get_blockchain_storage().get_difficulty_for_next_block(false /*POS*/); if ( lMiner.is_mining() ) { res.speed = lMiner.get_speed(); @@ -3067,7 +3067,8 @@ namespace cryptonote { namespace rpc { entry.funded = info.is_fully_funded(); entry.state_height = info.is_fully_funded() ? (info.is_decommissioned() ? info.last_decommission_height : info.active_since_height) : info.last_reward_block_height; - entry.earned_downtime_blocks = master_nodes::quorum_cop::calculate_decommission_credit(info, current_height,info.registration_hf_version); + uint8_t hf_version = m_core.get_blockchain_storage().get_network_version(); + entry.earned_downtime_blocks = master_nodes::quorum_cop::calculate_decommission_credit(info, current_height,hf_version); entry.decommission_count = info.decommission_count; entry.last_decommission_reason_consensus_all = info.last_decommission_reason_consensus_all; entry.last_decommission_reason_consensus_any = info.last_decommission_reason_consensus_any; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 9cb14c7c609..edaf3504d54 100755 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -599,7 +599,7 @@ namespace rpc { uint32_t threads_count; // Number of running mining threads. std::string address; // Account address daemon is mining to. Empty if not mining. std::string pow_algorithm; // Current hashing algorithm name - uint32_t block_target; // The expected time to solve per block, i.e. TARGET_BLOCK_TIMe + uint32_t block_target; // The expected time to solve per block, i.e. TARGET_BLOCK_TIME_OLD uint64_t block_reward; // Block reward for the current block being mined. uint64_t difficulty; // The difficulty for the current block being mined. diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index d47f86bae31..7871dc21df0 100755 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -5051,13 +5051,7 @@ bool simple_wallet::show_balance_unlocked(bool detailed) const std::string tag = m_wallet->get_account_tags().second[m_current_subaddress_account]; success_msg_writer() << tr("Tag: ") << (tag.empty() ? std::string{tr("(No tag assigned)")} : tag); uint64_t blocks_to_unlock, time_to_unlock; - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) - { - tools::fail_msg_writer() << tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED; - return false; - } - uint64_t unlocked_balance = m_wallet->unlocked_balance(m_current_subaddress_account, false, &blocks_to_unlock, &time_to_unlock,*hf_version); + uint64_t unlocked_balance = m_wallet->unlocked_balance(m_current_subaddress_account, false, &blocks_to_unlock, &time_to_unlock); std::string unlock_time_message; if (blocks_to_unlock > 0 && time_to_unlock > 0) unlock_time_message = fmt::format(" ({:d} block(s) and {}) to unlock)", blocks_to_unlock, tools::get_human_readable_timespan(std::chrono::seconds(time_to_unlock))); @@ -5068,7 +5062,7 @@ bool simple_wallet::show_balance_unlocked(bool detailed) success_msg_writer() << tr("Balance: ") << print_money(m_wallet->balance(m_current_subaddress_account, false)) << ", " << tr("unlocked balance: ") << print_money(unlocked_balance) << unlock_time_message << extra; std::map balance_per_subaddress = m_wallet->balance_per_subaddress(m_current_subaddress_account, false); - std::map>> unlocked_balance_per_subaddress = m_wallet->unlocked_balance_per_subaddress(m_current_subaddress_account, false,*hf_version); + std::map>> unlocked_balance_per_subaddress = m_wallet->unlocked_balance_per_subaddress(m_current_subaddress_account, false); if (!detailed || balance_per_subaddress.empty()) return true; success_msg_writer() << tr("Balance per address:"); @@ -5698,13 +5692,7 @@ bool simple_wallet::confirm_and_send_tx(std::vector 0) { - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) - { - tools::fail_msg_writer() << tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED; - return false; - } - float days = lock_time_in_blocks / static_cast(BLOCKS_EXPECTED_IN_DAYS(1,*hf_version)); + float days = lock_time_in_blocks / (double) BLOCKS_PER_DAY; prompt << boost::format(tr(".\nThis transaction (including %s change) will unlock on block %llu, in approximately %s days (assuming 2 minutes per block)")) % cryptonote::print_money(change) % ((unsigned long long)unlock_block) % days; } @@ -6526,13 +6514,8 @@ bool simple_wallet::bns_buy_mapping(std::vector args) *mapping_years == bns::mapping_years::bns_10years ? 10 : *mapping_years == bns::mapping_years::bns_5years ? 5 : *mapping_years == bns::mapping_years::bns_2years ? 2 :1; - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) - { - tools::fail_msg_writer() << tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED; - return false; - } - std::optional blocks = bns::expiry_blocks(m_wallet->nettype(), *mapping_years, *hf_version); + + std::optional blocks = bns::expiry_blocks(m_wallet->nettype(), *mapping_years); fmt::print(fmt::format(tr("Name : {}\n"), name)); fmt::print(fmt::format(tr("Value bchat : {}\n"), value_bchat.empty() ? "(none)" : value_bchat)); fmt::print(fmt::format(tr("Value wallet : {}\n"), value_wallet.empty() ? "(none)" : value_wallet)); @@ -6625,13 +6608,7 @@ bool simple_wallet::bns_renew_mapping(std::vector args) *mapping_years == bns::mapping_years::bns_5years ? 5 : *mapping_years == bns::mapping_years::bns_2years ? 2 :1; - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) - { - tools::fail_msg_writer() << tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED; - return false; - } - std::optional blocks = bns::expiry_blocks(m_wallet->nettype(), *mapping_years, *hf_version); + std::optional blocks = bns::expiry_blocks(m_wallet->nettype(), *mapping_years); fmt::print(fmt::format(tr("Renewal {} {} ({} blocks)\n"),(years > 1) ? "years :" : "year :", years, *blocks)); fmt::print(fmt::format(tr("New expiry : Block {}\n"), (*response[0].expiration_height + *blocks))); std::cout << std::flush; @@ -9325,12 +9302,6 @@ void simple_wallet::print_accounts(const std::string& tag) } success_msg_writer() << fmt::format(tr(" {:>15} {:>21} {:>21} {:>21}"), "Account", "Balance", "Unlocked balance", "Label"); uint64_t total_balance = 0, total_unlocked_balance = 0; - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) - { - tools::fail_msg_writer() << tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED; - return; - } for (uint32_t account_index = 0; account_index < m_wallet->get_num_subaddress_accounts(); ++account_index) { @@ -9341,10 +9312,10 @@ void simple_wallet::print_accounts(const std::string& tag) % account_index % m_wallet->get_subaddress_as_str({account_index, 0}).substr(0, 6) % print_money(m_wallet->balance(account_index, false)) - % print_money(m_wallet->unlocked_balance(account_index, false,NULL,NULL,*hf_version)) + % print_money(m_wallet->unlocked_balance(account_index, false,NULL,NULL)) % m_wallet->get_subaddress_label({account_index, 0}); total_balance += m_wallet->balance(account_index, false); - total_unlocked_balance += m_wallet->unlocked_balance(account_index, false,NULL,NULL,*hf_version); + total_unlocked_balance += m_wallet->unlocked_balance(account_index, false,NULL,NULL); } success_msg_writer() << tr("----------------------------------------------------------------------------------"); success_msg_writer() << fmt::format(tr("{:>15} {:>21} {:>21}"), "Total", print_money(total_balance), print_money(total_unlocked_balance)); @@ -10134,12 +10105,6 @@ bool simple_wallet::show_transfer(const std::vector &args) std::list> payments; m_wallet->get_payments(payments, 0, (uint64_t)-1, m_current_subaddress_account); -std::optional hf_version = m_wallet->get_hard_fork_version(); -if (!hf_version) -{ - tools::fail_msg_writer() << tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED; - return false; -} for (std::list>::const_iterator i = payments.begin(); i != payments.end(); ++i) { const tools::wallet2::payment_details &pd = i->second; if (pd.m_tx_hash == txid) { @@ -10157,7 +10122,7 @@ if (!hf_version) success_msg_writer() << "Payment ID: " << payment_id; if (pd.m_unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER) { - uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE)); + uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17); uint64_t suggested_threshold = 0; if (!pd.m_unmined_flash) { @@ -10176,7 +10141,7 @@ if (!hf_version) uint64_t current_time = static_cast(time(NULL)); - uint64_t threshold = current_time + tools::to_seconds((*hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V3:CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2)); + uint64_t threshold = current_time + tools::to_seconds(CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V3); if (threshold >= pd.m_unlock_time) success_msg_writer() << "unlocked for " << tools::get_human_readable_timespan(std::chrono::seconds(threshold - pd.m_unlock_time)); else @@ -10217,7 +10182,7 @@ if (!hf_version) success_msg_writer() << "Destinations: " << dests; if (pd.m_unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER) { - uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE)); + uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17); if (bh >= last_block_height) success_msg_writer() << "Locked: " << (bh - last_block_height) << " blocks to unlock"; else @@ -10226,7 +10191,7 @@ if (!hf_version) else { uint64_t current_time = static_cast(time(NULL)); - uint64_t threshold = current_time + tools::to_seconds((*hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V3:CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2)); + uint64_t threshold = current_time + tools::to_seconds(CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V3); if (threshold >= pd.m_unlock_time) success_msg_writer() << "unlocked for " << tools::get_human_readable_timespan(std::chrono::seconds(threshold - pd.m_unlock_time)); else diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 8a0a1c2bec1..ce187049eaf 100755 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -371,7 +371,7 @@ namespace cryptonote { auto current_time = std::chrono::system_clock::now(); auto hf_version = cryptonote::get_network_version(nettype, height); - const auto node_update_threshold = (hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME) / 2; + const auto node_update_threshold = (hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD) / 2; if (node_update_threshold < current_time - m_blockchain_height_update_time || m_blockchain_height <= height) { update_blockchain_height(); diff --git a/src/wallet/node_rpc_proxy.cpp b/src/wallet/node_rpc_proxy.cpp index dd4ed0fffda..ddf268b16ba 100755 --- a/src/wallet/node_rpc_proxy.cpp +++ b/src/wallet/node_rpc_proxy.cpp @@ -176,22 +176,14 @@ bool NodeRPCProxy::get_earliest_height(uint8_t version, uint64_t &earliest_heigh std::optional NodeRPCProxy::get_hardfork_version() const { - if (m_offline) - return std::nullopt; + if (m_offline) + return std::nullopt; - auto now = std::chrono::steady_clock::now(); - if (now >= m_hardfork_version_time + 30s) // re-cache every 30 seconds - { - try { - m_hardfork_version_time = now; - m_hardfork_version = invoke_json_rpc({}).version; + try { + return invoke_json_rpc({}).version; + }catch (...) {} - } catch (...) { - return std::nullopt; - } - } - if (m_hardfork_version==0) return std::nullopt; - return m_hardfork_version; + return std::nullopt; } bool NodeRPCProxy::refresh_dynamic_base_fee_cache(uint64_t grace_blocks) const diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index bb79a91f460..59d7997b8d5 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -901,22 +901,22 @@ namespace tools const char* wallet2::tr(const char* str) { return i18n_translate(str, "tools::wallet2"); } -gamma_picker::gamma_picker(const std::vector &rct_offsets, double shape, double scale,uint8_t hf_version): +gamma_picker::gamma_picker(const std::vector &rct_offsets, double shape, double scale): rct_offsets(rct_offsets) { gamma = std::gamma_distribution(shape, scale); - THROW_WALLET_EXCEPTION_IF(rct_offsets.size() <= (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE), error::wallet_internal_error, "Bad offset calculation"); - const size_t blocks_in_a_year = BLOCKS_EXPECTED_IN_YEARS(1,hf_version); + THROW_WALLET_EXCEPTION_IF(rct_offsets.size() <= CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17, error::wallet_internal_error, "Bad offset calculation"); + const size_t blocks_in_a_year = BLOCKS_PER_DAY * 365; const size_t blocks_to_consider = std::min(rct_offsets.size(), blocks_in_a_year); const double outputs_to_consider = rct_offsets.back() - (blocks_to_consider < rct_offsets.size() ? rct_offsets[rct_offsets.size() - blocks_to_consider - 1] : 0); begin = rct_offsets.data(); - end = rct_offsets.data() + rct_offsets.size() - (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE); + end = rct_offsets.data() + rct_offsets.size() - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17; num_rct_outputs = *(end - 1); THROW_WALLET_EXCEPTION_IF(num_rct_outputs == 0, error::wallet_internal_error, "No rct outputs"); - average_output_time = tools::to_seconds((hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * blocks_to_consider / outputs_to_consider; // this assumes constant target over the whole rct range + average_output_time = tools::to_seconds(TARGET_BLOCK_TIME) * blocks_to_consider / outputs_to_consider; // this assumes constant target over the whole rct range }; -gamma_picker::gamma_picker(const std::vector &rct_offsets, uint8_t hf_version): gamma_picker(rct_offsets, GAMMA_SHAPE, GAMMA_SCALE,hf_version) {} +gamma_picker::gamma_picker(const std::vector &rct_offsets): gamma_picker(rct_offsets, GAMMA_SHAPE, GAMMA_SCALE) {} uint64_t gamma_picker::pick() { @@ -4836,7 +4836,7 @@ crypto::secret_key wallet2::generate(const fs::path& wallet_, const epee::wipeab uint64_t wallet2::estimate_blockchain_height() { - const uint64_t blocks_per_month = BLOCKS_EXPECTED_IN_DAYS(30); + const uint64_t blocks_per_month = BLOCKS_PER_DAY * 30; // try asking the daemon first std::string err; @@ -6008,7 +6008,7 @@ uint64_t wallet2::balance(uint32_t index_major, bool strict) const return amount; } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::unlocked_balance(uint32_t index_major, bool strict, uint64_t *blocks_to_unlock, uint64_t *time_to_unlock,uint8_t hf_version) const +uint64_t wallet2::unlocked_balance(uint32_t index_major, bool strict, uint64_t *blocks_to_unlock, uint64_t *time_to_unlock) const { uint64_t amount = 0; if (blocks_to_unlock) @@ -6017,7 +6017,7 @@ uint64_t wallet2::unlocked_balance(uint32_t index_major, bool strict, uint64_t * *time_to_unlock = 0; if(m_light_wallet) return m_light_wallet_balance; - for (const auto& i : unlocked_balance_per_subaddress(index_major, strict, hf_version)) + for (const auto& i : unlocked_balance_per_subaddress(index_major, strict)) { amount += i.second.first; if (blocks_to_unlock && i.second.second.first > *blocks_to_unlock) @@ -6060,7 +6060,7 @@ std::map wallet2::balance_per_subaddress(uint32_t index_majo return amount_per_subaddr; } //---------------------------------------------------------------------------------------------------- -std::map>> wallet2::unlocked_balance_per_subaddress(uint32_t index_major, bool strict,uint8_t hf_version) const +std::map>> wallet2::unlocked_balance_per_subaddress(uint32_t index_major, bool strict) const { std::map>> amount_per_subaddr; const uint64_t blockchain_height = get_blockchain_current_height(); @@ -6079,7 +6079,7 @@ std::map>> wallet2:: else { uint64_t unlock_height = td.m_unmined_flash && td.m_block_height == 0 ? blockchain_height : td.m_block_height; - unlock_height += std::max((hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE), CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS); + unlock_height += std::max(CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17, 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; uint64_t unlock_time = td.m_tx.unlock_time >= CRYPTONOTE_MAX_BLOCK_NUMBER ? td.m_tx.unlock_time : 0; @@ -6117,12 +6117,10 @@ uint64_t wallet2::unlocked_balance_all(bool strict, uint64_t *blocks_to_unlock, if (time_to_unlock) *time_to_unlock = 0; - std::optional hf_version = get_hard_fork_version(); - THROW_WALLET_EXCEPTION_IF(!hf_version, error::get_hard_fork_version_error, "Failed to query current hard fork version"); for (uint32_t index_major = 0; index_major < get_num_subaddress_accounts(); ++index_major) { uint64_t local_blocks_to_unlock, local_time_to_unlock; - r += unlocked_balance(index_major, strict, blocks_to_unlock ? &local_blocks_to_unlock : NULL, time_to_unlock ? &local_time_to_unlock : NULL, *hf_version); + r += unlocked_balance(index_major, strict, blocks_to_unlock ? &local_blocks_to_unlock : NULL, time_to_unlock ? &local_time_to_unlock : NULL); if (blocks_to_unlock) *blocks_to_unlock = std::max(*blocks_to_unlock, local_blocks_to_unlock); if (time_to_unlock) @@ -6615,9 +6613,8 @@ bool wallet2::is_transfer_unlocked(uint64_t unlock_time, uint64_t block_height, if(!is_tx_spendtime_unlocked(unlock_time, block_height)) return false; - std::optional hf_version = get_hard_fork_version(); - THROW_WALLET_EXCEPTION_IF(!hf_version, error::get_hard_fork_version_error, "Failed to query current hard fork version"); - if(block_height + (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE) > blockchain_height) + + if(block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17 > blockchain_height) return false; if (m_offline) @@ -6975,13 +6972,11 @@ void wallet2::commit_tx(pending_tx& ptx, bool flash) for (size_t idx: ptx.selected_transfers) memwipe(m_transfers[idx].m_multisig_k.data(), m_transfers[idx].m_multisig_k.size() * sizeof(m_transfers[idx].m_multisig_k[0])); - std::optional hf_version = get_hard_fork_version(); - THROW_WALLET_EXCEPTION_IF(!hf_version, error::get_hard_fork_version_error, "Failed to query current hard fork version"); //fee includes dust if dust policy specified it. LOG_PRINT_L1("Transaction successfully " << (flash ? "flashed. " : "sent. ") << txid << "\nCommission: " << print_money(ptx.fee) << " (dust sent to dust addr: " << print_money((ptx.dust_added_to_fee ? 0 : ptx.dust)) << ")" << "\nBalance: " << print_money(balance(ptx.construction_data.subaddr_account, false)) - << "\nUnlocked: " << print_money(unlocked_balance(ptx.construction_data.subaddr_account, false,NULL,NULL, *hf_version)) + << "\nUnlocked: " << print_money(unlocked_balance(ptx.construction_data.subaddr_account, false,NULL,NULL)) << "\nPlease, wait for confirmation for your balance to be unlocked."); } @@ -8595,8 +8590,7 @@ wallet2::request_stake_unlock_result wallet2::can_request_stake_unlock(const cry result.msg.append(" has already been requested to be unlocked, unlocking at height: "); result.msg.append(std::to_string(node_info.requested_unlock_height)); result.msg.append(" (about "); - auto hf_version = cryptonote::get_network_version(nettype(), curr_height); - result.msg.append(tools::get_human_readable_timespan(std::chrono::seconds((node_info.requested_unlock_height - curr_height) * (hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)))); + result.msg.append(tools::get_human_readable_timespan(std::chrono::seconds((node_info.requested_unlock_height - curr_height) * TARGET_BLOCK_TIME))); result.msg.append(")"); return result; } @@ -8622,7 +8616,7 @@ wallet2::request_stake_unlock_result wallet2::can_request_stake_unlock(const cry result.msg.append("You will continue receiving rewards until the master node expires at the estimated height: "); result.msg.append(std::to_string(unlock_height)); result.msg.append(" (about "); - result.msg.append(tools::get_human_readable_timespan(std::chrono::seconds((unlock_height - curr_height) * (*hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)))); + result.msg.append(tools::get_human_readable_timespan(std::chrono::seconds((unlock_height - curr_height) * TARGET_BLOCK_TIME))); result.msg.append(")"); if(!tools::hex_to_type(contribution.key_image, unlock.key_image)) @@ -9269,8 +9263,6 @@ void wallet2::get_outs(std::vector> if (!m_node_rpc_proxy.get_height(height)) THROW_WALLET_EXCEPTION(tools::error::no_connection_to_daemon, __func__); - std::optional hf_version = get_hard_fork_version(); - THROW_WALLET_EXCEPTION_IF(!hf_version, error::get_hard_fork_version_error, "Failed to query current hard fork version"); bool is_shortly_after_segregation_fork = height >= segregation_fork_height && height < segregation_fork_height + SEGREGATION_FORK_VICINITY; bool is_after_segregation_fork = height >= segregation_fork_height; @@ -9301,7 +9293,7 @@ void wallet2::get_outs(std::vector> if (has_rct_distribution) { // check we're clear enough of rct start, to avoid corner cases below - THROW_WALLET_EXCEPTION_IF(rct_offsets.size() <= (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE), + THROW_WALLET_EXCEPTION_IF(rct_offsets.size() <= CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17, error::get_output_distribution, "Not enough rct outputs"); THROW_WALLET_EXCEPTION_IF(rct_offsets.back() <= max_rct_index, error::get_output_distribution, "Daemon reports suspicious number of rct outputs"); @@ -9344,10 +9336,7 @@ void wallet2::get_outs(std::vector> std::sort(req_t.amounts.begin(), req_t.amounts.end()); auto end = std::unique(req_t.amounts.begin(), req_t.amounts.end()); req_t.amounts.resize(std::distance(req_t.amounts.begin(), end)); - std::optional hf_version = get_hard_fork_version(); - THROW_WALLET_EXCEPTION_IF(!hf_version, error::get_hard_fork_version_error, "Failed to query current hard fork version"); - - uint64_t recent_output_blocks = BLOCKS_EXPECTED_IN_DAYS(RECENT_OUTPUT_DAYS,*hf_version); + uint64_t recent_output_blocks = RECENT_OUTPUT_DAYS * BLOCKS_PER_DAY; req_t.from_height = std::max(segregation_fork_height, recent_output_blocks) - recent_output_blocks; req_t.to_height = segregation_fork_height + 1; req_t.cumulative = true; @@ -9393,7 +9382,7 @@ void wallet2::get_outs(std::vector> std::unique_ptr gamma; if (has_rct_distribution) - gamma.reset(new gamma_picker(rct_offsets,*hf_version)); + gamma.reset(new gamma_picker(rct_offsets)); size_t num_selected_transfers = 0; for(size_t idx: selected_transfers) @@ -9403,7 +9392,7 @@ void wallet2::get_outs(std::vector> const uint64_t amount = td.is_rct() ? 0 : td.amount(); std::unordered_set seen_indices; // request more for rct in base recent (locked) coinbases are picked, since they're locked for longer - size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW - (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE) : 0); + size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17 : 0); size_t start = get_outputs.size(); bool use_histogram = amount != 0 || !has_rct_distribution; @@ -9472,7 +9461,7 @@ void wallet2::get_outs(std::vector> else { // the base offset of the first rct output in the first unlocked block (or the one to be if there's none) - num_outs = rct_offsets[rct_offsets.size() - (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE)]; + num_outs = rct_offsets[rct_offsets.size() - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17]; LOG_PRINT_L1("" << num_outs << " unlocked rct outputs"); THROW_WALLET_EXCEPTION_IF(num_outs == 0, error::wallet_internal_error, "histogram reports no unlocked rct outputs, not even ours"); @@ -9750,7 +9739,7 @@ void wallet2::get_outs(std::vector> for(size_t idx: selected_transfers) { const transfer_details &td = m_transfers[idx]; - size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW - (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE) : 0); + size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17 : 0); outs.push_back(std::vector()); outs.back().reserve(fake_outputs_count + 1); const rct::key mask = td.is_rct() ? rct::commit(td.amount(), td.m_mask) : rct::zeroCommit(td.amount()); @@ -9770,7 +9759,7 @@ void wallet2::get_outs(std::vector> } bool use_histogram = amount != 0 || !has_rct_distribution; if (!use_histogram) - num_outs = rct_offsets[rct_offsets.size() - (hf_version>=cryptonote::network_version_17_POS?CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17:CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE)]; + num_outs = rct_offsets[rct_offsets.size() - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE_V17]; // make sure the real outputs we asked for are really included, along // with the correct key and mask: this guards against an active attack @@ -10949,7 +10938,7 @@ std::vector wallet2::create_transactions_2(std::vector>> unlocked_balance_per_subaddr = unlocked_balance_per_subaddress(subaddr_account, false,tx_params.hf_version); + std::map>> unlocked_balance_per_subaddr = unlocked_balance_per_subaddress(subaddr_account, false); std::map balance_per_subaddr = balance_per_subaddress(subaddr_account, false); if (subaddr_indices.empty()) // "index=[,,...]" wasn't specified -> use all the indices with non-zero unlocked balance @@ -11128,7 +11117,7 @@ std::vector wallet2::create_transactions_2(std::vectorempty() && unused_transfers_indices->empty()) { LOG_PRINT_L2("No more outputs to choose from"); - THROW_WALLET_EXCEPTION_IF(1, error::tx_not_possible, unlocked_balance(subaddr_account, false,NULL,NULL,tx_params.hf_version), needed_money, accumulated_fee + needed_fee); + THROW_WALLET_EXCEPTION_IF(1, error::tx_not_possible, unlocked_balance(subaddr_account, false,NULL,NULL), needed_money, accumulated_fee + needed_fee); } // get a random unspent output and use it to pay part (or all) of the current destination (and maybe next one, etc) @@ -11344,7 +11333,7 @@ std::vector wallet2::create_transactions_2(std::vector wallet2::create_transactions_all(uint64_t below { std::vector unused_transfers_indices; std::vector unused_dust_indices; - std::optional hf_version = get_hard_fork_version(); - THROW_WALLET_EXCEPTION_IF(!hf_version, error::get_hard_fork_version_error, "Failed to query current hard fork version"); - THROW_WALLET_EXCEPTION_IF(unlocked_balance(subaddr_account, false,NULL,NULL, *hf_version) == 0, error::wallet_internal_error, "No unlocked balance in the entire wallet"); + THROW_WALLET_EXCEPTION_IF(unlocked_balance(subaddr_account, false,NULL,NULL) == 0, error::wallet_internal_error, "No unlocked balance in the entire wallet"); std::map, std::vector>> unused_transfer_dust_indices_per_subaddr; @@ -13008,9 +12995,11 @@ uint64_t wallet2::get_daemon_blockchain_target_height(std::string& err) uint64_t wallet2::get_approximate_blockchain_height() const { - const auto& netconf = cryptonote::get_config(m_nettype); + const auto &netconf = cryptonote::get_config(m_nettype); const time_t since_ts = time(nullptr) - netconf.HEIGHT_ESTIMATE_TIMESTAMP; - uint64_t approx_blockchain_height = netconf.HEIGHT_ESTIMATE_HEIGHT + (since_ts > 0 ? (uint64_t)since_ts / tools::to_seconds(TARGET_BLOCK_TIME_V17) : 0) - BLOCKS_EXPECTED_IN_DAYS(7); // subtract a week's worth of blocks to be conservative + uint64_t approx_blockchain_height = netconf.HEIGHT_ESTIMATE_HEIGHT + + (since_ts > 0 ? (uint64_t)since_ts / tools::to_seconds(TARGET_BLOCK_TIME) : 0) + - BLOCKS_PER_DAY * 7; // subtract a week's worth of blocks to be conservative LOG_PRINT_L2("Calculated blockchain height: " << approx_blockchain_height); return approx_blockchain_height; } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 22b860b7716..3ff3c4661c6 100755 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -103,8 +103,8 @@ namespace tools { public: uint64_t pick(); - gamma_picker(const std::vector &rct_offsets,uint8_t hf_version); - gamma_picker(const std::vector &rct_offsets, double shape, double scale,uint8_t hf_version); + gamma_picker(const std::vector &rct_offsets); + gamma_picker(const std::vector &rct_offsets, double shape, double scale); private: struct gamma_engine @@ -721,10 +721,10 @@ namespace tools // locked & unlocked balance of given or current subaddress account uint64_t balance(uint32_t subaddr_index_major, bool strict) const; - uint64_t unlocked_balance(uint32_t subaddr_index_major, bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL ,uint8_t hf_version =17) const; + uint64_t unlocked_balance(uint32_t subaddr_index_major, bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL) const; // locked & unlocked balance per subaddress of given or current subaddress account std::map balance_per_subaddress(uint32_t subaddr_index_major, bool strict) const; - std::map>> unlocked_balance_per_subaddress(uint32_t subaddr_index_major, bool strict,uint8_t hf_version) const; + std::map>> unlocked_balance_per_subaddress(uint32_t subaddr_index_major, bool strict) const; // all locked & unlocked balances of all subaddress accounts uint64_t balance_all(bool strict) const; uint64_t unlocked_balance_all(bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL) const; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 03c6961da55..aee4db6c5bb 100755 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -606,13 +606,10 @@ namespace tools GET_BALANCE::response wallet_rpc_server::invoke(GET_BALANCE::request&& req) { require_open(); - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) - throw wallet_rpc_error{error_code::HF_QUERY_FAILED, tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED}; GET_BALANCE::response res{}; { res.balance = req.all_accounts ? m_wallet->balance_all(req.strict) : m_wallet->balance(req.account_index, req.strict); - res.unlocked_balance = req.all_accounts ? m_wallet->unlocked_balance_all(req.strict, &res.blocks_to_unlock, &res.time_to_unlock) : m_wallet->unlocked_balance(req.account_index, req.strict, &res.blocks_to_unlock, &res.time_to_unlock,*hf_version); + res.unlocked_balance = req.all_accounts ? m_wallet->unlocked_balance_all(req.strict, &res.blocks_to_unlock, &res.time_to_unlock) : m_wallet->unlocked_balance(req.account_index, req.strict, &res.blocks_to_unlock, &res.time_to_unlock); res.multisig_import_needed = m_wallet->multisig() && m_wallet->has_multisig_partial_key_images(); std::map> balance_per_subaddress_per_account; std::map>>> unlocked_balance_per_subaddress_per_account; @@ -621,13 +618,13 @@ namespace tools for (uint32_t account_index = 0; account_index < m_wallet->get_num_subaddress_accounts(); ++account_index) { balance_per_subaddress_per_account[account_index] = m_wallet->balance_per_subaddress(account_index, req.strict); - unlocked_balance_per_subaddress_per_account[account_index] = m_wallet->unlocked_balance_per_subaddress(account_index, req.strict,*hf_version); + unlocked_balance_per_subaddress_per_account[account_index] = m_wallet->unlocked_balance_per_subaddress(account_index, req.strict); } } else { balance_per_subaddress_per_account[req.account_index] = m_wallet->balance_per_subaddress(req.account_index, req.strict); - unlocked_balance_per_subaddress_per_account[req.account_index] = m_wallet->unlocked_balance_per_subaddress(req.account_index, req.strict,*hf_version); + unlocked_balance_per_subaddress_per_account[req.account_index] = m_wallet->unlocked_balance_per_subaddress(req.account_index, req.strict); } std::vector transfers; m_wallet->get_transfers(transfers); @@ -757,9 +754,6 @@ namespace tools GET_ACCOUNTS::response wallet_rpc_server::invoke(GET_ACCOUNTS::request&& req) { require_open(); - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) - throw wallet_rpc_error{error_code::HF_QUERY_FAILED, tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED}; GET_ACCOUNTS::response res{}; { res.total_balance = 0; @@ -779,7 +773,7 @@ namespace tools info.account_index = subaddr_index.major; info.base_address = m_wallet->get_subaddress_as_str(subaddr_index); info.balance = m_wallet->balance(subaddr_index.major, req.strict_balances); - info.unlocked_balance = m_wallet->unlocked_balance(subaddr_index.major, req.strict_balances,NULL,NULL,*hf_version); + info.unlocked_balance = m_wallet->unlocked_balance(subaddr_index.major, req.strict_balances,NULL,NULL); info.label = m_wallet->get_subaddress_label(subaddr_index); info.tag = account_tags.second[subaddr_index.major]; res.subaddress_accounts.push_back(info); @@ -3334,9 +3328,6 @@ namespace { { require_open(); - std::optional hf_version = m_wallet->get_hard_fork_version(); - if (!hf_version) throw wallet_rpc_error{error_code::HF_QUERY_FAILED, tools::ERR_MSG_NETWORK_VERSION_QUERY_FAILED}; - std::string reason; for (auto& rec : req.names) { diff --git a/tests/core_tests/beldex_tests.cpp b/tests/core_tests/beldex_tests.cpp index 927e7f69999..77c6ac99ddf 100755 --- a/tests/core_tests/beldex_tests.cpp +++ b/tests/core_tests/beldex_tests.cpp @@ -898,7 +898,7 @@ bool beldex_core_test_deregister_too_old::generate(std::vector const auto pk = gen.top_quorum().obligations->workers[0]; const auto dereg_tx = gen.create_and_add_state_change_tx(master_nodes::new_state::deregister, pk, 0, 0); - gen.add_n_blocks(240); /// create enough blocks to make deregistrations invalid (240 blocks) + gen.add_n_blocks(master_nodes::STATE_CHANGE_TX_LIFETIME_IN_BLOCKS); /// create enough blocks to make deregistrations invalid (240 blocks) /// In the real world, this transaction should not make it into a block, but in this case we do try to add it (as in /// tests we must add specify transactions manually), which should exercise the same validation code and reject the @@ -1111,7 +1111,7 @@ static bns_keys_t make_bns_keys(cryptonote::account_base const &src) // belnet FAKECHAIN BNS expiry blocks uint64_t bns_expiry(bns::mapping_years map_years) { - auto exp = bns::expiry_blocks(cryptonote::FAKECHAIN, map_years, 17); + auto exp = bns::expiry_blocks(cryptonote::FAKECHAIN, map_years); if (!exp) throw std::logic_error{"test suite bug: bns_expiry called with non-mapping years"}; return *exp; } diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index d8f4631016a..5e6c09ac2bc 100755 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -46,7 +46,7 @@ namespace for (size_t i = 0; i < new_block_count; ++i) { block blk_next; - difficulty_type diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME), cryptonote::difficulty_calc_mode::normal); + difficulty_type diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME_OLD), cryptonote::difficulty_calc_mode::normal); if (!generator.construct_block_manually(blk_next, blk_prev, miner_account, test_generator::bf_timestamp | test_generator::bf_diffic, 0, 0, blk_prev.timestamp, crypto::hash(), diffic)) return false; @@ -176,7 +176,7 @@ bool gen_block_invalid_nonce::generate(std::vector& events) co return false; // Create invalid nonce - difficulty_type diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME), cryptonote::difficulty_calc_mode::normal); + difficulty_type diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME_OLD), cryptonote::difficulty_calc_mode::normal); assert(1 < diffic); const block& blk_last = var::get(events.back()); uint64_t timestamp = blk_last.timestamp; @@ -265,7 +265,7 @@ bool gen_block_unlock_time_is_timestamp_in_future::generate(std::vector& ev do { blk_last = var::get(events.back()); - diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME), cryptonote::difficulty_calc_mode::normal); + diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME_OLD), cryptonote::difficulty_calc_mode::normal); if (!lift_up_difficulty(events, timestamps, cummulative_difficulties, generator, 1, blk_last, miner_account)) return false; std::cout << "Block #" << events.size() << ", difficulty: " << diffic << std::endl; @@ -655,7 +655,7 @@ bool gen_block_invalid_binary_format::generate(std::vector& ev std::vector tx_hashes; tx_hashes.push_back(get_transaction_hash(tx_0)); size_t txs_weight = get_transaction_weight(tx_0); - diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME), cryptonote::difficulty_calc_mode::normal); + diffic = next_difficulty_v2(timestamps, cummulative_difficulties,tools::to_seconds(TARGET_BLOCK_TIME_OLD), cryptonote::difficulty_calc_mode::normal); if (!generator.construct_block_manually(blk_test, blk_last, miner_account, test_generator::bf_diffic | test_generator::bf_timestamp | test_generator::bf_tx_hashes, 0, 0, blk_last.timestamp, crypto::hash(), diffic, transaction(), tx_hashes, txs_weight)) diff --git a/tests/core_tests/bulletproofs.cpp b/tests/core_tests/bulletproofs.cpp index 23c4cbd88b1..422cd7932a9 100755 --- a/tests/core_tests/bulletproofs.cpp +++ b/tests/core_tests/bulletproofs.cpp @@ -89,7 +89,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector& eve test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version, first_hf, first_hf, - prev_block->timestamp + tools::to_seconds((first_hf>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * 2, // v2 has blocks twice as long + prev_block->timestamp + tools::to_seconds((first_hf>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), @@ -114,7 +114,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector& eve test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version, first_hf, first_hf, - blk_last.timestamp + tools::to_seconds((generator.m_hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * 2, // v2 has blocks twice as long + blk_last.timestamp + tools::to_seconds((generator.m_hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), @@ -143,7 +143,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector& eve test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version, generator.m_hf_version, generator.m_hf_version, - blk_last.timestamp + tools::to_seconds((generator.m_hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * 2, // v2 has blocks twice as long + blk_last.timestamp + tools::to_seconds((generator.m_hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), @@ -296,7 +296,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector& eve CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk_txes, blk_last, miner_account, test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_tx_hashes | test_generator::bf_hf_version, - generator.m_hf_version, generator.m_hf_version, blk_last.timestamp + tools::to_seconds((generator.m_hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * 2, // v2 has blocks twice as long + generator.m_hf_version, generator.m_hf_version, blk_last.timestamp + tools::to_seconds((generator.m_hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), starting_rct_tx_hashes, 0, txn_fee), false, "Failed to generate block"); if (!valid) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index d62a0389243..808446aa05c 100755 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -1142,7 +1142,7 @@ beldex_create_block_params beldex_chain_generator::next_block_params() const result.miner_acc = first_miner_; result.block_weights = last_n_block_weights(height(), CRYPTONOTE_REWARD_BLOCKS_WINDOW); result.hf_version = get_hf_version_at(next_height); - result.timestamp = prev.block.timestamp + tools::to_seconds((result.hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)); + result.timestamp = prev.block.timestamp + tools::to_seconds((result.hf_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)); result.block_leader = prev.master_node_state.get_block_leader(); result.total_fee = 0; // Request chain generator to calculate the fee return result; @@ -1424,7 +1424,7 @@ bool test_generator::construct_block(cryptonote::block &blk, uint64_t height = var::get(blk_prev.miner_tx.vin.front()).height + 1; crypto::hash prev_id = get_block_hash(blk_prev); // Keep difficulty unchanged - uint64_t timestamp = blk_prev.timestamp + tools::to_seconds((blk_prev.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)); + uint64_t timestamp = blk_prev.timestamp + tools::to_seconds((blk_prev.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)); uint64_t already_generated_coins = get_already_generated_coins(prev_id); std::vector block_weights; get_last_n_block_weights(block_weights, prev_id, CRYPTONOTE_REWARD_BLOCKS_WINDOW); @@ -1449,7 +1449,7 @@ bool test_generator::construct_block_manually( { blk.major_version = actual_params & bf_major_ver ? major_ver : static_cast(cryptonote::network_version_7); blk.minor_version = actual_params & bf_minor_ver ? minor_ver : static_cast(cryptonote::network_version_7); - blk.timestamp = actual_params & bf_timestamp ? timestamp : prev_block.timestamp + tools::to_seconds(blk.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME); // Keep difficulty unchanged + blk.timestamp = actual_params & bf_timestamp ? timestamp : prev_block.timestamp + tools::to_seconds(blk.major_version>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD); // Keep difficulty unchanged blk.prev_id = actual_params & bf_prev_id ? prev_id : get_block_hash(prev_block); blk.tx_hashes = actual_params & bf_tx_hashes ? tx_hashes : std::vector(); diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp index e6afdc07118..ce7123c0766 100755 --- a/tests/core_tests/multisig.cpp +++ b/tests/core_tests/multisig.cpp @@ -179,7 +179,7 @@ bool gen_multisig_tx_validation_base::generate_with(std::vectortimestamp + tools::to_seconds((block_major>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * 2, // v2 has blocks twice as long + block_major, block_minor, prev_block->timestamp + tools::to_seconds((block_major>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), std::vector(), 0), false, "Failed to generate block"); events.push_back(blocks[n]); @@ -195,7 +195,7 @@ bool gen_multisig_tx_validation_base::generate_with(std::vector=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME_V17:TARGET_BLOCK_TIME)) * 2, // v2 has blocks twice as long + block_major, block_minor, blk_last.timestamp + tools::to_seconds((block_major>=cryptonote::network_version_17_POS?TARGET_BLOCK_TIME:TARGET_BLOCK_TIME_OLD)) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), std::vector(), 0), false, "Failed to generate block"); events.push_back(blk); diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp index a99b9c1a32d..03b048fa8d1 100755 --- a/tests/core_tests/rct.cpp +++ b/tests/core_tests/rct.cpp @@ -59,7 +59,7 @@ bool gen_rct_tx_validation_base::generate_with_full(std::vectortimestamp + tools::to_seconds(TARGET_BLOCK_TIME) * 2, // v2 has blocks twice as long + 2, 2, prev_block->timestamp + tools::to_seconds(TARGET_BLOCK_TIME_OLD) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), std::vector(), 0), false, "Failed to generate block"); events.push_back(blocks[n]); @@ -75,7 +75,7 @@ bool gen_rct_tx_validation_base::generate_with_full(std::vector(), 0), false, "Failed to generate block"); events.push_back(blk); @@ -144,7 +144,7 @@ bool gen_rct_tx_validation_base::generate_with_full(std::vector(), 0), false, "Failed to generate block"); events.push_back(blk); diff --git a/tests/core_tests/v2_tests.cpp b/tests/core_tests/v2_tests.cpp index b63209c1b25..b6472e69931 100755 --- a/tests/core_tests/v2_tests.cpp +++ b/tests/core_tests/v2_tests.cpp @@ -54,7 +54,7 @@ bool gen_v2_tx_validation_base::generate_with(std::vector& eve miner_accounts[n].generate(); CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[n], *prev_block, miner_accounts[n], test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp, - 2, 2, prev_block->timestamp + tools::to_seconds(TARGET_BLOCK_TIME) * 2, // v2 has blocks twice as long + 2, 2, prev_block->timestamp + tools::to_seconds(TARGET_BLOCK_TIME_OLD) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), std::vector(), 0), false, "Failed to generate block"); events.push_back(blocks[n]); @@ -70,7 +70,7 @@ bool gen_v2_tx_validation_base::generate_with(std::vector& eve cryptonote::block blk; CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk, blk_last, miner_account, test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp, - 2, 2, blk_last.timestamp + tools::to_seconds(TARGET_BLOCK_TIME) * 2, // v2 has blocks twice as long + 2, 2, blk_last.timestamp + tools::to_seconds(TARGET_BLOCK_TIME_OLD) * 2, // v2 has blocks twice as long crypto::hash(), 0, transaction(), std::vector(), 0), false, "Failed to generate block"); events.push_back(blk); diff --git a/tests/difficulty/difficulty.cpp b/tests/difficulty/difficulty.cpp index 908efeb2fb7..2726938777a 100755 --- a/tests/difficulty/difficulty.cpp +++ b/tests/difficulty/difficulty.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { uint64_t res = cryptonote::next_difficulty_v2( std::vector(timestamps.begin() + begin, timestamps.begin() + end), std::vector(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), - tools::to_seconds(TARGET_BLOCK_TIME), //use old Blocktime + tools::to_seconds(TARGET_BLOCK_TIME_OLD), //use old Blocktime cryptonote::difficulty_calc_mode::normal); if (res != difficulty) { std::cerr << "Wrong difficulty for block " << n diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 106c97c2105..06c37bd65a4 100755 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -268,12 +268,12 @@ bool transactions_flow_test(std::string& working_folder, LOG_PRINT_L0( "waiting some new blocks..."); - std::this_thread::sleep_for(TARGET_BLOCK_TIME*20*1s);//wait two blocks before sync on another wallet on another daemon + std::this_thread::sleep_for(TARGET_BLOCK_TIME_OLD*20*1s);//wait two blocks before sync on another wallet on another daemon LOG_PRINT_L0( "refreshing..."); bool recvd_money = false; while(w2.refresh(true, blocks_fetched, recvd_money, ok) && ( (blocks_fetched && recvd_money) || !blocks_fetched ) ) { - std::this_thread::sleep_for(TARGET_BLOCK_TIME*1s);//wait two blocks before sync on another wallet on another daemon + std::this_thread::sleep_for(TARGET_BLOCK_TIME_OLD*1s);//wait two blocks before sync on another wallet on another daemon } uint64_t money_2 = w2.balance(0, true);