mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 11:23:26 +01:00
Merge pull request #2124
3b599d2b
wallet2: get current height from the daemon on creation (moneromooo-monero)d3bb72ff
wallet2: fix infinite loop on future refresh height (moneromooo-monero)32754784
wallet: fix refresh_from_height setting on new wallet (moneromooo-monero)
This commit is contained in:
commit
44e4bbd15c
@ -929,8 +929,6 @@ static bool might_be_partial_seed(std::string words)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
||||||
{
|
{
|
||||||
bool need_refresh_height = false;
|
|
||||||
|
|
||||||
if (!handle_command_line(vm))
|
if (!handle_command_line(vm))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1128,8 +1126,6 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
m_wallet_file = m_generate_new;
|
m_wallet_file = m_generate_new;
|
||||||
bool r = new_wallet(vm, m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, old_language);
|
bool r = new_wallet(vm, m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, old_language);
|
||||||
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
||||||
if (!m_restore_deterministic_wallet)
|
|
||||||
need_refresh_height = true;
|
|
||||||
}
|
}
|
||||||
if (!m_restore_height && m_restoring)
|
if (!m_restore_height && m_restoring)
|
||||||
{
|
{
|
||||||
@ -1222,14 +1218,6 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
m_http_client.set_server(m_wallet->get_daemon_address(), m_wallet->get_daemon_login());
|
m_http_client.set_server(m_wallet->get_daemon_address(), m_wallet->get_daemon_login());
|
||||||
m_wallet->callback(this);
|
m_wallet->callback(this);
|
||||||
|
|
||||||
if (need_refresh_height)
|
|
||||||
{
|
|
||||||
// for a totally new account, we don't care about older blocks.
|
|
||||||
MDEBUG("Calling daemon to set refresh height");
|
|
||||||
std::string err;
|
|
||||||
m_wallet->set_refresh_from_block_height(get_daemon_blockchain_height(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
@ -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)
|
while(m_run.load(std::memory_order_relaxed) && current_index < stop_height)
|
||||||
{
|
{
|
||||||
pull_hashes(0, blocks_start_height, short_chain_history, hashes);
|
pull_hashes(0, blocks_start_height, short_chain_history, hashes);
|
||||||
if (hashes.size() < 3)
|
if (hashes.size() <= 3)
|
||||||
return;
|
return;
|
||||||
if (hashes.size() + current_index < stop_height) {
|
if (hashes.size() + current_index < stop_height) {
|
||||||
std::list<crypto::hash>::iterator right;
|
std::list<crypto::hash>::iterator right;
|
||||||
@ -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;
|
||||||
@ -5010,11 +5019,10 @@ uint64_t wallet2::get_daemon_blockchain_target_height(string &err)
|
|||||||
|
|
||||||
uint64_t wallet2::get_approximate_blockchain_height() const
|
uint64_t wallet2::get_approximate_blockchain_height() const
|
||||||
{
|
{
|
||||||
if (m_testnet) return 0;
|
|
||||||
// time of v2 fork
|
// time of v2 fork
|
||||||
const time_t fork_time = 1458748658;
|
const time_t fork_time = m_testnet ? 1448285909 : 1458748658;
|
||||||
// v2 fork block
|
// v2 fork block
|
||||||
const uint64_t fork_block = 1009827;
|
const uint64_t fork_block = m_testnet ? 624634 : 1009827;
|
||||||
// avg seconds per block
|
// avg seconds per block
|
||||||
const int seconds_per_block = DIFFICULTY_TARGET_V2;
|
const int seconds_per_block = DIFFICULTY_TARGET_V2;
|
||||||
// Calculated blockchain height
|
// Calculated blockchain height
|
||||||
|
Loading…
Reference in New Issue
Block a user