Skip to content

Commit

Permalink
fix: zoe/spawner/pegasus: use unlimited Meter, not metered: true
Browse files Browse the repository at this point in the history
Zoe and spawner use `createVat()` to do their jobs. Previously, they used `{
metered: true }`, which provided a per-crank limit but not cumulative limit.
This changes both to use `createUnlimitedMeter()`, then pass that as a `{
meter }` option, to achieve the same effect.

When Zoe is ready to maintain (and refill) a Meter, change that to use
`createMeter()` instead of `createUnlimitedMeter()`.

This also adds `createMeter` and `createUnlimitedMeter` methods to the fake
vatAdmin objects used by the zoe/spawner/pegasus unit tests, so the new
Zoe/spawner code will work against the mocks.

refs #3308
  • Loading branch information
warner committed Jul 24, 2021
1 parent f389f8c commit e68888a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/pegasus/test/fakeVatAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { makePromiseKit } from '@agoric/promise-kit';
import { evalContractBundle } from '@agoric/zoe/src/contractFacet/evalContractCode';

export default harden({
createMeter: () => {},
createUnlimitedMeter: () => {},
createVat: bundle => {
return harden({
root: E(evalContractBundle(bundle)).buildRootObject(),
Expand Down
3 changes: 2 additions & 1 deletion packages/spawner/src/contractHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function makeSpawner(vatAdminSvc) {
assert(!oldModuleFormat, 'oldModuleFormat not supported');
return Far('installer', {
async spawn(argsP) {
const opts = { metered: true };
const meter = await E(vatAdminSvc).createUnlimitedMeter();
const opts = { meter };
const { root } = await E(vatAdminSvc).createVat(spawnBundle, opts);
return E(E(root).loadBundle(bundle)).start(argsP);
},
Expand Down
10 changes: 6 additions & 4 deletions packages/zoe/src/zoeService/createZCFVat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import zcfContractBundle from '../../bundles/bundle-contractFacet';
*/
export const setupCreateZCFVat = (vatAdminSvc, zcfBundleName = undefined) => {
/** @type {CreateZCFVat} */
const createZCFVat = () =>
typeof zcfBundleName === 'string'
? E(vatAdminSvc).createVatByName(zcfBundleName, { metered: true })
: E(vatAdminSvc).createVat(zcfContractBundle, { metered: true });
const createZCFVat = async () => {
const meter = await E(vatAdminSvc).createUnlimitedMeter();
return typeof zcfBundleName === 'string'
? E(vatAdminSvc).createVatByName(zcfBundleName, { meter })
: E(vatAdminSvc).createVat(zcfContractBundle, { meter });
};
return createZCFVat;
};
2 changes: 2 additions & 0 deletions packages/zoe/test/unitTests/zoe/test-createZCFVat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ test('setupCreateZCFVat', async t => {
// creates a new vat

const fakeVatAdminSvc = Far('fakeVatAdminSvc', {
createMeter: () => {},
createUnlimitedMeter: () => {},
createVatByName: name => name,
createVat: _bundle => 'zcfBundle',
});
Expand Down
2 changes: 2 additions & 0 deletions packages/zoe/tools/fakeVatAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function makeFakeVatAdmin(testContextSetter = undefined, makeRemote = x => x) {
// test-only state can be provided from contracts
// to their tests.
const admin = Far('vatAdmin', {
createMeter: () => {},
createUnlimitedMeter: () => {},
createVat: bundle => {
return harden({
root: makeRemote(
Expand Down

0 comments on commit e68888a

Please sign in to comment.