From d4233ff013a253c12981c773be39b32cc385d62a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 20 Jul 2019 14:36:12 +0200 Subject: [PATCH] fixed wallet for new PoS rules --- src/currency_core/blockchain_storage.cpp | 12 +++++++++--- src/currency_core/currency_config.h | 2 +- src/wallet/wallet2.cpp | 7 +++++++ src/wallet/wallet2.h | 10 +++++++--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 2c205162..6e9f5724 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -971,7 +971,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con wide_difficulty_type& dif = pos ? m_cached_next_pos_difficulty : m_cached_next_pow_difficulty; TIME_MEASURE_FINISH_PD(target_calculating_enum_blocks); TIME_MEASURE_START_PD(target_calculating_calc); - if (m_db_blocks.size() > ZANO_HARDFORK_1_AFTER_HEIGHT) + if (m_db_blocks.size() > m_core_runtime_config.hard_fork1_starts_after_height) { dif = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); } @@ -1010,7 +1010,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, co enum_blockchain(cb, alt_chain, split_height); wide_difficulty_type diff = 0; - if(abei.height > ZANO_HARDFORK_1_AFTER_HEIGHT) + if(abei.height > m_core_runtime_config.hard_fork1_starts_after_height) diff = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); else diff = next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); @@ -1698,7 +1698,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ const block_extended_info& alt_chain_bei = alt_chain.back()->second; const block_extended_info& connection_point = alt_chain.front()->second; - if (alt_chain_bei.bl.major_version == BLOCK_MAJOR_VERSION_INITAL || connection_point.height <= ZANO_HARDFORK_1_AFTER_HEIGHT) + if (alt_chain_bei.bl.major_version == BLOCK_MAJOR_VERSION_INITAL || connection_point.height <= m_core_runtime_config.hard_fork1_starts_after_height) { //use pre-hard fork, old-style comparing if (main_chain_bei.cumulative_diff_adjusted < alt_chain_bei.cumulative_diff_adjusted) @@ -4348,6 +4348,12 @@ bool blockchain_storage::validate_pos_block(const block& b, // Txs in alternative PoS blocks (including miner_tx) are validated by validate_alt_block_txs() r = check_tx_input(b.miner_tx, 1, coinstake_in, id, b.miner_tx.signatures[0], &max_related_block_height); CHECK_AND_ASSERT_MES(r, false, "Failed to validate coinstake input in miner tx, block_id = " << get_block_hash(b)); + + if (get_block_height(b) > m_core_runtime_config.hard_fork1_starts_after_height) + { + uint64_t last_pow_h = get_last_x_block_height(false); + CHECK_AND_ASSERT_MES(max_related_block_height < last_pow_h, false, "Failed to failed to validate coinbase in pos block, condition failed: max_related_block_height(" << max_related_block_height << ") < last_pow_h(" << last_pow_h << ")"); + } } uint64_t block_height = for_altchain ? split_height + alt_chain.size() : m_db_blocks.size(); diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 36976ba3..6cd9e7f4 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -203,7 +203,7 @@ #define BC_OFFERS_CURRENCY_MARKET_FILENAME "market.bin" -#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+64) +#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+65) #define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 3f84adec..25347722 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1027,6 +1027,8 @@ void wallet2::process_new_blockchain_entry(const currency::block& b, const curre m_blockchain.push_back(bl_id); ++m_local_bc_height; m_last_bc_timestamp = b.timestamp; + if (!is_pos_block(b)) + m_last_pow_block_h = height; m_wcallback->on_new_block(height, b); } @@ -1761,6 +1763,7 @@ bool wallet2::reset_all() m_last_bc_timestamp = 0; m_height_of_start_sync = 0; m_last_sync_percent = 0; + m_last_pow_block_h = 0; return true; } //---------------------------------------------------------------------------------------------------- @@ -2406,6 +2409,10 @@ bool wallet2::is_transfer_okay_for_pos(const transfer_details& tr) if (m_blockchain.size() - tr.m_ptx_wallet_info->m_block_height <= m_core_runtime_config.min_coinstake_age) return false; + + if (tr.m_ptx_wallet_info->m_block_height >= m_last_pow_block_h) + return false; + return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index ee92ebac..ccd60df7 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -310,7 +310,8 @@ namespace tools m_height_of_start_sync(0), m_last_sync_percent(0), m_do_rise_transfer(false), - m_watch_only(false) + m_watch_only(false), + m_last_pow_block_h(0) {}; public: wallet2() : m_stop(false), @@ -322,7 +323,8 @@ namespace tools m_fake_outputs_count(0), m_do_rise_transfer(false), m_log_prefix("???"), - m_watch_only(false) + m_watch_only(false), + m_last_pow_block_h(0) { m_core_runtime_config = currency::get_default_core_runtime_config(); }; @@ -615,7 +617,7 @@ namespace tools return; } - if (ver < 147) + if (ver < 149) { LOG_PRINT_MAGENTA("Wallet file truncated due to old version", LOG_LEVEL_0); return; @@ -650,6 +652,7 @@ namespace tools a & m_money_expirations; a & m_pending_key_images; a & m_tx_keys; + a & m_last_pow_block_h; } @@ -862,6 +865,7 @@ private: std::shared_ptr m_wcallback; uint64_t m_height_of_start_sync; uint64_t m_last_sync_percent; + uint64_t m_last_pow_block_h; currency::core_runtime_config m_core_runtime_config; escrow_contracts_container m_contracts; std::list m_money_expirations;