Skip to content

Commit

Permalink
Remove source code and state from runtime (#2009)
Browse files Browse the repository at this point in the history
In #1634 we removed the source
code and snap state from the runtime type. But the data was still being
saved wastefully in memory. This PR fixes this.
  • Loading branch information
FrederikBolding authored Dec 4, 2023
1 parent e301bda commit 59da0ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"branches": 90.11,
"branches": 90.07,
"functions": 96.35,
"lines": 97.3,
"statements": 96.98
Expand Down
13 changes: 3 additions & 10 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,7 @@ export class SnapController extends BaseController<
this.#registerMessageHandlers();

Object.values(state?.snaps ?? {}).forEach((snap) =>
this.#setupRuntime(snap.id, {
sourceCode: snap.sourceCode,
state: state?.snapStates?.[snap.id] ?? null,
}),
this.#setupRuntime(snap.id),
);
}

Expand Down Expand Up @@ -2129,7 +2126,7 @@ export class SnapController extends BaseController<
async #add(args: AddSnapArgs): Promise<PersistedSnap> {
const { id: snapId, location, versionRange } = args;

this.#setupRuntime(snapId, { sourceCode: null, state: null });
this.#setupRuntime(snapId);
const runtime = this.#getRuntimeExpect(snapId);
if (!runtime.installPromise) {
log(`Adding snap: ${snapId}`);
Expand Down Expand Up @@ -2906,10 +2903,7 @@ export class SnapController extends BaseController<
return runtime;
}

#setupRuntime(
snapId: SnapId,
data: { sourceCode: string | null; state: string | null },
) {
#setupRuntime(snapId: SnapId) {
if (this.#snapsRuntimeData.has(snapId)) {
return;
}
Expand All @@ -2933,7 +2927,6 @@ export class SnapController extends BaseController<
pendingInboundRequests: [],
pendingOutboundRequests: 0,
interpreter,
...data,
});
}

Expand Down

0 comments on commit 59da0ea

Please sign in to comment.