Skip to content

Commit

Permalink
removes 'clear*' methods from the walletDb (#5639)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hughy authored Nov 12, 2024
1 parent 76865c5 commit ab377a4
Showing 1 changed file with 1 addition and 43 deletions.
44 changes: 1 addition & 43 deletions ironfish/src/wallet/walletdb/walletdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export class WalletDB {
async removeAccount(account: Account, tx?: IDatabaseTransaction): Promise<void> {
await this.db.withTransaction(tx, async (tx) => {
await this.accounts.del(account.id, tx)
await this.clearBalance(account, tx)
await this.balances.clear(tx, account.prefixRange)
await this.accountIdsToCleanup.put(account.id, null, tx)
})
}
Expand Down Expand Up @@ -542,19 +542,6 @@ export class WalletDB {
await this.transactions.del([account.prefix, transactionHash], tx)
}

async clearTransactions(account: Account, tx?: IDatabaseTransaction): Promise<void> {
await this.transactions.clear(tx, account.prefixRange)
await this.timestampToTransactionHash.clear(tx, account.prefixRange)
}

async clearSequenceToNoteHash(account: Account, tx?: IDatabaseTransaction): Promise<void> {
await this.sequenceToNoteHash.clear(tx, account.prefixRange)
}

async clearNonChainNoteHashes(account: Account, tx?: IDatabaseTransaction): Promise<void> {
await this.nonChainNoteHashes.clear(tx, account.prefixRange)
}

async *getTransactionHashesBySequence(
account: Account,
tx?: IDatabaseTransaction,
Expand Down Expand Up @@ -658,20 +645,6 @@ export class WalletDB {
})
}

/*
* clears sequenceToNoteHash entries for all accounts for a given sequence
*/
async clearSequenceNoteHashes(sequence: number, tx?: IDatabaseTransaction): Promise<void> {
const encoding = this.sequenceToNoteHash.keyEncoding

const keyRange = StorageUtils.getPrefixesKeyRange(
encoding.serialize([Buffer.alloc(4, 0), [sequence, Buffer.alloc(0)]]),
encoding.serialize([Buffer.alloc(4, 255), [sequence, Buffer.alloc(0)]]),
)

await this.sequenceToNoteHash.clear(tx, keyRange)
}

async addUnspentNoteHash(
account: Account,
noteHash: Buffer,
Expand Down Expand Up @@ -1027,10 +1000,6 @@ export class WalletDB {
await this.decryptedNotes.del([account.prefix, noteHash], tx)
}

async clearDecryptedNotes(account: Account, tx?: IDatabaseTransaction): Promise<void> {
await this.decryptedNotes.clear(tx, account.prefixRange)
}

async *loadDecryptedNotes(
account: Account,
range?: DatabaseKeyRange,
Expand Down Expand Up @@ -1088,10 +1057,6 @@ export class WalletDB {
await this.balances.put([account.prefix, assetId], balance, tx)
}

async clearBalance(account: Account, tx?: IDatabaseTransaction): Promise<void> {
await this.balances.clear(tx, account.prefixRange)
}

async *loadExpiredTransactionHashes(
account: Account,
headSequence: number,
Expand Down Expand Up @@ -1221,13 +1186,6 @@ export class WalletDB {
await this.pendingTransactionHashes.del([account.prefix, [expiration, transactionHash]], tx)
}

async clearPendingTransactionHashes(
account: Account,
tx?: IDatabaseTransaction,
): Promise<void> {
await this.pendingTransactionHashes.clear(tx, account.prefixRange)
}

async forceCleanupDeletedAccounts(signal?: AbortSignal): Promise<void> {
return this.cleanupDeletedAccounts(Number.POSITIVE_INFINITY, signal)
}
Expand Down

0 comments on commit ab377a4

Please sign in to comment.