mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 03:03:17 +00:00
Merge pull request #2833
b0426d4c
Fixes #759 Add sanity check on restore height (Cifrado)
This commit is contained in:
commit
81fb832082
3 changed files with 44 additions and 20 deletions
|
@ -1801,8 +1801,18 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_restoring)
|
if (m_restoring)
|
||||||
|
{
|
||||||
|
uint64_t estimate_height = m_wallet->estimate_blockchain_height();
|
||||||
|
if (m_restore_height >= estimate_height)
|
||||||
|
{
|
||||||
|
success_msg_writer() << tr("Restore height ") << m_restore_height << (" is not yet reached. The current estimated height is ") << estimate_height;
|
||||||
|
std::string confirm = input_line(tr("Still apply restore height? (Y/Yes/N/No): "));
|
||||||
|
if (std::cin.eof() || command_line::is_no(confirm))
|
||||||
|
m_restore_height = 0;
|
||||||
|
}
|
||||||
m_wallet->set_refresh_from_block_height(m_restore_height);
|
m_wallet->set_refresh_from_block_height(m_restore_height);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(!m_wallet_file.empty());
|
assert(!m_wallet_file.empty());
|
||||||
|
|
|
@ -2476,6 +2476,34 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri
|
||||||
|
|
||||||
// try asking the daemon first
|
// try asking the daemon first
|
||||||
if(m_refresh_from_block_height == 0 && !recover){
|
if(m_refresh_from_block_height == 0 && !recover){
|
||||||
|
uint64_t height = estimate_blockchain_height();
|
||||||
|
m_refresh_from_block_height = height >= blocks_per_month ? height - blocks_per_month : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool r = store_keys(m_keys_file, password, false);
|
||||||
|
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
||||||
|
|
||||||
|
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
|
||||||
|
if(!r) MERROR("String with address text not saved");
|
||||||
|
|
||||||
|
cryptonote::block b;
|
||||||
|
generate_genesis(b);
|
||||||
|
m_blockchain.push_back(get_block_hash(b));
|
||||||
|
add_subaddress_account(tr("Primary account"));
|
||||||
|
|
||||||
|
store();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t wallet2::estimate_blockchain_height()
|
||||||
|
{
|
||||||
|
// -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
|
||||||
std::string err;
|
std::string err;
|
||||||
uint64_t height = 0;
|
uint64_t height = 0;
|
||||||
|
|
||||||
|
@ -2496,24 +2524,9 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const std::stri
|
||||||
uint64_t local_height = get_daemon_blockchain_height(err);
|
uint64_t local_height = get_daemon_blockchain_height(err);
|
||||||
if (err.empty() && local_height > height)
|
if (err.empty() && local_height > height)
|
||||||
height = local_height;
|
height = local_height;
|
||||||
m_refresh_from_block_height = height >= blocks_per_month ? height - blocks_per_month : 0;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool r = store_keys(m_keys_file, password, false);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
|
||||||
|
|
||||||
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
|
|
||||||
cryptonote::block b;
|
|
||||||
generate_genesis(b);
|
|
||||||
m_blockchain.push_back(get_block_hash(b));
|
|
||||||
add_subaddress_account(tr("Primary account"));
|
|
||||||
|
|
||||||
store();
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Creates a watch only wallet from a public address and a view secret key.
|
* \brief Creates a watch only wallet from a public address and a view secret key.
|
||||||
* \param wallet_ Name of wallet file
|
* \param wallet_ Name of wallet file
|
||||||
|
|
|
@ -742,6 +742,7 @@ namespace tools
|
||||||
* \brief Calculates the approximate blockchain height from current date/time.
|
* \brief Calculates the approximate blockchain height from current date/time.
|
||||||
*/
|
*/
|
||||||
uint64_t get_approximate_blockchain_height() const;
|
uint64_t get_approximate_blockchain_height() const;
|
||||||
|
uint64_t estimate_blockchain_height();
|
||||||
std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, bool trusted_daemon);
|
std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, 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_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_unmixable_outputs(bool trusted_daemon);
|
||||||
|
|
Loading…
Reference in a new issue