diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-02-10 10:38:33 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-02-16 17:13:06 +0000 |
commit | f2c4c39971f25adaecde377ad325856ea785b9ac (patch) | |
tree | 772b8ec46b08407cc073767f058e0c43b41b70f1 /src/wallet | |
parent | Merge pull request #3198 (diff) | |
download | monero-f2c4c39971f25adaecde377ad325856ea785b9ac.tar.xz |
wallet2: speed up subaddress generation (by about a third)
Diffstat (limited to 'src/wallet')
-rw-r--r-- | src/wallet/wallet2.cpp | 31 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 1 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7dc8a1e47..a17f0ffc6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -889,14 +889,13 @@ 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_subaddresses_inv[index2] = D; } } m_subaddress_labels.resize(index.major + 1, {"Untitled account"}); @@ -905,15 +904,15 @@ 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) - { - 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 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) + { + const crypto::public_key &D = pkeys[index2.minor - begin]; + m_subaddresses[D] = index2; + m_subaddresses_inv[index2] = D; } m_subaddress_labels[index.major].resize(index.minor + 1); } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f768581b2..e92abbc69 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -602,6 +602,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; |