Skip to content

Commit

Permalink
chore: Remove unused boolean return values from stores
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spalladino committed Mar 26, 2024
1 parent ef44674 commit b4f39ab
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ContractClassStore {
this.#contractClasses = db.openMap('archiver_contract_classes');
}

addContractClass(contractClass: ContractClassPublic): Promise<boolean> {
addContractClass(contractClass: ContractClassPublic): Promise<void> {
return this.#contractClasses.set(contractClass.id.toString(), serializeContractClassPublic(contractClass));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ContractInstanceStore {
this.#contractInstances = db.openMap('archiver_contract_instances');
}

addContractInstance(contractInstance: ContractInstanceWithAddress): Promise<boolean> {
addContractInstance(contractInstance: ContractInstanceWithAddress): Promise<void> {
return this.#contractInstances.set(
contractInstance.address.toString(),
new SerializableContractInstance(contractInstance).toBuffer(),
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/kv-store/src/interfaces/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface AztecCounter<K extends Key = Key> {
* @param key - The key to reset
* @param value - The value to reset the key to
*/
set(key: K, value: number): Promise<boolean>;
set(key: K, value: number): Promise<void>;

/**
* Updates the count of the given key by the given delta. This can be used to increment or decrement the count.
Expand All @@ -21,7 +21,7 @@ export interface AztecCounter<K extends Key = Key> {
* @param key - The key to update
* @param delta - The amount to modify the key by
*/
update(key: K, delta: number): Promise<boolean>;
update(key: K, delta: number): Promise<void>;

/**
* Gets the current count.
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/kv-store/src/interfaces/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export interface AztecMap<K extends Key, V> {
* @param key - The key to set the value at
* @param val - The value to set
*/
set(key: K, val: V): Promise<boolean>;
set(key: K, val: V): Promise<void>;

/**
* 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<boolean>;
swap(key: K, fn: (val: V | undefined) => V): Promise<void>;

/**
* Sets the value at the given key if it does not already exist.
Expand All @@ -42,7 +42,7 @@ export interface AztecMap<K extends Key, V> {
* Deletes the value at the given key.
* @param key - The key to delete the value at
*/
delete(key: K): Promise<boolean>;
delete(key: K): Promise<void>;

/**
* Iterates over the map's key-value entries in the key's natural order
Expand Down
8 changes: 3 additions & 5 deletions yarn-project/kv-store/src/lmdb/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export class LmdbAztecCounter<K extends Key> implements AztecCounter<K> {
this.#map = new LmdbAztecMap(db, name);
}

set(key: K, value: number): Promise<boolean> {
return this.#map.set(key, value);
async set(key: K, value: number): Promise<void> {
await this.#map.set(key, value);
}

update(key: K, delta = 1): Promise<boolean> {
update(key: K, delta = 1): Promise<void> {
return this.#db.childTransaction(() => {
const current = this.#map.get(key) ?? 0;
const next = current + delta;
Expand All @@ -38,8 +38,6 @@ export class LmdbAztecCounter<K extends Key> implements AztecCounter<K> {
// of the key when iterating over the database
void this.#map.set(key, next);
}

return true;
});
}

Expand Down
12 changes: 5 additions & 7 deletions yarn-project/kv-store/src/lmdb/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ export class LmdbAztecMap<K extends Key, V> implements AztecMultiMap<K, V> {
return this.db.doesExist(this.#slot(key));
}

set(key: K, val: V): Promise<boolean> {
return this.db.put(this.#slot(key), [key, val]);
async set(key: K, val: V): Promise<void> {
await this.db.put(this.#slot(key), [key, val]);
}

swap(key: K, fn: (val: V | undefined) => V): Promise<boolean> {
swap(key: K, fn: (val: V | undefined) => V): Promise<void> {
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;
});
}

Expand All @@ -67,8 +65,8 @@ export class LmdbAztecMap<K extends Key, V> implements AztecMultiMap<K, V> {
});
}

delete(key: K): Promise<boolean> {
return this.db.remove(this.#slot(key));
async delete(key: K): Promise<void> {
await this.db.remove(this.#slot(key));
}

async deleteValue(key: K, val: V): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/kv_pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class KVPxeDatabase implements PxeDatabase {
return this.#syncedBlockPerPublicKey.get(publicKey.toString());
}

setSynchedBlockNumberForPublicKey(publicKey: Point, blockNumber: number): Promise<boolean> {
setSynchedBlockNumberForPublicKey(publicKey: Point, blockNumber: number): Promise<void> {
return this.#syncedBlockPerPublicKey.set(publicKey.toString(), blockNumber);
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>;
setSynchedBlockNumberForPublicKey(publicKey: PublicKey, blockNumber: number): Promise<void>;

/**
* Get the synched block number for a given public key.
Expand Down
1 change: 1 addition & 0 deletions yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class NoteProcessor {
for (const functionLogs of txFunctionLogs) {
for (const log of functionLogs.logs) {
this.stats.seen++;
console.log('log.data', log.toString('hex'));
const taggedNote = TaggedNote.fromEncryptedBuffer(log, privateKey, curve);
if (taggedNote?.notePayload) {
const { notePayload: payload } = taggedNote;
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/pxe/src/synchronizer/synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export class Synchronizer {
}

const encryptedLogs = blocks.flatMap(block => block.body.encryptedLogs);
console.log(
`GOT ENCRYPTED LOGS FROM BLOCKS:\n${encryptedLogs.flatMap(log =>
log.txLogs.flatMap(log =>
log
.unrollLogs()
.map(log => log.toString('hex'))
.join('\n'),
),
)}`,
);

// Wrap blocks in block contexts & only keep those that match our query
const blockContexts = blocks.filter(block => block.number >= from).map(block => new L2BlockContext(block));
Expand Down

0 comments on commit b4f39ab

Please sign in to comment.