Skip to content

wallet2/wallet-rpc: Immediate lookahead table expansion + set_subaddresss_lookahead RPC endpoint #8981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

benevanoff
Copy link
Collaborator

@benevanoff benevanoff commented Sep 3, 2023

A fix for #8980 coupled with an implementation of feature request #8954

Basically the current behavior is that if you make a wallet with the default settings in the cli and then do set subaddress-lookahead 50:300, then the subaddress pubkey table hasnt actually expanded and you aren't looking any further when you scan. Instead, the table will get expanded to this look ahead only after either a new enote is found with the old lookahead or if the user requests a new subaddress with address new.

This patch makes sure that the wallet adjusts the pubkey table immediately after sending the set command if an increase in the lookahead is requested.

This patch also adds a new endpoint to the wallet-rpc program, /set_subaddress_lookahead which allows the user to expand the subaddress lookahead table via remote command. As mentioned in the original ticket, the change does not persist to disk when the wallet closes and changing the wallet-rpc program to save those cached values looks like kinda a pain but I hope that the requestor finds that something is better than nothing for now.

Copy link
Contributor

@UkoeHB UkoeHB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik you can start iterating from the current lookahead position (subaddress labels size + lookahead). It should be fine to call create_one_off_subaddress() for all new subaddresses in the lookahead delta (there shouldn't be duplicates, or no?). That way you don't need the inverted subaddresses map.

for (const auto& pair : m_subaddresses) {
subaddresses_inverted[pair.second] = pair.first; // inverting the keys and values makes it easier to lookup indices
}
for (uint32_t i = 0; i < m_subaddress_labels.size()+major-1; i++) { // m_subaddress_labels tells us how many accounts the user has actually requested without lookahead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overflows if labels.size() and major equal 0. Better to do i + 1 < ... (same for the minor loop below).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just slightly outside of the diff, the first thing this function does is assert that major is greater than zero and .size returns an unsigned int :) I still changed it

@benevanoff
Copy link
Collaborator Author

benevanoff commented Nov 3, 2023

You're right, thank you.

I think the expressions I used this time only make as many calls to create_one_off_subaddress as necessary, but you're also correct that there can't be duplicates because the pubkeys are of course unique and std::map::operator[] will write over the old value for keys already in the map (reassigning a reference) https://en.cppreference.com/w/cpp/container/map/operator_at

@benevanoff benevanoff force-pushed the fix-set-subaddr-lookahead branch from f147882 to d6340d7 Compare November 3, 2023 06:20
@benevanoff benevanoff requested a review from UkoeHB November 3, 2023 06:20
@benevanoff benevanoff force-pushed the fix-set-subaddr-lookahead branch from d6340d7 to 2440f18 Compare November 3, 2023 06:31
@benevanoff benevanoff closed this Nov 3, 2023
@benevanoff benevanoff force-pushed the fix-set-subaddr-lookahead branch from 2440f18 to 8123d94 Compare November 3, 2023 06:46
@benevanoff benevanoff reopened this Nov 3, 2023
@benevanoff benevanoff force-pushed the fix-set-subaddr-lookahead branch 4 times, most recently from d07b6f6 to e97736e Compare November 3, 2023 06:57
@benevanoff benevanoff marked this pull request as draft November 3, 2023 16:08
@benevanoff benevanoff force-pushed the fix-set-subaddr-lookahead branch from 17d86ba to 975f7b7 Compare November 3, 2023 16:18
@benevanoff benevanoff marked this pull request as ready for review November 3, 2023 16:18
@benevanoff
Copy link
Collaborator Author

OK, I made a mess of the changelog but it should be ready for review now :)

test_idx = {100, 299};
subaddr = w1.get_subaddress(test_idx);
EXPECT_NE(boost::none, w1.get_subaddress_index(subaddr));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but please add a newline here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it 👍

@benevanoff benevanoff force-pushed the fix-set-subaddr-lookahead branch from 975f7b7 to 0be321f Compare November 3, 2023 18:07
@benevanoff benevanoff requested a review from selsta November 3, 2023 18:08
@benevanoff benevanoff changed the title wallet2: ensure subaddress keys table is at least size of requested lookahead wallet2/wallet-rpc: Immediate lookahead table expansion + set_subaddresss_lookahead RPC endpoint Nov 3, 2023
@benevanoff
Copy link
Collaborator Author

I've updated the PR to address #8954 as well. I thought about opening a separate PR but figured I would just lump it in here since the RPC endpoint depends on these changes to wallet2. I hope that's alright, but I can still break them apart if y'all would prefer.

Copy link
Collaborator

@selsta selsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‎I think WALLET_RPC_VERSION_MINOR needs to be bumped

@woodser
Copy link
Contributor

woodser commented Nov 21, 2023

Will be nice to have this implemented. Thanks.

@woodser
Copy link
Contributor

woodser commented Dec 6, 2023

the change does not persist to disk when the wallet closes and changing the wallet-rpc program to save those cached values looks like kinda a pain but I hope that the requestor finds that something is better than nothing for now.

In that case, /set_subaddress_lookahead would need to be called each time the wallet is opened in order to scan all subaddresses in excess of 250 (if I recall the default correctly)?

And just confirming, there's no other way to set the wallet's subaddress lookahead through monero-wallet-rpc to avoid that, right?

Something is better than nothing in that case since it can be manually set when opened, but of course not ideal.

@tumblingman
Copy link

@benevanoff @woodser @selsta @UkoeHB @EdwardBetts

Hi everyone,

I'm interested in this feature and wanted to ask if there's any update on whether this PR will be merged? It seems like all the feedback has been addressed, but it hasn't been accepted yet.

Additionally, is there currently any other way to change the scanned subaddress range via RPC? This would be extremely helpful for managing large wallets.

Thank you!

@selsta
Copy link
Collaborator

selsta commented Jun 12, 2025

Continuing in #9953

@selsta selsta closed this Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants