From c73dd8d8ea3b7859313f245537f04dd6f92ba0c6 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 24 Jul 2021 11:38:42 -0700 Subject: [PATCH] feat(swingset)!: make dynamic vats unmetered by default When #3308 lands, the definition of "metering" will change. Previously, a "metered dynamic vat" just meant that 1: each crank was limited to some fixed amount of computrons, and 2: the low-level `deliveryResult` included the number of computrons consumed by that delivery (but nobody paid attention to the value). In the new system, metering requires a Meter: an object with a `remaining` capacity, which is deducted by the consumption of each delivery. Each metered vat is associated with (exactly one) Meter. The presence of a Meter still implies a per-crank limit: unmetered vats do not have a per-crank limit either. Previously, all dynamic vats were metered by default. Since the new metering needs a Meter, it would be awkward to retain this default: we'd have to allocate a new Meter during `createVat` without the caller's awareness, and then there would be nobody to pay attention to it (or refill it when it runs low). So this commit changes the default to "false". Dynamic vats will be unmetered (neither per-crank limits nor cumulative limits) by default. Callers who want to retain the per-crank limits should add `metered: true` to their `createVat` options. Such callers will need to create a Meter object once #3308 is done. The commit also updates swingset metering tests to add `metered: true`. refs #3308 --- packages/SwingSet/src/kernel/loadVat.js | 4 ++-- .../SwingSet/test/metering/test-dynamic-vat-metered.js | 8 +++----- .../test/metering/test-dynamic-vat-subcompartment.js | 4 +++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/SwingSet/src/kernel/loadVat.js b/packages/SwingSet/src/kernel/loadVat.js index 37f68de8751..09daff61b42 100644 --- a/packages/SwingSet/src/kernel/loadVat.js +++ b/packages/SwingSet/src/kernel/loadVat.js @@ -138,7 +138,7 @@ export function makeVatLoader(stuff) { * the amount of computation and allocation that can occur during any * given crank. Stack frames are limited as well. The meter is refilled * between cranks, but if the meter ever underflows, the vat is - * terminated. If false, the vat is unmetered. Defaults to true for + * terminated. If false, the vat is unmetered. Defaults to false for * dynamic vats; static vats may not be metered. * * @param {Record} [options.vatParameters] provides @@ -199,7 +199,7 @@ export function makeVatLoader(stuff) { isDynamic ? allowedDynamicOptions : allowedStaticOptions, ); const { - metered = isDynamic, + metered = false, vatParameters = {}, managerType, enableSetup = false, diff --git a/packages/SwingSet/test/metering/test-dynamic-vat-metered.js b/packages/SwingSet/test/metering/test-dynamic-vat-metered.js index 0496f84fa05..a33fd975910 100644 --- a/packages/SwingSet/test/metering/test-dynamic-vat-metered.js +++ b/packages/SwingSet/test/metering/test-dynamic-vat-metered.js @@ -57,11 +57,9 @@ async function runOneTest(t, explosion, managerType) { await c.run(); // 'createVat' will import the bundle - c.queueToVatRoot( - 'bootstrap', - 'createVat', - capargs([dynamicVatBundle, { managerType }]), - ); + const cvopts = { managerType, metered: true }; + const cvargs = capargs([dynamicVatBundle, cvopts]); + c.queueToVatRoot('bootstrap', 'createVat', cvargs); await c.run(); t.deepEqual(nextLog(), ['created'], 'first create'); diff --git a/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js b/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js index 0dc345c5c7a..74830b61357 100644 --- a/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js +++ b/packages/SwingSet/test/metering/test-dynamic-vat-subcompartment.js @@ -43,7 +43,9 @@ test('metering dynamic vat which imports bundle', async t => { ); // 'createVat' will import the bundle - c.queueToVatRoot('bootstrap', 'createVat', capargs([dynamicVatBundle])); + const cvopts = { metered: true }; + const cvargs = capargs([dynamicVatBundle, cvopts]); + c.queueToVatRoot('bootstrap', 'createVat', cvargs); await c.run(); t.deepEqual(nextLog(), ['created'], 'first create');