Skip to content

Commit ab377a4

Browse files
authored
removes 'clear*' methods from the walletDb (#5639)
the walletDb has serveral leftover implementations of methods that clear datastores these methods are unused not only are these methods unused, but they _should not_ be used: calling 'clear' on a datastore has the potential to block the wallet and node process while deleting from the database. data are deleted from these stores incrementally in the background using 'cleanUpDeletedAccounts' for this reason
1 parent 76865c5 commit ab377a4

File tree

1 file changed

+1
-43
lines changed

1 file changed

+1
-43
lines changed

ironfish/src/wallet/walletdb/walletdb.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ export class WalletDB {
418418
async removeAccount(account: Account, tx?: IDatabaseTransaction): Promise<void> {
419419
await this.db.withTransaction(tx, async (tx) => {
420420
await this.accounts.del(account.id, tx)
421-
await this.clearBalance(account, tx)
421+
await this.balances.clear(tx, account.prefixRange)
422422
await this.accountIdsToCleanup.put(account.id, null, tx)
423423
})
424424
}
@@ -542,19 +542,6 @@ export class WalletDB {
542542
await this.transactions.del([account.prefix, transactionHash], tx)
543543
}
544544

545-
async clearTransactions(account: Account, tx?: IDatabaseTransaction): Promise<void> {
546-
await this.transactions.clear(tx, account.prefixRange)
547-
await this.timestampToTransactionHash.clear(tx, account.prefixRange)
548-
}
549-
550-
async clearSequenceToNoteHash(account: Account, tx?: IDatabaseTransaction): Promise<void> {
551-
await this.sequenceToNoteHash.clear(tx, account.prefixRange)
552-
}
553-
554-
async clearNonChainNoteHashes(account: Account, tx?: IDatabaseTransaction): Promise<void> {
555-
await this.nonChainNoteHashes.clear(tx, account.prefixRange)
556-
}
557-
558545
async *getTransactionHashesBySequence(
559546
account: Account,
560547
tx?: IDatabaseTransaction,
@@ -658,20 +645,6 @@ export class WalletDB {
658645
})
659646
}
660647

661-
/*
662-
* clears sequenceToNoteHash entries for all accounts for a given sequence
663-
*/
664-
async clearSequenceNoteHashes(sequence: number, tx?: IDatabaseTransaction): Promise<void> {
665-
const encoding = this.sequenceToNoteHash.keyEncoding
666-
667-
const keyRange = StorageUtils.getPrefixesKeyRange(
668-
encoding.serialize([Buffer.alloc(4, 0), [sequence, Buffer.alloc(0)]]),
669-
encoding.serialize([Buffer.alloc(4, 255), [sequence, Buffer.alloc(0)]]),
670-
)
671-
672-
await this.sequenceToNoteHash.clear(tx, keyRange)
673-
}
674-
675648
async addUnspentNoteHash(
676649
account: Account,
677650
noteHash: Buffer,
@@ -1027,10 +1000,6 @@ export class WalletDB {
10271000
await this.decryptedNotes.del([account.prefix, noteHash], tx)
10281001
}
10291002

1030-
async clearDecryptedNotes(account: Account, tx?: IDatabaseTransaction): Promise<void> {
1031-
await this.decryptedNotes.clear(tx, account.prefixRange)
1032-
}
1033-
10341003
async *loadDecryptedNotes(
10351004
account: Account,
10361005
range?: DatabaseKeyRange,
@@ -1088,10 +1057,6 @@ export class WalletDB {
10881057
await this.balances.put([account.prefix, assetId], balance, tx)
10891058
}
10901059

1091-
async clearBalance(account: Account, tx?: IDatabaseTransaction): Promise<void> {
1092-
await this.balances.clear(tx, account.prefixRange)
1093-
}
1094-
10951060
async *loadExpiredTransactionHashes(
10961061
account: Account,
10971062
headSequence: number,
@@ -1221,13 +1186,6 @@ export class WalletDB {
12211186
await this.pendingTransactionHashes.del([account.prefix, [expiration, transactionHash]], tx)
12221187
}
12231188

1224-
async clearPendingTransactionHashes(
1225-
account: Account,
1226-
tx?: IDatabaseTransaction,
1227-
): Promise<void> {
1228-
await this.pendingTransactionHashes.clear(tx, account.prefixRange)
1229-
}
1230-
12311189
async forceCleanupDeletedAccounts(signal?: AbortSignal): Promise<void> {
12321190
return this.cleanupDeletedAccounts(Number.POSITIVE_INFINITY, signal)
12331191
}

0 commit comments

Comments
 (0)