diff --git a/packages/neuron-ui/src/components/MultisigAddress/hooks.ts b/packages/neuron-ui/src/components/MultisigAddress/hooks.ts index c302ce905e..c2e0613d4b 100644 --- a/packages/neuron-ui/src/components/MultisigAddress/hooks.ts +++ b/packages/neuron-ui/src/components/MultisigAddress/hooks.ts @@ -335,7 +335,7 @@ export const useSubscription = ({ const tmp: Record = {} res.result.forEach(v => { if (hashToPayload[v.hash]) { - tmp[hashToPayload[v.hash]] = v.blockStartNumber + tmp[hashToPayload[v.hash]] = v.localSavedBlockNumber } }) setMultisigSyncProgress(tmp) diff --git a/packages/neuron-ui/src/services/remote/multisig.ts b/packages/neuron-ui/src/services/remote/multisig.ts index 4ac2b4aa2b..79332443d4 100644 --- a/packages/neuron-ui/src/services/remote/multisig.ts +++ b/packages/neuron-ui/src/services/remote/multisig.ts @@ -49,6 +49,6 @@ export const generateMultisigSendAllTx = remoteApi<{ multisigConfig: MultisigConfig }>('generate-multisig-send-all-tx') export const loadMultisigTxJson = remoteApi('load-multisig-tx-json') -export const getMultisigSyncProgress = remoteApi( +export const getMultisigSyncProgress = remoteApi( 'get-sync-progress-by-addresses' ) diff --git a/packages/neuron-wallet/src/block-sync-renderer/index.ts b/packages/neuron-wallet/src/block-sync-renderer/index.ts index f6e0e0ac95..95576c84a7 100644 --- a/packages/neuron-wallet/src/block-sync-renderer/index.ts +++ b/packages/neuron-wallet/src/block-sync-renderer/index.ts @@ -9,7 +9,7 @@ import DataUpdateSubject from '../models/subjects/data-update' import AddressCreatedSubject from '../models/subjects/address-created-subject' import WalletDeletedSubject from '../models/subjects/wallet-deleted-subject' import TxDbChangedSubject from '../models/subjects/tx-db-changed-subject' -import { LumosCellQuery, LumosCell } from './sync/connector' +import { LumosCellQuery, LumosCell } from './sync/synchronizer' import { WorkerMessage, StartParams, QueryIndexerParams } from './task' import logger from '../utils/logger' import CommonUtils from '../utils/common' diff --git a/packages/neuron-wallet/src/block-sync-renderer/sync/indexer-connector.ts b/packages/neuron-wallet/src/block-sync-renderer/sync/full-synchronizer.ts similarity index 95% rename from packages/neuron-wallet/src/block-sync-renderer/sync/indexer-connector.ts rename to packages/neuron-wallet/src/block-sync-renderer/sync/full-synchronizer.ts index cec772ad50..972d37e5f0 100644 --- a/packages/neuron-wallet/src/block-sync-renderer/sync/indexer-connector.ts +++ b/packages/neuron-wallet/src/block-sync-renderer/sync/full-synchronizer.ts @@ -3,11 +3,11 @@ import logger from '../../utils/logger' import CommonUtils from '../../utils/common' import RpcService from '../../services/rpc-service' import { Address } from '../../models/address' -import { Connector } from './connector' +import { Synchronizer } from './synchronizer' import { NetworkType } from '../../models/network' import IndexerCacheService from './indexer-cache-service' -export default class IndexerConnector extends Connector { +export default class FullSynchronizer extends Synchronizer { private rpcService: RpcService constructor(addresses: Address[], nodeUrl: string, indexerUrl: string, nodeType: NetworkType) { diff --git a/packages/neuron-wallet/src/block-sync-renderer/sync/light-connector.ts b/packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts similarity index 80% rename from packages/neuron-wallet/src/block-sync-renderer/sync/light-connector.ts rename to packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts index 9a02faa48d..00ad630bea 100644 --- a/packages/neuron-wallet/src/block-sync-renderer/sync/light-connector.ts +++ b/packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts @@ -4,7 +4,7 @@ import { Address } from '../../models/address' import AddressMeta from '../../database/address/meta' import { scheduler } from 'timers/promises' import SyncProgressService from '../../services/sync-progress' -import { Connector, AppendScript } from './connector' +import { Synchronizer, AppendScript } from './synchronizer' import { computeScriptHash as scriptToHash } from '@ckb-lumos/base/lib/utils' import { FetchTransactionReturnType, LightRPC, LightScriptFilter } from '../../utils/ckb-rpc' import Multisig from '../../services/multisig' @@ -24,7 +24,7 @@ import NetworksService from '../../services/networks' const unpackGroup = molecule.vector(blockchain.OutPoint) -export default class LightConnector extends Connector { +export default class LightSynchronizer extends Synchronizer { private lightRpc: LightRPC private addressMetas: AddressMeta[] @@ -87,7 +87,7 @@ export default class LightConnector extends Connector { private async synchronize() { const syncScripts = await this.upsertTxHashes() await this.updateSyncedBlockOfScripts(syncScripts) - const minSyncBlockNumber = await SyncProgressService.getCurrentWalletMinBlockNumber() + const minSyncBlockNumber = await SyncProgressService.getCurrentWalletMinSyncedBlockNumber() const hasNextBlock = await this.notifyAndSyncNext(minSyncBlockNumber) if (!hasNextBlock) { await this.updateBlockStartNumber(minSyncBlockNumber) @@ -138,7 +138,7 @@ export default class LightConnector extends Connector { const txs = await this.getTransactions({ script: syncScript.script, scriptType: syncScript.scriptType, - blockRange: [BI.from(syncStatus.blockEndNumber).toHexString(), syncScript.blockNumber], + blockRange: [BI.from(syncStatus.syncedBlockNumber).toHexString(), syncScript.blockNumber], }) insertTxCaches.push( ...txs.map(v => ({ @@ -164,7 +164,7 @@ export default class LightConnector extends Connector { syncScripts.forEach(v => { const currentSyncProgress = syncStatusMap.get(scriptToHash(v.script)) if (currentSyncProgress) { - currentSyncProgress.blockEndNumber = parseInt(v.blockNumber) + currentSyncProgress.syncedBlockNumber = parseInt(v.blockNumber) updatedSyncProgress.push(currentSyncProgress) } }) @@ -196,35 +196,42 @@ export default class LightConnector extends Connector { })) }) .flat() - const walletMinBlockNumber = await SyncProgressService.getWalletMinBlockNumber() + const walletMinBlockNumber = await SyncProgressService.getWalletMinLocalSavedBlockNumber() const wallets = await WalletService.getInstance().getAll() const walletStartBlockMap = wallets.reduce>( (pre, cur) => ({ ...pre, [cur.id]: cur.startBlockNumber }), {} ) const otherTypeSyncBlockNumber = await SyncProgressService.getOtherTypeSyncBlockNumber() - const setScriptsParams = [ - ...allScripts.map(v => { - const blockNumber = Math.max( - parseInt(walletStartBlockMap[v.walletId] ?? '0x0'), - walletMinBlockNumber?.[v.walletId] ?? 0, - parseInt(existSyncscripts[scriptToHash(v.script)]?.blockNumber ?? '0x0') - ) - return { + const addScripts = [ + ...allScripts + .filter(v => !existSyncscripts[scriptToHash(v.script)]) + .map(v => { + const blockNumber = Math.max( + parseInt(walletStartBlockMap[v.walletId] ?? '0x0'), + walletMinBlockNumber?.[v.walletId] ?? 0 + ) + return { + ...v, + blockNumber: `0x${blockNumber.toString(16)}`, + } + }), + ...appendScripts + .filter(v => !existSyncscripts[scriptToHash(v.script)]) + .map(v => ({ ...v, - blockNumber: `0x${blockNumber.toString(16)}`, - } - }), - ...appendScripts.map(v => ({ - ...v, - blockNumber: - existSyncscripts[scriptToHash(v.script)]?.blockNumber ?? - `0x${(otherTypeSyncBlockNumber[scriptToHash(v.script)] ?? 0).toString(16)}`, - })), + blockNumber: `0x${(otherTypeSyncBlockNumber[scriptToHash(v.script)] ?? 0).toString(16)}`, + })), ] - await this.lightRpc.setScripts(setScriptsParams) + await this.lightRpc.setScripts(addScripts, 'partial') + const allScriptHashes = new Set([ + ...allScripts.map(v => scriptToHash(v.script)), + ...appendScripts.map(v => scriptToHash(v.script)), + ]) + const deleteScript = syncScripts.filter(v => !allScriptHashes.has(scriptToHash(v.script))) + await this.lightRpc.setScripts(deleteScript, 'delete') const walletIds = [...new Set(this.addressMetas.map(v => v.walletId))] - await SyncProgressService.resetSyncProgress(setScriptsParams) + await SyncProgressService.resetSyncProgress(addScripts) await SyncProgressService.updateSyncProgressFlag(walletIds) await SyncProgressService.removeByHashesAndAddressType( SyncAddressType.Multisig, @@ -281,9 +288,25 @@ export default class LightConnector extends Connector { this.initSyncProgress(scripts) } + private async checkTxExist(txHashes: string[]) { + const transactions = await this.lightRpc + .createBatchRequest<'getTransaction', string[], TransactionWithStatus[]>(txHashes.map(v => ['getTransaction', v])) + .exec() + return transactions.every(v => !!v.transaction) + } + async processTxsInNextBlockNumber() { const [nextBlockNumber, txHashesInNextBlock] = await this.getTxHashesWithNextUnprocessedBlockNumber() - if (nextBlockNumber !== undefined && txHashesInNextBlock.length) { + const minSyncBlockNumber = await SyncProgressService.getCurrentWalletMinSyncedBlockNumber() + if ( + nextBlockNumber !== undefined && + txHashesInNextBlock.length && + // For light client, if tx hash has been called with fetch_transaction, the tx can not return by get_transactions + // So before derived address synced to bigger than next synced block number, do not sync the next block number + minSyncBlockNumber >= parseInt(nextBlockNumber) && + // check whether the tx is sync from light client, after split the light client and full DB file, this check will remove + (await this.checkTxExist(txHashesInNextBlock)) + ) { this.processingBlockNumber = nextBlockNumber await this.fetchPreviousOutputs(txHashesInNextBlock) this.transactionsSubject.next({ txHashes: txHashesInNextBlock, params: this.processingBlockNumber }) @@ -296,7 +319,7 @@ export default class LightConnector extends Connector { } else { return } - const minCachedBlockNumber = await SyncProgressService.getCurrentWalletMinBlockNumber() + const minCachedBlockNumber = await SyncProgressService.getCurrentWalletMinSyncedBlockNumber() await this.updateBlockStartNumber(Math.min(parseInt(blockNumber), minCachedBlockNumber)) this.processNextBlockNumber() } diff --git a/packages/neuron-wallet/src/block-sync-renderer/sync/queue.ts b/packages/neuron-wallet/src/block-sync-renderer/sync/queue.ts index 36944d7dcc..a09055eb58 100644 --- a/packages/neuron-wallet/src/block-sync-renderer/sync/queue.ts +++ b/packages/neuron-wallet/src/block-sync-renderer/sync/queue.ts @@ -12,13 +12,13 @@ import AddressParser from '../../models/address-parser' import Multisig from '../../models/multisig' import BlockHeader from '../../models/chain/block-header' import TxAddressFinder from './tx-address-finder' -import IndexerConnector from './indexer-connector' +import FullSynchronizer from './full-synchronizer' import IndexerCacheService from './indexer-cache-service' import logger from '../../utils/logger' import CommonUtils from '../../utils/common' import { ShouldInChildProcess } from '../../exceptions' -import { AppendScript, BlockTips, Connector } from './connector' -import LightConnector from './light-connector' +import { AppendScript, BlockTips, Synchronizer } from './synchronizer' +import LightSynchronizer from './light-synchronizer' import { generateRPC } from '../../utils/ckb-rpc' import { BUNDLED_LIGHT_CKB_URL } from '../../utils/const' import { NetworkType } from '../../models/network' @@ -30,7 +30,7 @@ export default class Queue { #indexerUrl: string #addresses: AddressInterface[] #rpcService: RpcService - #indexerConnector: Connector | undefined + #indexerConnector: Synchronizer | undefined #checkAndSaveQueue: QueueObject<{ txHashes: CKBComponents.Hash[]; params: unknown }> | undefined #lockArgsSet: Set = new Set() @@ -67,9 +67,9 @@ export default class Queue { logger.info('Queue:\tstart') try { if (this.#url === BUNDLED_LIGHT_CKB_URL) { - this.#indexerConnector = new LightConnector(this.#addresses, this.#url) + this.#indexerConnector = new LightSynchronizer(this.#addresses, this.#url) } else { - this.#indexerConnector = new IndexerConnector(this.#addresses, this.#url, this.#indexerUrl, this.#nodeType) + this.#indexerConnector = new FullSynchronizer(this.#addresses, this.#url, this.#indexerUrl, this.#nodeType) } await this.#indexerConnector!.connect() } catch (error) { @@ -110,7 +110,7 @@ export default class Queue { }) } - getIndexerConnector = (): Connector => this.#indexerConnector! + getIndexerConnector = (): Synchronizer => this.#indexerConnector! stop = () => this.#indexerConnector!.stop() diff --git a/packages/neuron-wallet/src/block-sync-renderer/sync/connector.ts b/packages/neuron-wallet/src/block-sync-renderer/sync/synchronizer.ts similarity index 99% rename from packages/neuron-wallet/src/block-sync-renderer/sync/connector.ts rename to packages/neuron-wallet/src/block-sync-renderer/sync/synchronizer.ts index fd19a734f2..7b1fd0b4e8 100644 --- a/packages/neuron-wallet/src/block-sync-renderer/sync/connector.ts +++ b/packages/neuron-wallet/src/block-sync-renderer/sync/synchronizer.ts @@ -49,7 +49,7 @@ export interface AppendScript { scriptType: CKBRPC.ScriptType } -export abstract class Connector { +export abstract class Synchronizer { public readonly blockTipsSubject: Subject = new Subject() public readonly transactionsSubject = new Subject<{ txHashes: CKBComponents.Hash[]; params: string }>() protected indexer: CkbIndexer diff --git a/packages/neuron-wallet/src/block-sync-renderer/task.ts b/packages/neuron-wallet/src/block-sync-renderer/task.ts index 0706e72e64..b0e0cc6c27 100644 --- a/packages/neuron-wallet/src/block-sync-renderer/task.ts +++ b/packages/neuron-wallet/src/block-sync-renderer/task.ts @@ -1,4 +1,4 @@ -import type { LumosCellQuery } from './sync/connector' +import type { LumosCellQuery } from './sync/synchronizer' import initConnection from '../database/chain/ormconfig' import { register as registerTxStatusListener } from './tx-status-listener' import SyncQueue from './sync/queue' diff --git a/packages/neuron-wallet/src/database/chain/entities/sync-progress.ts b/packages/neuron-wallet/src/database/chain/entities/sync-progress.ts index abacf26067..75229b5ec4 100644 --- a/packages/neuron-wallet/src/database/chain/entities/sync-progress.ts +++ b/packages/neuron-wallet/src/database/chain/entities/sync-progress.ts @@ -28,10 +28,13 @@ export default class SyncProgress { walletId!: string @Column() - blockStartNumber: number = 0 + lightStartBlockNumber: number = 0 @Column() - blockEndNumber: number = 0 + localSavedBlockNumber: number = 0 + + @Column() + syncedBlockNumber: number = 0 @Column({ type: 'varchar' }) cursor?: HexString @@ -58,8 +61,9 @@ export default class SyncProgress { res.scriptType = obj.scriptType res.delete = false res.addressType = obj.addressType ?? SyncAddressType.Default - res.blockStartNumber = parseInt(obj.blockNumber) - res.blockEndNumber = parseInt(obj.blockNumber) + res.lightStartBlockNumber = parseInt(obj.blockNumber) + res.localSavedBlockNumber = parseInt(obj.blockNumber) + res.syncedBlockNumber = parseInt(obj.blockNumber) return res } } diff --git a/packages/neuron-wallet/src/database/chain/migrations/1690361215400-ResetSyncProgressPrimaryKey.ts b/packages/neuron-wallet/src/database/chain/migrations/1690361215400-ResetSyncProgressPrimaryKey.ts index 17bbd1cef2..99c3ab1888 100644 --- a/packages/neuron-wallet/src/database/chain/migrations/1690361215400-ResetSyncProgressPrimaryKey.ts +++ b/packages/neuron-wallet/src/database/chain/migrations/1690361215400-ResetSyncProgressPrimaryKey.ts @@ -1,15 +1,15 @@ import {MigrationInterface, QueryRunner} from "typeorm"; -import SyncProgress from "../entities/sync-progress"; +const chunk = 100 export class ResetSyncProgressPrimaryKey1690361215400 implements MigrationInterface { name = 'ResetSyncProgressPrimaryKey1690361215400' public async up(queryRunner: QueryRunner): Promise { - const syncProgresses = await queryRunner.manager.find(SyncProgress) + const syncProgresses = await queryRunner.manager.query('select * from sync_progress') await queryRunner.query(`DROP TABLE "sync_progress"`) await queryRunner.query(`CREATE TABLE "sync_progress" ("hash" varchar NOT NULL, "args" varchar NOT NULL, "codeHash" varchar NOT NULL, "hashType" varchar NOT NULL, "scriptType" varchar NOT NULL, "walletId" varchar NOT NULL, "blockStartNumber" integer NOT NULL, "blockEndNumber" integer, "cursor" varchar, "delete" boolean, "addressType" integer, PRIMARY KEY ("hash", "walletId"))`) - for (let index = 0; index < syncProgresses.length; index += 500) { - await queryRunner.manager.save(syncProgresses.slice(index, index + 500)) + for (let index = 0; index < syncProgresses.length; index += chunk) { + await queryRunner.manager.query(`INSERT INTO sync_progress VALUES ${syncProgresses.slice(index, index + chunk).reduce((pre: string, cur: any) => `${pre ? `${pre},` : ''}("${cur.hash}","${cur.args}","${cur.codeHash}","${cur.hashType}","${cur.scriptType}","${cur.walletId}",${cur.blockStartNumber},${cur.blockEndNumber},${cur.cursor ? `"${cur.cursor}"` : 'NULL'},${cur.delete},${cur.addressType})`, '')};`) } } diff --git a/packages/neuron-wallet/src/database/chain/migrations/1702781527414-RenameSyncProgress.ts b/packages/neuron-wallet/src/database/chain/migrations/1702781527414-RenameSyncProgress.ts new file mode 100644 index 0000000000..4a6c4b78d8 --- /dev/null +++ b/packages/neuron-wallet/src/database/chain/migrations/1702781527414-RenameSyncProgress.ts @@ -0,0 +1,21 @@ +import {MigrationInterface, QueryRunner, TableColumn} from "typeorm"; + +export class RenameSyncProgress1702781527414 implements MigrationInterface { + name = 'RenameSyncProgress1702781527414' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.renameColumn('sync_progress', 'blockStartNumber', 'localSavedBlockNumber') + await queryRunner.renameColumn('sync_progress', 'blockEndNumber', 'syncedBlockNumber') + await queryRunner.addColumn('sync_progress', new TableColumn({ + name: 'lightStartBlockNumber', + type: 'integer', + default: 0 + })) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.renameColumn('sync_progress', 'localSavedBlockNumber', 'blockStartNumber') + await queryRunner.renameColumn('sync_progress', 'syncedBlockNumber', 'blockEndNumber') + } + +} diff --git a/packages/neuron-wallet/src/database/chain/ormconfig.ts b/packages/neuron-wallet/src/database/chain/ormconfig.ts index d87ac1cbd0..f7667901a4 100644 --- a/packages/neuron-wallet/src/database/chain/ormconfig.ts +++ b/packages/neuron-wallet/src/database/chain/ormconfig.ts @@ -58,6 +58,7 @@ import { ResetSyncProgressPrimaryKey1690361215400 } from './migrations/169036121 import { TxLockAddArgs1694746034975 } from './migrations/1694746034975-TxLockAddArgs' import { IndexerTxHashCacheRemoveField1701234043431 } from './migrations/1701234043431-IndexerTxHashCacheRemoveField' import { CreateCellLocalInfo1701234043432 } from './migrations/1701234043432-CreateCellLocalInfo' +import { RenameSyncProgress1702781527414 } from './migrations/1702781527414-RenameSyncProgress' export const CONNECTION_NOT_FOUND_NAME = 'ConnectionNotFoundError' @@ -132,6 +133,7 @@ const connectOptions = async (genesisBlockHash: string): Promise = { type: ScriptHashType.Type, diff --git a/packages/neuron-wallet/src/services/live-cell-service.ts b/packages/neuron-wallet/src/services/live-cell-service.ts index 8c6694e935..4b7766d3db 100644 --- a/packages/neuron-wallet/src/services/live-cell-service.ts +++ b/packages/neuron-wallet/src/services/live-cell-service.ts @@ -1,7 +1,7 @@ import Script from '../models/chain/script' import LiveCell from '../models/chain/live-cell' import { queryIndexer } from '../block-sync-renderer/index' -import { LumosCell, LumosCellQuery } from '../block-sync-renderer/sync/connector' +import { LumosCell, LumosCellQuery } from '../block-sync-renderer/sync/synchronizer' export default class LiveCellService { private static instance: LiveCellService diff --git a/packages/neuron-wallet/src/services/multisig.ts b/packages/neuron-wallet/src/services/multisig.ts index 922fbf7161..d26b678b17 100644 --- a/packages/neuron-wallet/src/services/multisig.ts +++ b/packages/neuron-wallet/src/services/multisig.ts @@ -270,7 +270,7 @@ export default class MultisigService { .where({ hash: In(multisigScriptHashList) }) .getMany() const syncBlockNumbersMap: Record = syncBlockNumbers.reduce( - (pre, cur) => ({ ...pre, [cur.hash]: cur.blockStartNumber }), + (pre, cur) => ({ ...pre, [cur.hash]: cur.localSavedBlockNumber }), {} ) await getConnection() diff --git a/packages/neuron-wallet/src/services/sync-progress.ts b/packages/neuron-wallet/src/services/sync-progress.ts index 962f5ad287..2d42843bab 100644 --- a/packages/neuron-wallet/src/services/sync-progress.ts +++ b/packages/neuron-wallet/src/services/sync-progress.ts @@ -50,8 +50,8 @@ export default class SyncProgressService { await getConnection() .createQueryBuilder() .update(SyncProgress) - .set({ blockStartNumber: blockNumber }) - .where({ args: In(blake160s), blockStartNumber: LessThan(blockNumber) }) + .set({ localSavedBlockNumber: blockNumber }) + .where({ args: In(blake160s), localSavedBlockNumber: LessThan(blockNumber) }) .execute() } @@ -78,7 +78,7 @@ export default class SyncProgressService { return result } - static async getCurrentWalletMinBlockNumber() { + static async getCurrentWalletMinSyncedBlockNumber() { const currentWallet = WalletService.getInstance().getCurrent() const item = await getConnection() .getRepository(SyncProgress) @@ -88,27 +88,30 @@ export default class SyncProgressService { addressType: SyncAddressType.Default, ...(currentWallet ? { walletId: currentWallet.id } : {}), }) - .orderBy('blockEndNumber', 'ASC') + .orderBy('syncedBlockNumber', 'ASC') .getOne() - return item?.blockEndNumber || 0 + return item?.syncedBlockNumber || 0 } - static async getWalletMinBlockNumber() { + static async getWalletMinLocalSavedBlockNumber() { const items = await getConnection() .getRepository(SyncProgress) .createQueryBuilder() - .select('MIN(blockStartNumber) as blockStartNumber, walletId') + .select('MIN(localSavedBlockNumber) as localSavedBlockNumber, walletId') .where({ addressType: SyncAddressType.Default }) .groupBy('walletId') - .getRawMany<{ blockStartNumber: number; walletId: string }>() - return items.reduce>((pre, cur) => ({ ...pre, [cur.walletId]: cur.blockStartNumber }), {}) + .getRawMany<{ localSavedBlockNumber: number; walletId: string }>() + return items.reduce>( + (pre, cur) => ({ ...pre, [cur.walletId]: cur.localSavedBlockNumber }), + {} + ) } static async getOtherTypeSyncBlockNumber() { const items = await getConnection().getRepository(SyncProgress).find({ addressType: SyncAddressType.Multisig, }) - return items.reduce>((pre, cur) => ({ ...pre, [cur.hash]: cur.blockStartNumber }), {}) + return items.reduce>((pre, cur) => ({ ...pre, [cur.hash]: cur.localSavedBlockNumber }), {}) } static async getSyncProgressByHashes(hashes: string[]) { @@ -123,7 +126,7 @@ export default class SyncProgressService { await getConnection() .createQueryBuilder() .update(SyncProgress) - .set({ blockStartNumber: 0, blockEndNumber: 0 }) + .set({ localSavedBlockNumber: 0, syncedBlockNumber: 0 }) .execute() } } diff --git a/packages/neuron-wallet/src/utils/ckb-rpc.ts b/packages/neuron-wallet/src/utils/ckb-rpc.ts index 0d4c69b4d2..fc33fbefe7 100644 --- a/packages/neuron-wallet/src/utils/ckb-rpc.ts +++ b/packages/neuron-wallet/src/utils/ckb-rpc.ts @@ -144,7 +144,7 @@ export type FetchTransactionReturnType = { } export class LightRPC extends Base { - setScripts: (params: LightScriptFilter[]) => Promise + setScripts: (params: LightScriptFilter[], setScriptCommand: 'all' | 'partial' | 'delete') => Promise getScripts: () => Promise // TODO: the type is not the same as full node here // @ts-ignore diff --git a/packages/neuron-wallet/tests/block-sync-renderer/indexer-connector.test.ts b/packages/neuron-wallet/tests/block-sync-renderer/full-synchronizer.test.ts similarity index 96% rename from packages/neuron-wallet/tests/block-sync-renderer/indexer-connector.test.ts rename to packages/neuron-wallet/tests/block-sync-renderer/full-synchronizer.test.ts index b79147f525..19a6ef6f18 100644 --- a/packages/neuron-wallet/tests/block-sync-renderer/indexer-connector.test.ts +++ b/packages/neuron-wallet/tests/block-sync-renderer/full-synchronizer.test.ts @@ -3,7 +3,7 @@ import { when } from 'jest-when' import { AddressType } from '../../src/models/keys/address' import { Address, AddressVersion } from '../../src/models/address' import SystemScriptInfo from '../../src/models/system-script-info' -import IndexerConnector from '../../src/block-sync-renderer/sync/indexer-connector' +import FullSynchronizer from '../../src/block-sync-renderer/sync/full-synchronizer' import { flushPromises } from '../test-utils' const stubbedTipFn = jest.fn() @@ -15,8 +15,8 @@ const stubbedLoggerErrorFn = jest.fn() const stubbedNextUnprocessedBlock = jest.fn() const stubbedCellCellectFn = jest.fn() -const connectIndexer = async (indexerConnector: IndexerConnector) => { - const connectPromise = indexerConnector.connect() +const connectIndexer = async (synchronizer: FullSynchronizer) => { + const connectPromise = synchronizer.connect() const errSpy = jest.fn() connectPromise.catch(err => { errSpy(err) @@ -27,7 +27,7 @@ const connectIndexer = async (indexerConnector: IndexerConnector) => { describe('unit tests for IndexerConnector', () => { const nodeUrl = 'http://nodeurl:8114' - let stubbedIndexerConnector: any + let stubbedFullSynchronizer: any let stubbedIndexerConstructor: any let stubbedIndexerCacheService: any @@ -76,7 +76,7 @@ describe('unit tests for IndexerConnector', () => { upsertTxHashes: stubbedUpsertTxHashesFn, })) }) - stubbedIndexerConnector = require('../../src/block-sync-renderer/sync/indexer-connector').default + stubbedFullSynchronizer = require('../../src/block-sync-renderer/sync/full-synchronizer').default beforeEach(() => { resetMocks() @@ -91,7 +91,7 @@ describe('unit tests for IndexerConnector', () => { describe('when init with indexer folder path', () => { beforeEach(() => { - new stubbedIndexerConnector([], nodeUrl, STUB_URI) + new stubbedFullSynchronizer([], nodeUrl, STUB_URI) }) it('inits lumos indexer with a node url and indexer folder path', () => { expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl, STUB_URI) @@ -99,7 +99,7 @@ describe('unit tests for IndexerConnector', () => { }) describe('when init without indexer folder path', () => { beforeEach(() => { - new stubbedIndexerConnector([], nodeUrl) + new stubbedFullSynchronizer([], nodeUrl) }) it('inits mercury indexer with a node url and a default port', () => { expect(stubbedIndexerConstructor).toHaveBeenCalledWith(nodeUrl, STUB_URI) @@ -141,7 +141,7 @@ describe('unit tests for IndexerConnector', () => { blockTimestamp: fakeTx3.transaction.blockTimestamp, } - let indexerConnector: IndexerConnector + let indexerConnector: FullSynchronizer const shortAddressInfo = { lock: SystemScriptInfo.generateSecpScript('0x36c329ed630d6ce750712a477543672adab57f4c'), } @@ -179,7 +179,7 @@ describe('unit tests for IndexerConnector', () => { const addressesToWatch = [addressObj1, addressObj2] beforeEach(() => { - indexerConnector = new stubbedIndexerConnector(addressesToWatch, '', '') + indexerConnector = new stubbedFullSynchronizer(addressesToWatch, '', '') }) describe('polls for new data', () => { describe('#transactionsSubject', () => { @@ -187,7 +187,7 @@ describe('unit tests for IndexerConnector', () => { beforeEach(() => { stubbedTipFn.mockReturnValueOnce(fakeTip1) - indexerConnector = new stubbedIndexerConnector(addressesToWatch, '', '') + indexerConnector = new stubbedFullSynchronizer(addressesToWatch, '', '') transactionsSubject = indexerConnector.transactionsSubject }) diff --git a/packages/neuron-wallet/tests/block-sync-renderer/light-connector.test.ts b/packages/neuron-wallet/tests/block-sync-renderer/light-synchronizer.test.ts similarity index 66% rename from packages/neuron-wallet/tests/block-sync-renderer/light-connector.test.ts rename to packages/neuron-wallet/tests/block-sync-renderer/light-synchronizer.test.ts index e02ec508e5..4b23436501 100644 --- a/packages/neuron-wallet/tests/block-sync-renderer/light-connector.test.ts +++ b/packages/neuron-wallet/tests/block-sync-renderer/light-synchronizer.test.ts @@ -1,14 +1,14 @@ import type { Script } from '@ckb-lumos/base' -import LightConnector from '../../src/block-sync-renderer/sync/light-connector' +import LightSynchronizer from '../../src/block-sync-renderer/sync/light-synchronizer' import AddressMeta from '../../src/database/address/meta' const getSyncStatusMock = jest.fn() -const getCurrentWalletMinBlockNumberMock = jest.fn() +const getCurrentWalletMinSyncedBlockNumberMock = jest.fn() const getAllSyncStatusToMapMock = jest.fn() const resetSyncProgressMock = jest.fn() const updateSyncStatusMock = jest.fn() const updateSyncProgressFlagMock = jest.fn() -const getWalletMinBlockNumberMock = jest.fn() +const getWalletMinLocalSavedBlockNumberMock = jest.fn() const removeByHashesAndAddressType = jest.fn() const getOtherTypeSyncProgressMock = jest.fn() const getOtherTypeSyncBlockNumberMock = jest.fn() @@ -26,11 +26,11 @@ const walletGetAllMock = jest.fn() function mockReset() { getSyncStatusMock.mockReset() - getCurrentWalletMinBlockNumberMock.mockReset() + getCurrentWalletMinSyncedBlockNumberMock.mockReset() getAllSyncStatusToMapMock.mockReset() resetSyncProgressMock.mockReset() updateSyncStatusMock.mockReset() - getWalletMinBlockNumberMock.mockReset() + getWalletMinLocalSavedBlockNumberMock.mockReset() getOtherTypeSyncProgressMock.mockReset() getOtherTypeSyncBlockNumberMock.mockReset() @@ -50,12 +50,12 @@ function mockReset() { jest.mock('../../src/services/sync-progress', () => { return class { static getSyncStatus: any = () => getSyncStatusMock() - static getCurrentWalletMinBlockNumber: any = () => getCurrentWalletMinBlockNumberMock() + static getCurrentWalletMinSyncedBlockNumber: any = () => getCurrentWalletMinSyncedBlockNumberMock() static getAllSyncStatusToMap: any = () => getAllSyncStatusToMapMock() static resetSyncProgress: any = (arg: any) => resetSyncProgressMock(arg) static updateSyncStatus: any = (hash: string, update: any) => updateSyncStatusMock(hash, update) static updateSyncProgressFlag: any = (walletIds: string[]) => updateSyncProgressFlagMock(walletIds) - static getWalletMinBlockNumber: any = () => getWalletMinBlockNumberMock() + static getWalletMinLocalSavedBlockNumber: any = () => getWalletMinLocalSavedBlockNumberMock() static removeByHashesAndAddressType: any = (type: number, scripts: Script[]) => removeByHashesAndAddressType(type, scripts) @@ -103,7 +103,7 @@ const script: Script = { // const scriptHash = scriptToHash(script) const address = 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2q8ux5aqem92xnwfmj5cl6e233phlwlysqhjx5w' -describe('test light connector', () => { +describe('test light synchronizer', () => { beforeEach(() => { walletGetAllMock.mockReturnValue([]) createBatchRequestMock.mockResolvedValue([]) @@ -116,21 +116,23 @@ describe('test light connector', () => { describe('test initSyncProgress', () => { it('there is not exist addressmata', async () => { - const connect = new LightConnector([], '') + const connect = new LightSynchronizer([], '') //@ts-ignore await connect.initSyncProgress() expect(getScriptsMock).toBeCalledTimes(0) }) it('append multisig script', async () => { getScriptsMock.mockResolvedValue([]) - const connect = new LightConnector([], '') + const connect = new LightSynchronizer([], '') getOtherTypeSyncBlockNumberMock.mockResolvedValueOnce({}) //@ts-ignore await connect.initSyncProgress([{ walletId: 'walletId', script, addressType: 1, scriptType: 'lock' }]) expect(getScriptsMock).toBeCalledTimes(1) - expect(setScriptsMock).toBeCalledWith([ - { script, scriptType: 'lock', walletId: 'walletId', blockNumber: '0x0', addressType: 1 }, - ]) + expect(setScriptsMock).toHaveBeenNthCalledWith( + 1, + [{ script, scriptType: 'lock', walletId: 'walletId', blockNumber: '0x0', addressType: 1 }], + 'partial' + ) }) it('there is not exist sync scripts with light client', async () => { getScriptsMock.mockResolvedValue([{ script, blockNumber: '0xaa' }]) @@ -142,36 +144,29 @@ describe('test light connector', () => { addressType: 0, blake160: script.args, }) - const connect = new LightConnector([addressMeta], '') + const connect = new LightSynchronizer([addressMeta], '') //@ts-ignore await connect.initSyncProgress() - expect(setScriptsMock).toBeCalledWith([ - { - script: addressMeta.generateDefaultLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, - { - script: addressMeta.generateACPLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0x0', - }, - { - script: addressMeta.generateLegacyACPLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0x0', - }, - ]) + expect(setScriptsMock).toHaveBeenNthCalledWith( + 1, + [ + { + script: addressMeta.generateACPLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0x0', + }, + { + script: addressMeta.generateLegacyACPLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0x0', + }, + ], + 'partial' + ) + expect(setScriptsMock).toHaveBeenLastCalledWith([], 'delete') expect(resetSyncProgressMock).toBeCalledWith([ - { - script: addressMeta.generateDefaultLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, { script: addressMeta.generateACPLockScript().toSDK(), scriptType: 'lock', @@ -197,30 +192,34 @@ describe('test light connector', () => { addressType: 0, blake160: script.args, }) - getWalletMinBlockNumberMock.mockResolvedValue({ walletId: 170 }) - const connect = new LightConnector([addressMeta], '') + getWalletMinLocalSavedBlockNumberMock.mockResolvedValue({ walletId: 170 }) + const connect = new LightSynchronizer([addressMeta], '') //@ts-ignore await connect.initSyncProgress() - expect(setScriptsMock).toBeCalledWith([ - { - script: addressMeta.generateDefaultLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, - { - script: addressMeta.generateACPLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, - { - script: addressMeta.generateLegacyACPLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, - ]) + expect(setScriptsMock).toHaveBeenNthCalledWith( + 1, + [ + { + script: addressMeta.generateDefaultLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0xaa', + }, + { + script: addressMeta.generateACPLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0xaa', + }, + { + script: addressMeta.generateLegacyACPLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0xaa', + }, + ], + 'partial' + ) }) it('set new script with start block number in wallet', async () => { getScriptsMock.mockResolvedValue([]) @@ -232,37 +231,42 @@ describe('test light connector', () => { addressType: 0, blake160: script.args, }) - getWalletMinBlockNumberMock.mockResolvedValue({}) + getWalletMinLocalSavedBlockNumberMock.mockResolvedValue({}) walletGetAllMock.mockReturnValue([{ id: 'walletId', startBlockNumber: '0xaa' }]) - const connect = new LightConnector([addressMeta], '') + const connect = new LightSynchronizer([addressMeta], '') //@ts-ignore await connect.initSyncProgress() - expect(setScriptsMock).toBeCalledWith([ - { - script: addressMeta.generateDefaultLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, - { - script: addressMeta.generateACPLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, - { - script: addressMeta.generateLegacyACPLockScript().toSDK(), - scriptType: 'lock', - walletId: 'walletId', - blockNumber: '0xaa', - }, - ]) + expect(setScriptsMock).toHaveBeenNthCalledWith( + 1, + [ + { + script: addressMeta.generateDefaultLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0xaa', + }, + { + script: addressMeta.generateACPLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0xaa', + }, + { + script: addressMeta.generateLegacyACPLockScript().toSDK(), + scriptType: 'lock', + walletId: 'walletId', + blockNumber: '0xaa', + }, + ], + 'partial' + ) + expect(setScriptsMock).toHaveBeenLastCalledWith([], 'delete') }) }) describe('test initSync', () => { it('pollingIndexer is false', async () => { - const connect = new LightConnector([], '') + const connect = new LightSynchronizer([], '') //@ts-ignore connect.synchronize = jest.fn() //@ts-ignore @@ -270,7 +274,7 @@ describe('test light connector', () => { expect(schedulerWaitMock).toBeCalledTimes(0) }) it('pollingIndexer is true', async () => { - const connect = new LightConnector([], '') + const connect = new LightSynchronizer([], '') schedulerWaitMock.mockImplementation(() => { connect.stop() }) @@ -290,14 +294,14 @@ describe('test light connector', () => { mockFn.mockReset() }) it('connect success', async () => { - const connect = new LightConnector([], '') + const connect = new LightSynchronizer([], '') //@ts-ignore connect.initSync = mockFn await connect.connect() expect(mockFn).toBeCalledTimes(1) }) it('connect failed', async () => { - const connect = new LightConnector([], '') + const connect = new LightSynchronizer([], '') //@ts-ignore connect.initSync = mockFn mockFn.mockImplementation(() => { @@ -309,7 +313,7 @@ describe('test light connector', () => { describe('test stop', () => { it('test stop', () => { - const connect = new LightConnector([], '') + const connect = new LightSynchronizer([], '') //@ts-ignore connect.pollingIndexer = true connect.stop() @@ -319,28 +323,28 @@ describe('test light connector', () => { }) describe('#notifyCurrentBlockNumberProcessed', () => { - const connector = new LightConnector([], '') + const synchronizer = new LightSynchronizer([], '') const updateBlockStartNumberMock = jest.fn() beforeAll(() => { // @ts-ignore private property - connector.updateBlockStartNumber = updateBlockStartNumberMock + synchronizer.updateBlockStartNumber = updateBlockStartNumberMock }) beforeEach(() => { updateBlockStartNumberMock.mockReset() }) it('last process block number finish', async () => { // @ts-ignore private property - connector.processingBlockNumber = '0xaa' - getCurrentWalletMinBlockNumberMock.mockResolvedValueOnce(100) - await connector.notifyCurrentBlockNumberProcessed('0xaa') + synchronizer.processingBlockNumber = '0xaa' + getCurrentWalletMinSyncedBlockNumberMock.mockResolvedValueOnce(100) + await synchronizer.notifyCurrentBlockNumberProcessed('0xaa') // @ts-ignore private property - expect(connector.processingBlockNumber).toBeUndefined() + expect(synchronizer.processingBlockNumber).toBeUndefined() expect(updateBlockStartNumberMock).toBeCalledWith(100) }) it('not last process block number finish', async () => { // @ts-ignore private property - connector.processingBlockNumber = undefined - await connector.notifyCurrentBlockNumberProcessed('0xaa') + synchronizer.processingBlockNumber = undefined + await synchronizer.notifyCurrentBlockNumberProcessed('0xaa') expect(updateBlockStartNumberMock).toBeCalledTimes(0) }) }) diff --git a/packages/neuron-wallet/tests/block-sync-renderer/queue.test.ts b/packages/neuron-wallet/tests/block-sync-renderer/queue.test.ts index 9886c3e881..d181a4ae5c 100644 --- a/packages/neuron-wallet/tests/block-sync-renderer/queue.test.ts +++ b/packages/neuron-wallet/tests/block-sync-renderer/queue.test.ts @@ -161,7 +161,7 @@ describe('queue', () => { jest.doMock('utils/logger', () => { return { error: stubbedLoggerErrorFn, info: jest.fn() } }) - jest.doMock('../../src/block-sync-renderer/sync/indexer-connector', () => { + jest.doMock('../../src/block-sync-renderer/sync/full-synchronizer', () => { return stubbedIndexerConnector }) jest.doMock('../../src/block-sync-renderer/sync/tx-address-finder', () => { @@ -274,7 +274,7 @@ describe('queue', () => { message: [fakeWalletId], }) }) - it('notify indexer connector of processed block number', () => { + it('notify full synchronizer of processed block number', () => { expect(stubbedNotifyCurrentBlockNumberProcessedFn).toHaveBeenCalledWith( fakeTxs[0].transaction.blockNumber ) diff --git a/packages/neuron-wallet/tests/block-sync-renderer/connector.test.ts b/packages/neuron-wallet/tests/block-sync-renderer/synchronizer.test.ts similarity index 88% rename from packages/neuron-wallet/tests/block-sync-renderer/connector.test.ts rename to packages/neuron-wallet/tests/block-sync-renderer/synchronizer.test.ts index acc7b37354..e3b610763c 100644 --- a/packages/neuron-wallet/tests/block-sync-renderer/connector.test.ts +++ b/packages/neuron-wallet/tests/block-sync-renderer/synchronizer.test.ts @@ -2,7 +2,7 @@ import { scriptToAddress } from '../../src/utils/scriptAndAddress' import { AddressType } from '../../src/models/keys/address' import { Address, AddressVersion } from '../../src/models/address' import SystemScriptInfo from '../../src/models/system-script-info' -import { Connector, type LumosCell, type LumosCellQuery } from '../../src/block-sync-renderer/sync/connector' +import { Synchronizer, type LumosCell, type LumosCellQuery } from '../../src/block-sync-renderer/sync/synchronizer' import AddressMeta from '../../src/database/address/meta' import IndexerTxHashCache from '../../src/database/chain/entities/indexer-tx-hash-cache' import { ScriptHashType } from '../../src/models/chain/script' @@ -15,7 +15,7 @@ const stubbedCellCollectorConstructor = jest.fn() const stubbedBlockTipsSubscribe = jest.fn() const stubbedCellCellectFn = jest.fn() -class TestConnector extends Connector { +class TestSynchronizer extends Synchronizer { async connect() {} async processTxsInNextBlockNumber(): Promise { return stubbedProcessTxsInNextBlockNumberFn() @@ -113,7 +113,7 @@ describe('unit tests for IndexerConnector', () => { const STUB_URI = 'stub_uri' it('inits lumos indexer with a node url and indexer folder path', () => { - new TestConnector({ + new TestSynchronizer({ addresses: [], nodeUrl, indexerUrl: STUB_URI, @@ -122,18 +122,22 @@ describe('unit tests for IndexerConnector', () => { }) it('init with addresses', () => { - const connector = new TestConnector({ + const synchronizer = new TestSynchronizer({ addresses: [addressObj1, addressObj2], nodeUrl, indexerUrl: STUB_URI, }) - expect(connector.getAddressesByWalletId().get(walletId1)?.[0]).toStrictEqual(AddressMeta.fromObject(addressObj1)) - expect(connector.getAddressesByWalletId().get(walletId2)?.[0]).toStrictEqual(AddressMeta.fromObject(addressObj2)) + expect(synchronizer.getAddressesByWalletId().get(walletId1)?.[0]).toStrictEqual( + AddressMeta.fromObject(addressObj1) + ) + expect(synchronizer.getAddressesByWalletId().get(walletId2)?.[0]).toStrictEqual( + AddressMeta.fromObject(addressObj2) + ) }) }) describe('#getTxHashesWithNextUnprocessedBlockNumber', () => { - const connector = new TestConnector({ + const synchronizer = new TestSynchronizer({ addresses: [addressObj1, addressObj2], nodeUrl, indexerUrl: '', @@ -141,7 +145,7 @@ describe('unit tests for IndexerConnector', () => { it('no cached tx', async () => { stubbedNextUnprocessedTxsGroupedByBlockNumberFn.mockResolvedValue([]) // @ts-ignore private method - const result = await connector.getTxHashesWithNextUnprocessedBlockNumber() + const result = await synchronizer.getTxHashesWithNextUnprocessedBlockNumber() expect(result).toStrictEqual([undefined, []]) }) it('get cached tx and sort by block number', async () => { @@ -167,25 +171,25 @@ describe('unit tests for IndexerConnector', () => { ] ) // @ts-ignore private method - const result = await connector.getTxHashesWithNextUnprocessedBlockNumber() + const result = await synchronizer.getTxHashesWithNextUnprocessedBlockNumber() expect(result).toStrictEqual(['2', ['hash2']]) }) }) describe('#notifyAndSyncNext', () => { - const connector = new TestConnector({ + const synchronizer = new TestSynchronizer({ addresses: [addressObj1, addressObj2], nodeUrl, indexerUrl: '', }) - connector.blockTipsSubject.subscribe(stubbedBlockTipsSubscribe) + synchronizer.blockTipsSubject.subscribe(stubbedBlockTipsSubscribe) it('exist unprocessed block and no current process block', async () => { //@ts-ignore private property - connector.processingBlockNumber = undefined + synchronizer.processingBlockNumber = undefined stubbedNextUnprocessedBlockFn.mockResolvedValue('10') //@ts-ignore private method - await connector.notifyAndSyncNext(100) + await synchronizer.notifyAndSyncNext(100) expect(stubbedBlockTipsSubscribe).toHaveBeenCalledWith({ cacheTipNumber: 10, indexerTipNumber: 100, @@ -194,10 +198,10 @@ describe('unit tests for IndexerConnector', () => { }) it('exist unprocessed block and has current process block', async () => { //@ts-ignore private property - connector.processingBlockNumber = '5' + synchronizer.processingBlockNumber = '5' stubbedNextUnprocessedBlockFn.mockResolvedValue('10') //@ts-ignore private method - await connector.notifyAndSyncNext(100) + await synchronizer.notifyAndSyncNext(100) expect(stubbedBlockTipsSubscribe).toHaveBeenCalledWith({ cacheTipNumber: 10, indexerTipNumber: 100, @@ -206,10 +210,10 @@ describe('unit tests for IndexerConnector', () => { }) it('no unprocessed block', async () => { //@ts-ignore private property - connector.processingBlockNumber = '5' + synchronizer.processingBlockNumber = '5' stubbedNextUnprocessedBlockFn.mockResolvedValue(undefined) //@ts-ignore private method - await connector.notifyAndSyncNext(100) + await synchronizer.notifyAndSyncNext(100) expect(stubbedBlockTipsSubscribe).toHaveBeenCalledWith({ cacheTipNumber: 100, indexerTipNumber: 100, @@ -263,7 +267,7 @@ describe('unit tests for IndexerConnector', () => { } const fakeCells = [fakeCell1, fakeCell2] - const connector = new TestConnector({ + const synchronizer = new TestSynchronizer({ addresses: [addressObj1, addressObj2], nodeUrl, indexerUrl: '', @@ -291,7 +295,7 @@ describe('unit tests for IndexerConnector', () => { ]) //@ts-ignore - cells = await connector.getLiveCellsByScript(query) + cells = await synchronizer.getLiveCellsByScript(query) }) it('transform the query parameter', () => { expect(stubbedCellCollectorConstructor.mock.calls[0][1]).toEqual({ @@ -373,13 +377,13 @@ describe('unit tests for IndexerConnector', () => { const promises = Promise.all([ new Promise(resolve => { - connector.getLiveCellsByScript(query1).then(cells => { + synchronizer.getLiveCellsByScript(query1).then(cells => { results.push(cells) resolve() }) }), new Promise(resolve => { - connector.getLiveCellsByScript(query2).then(cells => { + synchronizer.getLiveCellsByScript(query2).then(cells => { results.push(cells) resolve() }) @@ -399,7 +403,7 @@ describe('unit tests for IndexerConnector', () => { it('throws error', async () => { let err try { - await connector.getLiveCellsByScript({ lock: null, type: null, data: null }) + await synchronizer.getLiveCellsByScript({ lock: null, type: null, data: null }) } catch (error) { err = error } diff --git a/packages/neuron-wallet/tests/models/chain/live-cell.test.ts b/packages/neuron-wallet/tests/models/chain/live-cell.test.ts index 9385e21de1..84a9b97830 100644 --- a/packages/neuron-wallet/tests/models/chain/live-cell.test.ts +++ b/packages/neuron-wallet/tests/models/chain/live-cell.test.ts @@ -1,5 +1,5 @@ import Script, { ScriptHashType } from '../../../src/models/chain/script' -import { LumosCell } from '../../../src/block-sync-renderer/sync/connector' +import { LumosCell } from '../../../src/block-sync-renderer/sync/synchronizer' import LiveCell from '../../../src/models/chain/live-cell' describe('LiveCell Test', () => { diff --git a/packages/neuron-wallet/tests/services/tx/transaction-generator.test.ts b/packages/neuron-wallet/tests/services/tx/transaction-generator.test.ts index 46551c7a02..8a87127ffa 100644 --- a/packages/neuron-wallet/tests/services/tx/transaction-generator.test.ts +++ b/packages/neuron-wallet/tests/services/tx/transaction-generator.test.ts @@ -87,7 +87,7 @@ import HdPublicKeyInfo from '../../../src/database/chain/entities/hd-public-key- import AssetAccount from '../../../src/models/asset-account' import MultisigConfigModel from '../../../src/models/multisig-config' import MultisigOutput from '../../../src/database/chain/entities/multisig-output' -import { LumosCell } from '../../../src/block-sync-renderer/sync/connector' +import { LumosCell } from '../../../src/block-sync-renderer/sync/synchronizer' describe('TransactionGenerator', () => { beforeAll(async () => {