aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r--src/wallet/wallet2.cpp51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 808a6fdc2..64dfc2d3b 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -1965,26 +1965,41 @@ void wallet2::set_subaddress_lookahead(size_t major, size_t minor)
THROW_WALLET_EXCEPTION_IF(minor == 0, error::wallet_internal_error, "Subaddress minor lookahead may not be zero");
THROW_WALLET_EXCEPTION_IF(minor > 0xffffffff, error::wallet_internal_error, "Subaddress minor lookahead is too large");
- if (major > m_subaddress_lookahead_major) { // if increasing the lookahead
- // then generate new subaddress pubkeys and add them to m_subaddresses table
- for (uint32_t i = m_subaddress_labels.size()+m_subaddress_lookahead_major; i < m_subaddress_labels.size()+major; i++) { // m_subaddress_labels are the accounts the user is conciously keeping track of. We want that number plus the lookahead major accounts in our key table
- for (uint32_t j = 0; j < minor; j++) { // these are newly made accounts, minor index will start from zero
- cryptonote::subaddress_index idx = {i,j};
- create_one_off_subaddress(idx); // then generate the key and add it to the table
- }
- }
- }
- if (minor > m_subaddress_lookahead_minor) { // if increasing the minor lookahead we need to also go back and expand the existing accounts
- for (uint32_t i = 0; i < m_subaddress_labels.size()+m_subaddress_lookahead_major; i++) {
- uint32_t minor_idx_start = i < m_subaddress_labels.size() ? m_subaddress_labels[i].size()+m_subaddress_lookahead_minor : m_subaddress_lookahead_minor; // if there are existing minor indices being tracked under this account we need to account for that
- for (uint32_t j = minor_idx_start; j < minor; j++) {
- cryptonote::subaddress_index idx = {i,j};
- create_one_off_subaddress(idx);
- }
- }
- }
+ const uint32_t old_major_lookahead = m_subaddress_lookahead_major;
+ const uint32_t old_minor_lookahead = m_subaddress_lookahead_minor;
+
m_subaddress_lookahead_major = major;
m_subaddress_lookahead_minor = minor;
+
+ if (old_major_lookahead >= major && old_minor_lookahead >= minor)
+ return;
+
+ // Expand the subaddresses map so that outputs received to the higher lookaheads will be identified in the scan loop
+ hw::device &hwdev = m_account.get_device();
+ cryptonote::subaddress_index index2;
+ const uint32_t max_major_idx = this->get_num_subaddress_accounts() > 0 ? (this->get_num_subaddress_accounts() - 1) : 0;
+ const uint32_t major_end = get_subaddress_clamped_sum(max_major_idx, major);
+ for (index2.major = 0; index2.major < major_end; ++index2.major)
+ {
+ // The existing minor addresses already set for this account
+ const uint32_t n_minor_subaddrs = this->get_num_subaddresses(index2.major);
+
+ // The subaddress lookahead is expected to expand from the max index in expand_subaddresses
+ const uint32_t max_minor_idx = n_minor_subaddrs > 0 ? (n_minor_subaddrs - 1) : 0;
+ const uint32_t begin = (n_minor_subaddrs || index2.major < old_major_lookahead) ? get_subaddress_clamped_sum(max_minor_idx, old_minor_lookahead) : 0;
+ // The expected new n minor subaddresses allocated for this account
+ const uint32_t end = get_subaddress_clamped_sum(max_minor_idx, minor);
+
+ if (begin >= end)
+ continue;
+
+ const std::vector<crypto::public_key> pkeys = hwdev.get_subaddress_spend_public_keys(m_account.get_keys(), index2.major, begin, end);
+ for (index2.minor = begin; index2.minor < end; ++index2.minor)
+ {
+ const crypto::public_key &D = pkeys.at(index2.minor - begin);
+ m_subaddresses[D] = index2;
+ }
+ }
}
//----------------------------------------------------------------------------------------------------
/*!