From 32754784dbacf3e9f30d0aaab0f656c4df32744b Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 26 Jun 2017 06:54:53 +0100 Subject: wallet: fix refresh_from_height setting on new wallet The previous patch was based on a wrong premise (that the daemon height was 0 because the daemon calling code wasn't yet initialized). In fact, current height approximation was not setup for testnet. Fix this. --- src/wallet/wallet2.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index ee2b6055c..3cbe4cfe7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5010,11 +5010,10 @@ uint64_t wallet2::get_daemon_blockchain_target_height(string &err) uint64_t wallet2::get_approximate_blockchain_height() const { - if (m_testnet) return 0; // time of v2 fork - const time_t fork_time = 1458748658; + const time_t fork_time = m_testnet ? 1448285909 : 1458748658; // v2 fork block - const uint64_t fork_block = 1009827; + const uint64_t fork_block = m_testnet ? 624634 : 1009827; // avg seconds per block const int seconds_per_block = DIFFICULTY_TARGET_V2; // Calculated blockchain height -- cgit v1.2.3 From d3bb72fff16cd12a41720887dbf576e11ee47f4a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 26 Jun 2017 06:56:44 +0100 Subject: wallet2: fix infinite loop on future refresh height If the refresh height is in the future, the current code will loop till the actual height reaches this. Fix it by bailing out if we receive only three hashes, which is what we set in the call parameters. --- src/wallet/wallet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 3cbe4cfe7..d357815b7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1601,7 +1601,7 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, while(m_run.load(std::memory_order_relaxed) && current_index < stop_height) { pull_hashes(0, blocks_start_height, short_chain_history, hashes); - if (hashes.size() < 3) + if (hashes.size() <= 3) return; if (hashes.size() + current_index < stop_height) { std::list::iterator right; -- cgit v1.2.3 From 3b599d2b7ed0916e18e5736365cd61face66cfa4 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 26 Jun 2017 08:11:14 +0100 Subject: wallet2: get current height from the daemon on creation Use current time to estimate current height only if the daemon cannot be queried. --- src/wallet/wallet2.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d357815b7..6b1026a55 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2165,14 +2165,23 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri m_account_public_address = m_account.get_keys().m_account_address; m_watch_only = false; + // -1 month for fluctuations in block time and machine date/time setup. + // avg seconds per block + const int seconds_per_block = DIFFICULTY_TARGET_V2; + // ~num blocks per month + const uint64_t blocks_per_month = 60*60*24*30/seconds_per_block; + + // try asking the daemon first + if(m_refresh_from_block_height == 0 && !recover){ + std::string err; + uint64_t height = get_daemon_blockchain_height(err); + if (err.empty()) + m_refresh_from_block_height = height - blocks_per_month; + } + if(m_refresh_from_block_height == 0 && !recover){ // Wallets created offline don't know blockchain height. // Set blockchain height calculated from current date/time - // -1 month for fluctuations in block time and machine date/time setup. - // avg seconds per block - const int seconds_per_block = DIFFICULTY_TARGET_V2; - // ~num blocks per month - const uint64_t blocks_per_month = 60*60*24*30/seconds_per_block; uint64_t approx_blockchain_height = get_approximate_blockchain_height(); if(approx_blockchain_height > 0) { m_refresh_from_block_height = approx_blockchain_height - blocks_per_month; -- cgit v1.2.3