From f2c4c39971f25adaecde377ad325856ea785b9ac Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 10 Feb 2018 10:38:33 +0000 Subject: wallet2: speed up subaddress generation (by about a third) --- src/wallet/wallet2.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/wallet/wallet2.cpp') 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 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 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); } -- cgit v1.2.3 From 89ad162a3ff11629b2fae126a7e12b5d2fd49432 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 13 Feb 2018 16:45:04 +0000 Subject: wallet2: remove unused m_subaddresses_inv --- src/wallet/wallet2.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/wallet/wallet2.cpp') diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a17f0ffc6..1ed0d2b57 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -895,7 +895,6 @@ void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index) { 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"}); @@ -912,7 +911,6 @@ void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index) { 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); } @@ -2342,7 +2340,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; } @@ -3184,7 +3181,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")); -- cgit v1.2.3