wallet2: get current height from the daemon on creation
Use current time to estimate current height only if the daemon cannot be queried.
This commit is contained in:
parent
d3bb72fff1
commit
3b599d2b7e
|
@ -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_account_public_address = m_account.get_keys().m_account_address;
|
||||||
m_watch_only = false;
|
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){
|
if(m_refresh_from_block_height == 0 && !recover){
|
||||||
// Wallets created offline don't know blockchain height.
|
// Wallets created offline don't know blockchain height.
|
||||||
// Set blockchain height calculated from current date/time
|
// 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();
|
uint64_t approx_blockchain_height = get_approximate_blockchain_height();
|
||||||
if(approx_blockchain_height > 0) {
|
if(approx_blockchain_height > 0) {
|
||||||
m_refresh_from_block_height = approx_blockchain_height - blocks_per_month;
|
m_refresh_from_block_height = approx_blockchain_height - blocks_per_month;
|
||||||
|
|
Loading…
Reference in New Issue