From 79100c29c00d47f666f81344c70116f595216341 Mon Sep 17 00:00:00 2001 From: danield9tqh Date: Wed, 13 Nov 2024 18:10:08 -0500 Subject: [PATCH] WIP --- ironfish/src/wallet/scanner/walletScanner.ts | 29 ++++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/ironfish/src/wallet/scanner/walletScanner.ts b/ironfish/src/wallet/scanner/walletScanner.ts index feb56da343..b34879a5f8 100644 --- a/ironfish/src/wallet/scanner/walletScanner.ts +++ b/ironfish/src/wallet/scanner/walletScanner.ts @@ -9,7 +9,7 @@ import type { HeadValue } from '../walletdb/headValue' import { Config } from '../../fileStores' import { Logger } from '../../logger' import { Mutex } from '../../mutex' -import { BlockHeader, Transaction } from '../../primitives' +import { BlockHeader, GENESIS_BLOCK_SEQUENCE, Transaction } from '../../primitives' import { BufferUtils, HashUtils } from '../../utils' import { WorkerPool } from '../../workerPool' import { ChainProcessorWithTransactions } from './chainProcessorWithTransactions' @@ -33,7 +33,10 @@ export class WalletScanner { * A snapshot of the accounts that have `scanningEnabled` set to true. Used * to tell what accounts should be scanned, and from what block. */ - private scanningAccounts = new Array<{ account: Account; scanFrom: HeadValue | null }>() + private scanningAccounts = new Array<{ + account: Account + scanFrom: { head: HeadValue | null } | null + }>() constructor(options: { logger: Logger @@ -183,7 +186,10 @@ export class WalletScanner { for (const candidate of this.scanningAccounts) { if ( !candidate.scanFrom || - BufferUtils.equalsNullable(candidate.scanFrom.hash, blockHeader.previousBlockHash) + candidate.scanFrom.head?.hash.equals(blockHeader.previousBlockHash) || + (blockHeader.sequence === GENESIS_BLOCK_SEQUENCE && + candidate.scanFrom.head === null && + candidate.account.createdAt === null) ) { candidate.scanFrom = null @@ -195,6 +201,12 @@ export class WalletScanner { } else { connectOnlyAccounts.push(candidate.account) } + } else if ( + candidate.scanFrom.head === null && + candidate.account.createdAt && + candidate.account.createdAt.sequence === blockHeader.sequence + ) { + decryptAndConnectAccounts.push(candidate.account) } } @@ -241,7 +253,7 @@ export class WalletScanner { } for (const account of this.scanningAccounts) { - if (account.scanFrom && BufferUtils.equalsNullable(account.scanFrom.hash, header.hash)) { + if (account.scanFrom?.head?.hash.equals(header.hash)) { account.scanFrom = null } } @@ -308,13 +320,18 @@ export class WalletScanner { */ private async refreshScanningAccounts(): Promise { this.scanningAccounts = (await this.getScanningAccountsWithHead()).map( - ({ account, head }) => ({ account, scanFrom: head }), + ({ account, head }) => ({ account, scanFrom: { head } }), ) } private getEarliestHead(): HeadValue | null { let earliestHead = null - for (const { scanFrom: head } of this.scanningAccounts) { + for (const { scanFrom } of this.scanningAccounts) { + if (!scanFrom) { + continue + } + + const head = scanFrom.head if (!head) { return null }