diff options
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet2.cpp | 87 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 12 | ||||
-rw-r--r-- | src/wallet/wallet_errors.h | 5 |
3 files changed, 100 insertions, 4 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6d8b1d802..6218eff4b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -578,6 +578,24 @@ void wallet2::pull_blocks(uint64_t start_height, uint64_t &blocks_start_height, blocks = res.blocks; } //---------------------------------------------------------------------------------------------------- +void wallet2::pull_hashes(uint64_t start_height, uint64_t &blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<crypto::hash> &hashes) +{ + cryptonote::COMMAND_RPC_GET_HASHES_FAST::request req = AUTO_VAL_INIT(req); + cryptonote::COMMAND_RPC_GET_HASHES_FAST::response res = AUTO_VAL_INIT(res); + req.block_ids = short_chain_history; + + req.start_height = start_height; + m_daemon_rpc_mutex.lock(); + bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/gethashes.bin", req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT); + m_daemon_rpc_mutex.unlock(); + THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "gethashes.bin"); + THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "gethashes.bin"); + THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_hashes_error, res.status); + + blocks_start_height = res.start_height; + hashes = res.m_block_ids; +} +//---------------------------------------------------------------------------------------------------- void wallet2::process_blocks(uint64_t start_height, const std::list<cryptonote::block_complete_entry> &blocks, uint64_t& blocks_added) { size_t current_index = start_height; @@ -772,6 +790,60 @@ void wallet2::check_pending_txes() } } //---------------------------------------------------------------------------------------------------- +void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history) +{ + std::list<crypto::hash> hashes; + size_t current_index = m_blockchain.size(); + while(current_index < stop_height) + { + pull_hashes(0, blocks_start_height, short_chain_history, hashes); + if (hashes.size() < 3) + return; + if (hashes.size() + current_index < stop_height) { + std::list<crypto::hash>::iterator right; + // drop early 3 off, skipping the genesis block + if (short_chain_history.size() > 3) { + right = short_chain_history.end(); + std::advance(right,-1); + std::list<crypto::hash>::iterator left = right; + std::advance(left, -3); + short_chain_history.erase(left, right); + } + right = hashes.end(); + // prepend 3 more + for (int i = 0; i<3; i++) { + right--; + short_chain_history.push_front(*right); + } + } + current_index = blocks_start_height; + BOOST_FOREACH(auto& bl_id, hashes) + { + if(current_index >= m_blockchain.size()) + { + LOG_PRINT_L2( "Skipped block by height: " << current_index); + m_blockchain.push_back(bl_id); + ++m_local_bc_height; + + if (0 != m_callback) + { // FIXME: this isn't right, but simplewallet just logs that we got a block. + cryptonote::block dummy; + m_callback->on_new_block(current_index, dummy); + } + } + else if(bl_id != m_blockchain[current_index]) + { + //split detected here !!! + return; + } + ++current_index; + if (current_index >= stop_height) + return; + } + } +} + +//---------------------------------------------------------------------------------------------------- void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money) { received_money = false; @@ -786,7 +858,22 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re // pull the first set of blocks get_short_chain_history(short_chain_history); + if (start_height > m_blockchain.size() || m_refresh_from_block_height > m_blockchain.size()) { + if (!start_height) + start_height = m_refresh_from_block_height; + // we can shortcut by only pulling hashes up to the start_height + 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); + start_height = 0; + // and then fall through to regular refresh processing + } + pull_blocks(start_height, blocks_start_height, short_chain_history, blocks); + // always reset start_height to 0 to force short_chain_ history to be used on + // subsequent pulls in this refresh. + start_height = 0; m_run.store(true, std::memory_order_relaxed); while(m_run.load(std::memory_order_relaxed)) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index dc3b8482f..89c157c16 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -365,6 +365,12 @@ namespace tools std::string get_wallet_file() const; std::string get_keys_file() const; + + std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool trusted_daemon); + std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f); + std::vector<size_t> select_available_unmixable_outputs(bool trusted_daemon); + std::vector<size_t> select_available_mixable_outputs(bool trusted_daemon); + private: /*! * \brief Stores wallet information to wallet file. @@ -388,6 +394,8 @@ namespace tools bool is_transfer_unlocked(const transfer_details& td) const; bool clear(); void pull_blocks(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<cryptonote::block_complete_entry> &blocks); + void pull_hashes(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<crypto::hash> &hashes); + void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history); void pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::list<cryptonote::block_complete_entry> &prev_blocks, std::list<cryptonote::block_complete_entry> &blocks, bool &error); void process_blocks(uint64_t start_height, const std::list<cryptonote::block_complete_entry> &blocks, uint64_t& blocks_added); uint64_t select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::list<transfer_container::iterator>& selected_transfers, bool trusted_daemon); @@ -404,10 +412,6 @@ namespace tools uint64_t get_upper_tranaction_size_limit(); void check_pending_txes(); std::vector<uint64_t> get_unspent_amounts_vector(); - std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool trusted_daemon); - std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f); - std::vector<size_t> select_available_unmixable_outputs(bool trusted_daemon); - std::vector<size_t> select_available_mixable_outputs(bool trusted_daemon); cryptonote::account_base m_account; std::string m_daemon_address; diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 3de97f49d..184d8a2a1 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -60,6 +60,7 @@ namespace tools // acc_outs_lookup_error // block_parse_error // get_blocks_error + // get_hashes_error // get_out_indexes_error // tx_parse_error // get_tx_pool_error @@ -107,12 +108,14 @@ namespace tools //---------------------------------------------------------------------------------------------------- const char* const failed_rpc_request_messages[] = { "failed to get blocks", + "failed to get hashes", "failed to get out indices", "failed to get random outs" }; enum failed_rpc_request_message_indices { get_blocks_error_message_index, + get_hashes_error_message_index, get_out_indices_error_message_index, get_random_outs_error_message_index }; @@ -291,6 +294,8 @@ namespace tools //---------------------------------------------------------------------------------------------------- typedef failed_rpc_request<refresh_error, get_blocks_error_message_index> get_blocks_error; //---------------------------------------------------------------------------------------------------- + typedef failed_rpc_request<refresh_error, get_hashes_error_message_index> get_hashes_error; + //---------------------------------------------------------------------------------------------------- typedef failed_rpc_request<refresh_error, get_out_indices_error_message_index> get_out_indices_error; //---------------------------------------------------------------------------------------------------- struct tx_parse_error : public refresh_error |