diff options
author | luigi1111 <luigi1111w@gmail.com> | 2018-06-27 16:30:38 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2018-06-27 16:30:38 -0500 |
commit | 8a27caeb22a05149a55d29842c07dcce552ad60e (patch) | |
tree | 84bae2d728602cefbbc721e7cc304d644990b370 | |
parent | Merge pull request #3995 (diff) | |
parent | wallet: on first refresh, start off with a quantized height (diff) | |
download | monero-8a27caeb22a05149a55d29842c07dcce552ad60e.tar.xz |
Merge pull request #3998
8db23df wallet: on first refresh, start off with a quantized height (moneromooo-monero)
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 4 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 32 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 11 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 4 | ||||
-rw-r--r-- | tests/functional_tests/transactions_flow_test.cpp | 14 |
5 files changed, 36 insertions, 29 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 17cafc7bc..50c2fa642 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -4005,7 +4005,7 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset, bool is_init { m_in_manual_refresh.store(true, std::memory_order_relaxed); epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){m_in_manual_refresh.store(false, std::memory_order_relaxed);}); - m_wallet->refresh(start_height, fetched_blocks); + m_wallet->refresh(is_daemon_trusted(), start_height, fetched_blocks); ok = true; // Clear line "Height xxx of xxx" std::cout << "\r \r"; @@ -6531,7 +6531,7 @@ void simple_wallet::wallet_idle_thread() { uint64_t fetched_blocks; if (try_connect_to_daemon(true)) - m_wallet->refresh(0, fetched_blocks); + m_wallet->refresh(is_daemon_trusted(), 0, fetched_blocks); } catch(...) {} m_auto_refresh_refreshing = false; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 651a68ea5..cd4c1102c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -117,6 +117,8 @@ using namespace cryptonote; #define STAGENET_SEGREGATION_FORK_HEIGHT 1000000 #define SEGREGATION_FORK_VICINITY 1500 /* blocks */ +#define FIRST_REFRESH_GRANULARITY 1024 + static const std::string MULTISIG_SIGNATURE_MAGIC = "SigMultisigPkV1"; std::atomic<unsigned int> tools::wallet2::key_ref::refs(0); @@ -658,6 +660,7 @@ wallet2::wallet2(network_type nettype, bool restricted): m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), + m_first_refresh_done(false), m_refresh_from_block_height(0), m_explicit_refresh_from_block_height(true), m_confirm_missing_payment_id(true), @@ -1685,11 +1688,12 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry m_callback->on_new_block(height, b); } //---------------------------------------------------------------------------------------------------- -void wallet2::get_short_chain_history(std::list<crypto::hash>& ids) const +void wallet2::get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity) const { size_t i = 0; size_t current_multiplier = 1; - size_t sz = m_blockchain.size() - m_blockchain.offset(); + size_t blockchain_size = std::max(m_blockchain.size() / granularity * granularity, m_blockchain.offset()); + size_t sz = blockchain_size - m_blockchain.offset(); if(!sz) { ids.push_back(m_blockchain.genesis()); @@ -1923,16 +1927,16 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry } } //---------------------------------------------------------------------------------------------------- -void wallet2::refresh() +void wallet2::refresh(bool trusted_daemon) { uint64_t blocks_fetched = 0; - refresh(0, blocks_fetched); + refresh(trusted_daemon, 0, blocks_fetched); } //---------------------------------------------------------------------------------------------------- -void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched) +void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched) { bool received_money = false; - refresh(start_height, blocks_fetched, received_money); + refresh(trusted_daemon, start_height, blocks_fetched, received_money); } //---------------------------------------------------------------------------------------------------- void wallet2::pull_and_parse_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::vector<cryptonote::block_complete_entry> &prev_blocks, const std::vector<parsed_block> &prev_parsed_blocks, std::vector<cryptonote::block_complete_entry> &blocks, std::vector<parsed_block> &parsed_blocks, bool &error) @@ -2334,7 +2338,7 @@ bool wallet2::delete_address_book_row(std::size_t row_id) { } //---------------------------------------------------------------------------------------------------- -void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money) +void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money) { key_ref kref(*this); @@ -2384,7 +2388,7 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re bool refreshed = false; // pull the first set of blocks - get_short_chain_history(short_chain_history); + get_short_chain_history(short_chain_history, (m_first_refresh_done || trusted_daemon) ? 1 : FIRST_REFRESH_GRANULARITY); m_run.store(true, std::memory_order_relaxed); if (start_height > m_blockchain.size() || m_refresh_from_block_height > m_blockchain.size()) { if (!start_height) @@ -2393,7 +2397,7 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re fast_refresh(start_height, blocks_start_height, short_chain_history); // regenerate the history now that we've got a full set of hashes short_chain_history.clear(); - get_short_chain_history(short_chain_history); + get_short_chain_history(short_chain_history, (m_first_refresh_done || trusted_daemon) ? 1 : FIRST_REFRESH_GRANULARITY); start_height = 0; // and then fall through to regular refresh processing } @@ -2477,14 +2481,16 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re LOG_PRINT_L1("Failed to check pending transactions"); } + m_first_refresh_done = true; + LOG_PRINT_L1("Refresh done, blocks received: " << blocks_fetched << ", balance (all accounts): " << print_money(balance_all()) << ", unlocked: " << print_money(unlocked_balance_all())); } //---------------------------------------------------------------------------------------------------- -bool wallet2::refresh(uint64_t & blocks_fetched, bool& received_money, bool& ok) +bool wallet2::refresh(bool trusted_daemon, uint64_t & blocks_fetched, bool& received_money, bool& ok) { try { - refresh(0, blocks_fetched, received_money); + refresh(trusted_daemon, 0, blocks_fetched, received_money); ok = true; } catch (...) @@ -4408,7 +4414,7 @@ void wallet2::rescan_blockchain(bool refresh) add_subaddress_account(tr("Primary account")); if (refresh) - this->refresh(); + this->refresh(false); } //---------------------------------------------------------------------------------------------------- bool wallet2::is_transfer_unlocked(const transfer_details& td) const @@ -10424,7 +10430,7 @@ size_t wallet2::import_multisig(std::vector<cryptonote::blobdata> blobs) m_multisig_rescan_info = &info; try { - refresh(); + refresh(false); } catch (...) {} m_multisig_rescan_info = NULL; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 7b7190dd3..330e6796b 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -677,10 +677,10 @@ namespace tools * \brief Tells if the wallet file is deprecated. */ bool is_deprecated() const; - void refresh(); - void refresh(uint64_t start_height, uint64_t & blocks_fetched); - void refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money); - bool refresh(uint64_t & blocks_fetched, bool& received_money, bool& ok); + void refresh(bool trusted_daemon); + void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched); + void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money); + bool refresh(bool trusted_daemon, uint64_t & blocks_fetched, bool& received_money, bool& ok); void set_refresh_type(RefreshType refresh_type) { m_refresh_type = refresh_type; } RefreshType get_refresh_type() const { return m_refresh_type; } @@ -1156,7 +1156,7 @@ namespace tools void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &o_indices, uint64_t height, uint64_t ts, bool miner_tx, bool pool, bool double_spend_seen, const tx_cache_data &tx_cache_data); void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const parsed_block &parsed_block, const crypto::hash& bl_id, uint64_t height, const std::vector<tx_cache_data> &tx_cache_data, size_t tx_cache_data_offset); void detach_blockchain(uint64_t height); - void get_short_chain_history(std::list<crypto::hash>& ids) const; + void get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity = 1) const; bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height) const; bool clear(); void pull_blocks(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::vector<cryptonote::block_complete_entry> &blocks, std::vector<cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices> &o_indices); @@ -1259,6 +1259,7 @@ namespace tools uint32_t m_default_priority; RefreshType m_refresh_type; bool m_auto_refresh; + bool m_first_refresh_done; uint64_t m_refresh_from_block_height; // If m_refresh_from_block_height is explicitly set to zero we need this to differentiate it from the case that // m_refresh_from_block_height was defaulted to zero.*/ diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 7f7d33642..7158e666c 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -104,7 +104,7 @@ namespace tools m_stop = false; m_net_server.add_idle_handler([this](){ try { - if (m_wallet) m_wallet->refresh(); + if (m_wallet) m_wallet->refresh(m_trusted_daemon); } catch (const std::exception& ex) { LOG_ERROR("Exception at while refreshing, what=" << ex.what()); } @@ -3196,7 +3196,7 @@ int main(int argc, char** argv) { wal->stop(); }); - wal->refresh(); + wal->refresh(command_line::get_arg(*vm, arg_trusted_daemon)); // if we ^C during potentially length load/refresh, there's no server loop yet if (quit) { diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 55c18283e..c36c53b89 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -143,7 +143,7 @@ bool transactions_flow_test(std::string& working_folder, uint64_t blocks_fetched = 0; bool received_money; bool ok; - if(!w1.refresh(blocks_fetched, received_money, ok)) + if(!w1.refresh(true, blocks_fetched, received_money, ok)) { LOG_ERROR( "failed to refresh source wallet from " << daemon_addr_a ); return false; @@ -171,11 +171,11 @@ bool transactions_flow_test(std::string& working_folder, CHECK_AND_ASSERT_MES(daemon_rsp.status == CORE_RPC_STATUS_OK, false, "failed to getrandom_outs.bin"); //wait for money, until balance will have enough money - w1.refresh(blocks_fetched, received_money, ok); + w1.refresh(true, blocks_fetched, received_money, ok); while(w1.unlocked_balance(0) < amount_to_transfer) { misc_utils::sleep_no_w(1000); - w1.refresh(blocks_fetched, received_money, ok); + w1.refresh(true, blocks_fetched, received_money, ok); } //lets make a lot of small outs to ourselves @@ -202,7 +202,7 @@ bool transactions_flow_test(std::string& working_folder, }else { misc_utils::sleep_no_w(1000); - w1.refresh(blocks_fetched, received_money, ok); + w1.refresh(true, blocks_fetched, received_money, ok); } } //do actual transfer @@ -224,7 +224,7 @@ bool transactions_flow_test(std::string& working_folder, { misc_utils::sleep_no_w(1000); LOG_PRINT_L0("not enough money, waiting for cashback or mining"); - w1.refresh(blocks_fetched, received_money, ok); + w1.refresh(true, blocks_fetched, received_money, ok); } transaction tx; @@ -239,7 +239,7 @@ bool transactions_flow_test(std::string& working_folder, if(!do_send_money(w1, w2, mix_in_factor, amount_to_tx, tx)) { LOG_PRINT_L0("failed to transfer money, tx: " << get_transaction_hash(tx) << ", refresh and try again" ); - w1.refresh(blocks_fetched, received_money, ok); + w1.refresh(true, blocks_fetched, received_money, ok); if(!do_send_money(w1, w2, mix_in_factor, amount_to_tx, tx)) { LOG_PRINT_L0( "failed to transfer money, second chance. tx: " << get_transaction_hash(tx) << ", exit" ); @@ -264,7 +264,7 @@ bool transactions_flow_test(std::string& working_folder, misc_utils::sleep_no_w(DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN*20*1000);//wait two blocks before sync on another wallet on another daemon LOG_PRINT_L0( "refreshing..."); bool recvd_money = false; - while(w2.refresh(blocks_fetched, recvd_money, ok) && ( (blocks_fetched && recvd_money) || !blocks_fetched ) ) + while(w2.refresh(true, blocks_fetched, recvd_money, ok) && ( (blocks_fetched && recvd_money) || !blocks_fetched ) ) { misc_utils::sleep_no_w(DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN*1000);//wait two blocks before sync on another wallet on another daemon } |