#36 simplewallet refresh include optional height param

height param is used optionally in refresh command 

TODO: This should also be the default behaviour 
when generating a new wallet.
This commit is contained in:
Jakob Lind 2014-08-01 10:17:50 +02:00
parent 7869667799
commit e4273f2415
9 changed files with 39 additions and 22 deletions

View File

@ -1149,11 +1149,15 @@ bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash
return true; return true;
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) bool blockchain_storage::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count)
{ {
CRITICAL_REGION_LOCAL(m_blockchain_lock); CRITICAL_REGION_LOCAL(m_blockchain_lock);
if(req_start_block > 0) {
start_height = req_start_block;
} else {
if(!find_blockchain_supplement(qblock_ids, start_height)) if(!find_blockchain_supplement(qblock_ids, start_height))
return false; return false;
}
total_height = get_current_blockchain_height(); total_height = get_current_blockchain_height();
size_t count = 0; size_t count = 0;

View File

@ -120,7 +120,7 @@ namespace cryptonote
bool get_short_chain_history(std::list<crypto::hash>& ids); bool get_short_chain_history(std::list<crypto::hash>& ids);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp); bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, uint64_t& starter_offset); bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, uint64_t& starter_offset);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count); bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count);
bool handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp); bool handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp);
bool handle_get_objects(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res); bool handle_get_objects(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res);
bool get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res); bool get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res);

View File

@ -323,9 +323,9 @@ namespace cryptonote
return m_blockchain_storage.find_blockchain_supplement(qblock_ids, resp); return m_blockchain_storage.find_blockchain_supplement(qblock_ids, resp);
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count) bool core::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count)
{ {
return m_blockchain_storage.find_blockchain_supplement(qblock_ids, blocks, total_height, start_height, max_count); return m_blockchain_storage.find_blockchain_supplement(req_start_block, qblock_ids, blocks, total_height, start_height, max_count);
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
void core::print_blockchain(uint64_t start_index, uint64_t end_index) void core::print_blockchain(uint64_t start_index, uint64_t end_index)

View File

@ -100,7 +100,7 @@ namespace cryptonote
bool have_block(const crypto::hash& id); bool have_block(const crypto::hash& id);
bool get_short_chain_history(std::list<crypto::hash>& ids); bool get_short_chain_history(std::list<crypto::hash>& ids);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp); bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count); bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count);
bool get_stat_info(core_stat_info& st_inf); bool get_stat_info(core_stat_info& st_inf);
//bool get_backward_blocks_sizes(uint64_t from_height, std::vector<size_t>& sizes, size_t count); //bool get_backward_blocks_sizes(uint64_t from_height, std::vector<size_t>& sizes, size_t count);
bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs); bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs);

View File

@ -125,7 +125,8 @@ namespace cryptonote
{ {
CHECK_CORE_BUSY(); CHECK_CORE_BUSY();
std::list<std::pair<block, std::list<transaction> > > bs; std::list<std::pair<block, std::list<transaction> > > bs;
if(!m_core.find_blockchain_supplement(req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
{ {
res.status = "Failed"; res.status = "Failed";
return false; return false;

View File

@ -66,9 +66,10 @@ namespace cryptonote
struct request struct request
{ {
std::list<crypto::hash> block_ids; //*first 10 blocks id goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */ std::list<crypto::hash> block_ids; //*first 10 blocks id goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */
uint64_t start_height;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids) KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids)
KV_SERIALIZE(start_height)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View File

@ -622,12 +622,25 @@ bool simple_wallet::refresh(const std::vector<std::string>& args)
return true; return true;
message_writer() << "Starting refresh..."; message_writer() << "Starting refresh...";
size_t fetched_blocks = 0; size_t fetched_blocks = 0;
size_t start_height = 0;
if(!args.empty()){
try
{
start_height = boost::lexical_cast<int>( args[0] );
}
catch(const boost::bad_lexical_cast &)
{
start_height = 0;
}
}
bool ok = false; bool ok = false;
std::ostringstream ss; std::ostringstream ss;
try try
{ {
m_wallet->refresh(fetched_blocks); m_wallet->refresh(start_height, fetched_blocks);
ok = true; ok = true;
// Clear line "Height xxx of xxx" // Clear line "Height xxx of xxx"
std::cout << "\r \r"; std::cout << "\r \r";

View File

@ -192,8 +192,6 @@ void wallet2::process_unconfirmed(const cryptonote::transaction& tx)
void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonote::block_complete_entry& bche, crypto::hash& bl_id, uint64_t height) void wallet2::process_new_blockchain_entry(const cryptonote::block& b, cryptonote::block_complete_entry& bche, crypto::hash& bl_id, uint64_t height)
{ {
//handle transactions from new block //handle transactions from new block
THROW_WALLET_EXCEPTION_IF(height != m_blockchain.size(), error::wallet_internal_error,
"current_index=" + std::to_string(height) + ", m_blockchain.size()=" + std::to_string(m_blockchain.size()));
//optimization: seeking only for blocks that are not older then the wallet creation time plus 1 day. 1 day is for possible user incorrect time setup //optimization: seeking only for blocks that are not older then the wallet creation time plus 1 day. 1 day is for possible user incorrect time setup
if(b.timestamp + 60*60*24 > m_account.get_createtime()) if(b.timestamp + 60*60*24 > m_account.get_createtime())
@ -300,16 +298,16 @@ void wallet2::pull_blocks(size_t& blocks_added)
void wallet2::refresh() void wallet2::refresh()
{ {
size_t blocks_fetched = 0; size_t blocks_fetched = 0;
refresh(blocks_fetched); refresh(0, blocks_fetched);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void wallet2::refresh(size_t & blocks_fetched) void wallet2::refresh(uint64_t start_height, size_t & blocks_fetched)
{ {
bool received_money = false; bool received_money = false;
refresh(blocks_fetched, received_money); refresh(start_height, blocks_fetched, received_money);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void wallet2::refresh(size_t & blocks_fetched, bool& received_money) void wallet2::refresh(uint64_t start_height, size_t & blocks_fetched, bool& received_money)
{ {
received_money = false; received_money = false;
blocks_fetched = 0; blocks_fetched = 0;
@ -321,7 +319,7 @@ void wallet2::refresh(size_t & blocks_fetched, bool& received_money)
{ {
try try
{ {
pull_blocks(added_blocks); pull_blocks(start_height, added_blocks);
blocks_fetched += added_blocks; blocks_fetched += added_blocks;
if(!added_blocks) if(!added_blocks)
break; break;
@ -351,7 +349,7 @@ bool wallet2::refresh(size_t & blocks_fetched, bool& received_money, bool& ok)
{ {
try try
{ {
refresh(blocks_fetched, received_money); refresh(0, blocks_fetched, received_money);
ok = true; ok = true;
} }
catch (...) catch (...)

View File

@ -152,8 +152,8 @@ namespace tools
void callback(i_wallet2_callback* callback) { m_callback = callback; } void callback(i_wallet2_callback* callback) { m_callback = callback; }
void refresh(); void refresh();
void refresh(size_t & blocks_fetched); void refresh(uint64_t start_height, size_t & blocks_fetched);
void refresh(size_t & blocks_fetched, bool& received_money); void refresh(uint64_t start_height, size_t & blocks_fetched, bool& received_money);
bool refresh(size_t & blocks_fetched, bool& received_money, bool& ok); bool refresh(size_t & blocks_fetched, bool& received_money, bool& ok);
uint64_t balance(); uint64_t balance();
@ -202,7 +202,7 @@ namespace tools
bool is_tx_spendtime_unlocked(uint64_t unlock_time) const; bool is_tx_spendtime_unlocked(uint64_t unlock_time) const;
bool is_transfer_unlocked(const transfer_details& td) const; bool is_transfer_unlocked(const transfer_details& td) const;
bool clear(); bool clear();
void pull_blocks(size_t& blocks_added); void pull_blocks(uint64_t start_height, size_t& blocks_added);
uint64_t select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, std::list<transfer_container::iterator>& selected_transfers); uint64_t select_transfers(uint64_t needed_money, bool add_dust, uint64_t dust, std::list<transfer_container::iterator>& selected_transfers);
bool prepare_file_names(const std::string& file_path); bool prepare_file_names(const std::string& file_path);
void process_unconfirmed(const cryptonote::transaction& tx); void process_unconfirmed(const cryptonote::transaction& tx);