Merge pull request #3247

89ad162a wallet2: remove unused m_subaddresses_inv (moneromooo-monero)
f2c4c399 wallet2: speed up subaddress generation (by about a third) (moneromooo-monero)
This commit is contained in:
Riccardo Spagni
2018-02-20 17:46:40 +02:00
4 changed files with 55 additions and 19 deletions
+12 -17
View File
@@ -888,14 +888,12 @@ void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index)
cryptonote::subaddress_index index2;
for (index2.major = m_subaddress_labels.size(); index2.major < index.major + m_subaddress_lookahead_major; ++index2.major)
{
for (index2.minor = 0; index2.minor < (index2.major == index.major ? index.minor : 0) + m_subaddress_lookahead_minor; ++index2.minor)
const uint32_t end = (index2.major == index.major ? index.minor : 0) + m_subaddress_lookahead_minor;
const std::vector<crypto::public_key> pkeys = cryptonote::get_subaddress_spend_public_keys(m_account.get_keys(), index2.major, 0, end);
for (index2.minor = 0; index2.minor < end; ++index2.minor)
{
if (m_subaddresses_inv.count(index2) == 0)
{
crypto::public_key D = get_subaddress_spend_public_key(index2);
m_subaddresses[D] = index2;
m_subaddresses_inv[index2] = D;
}
const crypto::public_key &D = pkeys[index2.minor];
m_subaddresses[D] = index2;
}
}
m_subaddress_labels.resize(index.major + 1, {"Untitled account"});
@@ -904,15 +902,14 @@ void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index)
else if (m_subaddress_labels[index.major].size() <= index.minor)
{
// add new subaddresses
cryptonote::subaddress_index index2 = index;
for (index2.minor = m_subaddress_labels[index.major].size(); index2.minor < index.minor + m_subaddress_lookahead_minor; ++index2.minor)
const uint32_t end = index.minor + m_subaddress_lookahead_minor;
const uint32_t begin = m_subaddress_labels[index.major].size();
cryptonote::subaddress_index index2 = {index.major, begin};
const std::vector<crypto::public_key> pkeys = cryptonote::get_subaddress_spend_public_keys(m_account.get_keys(), index2.major, index2.minor, end);
for (; index2.minor < end; ++index2.minor)
{
if (m_subaddresses_inv.count(index2) == 0)
{
crypto::public_key D = get_subaddress_spend_public_key(index2);
m_subaddresses[D] = index2;
m_subaddresses_inv[index2] = D;
}
const crypto::public_key &D = pkeys[index2.minor - begin];
m_subaddresses[D] = index2;
}
m_subaddress_labels[index.major].resize(index.minor + 1);
}
@@ -2352,7 +2349,6 @@ bool wallet2::clear()
m_address_book.clear();
m_local_bc_height = 1;
m_subaddresses.clear();
m_subaddresses_inv.clear();
m_subaddress_labels.clear();
return true;
}
@@ -3194,7 +3190,6 @@ bool wallet2::finalize_multisig(const epee::wipeable_string &password, std::unor
}
m_subaddresses.clear();
m_subaddresses_inv.clear();
m_subaddress_labels.clear();
add_subaddress_account(tr("Primary account"));
+3 -2
View File
@@ -605,6 +605,7 @@ namespace tools
cryptonote::account_public_address get_subaddress(const cryptonote::subaddress_index& index) const;
cryptonote::account_public_address get_address() const { return get_subaddress({0,0}); }
crypto::public_key get_subaddress_spend_public_key(const cryptonote::subaddress_index& index) const;
std::vector<crypto::public_key> get_subaddress_spend_public_keys(uint32_t account, uint32_t begin, uint32_t end) const;
std::string get_subaddress_as_str(const cryptonote::subaddress_index& index) const;
std::string get_address_as_str() const { return get_subaddress_as_str({0, 0}); }
std::string get_integrated_address_as_str(const crypto::hash8& payment_id) const;
@@ -782,7 +783,8 @@ namespace tools
if (ver < 20)
return;
a & m_subaddresses;
a & m_subaddresses_inv;
std::unordered_map<cryptonote::subaddress_index, crypto::public_key> dummy_subaddresses_inv;
a & dummy_subaddresses_inv;
a & m_subaddress_labels;
a & m_additional_tx_keys;
if(ver < 21)
@@ -1089,7 +1091,6 @@ namespace tools
std::unordered_map<crypto::public_key, size_t> m_pub_keys;
cryptonote::account_public_address m_account_public_address;
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> m_subaddresses;
std::unordered_map<cryptonote::subaddress_index, crypto::public_key> m_subaddresses_inv;
std::vector<std::vector<std::string>> m_subaddress_labels;
std::unordered_map<crypto::hash, std::string> m_tx_notes;
std::unordered_map<std::string, std::string> m_attributes;