Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Aug 9, 2024
1 parent cd23a09 commit af1555e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 4 additions & 9 deletions packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,11 @@ export function makeVatKeeper(
*/
function deleteSnapshots(budget = undefined) {
// Each budget=1 allows us to delete one snapshot entry.
let cleanups = 0;
if (!snapStore) {
return { done: true, cleanups };
return { done: true, cleanups: 0 };
}
// initially uses 2+2*budget DB statements, then just 1 when done
const dc = snapStore.deleteVatSnapshots(vatID, budget);
cleanups = dc.cleanups;
return { done: dc.done, cleanups };
return snapStore.deleteVatSnapshots(vatID, budget);
}

/**
Expand All @@ -704,11 +701,9 @@ export function makeVatKeeper(
// have historical transcript items, some will not. Using budget=5
// and snapshotInterval=200 means we delete 5 span records and
// maybe 1000 span items.
let cleanups = 0;

// initially uses 2+3*budget DB statements, then just 1 when done
const dc = transcriptStore.deleteVatTranscripts(vatID, budget);
cleanups = dc.cleanups;
return { done: dc.done, cleanups };
return transcriptStore.deleteVatTranscripts(vatID, budget);
}

function beginNewIncarnation() {
Expand Down
13 changes: 9 additions & 4 deletions packages/SwingSet/src/lib/runPolicies.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ export function crankCounter(
return policy;
}

export function computronCounter(limit) {
export function computronCounter(limit, options = {}) {
assert.typeof(limit, 'bigint');
const {
cleanupBudget = 100,
vatCreatedComputrons = 100_000n, // pretend that's the cost
crankFailedComputrons = 1_000_000n,
} = options;
let total = 0n;
/** @type { RunPolicy } */
const policy = harden({
allowCleanup() {
return { budget: 100 }; // limited budget
return { budget: cleanupBudget }; // limited budget
},
vatCreated() {
total += 100000n; // pretend vat creation takes 100k computrons
total += vatCreatedComputrons;
return total < limit;
},
crankComplete(details = {}) {
Expand All @@ -74,7 +79,7 @@ export function computronCounter(limit) {
return total < limit;
},
crankFailed() {
total += 1000000n; // who knows, 1M is as good as anything
total += crankFailedComputrons;
return total < limit;
},
emptyCrank() {
Expand Down

0 comments on commit af1555e

Please sign in to comment.