Skip to content
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

Scan wallet accounts from earliest account head first #4964

Merged
merged 6 commits into from
May 23, 2024

Conversation

dguenther
Copy link
Member

@dguenther dguenther commented May 14, 2024

Summary

This PR updates the chain processor's head before every loop in updateHead, rather than loading the earliest account head into the chain processor when the node starts.

Notably, this also removes the idea of a wallet head (previously, chainProcessor.hash), since each account has its own head.

Also notably, sendTransaction was previously gated on whether the account head was the same as the chain processor head, but now it's gated on whether the account head is within confirmations blocks of the chain head. I don't think the gate made sense before, but I'm concerned it might be too sensitive now.

This PR should make it easier to implement starting/stopping scanning (See #4943), because when scanning is resumed on an account, it'll automatically be picked up by updateHead without needing to trigger a manual rescan.

FIxes IFL-2568

Testing Plan

Did some manual testing of this by adding and removing multiple accounts.

Documentation

Does this change require any updates to the Iron Fish Docs (ex. the RPC API
Reference
)? If yes, link a
related documentation pull request for the website.

[ ] Yes

Breaking Change

Is this a breaking change? If yes, add notes below on why this is breaking and label it with breaking-change-rpc or breaking-change-sdk.

[ ] Yes

dguenther added 2 commits May 16, 2024 12:00
The previous version of isAccountUpToDate checked against the wallet's
head, but the wallet head is an arbitrary block, so the chain head would
be more appropriate. However, I think this is too restrictive to be
enforced as a hard requirement at the SDK level, since you might have
knowledge that your account only has transactions through a limited
number of blocks.

A potential downside could be accidentally creating double spends where
users would have previously been prevented from creating transactions.
@dguenther dguenther marked this pull request as ready for review May 22, 2024 18:37
@dguenther dguenther requested a review from a team as a code owner May 22, 2024 18:37
@dguenther dguenther changed the title WIP: Scan wallet accounts from earliest account head first Scan wallet accounts from earliest account head first May 22, 2024
@@ -1822,14 +1757,16 @@ export class Wallet {
return latestHead ? latestHead.hash : null
}

async isAccountUpToDate(account: Account): Promise<boolean> {
async isAccountUpToDate(account: Account, confirmations?: number): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like the only place this is used now is in RPC calls to remove an account

i'm not really sure why we require confirmation to remove an account that isn't synced 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good question... seems like the main case might be when you export, then re-import an account, you might want to make sure the account doesn't have a balance before deleting it, in case you haven't backed it up.

Or if you somehow create an account without a birthday, give someone the public address, they send you tokens, and you delete the account (thinking the transaction didn't work) before fully syncing up.

We could probably re-think how we prompt users about that though 🤔

@@ -187,6 +187,7 @@ export class Wallet {
try {
let hashChanged = false
do {
this.chainProcessor.hash = await this.getEarliestHeadHash()
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think that iterating over heads will have an impact relative to the current performance since right now we're checking isAccountUpToDate on every account before decrypting notes

@dguenther dguenther merged commit 2c17136 into staging May 23, 2024
9 checks passed
@dguenther dguenther deleted the oldest-first-syncing branch May 23, 2024 22:07
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.

3 participants