Merge pull request #6485

7a8c1ee wallet2: fix subaddress expansion when receiving monero (moneromooo-monero)
This commit is contained in:
luigi1111 2020-05-06 00:31:51 -05:00
commit 3de804f1e9
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
2 changed files with 17 additions and 3 deletions

View file

@ -1523,6 +1523,18 @@ void wallet2::add_subaddress(uint32_t index_major, const std::string& label)
m_subaddress_labels[index_major][index_minor] = label; m_subaddress_labels[index_major][index_minor] = label;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
bool wallet2::should_expand(const cryptonote::subaddress_index &index) const
{
const uint32_t last_major = m_subaddress_labels.size() - 1 > (std::numeric_limits<uint32_t>::max() - m_subaddress_lookahead_major) ? std::numeric_limits<uint32_t>::max() : (m_subaddress_labels.size() + m_subaddress_lookahead_major - 1);
if (index.major > last_major)
return false;
const size_t nsub = index.major < m_subaddress_labels.size() ? m_subaddress_labels[index.major].size() : 0;
const uint32_t last_minor = nsub - 1 > (std::numeric_limits<uint32_t>::max() - m_subaddress_lookahead_minor) ? std::numeric_limits<uint32_t>::max() : (nsub + m_subaddress_lookahead_minor - 1);
if (index.minor > last_minor)
return false;
return true;
}
//----------------------------------------------------------------------------------------------------
void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index) void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index)
{ {
hw::device &hwdev = m_account.get_device(); hw::device &hwdev = m_account.get_device();
@ -2108,7 +2120,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
td.m_amount = amount; td.m_amount = amount;
td.m_pk_index = pk_index - 1; td.m_pk_index = pk_index - 1;
td.m_subaddr_index = tx_scan_info[o].received->index; td.m_subaddr_index = tx_scan_info[o].received->index;
if (tx_scan_info[o].received->index.major < m_subaddress_labels.size() && tx_scan_info[o].received->index.minor < m_subaddress_labels[tx_scan_info[o].received->index.major].size()) if (should_expand(tx_scan_info[o].received->index))
expand_subaddresses(tx_scan_info[o].received->index); expand_subaddresses(tx_scan_info[o].received->index);
if (tx.vout[o].amount == 0) if (tx.vout[o].amount == 0)
{ {
@ -2187,7 +2199,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
td.m_amount = amount; td.m_amount = amount;
td.m_pk_index = pk_index - 1; td.m_pk_index = pk_index - 1;
td.m_subaddr_index = tx_scan_info[o].received->index; td.m_subaddr_index = tx_scan_info[o].received->index;
if (tx_scan_info[o].received->index.major < m_subaddress_labels.size() && tx_scan_info[o].received->index.minor < m_subaddress_labels[tx_scan_info[o].received->index.major].size()) if (should_expand(tx_scan_info[o].received->index))
expand_subaddresses(tx_scan_info[o].received->index); expand_subaddresses(tx_scan_info[o].received->index);
if (tx.vout[o].amount == 0) if (tx.vout[o].amount == 0)
{ {
@ -12772,7 +12784,7 @@ process:
const crypto::public_key& out_key = boost::get<cryptonote::txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key; const crypto::public_key& out_key = boost::get<cryptonote::txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key;
bool r = cryptonote::generate_key_image_helper(m_account.get_keys(), m_subaddresses, out_key, tx_pub_key, additional_tx_pub_keys, td.m_internal_output_index, in_ephemeral, td.m_key_image, m_account.get_device()); bool r = cryptonote::generate_key_image_helper(m_account.get_keys(), m_subaddresses, out_key, tx_pub_key, additional_tx_pub_keys, td.m_internal_output_index, in_ephemeral, td.m_key_image, m_account.get_device());
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to generate key image"); THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to generate key image");
if (td.m_subaddr_index.major < m_subaddress_labels.size() && td.m_subaddr_index.minor < m_subaddress_labels[td.m_subaddr_index.major].size()) if (should_expand(td.m_subaddr_index))
expand_subaddresses(td.m_subaddr_index); expand_subaddresses(td.m_subaddr_index);
td.m_key_image_known = true; td.m_key_image_known = true;
td.m_key_image_request = true; td.m_key_image_request = true;

View file

@ -1516,6 +1516,8 @@ private:
std::string get_client_signature() const; std::string get_client_signature() const;
void check_rpc_cost(const char *call, uint64_t post_call_credits, uint64_t pre_credits, double expected_cost); void check_rpc_cost(const char *call, uint64_t post_call_credits, uint64_t pre_credits, double expected_cost);
bool should_expand(const cryptonote::subaddress_index &index) const;
cryptonote::account_base m_account; cryptonote::account_base m_account;
boost::optional<epee::net_utils::http::login> m_daemon_login; boost::optional<epee::net_utils::http::login> m_daemon_login;
std::string m_daemon_address; std::string m_daemon_address;