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

WalletScanner skips accounts with createdAt until createdAt sequence is reached #5652

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from

Conversation

danield9tqh
Copy link
Member

@danield9tqh danield9tqh commented Nov 13, 2024

Summary

When an account has the following
createdAt: 10
head: null

the wallet scanner should not take any action on this account until it reaches block 10. Currently the wallet scanner will still connect blocks 1-10 (without decrypting transactions) but it still takes some time and it doesn't provide any value over just connecting block 10 directly

Testing Plan

Unit tests + running local wallet tests

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

@danield9tqh danield9tqh changed the title WIP Have wallet scanner skip accounts with createdAt and no head until createdAt sequence is reached Nov 13, 2024
@danield9tqh danield9tqh changed the title Have wallet scanner skip accounts with createdAt and no head until createdAt sequence is reached WalletScanner skips accounts with createdAt until createdAt sequence is reached Nov 13, 2024
private scanningAccounts = new Array<{ account: Account; scanFrom: HeadValue | null }>()
private scanningAccounts = new Array<{
account: Account
scanFrom: { head: HeadValue | null } | null
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic in this module is tricky sometimes. I haven't read the changes yet, but I know I will have a lot of trouble differentiating between scanFrom === null and scanFrom.head === null. Can we find a way to make the meaning of the values more intuitive? Maybe something like this (if it makes sense):

scanFrom: { head: HeadValue } | 'always-scan' | 'something-else'

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea I think that's a good idea. you're right that's the main thing I'm trying to differentiate with the change though

Copy link
Contributor

@hughy hughy left a comment

Choose a reason for hiding this comment

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

Based on the description it seems like this should be getting rid of connectOnlyAccounts altogether -- if there's no reason to decrypt there's no reason to connect

@danield9tqh danield9tqh force-pushed the dont-scan-empty-accounts-with-birthday branch from 79100c2 to 6c2f87a Compare November 14, 2024 21:41
Comment on lines +193 to 199
if (account.createdAt === null && blockHeader.sequence === GENESIS_BLOCK_SEQUENCE) {
candidate.scanFrom = 'always-scan'
}

if (account.createdAt && blockHeader.sequence >= account.createdAt.sequence) {
candidate.scanFrom = 'always-scan'
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think this can be simplified as:

const createdAtSequence = account.createdAt?.sequence ?? GENESIS_BLOCK_SEQUENCE
if (blockHeader.sequence >= createdAtSequence) {
    candidate.scanFrom = 'always-scan'
}

Comment on lines +324 to +327
for (const { scanFrom } of this.scanningAccounts) {
if (scanFrom === 'always-scan') {
continue
}
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 this will have any effect at the moment. We only call getEarliestHead right after calling refreshScanningAccounts, which will set scanFrom back to the head for each account.

Comment on lines +207 to +210
const decryptAndConnectAccounts = this.scanningAccounts
.filter(({ scanFrom }) => scanFrom === 'always-scan')
.map(({ account }) => account)

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we use 'always-scan' as a way to to divide scanningAccounts into two lists: one list that the walletScanner is currently scanning for (the always-scan accounts), and a list of accounts that are waiting for the walletScanner to get to them.

I wonder if it would be easier to keep the accounts separate or if it would make it harder to follow?

Copy link
Member Author

Choose a reason for hiding this comment

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

Might be easier but popping and pushing the accounts across arrays would be more verbose. I can look into something like this though

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