Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Delete forks after proving job has finished #7972

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export interface MerkleTreeOperations {
* Rolls back pending changes.
*/
rollback(): Promise<void>;

/** Deletes this database. Useful for cleaning up forks. */
delete(): Promise<void>;
}

/** Return type for handleL2BlockAndMessages */
Expand Down
7 changes: 6 additions & 1 deletion yarn-project/kv-store/src/interfaces/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ export interface AztecKVStore {
transaction<T extends Exclude<any, Promise<any>>>(callback: () => T): Promise<T>;

/**
* Clears the store
* Clears all entries in the store
*/
clear(): Promise<void>;

/**
* Forks the store.
*/
fork(): Promise<AztecKVStore>;

/**
* Deletes the store
*/
delete(): Promise<void>;
}
3 changes: 3 additions & 0 deletions yarn-project/kv-store/src/lmdb/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('AztecLmdbStore', () => {
expect(forkedSingleton.get()).toEqual('foo');
await forkedSingleton.set('bar');
expect(singleton.get()).toEqual('foo');
expect(forkedSingleton.get()).toEqual('bar');
await forkedSingleton.delete();
expect(singleton.get()).toEqual('foo');
};

it('forks a persistent store', async () => {
Expand Down
7 changes: 6 additions & 1 deletion yarn-project/kv-store/src/lmdb/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ export class AztecLmdbStore implements AztecKVStore {
}

/**
* Clears the store
* Clears all entries in the store
*/
async clear() {
await this.#rootDb.clearAsync();
}

/** Deletes this store */
async delete() {
await this.#rootDb.drop();
}
}
3 changes: 3 additions & 0 deletions yarn-project/prover-node/src/job/block-proving-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class BlockProvingJob {
private l2BlockSource: L2BlockSource,
private l1ToL2MessageSource: L1ToL2MessageSource,
private txProvider: TxProvider,
private cleanUp: () => Promise<void> = () => Promise.resolve(),
) {}

public getState(): BlockProvingJobState {
Expand Down Expand Up @@ -105,6 +106,8 @@ export class BlockProvingJob {
} catch (err) {
this.log.error(`Error running block prover job: ${err}`);
this.state = 'failed';
} finally {
await this.cleanUp();
}
}

Expand Down
1 change: 1 addition & 0 deletions yarn-project/prover-node/src/prover-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class ProverNode {
this.l2BlockSource,
this.l1ToL2MessageSource,
this.txProvider,
() => db.delete(),
);
}
}
3 changes: 3 additions & 0 deletions yarn-project/world-state/src/world-state-db/merkle_tree_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ export type MerkleTreeDb = {
* Forks the database at its current state.
*/
fork(): Promise<MerkleTreeDb>;

/** Deletes this database. */
delete(): Promise<void>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,8 @@ export class MerkleTreeOperationsFacade implements MerkleTreeOperations {
): Promise<BatchInsertionResult<TreeHeight, SubtreeSiblingPathHeight>> {
return this.trees.batchInsert(treeId, leaves, subtreeHeight);
}

public delete(): Promise<void> {
return this.trees.delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export class MerkleTreeSnapshotOperationsFacade implements MerkleTreeOperations
return Promise.reject(new Error('Tree snapshot operations are read-only'));
}

delete(): Promise<void> {
return Promise.reject(new Error('Tree snapshot operations are read-only'));
}

updateHistoricArchive(): Promise<void> {
return Promise.reject(new Error('Tree snapshot operations are read-only'));
}
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/world-state/src/world-state-db/merkle_trees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ export class MerkleTrees implements MerkleTreeDb {
return MerkleTrees.new(forked, this.log);
}

public async delete() {
await this.store.delete();
}

public getInitialHeader(): Header {
return Header.empty({ state: this.#loadInitialStateReference() });
}
Expand Down
Loading