From 07794ee11ddd98dd824fba9c858267a502f4671e Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Wed, 3 Apr 2024 14:39:42 -0300 Subject: [PATCH] chore: Remove unused boolean return values from stores (#5470) LMDB operations return a false boolean if an insert or delete operation fails due to a failed version check, which we are not using. So we just turn every return value to void. Context [here](https://github.com/AztecProtocol/aztec-packages/pull/5318#discussion_r1535471877). --- .../kv_archiver_store/contract_class_store.ts | 2 +- .../kv_archiver_store/contract_instance_store.ts | 2 +- yarn-project/kv-store/src/interfaces/counter.ts | 4 ++-- yarn-project/kv-store/src/interfaces/map.ts | 6 +++--- yarn-project/kv-store/src/lmdb/counter.ts | 8 +++----- yarn-project/kv-store/src/lmdb/map.test.ts | 2 +- yarn-project/kv-store/src/lmdb/map.ts | 12 +++++------- yarn-project/pxe/src/database/kv_pxe_database.ts | 2 +- yarn-project/pxe/src/database/pxe_database.ts | 2 +- 9 files changed, 18 insertions(+), 22 deletions(-) diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts index 8a4525a1228..8c14213d37e 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts @@ -17,7 +17,7 @@ export class ContractClassStore { this.#contractClasses = db.openMap('archiver_contract_classes'); } - addContractClass(contractClass: ContractClassPublic): Promise { + addContractClass(contractClass: ContractClassPublic): Promise { return this.#contractClasses.set(contractClass.id.toString(), serializeContractClassPublic(contractClass)); } diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_instance_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_instance_store.ts index 915363d0ae1..0c8b8597b65 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_instance_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_instance_store.ts @@ -12,7 +12,7 @@ export class ContractInstanceStore { this.#contractInstances = db.openMap('archiver_contract_instances'); } - addContractInstance(contractInstance: ContractInstanceWithAddress): Promise { + addContractInstance(contractInstance: ContractInstanceWithAddress): Promise { return this.#contractInstances.set( contractInstance.address.toString(), new SerializableContractInstance(contractInstance).toBuffer(), diff --git a/yarn-project/kv-store/src/interfaces/counter.ts b/yarn-project/kv-store/src/interfaces/counter.ts index 67c8151ffbc..0fa636c58dd 100644 --- a/yarn-project/kv-store/src/interfaces/counter.ts +++ b/yarn-project/kv-store/src/interfaces/counter.ts @@ -12,7 +12,7 @@ export interface AztecCounter { * @param key - The key to reset * @param value - The value to reset the key to */ - set(key: K, value: number): Promise; + set(key: K, value: number): Promise; /** * Updates the count of the given key by the given delta. This can be used to increment or decrement the count. @@ -21,7 +21,7 @@ export interface AztecCounter { * @param key - The key to update * @param delta - The amount to modify the key by */ - update(key: K, delta: number): Promise; + update(key: K, delta: number): Promise; /** * Gets the current count. diff --git a/yarn-project/kv-store/src/interfaces/map.ts b/yarn-project/kv-store/src/interfaces/map.ts index d763254d31a..9b0d0ca4d17 100644 --- a/yarn-project/kv-store/src/interfaces/map.ts +++ b/yarn-project/kv-store/src/interfaces/map.ts @@ -22,14 +22,14 @@ export interface AztecMap { * @param key - The key to set the value at * @param val - The value to set */ - set(key: K, val: V): Promise; + set(key: K, val: V): Promise; /** * Atomically swap the value at the given key * @param key - The key to swap the value at * @param fn - The function to swap the value with */ - swap(key: K, fn: (val: V | undefined) => V): Promise; + swap(key: K, fn: (val: V | undefined) => V): Promise; /** * Sets the value at the given key if it does not already exist. @@ -42,7 +42,7 @@ export interface AztecMap { * Deletes the value at the given key. * @param key - The key to delete the value at */ - delete(key: K): Promise; + delete(key: K): Promise; /** * Iterates over the map's key-value entries in the key's natural order diff --git a/yarn-project/kv-store/src/lmdb/counter.ts b/yarn-project/kv-store/src/lmdb/counter.ts index 26b60b624f0..78e70f5d3ff 100644 --- a/yarn-project/kv-store/src/lmdb/counter.ts +++ b/yarn-project/kv-store/src/lmdb/counter.ts @@ -18,11 +18,11 @@ export class LmdbAztecCounter implements AztecCounter { this.#map = new LmdbAztecMap(db, name); } - set(key: K, value: number): Promise { - return this.#map.set(key, value); + async set(key: K, value: number): Promise { + await this.#map.set(key, value); } - update(key: K, delta = 1): Promise { + update(key: K, delta = 1): Promise { return this.#db.childTransaction(() => { const current = this.#map.get(key) ?? 0; const next = current + delta; @@ -38,8 +38,6 @@ export class LmdbAztecCounter implements AztecCounter { // of the key when iterating over the database void this.#map.set(key, next); } - - return true; }); } diff --git a/yarn-project/kv-store/src/lmdb/map.test.ts b/yarn-project/kv-store/src/lmdb/map.test.ts index 9195dbcfd39..a13aa16e126 100644 --- a/yarn-project/kv-store/src/lmdb/map.test.ts +++ b/yarn-project/kv-store/src/lmdb/map.test.ts @@ -31,7 +31,7 @@ describe('LmdbAztecMap', () => { await map.set('foo', 'bar'); await map.set('baz', 'qux'); - expect(await map.delete('foo')).toEqual(true); + await map.delete('foo'); expect(map.get('foo')).toEqual(undefined); expect(map.get('baz')).toEqual('qux'); diff --git a/yarn-project/kv-store/src/lmdb/map.ts b/yarn-project/kv-store/src/lmdb/map.ts index be303a7ffab..3711fa36f55 100644 --- a/yarn-project/kv-store/src/lmdb/map.ts +++ b/yarn-project/kv-store/src/lmdb/map.ts @@ -46,17 +46,15 @@ export class LmdbAztecMap implements AztecMultiMap { return this.db.doesExist(this.#slot(key)); } - set(key: K, val: V): Promise { - return this.db.put(this.#slot(key), [key, val]); + async set(key: K, val: V): Promise { + await this.db.put(this.#slot(key), [key, val]); } - swap(key: K, fn: (val: V | undefined) => V): Promise { + swap(key: K, fn: (val: V | undefined) => V): Promise { return this.db.childTransaction(() => { const slot = this.#slot(key); const entry = this.db.get(slot); void this.db.put(slot, [key, fn(entry?.[1])]); - - return true; }); } @@ -67,8 +65,8 @@ export class LmdbAztecMap implements AztecMultiMap { }); } - delete(key: K): Promise { - return this.db.remove(this.#slot(key)); + async delete(key: K): Promise { + await this.db.remove(this.#slot(key)); } async deleteValue(key: K, val: V): Promise { diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index aae846bde60..aadab576f8d 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -397,7 +397,7 @@ export class KVPxeDatabase implements PxeDatabase { return this.#syncedBlockPerPublicKey.get(publicKey.toString()); } - setSynchedBlockNumberForPublicKey(publicKey: Point, blockNumber: number): Promise { + setSynchedBlockNumberForPublicKey(publicKey: Point, blockNumber: number): Promise { return this.#syncedBlockPerPublicKey.set(publicKey.toString(), blockNumber); } diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index 13aeccf6158..b95d5e01d8c 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -150,7 +150,7 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD * @param publicKey - The public key to set the synched block number for. * @param blockNumber - The block number to set. */ - setSynchedBlockNumberForPublicKey(publicKey: PublicKey, blockNumber: number): Promise; + setSynchedBlockNumberForPublicKey(publicKey: PublicKey, blockNumber: number): Promise; /** * Get the synched block number for a given public key.