@agoric/cosmic-swingset 0.41.4-dev-963ebe1.0 → 0.41.4-dev-ef82fbf.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmic-swingset",
3
- "version": "0.41.4-dev-963ebe1.0+963ebe1",
3
+ "version": "0.41.4-dev-ef82fbf.0+ef82fbf",
4
4
  "description": "Agoric's Cosmos blockchain integration",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,15 +22,15 @@
22
22
  "author": "Agoric",
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@agoric/builders": "0.1.1-dev-963ebe1.0+963ebe1",
26
- "@agoric/cosmos": "0.34.2-dev-963ebe1.0+963ebe1",
27
- "@agoric/deploy-script-support": "0.10.4-dev-963ebe1.0+963ebe1",
28
- "@agoric/internal": "0.3.3-dev-963ebe1.0+963ebe1",
29
- "@agoric/store": "0.9.3-dev-963ebe1.0+963ebe1",
30
- "@agoric/swing-store": "0.9.2-dev-963ebe1.0+963ebe1",
31
- "@agoric/swingset-vat": "0.32.3-dev-963ebe1.0+963ebe1",
32
- "@agoric/telemetry": "0.6.3-dev-963ebe1.0+963ebe1",
33
- "@agoric/vm-config": "0.1.1-dev-963ebe1.0+963ebe1",
25
+ "@agoric/builders": "0.1.1-dev-ef82fbf.0+ef82fbf",
26
+ "@agoric/cosmos": "0.34.2-dev-ef82fbf.0+ef82fbf",
27
+ "@agoric/deploy-script-support": "0.10.4-dev-ef82fbf.0+ef82fbf",
28
+ "@agoric/internal": "0.3.3-dev-ef82fbf.0+ef82fbf",
29
+ "@agoric/store": "0.9.3-dev-ef82fbf.0+ef82fbf",
30
+ "@agoric/swing-store": "0.9.2-dev-ef82fbf.0+ef82fbf",
31
+ "@agoric/swingset-vat": "0.32.3-dev-ef82fbf.0+ef82fbf",
32
+ "@agoric/telemetry": "0.6.3-dev-ef82fbf.0+ef82fbf",
33
+ "@agoric/vm-config": "0.1.1-dev-ef82fbf.0+ef82fbf",
34
34
  "@endo/bundle-source": "^3.5.0",
35
35
  "@endo/env-options": "^1.1.8",
36
36
  "@endo/errors": "^1.2.8",
@@ -71,5 +71,5 @@
71
71
  "typeCoverage": {
72
72
  "atLeast": 82.83
73
73
  },
74
- "gitHead": "963ebe1ef4878501359342bc3357f81fe52ce860"
74
+ "gitHead": "ef82fbf7466ea1b57c321f735d73fcee2c66fd11"
75
75
  }
@@ -0,0 +1,115 @@
1
+ // @ts-check
2
+
3
+ import { assert } from '@endo/errors';
4
+ import {
5
+ BeansPerBlockComputeLimit,
6
+ BeansPerVatCreation,
7
+ BeansPerXsnapComputron,
8
+ } from './sim-params.js';
9
+
10
+ const { hasOwn } = Object;
11
+
12
+ /**
13
+ * @typedef {object} BeansPerUnit
14
+ * @property {bigint} blockComputeLimit
15
+ * @property {bigint} vatCreation
16
+ * @property {bigint} xsnapComputron
17
+ */
18
+
19
+ /**
20
+ * Return a stateful run policy that supports two phases: first allow
21
+ * non-cleanup work (presumably deliveries) until an overrideable computron
22
+ * budget is exhausted, then (iff no work was done and at least one vat cleanup
23
+ * budget field is positive) a cleanup phase that allows cleanup work (and
24
+ * presumably nothing else) until one of those fields is exhausted.
25
+ * https://github.com/Agoric/agoric-sdk/issues/8928#issuecomment-2053357870
26
+ *
27
+ * @param {object} params
28
+ * @param {BeansPerUnit} params.beansPerUnit
29
+ * @param {import('@agoric/swingset-vat').CleanupBudget} [params.vatCleanupBudget]
30
+ * @param {boolean} [ignoreBlockLimit]
31
+ * @returns {import('./launch-chain.js').ChainRunPolicy}
32
+ */
33
+ export function computronCounter(
34
+ { beansPerUnit, vatCleanupBudget },
35
+ ignoreBlockLimit = false,
36
+ ) {
37
+ const {
38
+ [BeansPerBlockComputeLimit]: blockComputeLimit,
39
+ [BeansPerVatCreation]: vatCreation,
40
+ [BeansPerXsnapComputron]: xsnapComputron,
41
+ } = beansPerUnit;
42
+ assert.typeof(blockComputeLimit, 'bigint');
43
+ assert.typeof(vatCreation, 'bigint');
44
+ assert.typeof(xsnapComputron, 'bigint');
45
+
46
+ let totalBeans = 0n;
47
+ const shouldRun = () => ignoreBlockLimit || totalBeans < blockComputeLimit;
48
+
49
+ const remainingCleanups = { default: Infinity, ...vatCleanupBudget };
50
+ const defaultCleanupBudget = remainingCleanups.default;
51
+ let cleanupStarted = false;
52
+ let cleanupDone = false;
53
+ const cleanupPossible =
54
+ Object.values(remainingCleanups).length > 0
55
+ ? Object.values(remainingCleanups).some(n => n > 0)
56
+ : defaultCleanupBudget > 0;
57
+ if (!cleanupPossible) cleanupDone = true;
58
+ /** @type {() => (false | import('@agoric/swingset-vat').CleanupBudget)} */
59
+ const allowCleanup = () =>
60
+ cleanupStarted && !cleanupDone && { ...remainingCleanups };
61
+ const startCleanup = () => {
62
+ assert(!cleanupStarted);
63
+ cleanupStarted = true;
64
+ return totalBeans === 0n && !cleanupDone;
65
+ };
66
+ const didCleanup = details => {
67
+ for (const [phase, count] of Object.entries(details.cleanups)) {
68
+ if (phase === 'total') continue;
69
+ if (!hasOwn(remainingCleanups, phase)) {
70
+ // TODO: log unknown phases?
71
+ remainingCleanups[phase] = defaultCleanupBudget;
72
+ }
73
+ remainingCleanups[phase] -= count;
74
+ if (remainingCleanups[phase] <= 0) cleanupDone = true;
75
+ }
76
+ // We return true to allow processing of any BOYD/GC prompted by cleanup,
77
+ // even if cleanup as such is now done.
78
+ return true;
79
+ };
80
+
81
+ const policy = harden({
82
+ vatCreated() {
83
+ totalBeans += vatCreation;
84
+ return shouldRun();
85
+ },
86
+ crankComplete(details = {}) {
87
+ assert.typeof(details, 'object');
88
+ if (details.computrons) {
89
+ assert.typeof(details.computrons, 'bigint');
90
+
91
+ // TODO: xsnapComputron should not be assumed here.
92
+ // Instead, SwingSet should describe the computron model it uses.
93
+ totalBeans += details.computrons * xsnapComputron;
94
+ }
95
+ return shouldRun();
96
+ },
97
+ crankFailed() {
98
+ const failedComputrons = 1000000n; // who knows, 1M is as good as anything
99
+ totalBeans += failedComputrons * xsnapComputron;
100
+ return shouldRun();
101
+ },
102
+ emptyCrank() {
103
+ return shouldRun();
104
+ },
105
+ allowCleanup,
106
+ didCleanup,
107
+
108
+ shouldRun,
109
+ remainingBeans: () =>
110
+ ignoreBlockLimit ? undefined : blockComputeLimit - totalBeans,
111
+ totalBeans: () => totalBeans,
112
+ startCleanup,
113
+ });
114
+ return policy;
115
+ }
@@ -43,17 +43,11 @@ import {
43
43
  makeSlogCallbacks,
44
44
  } from './kernel-stats.js';
45
45
 
46
- import {
47
- BeansPerBlockComputeLimit,
48
- BeansPerVatCreation,
49
- BeansPerXsnapComputron,
50
- } from './sim-params.js';
51
46
  import { parseParams } from './params.js';
52
47
  import { makeQueue, makeQueueStorageMock } from './helpers/make-queue.js';
53
48
  import { exportStorage } from './export-storage.js';
54
49
  import { parseLocatedJson } from './helpers/json.js';
55
-
56
- const { hasOwn } = Object;
50
+ import { computronCounter } from './computron-counter.js';
57
51
 
58
52
  /** @import { BlockInfo } from '@agoric/internal/src/chain-utils.js' */
59
53
  /** @import { Mailbox, RunPolicy, SwingSetConfig } from '@agoric/swingset-vat' */
@@ -282,111 +276,6 @@ export async function buildSwingset(
282
276
  * }} ChainRunPolicy
283
277
  */
284
278
 
285
- /**
286
- * @typedef {object} BeansPerUnit
287
- * @property {bigint} blockComputeLimit
288
- * @property {bigint} vatCreation
289
- * @property {bigint} xsnapComputron
290
- */
291
-
292
- /**
293
- * Return a stateful run policy that supports two phases: first allow
294
- * non-cleanup work (presumably deliveries) until an overrideable computron
295
- * budget is exhausted, then (iff no work was done and at least one vat cleanup
296
- * budget field is positive) a cleanup phase that allows cleanup work (and
297
- * presumably nothing else) until one of those fields is exhausted.
298
- * https://github.com/Agoric/agoric-sdk/issues/8928#issuecomment-2053357870
299
- *
300
- * @param {object} params
301
- * @param {BeansPerUnit} params.beansPerUnit
302
- * @param {import('@agoric/swingset-vat').CleanupBudget} [params.vatCleanupBudget]
303
- * @param {boolean} [ignoreBlockLimit]
304
- * @returns {ChainRunPolicy}
305
- */
306
- function computronCounter(
307
- { beansPerUnit, vatCleanupBudget },
308
- ignoreBlockLimit = false,
309
- ) {
310
- const {
311
- [BeansPerBlockComputeLimit]: blockComputeLimit,
312
- [BeansPerVatCreation]: vatCreation,
313
- [BeansPerXsnapComputron]: xsnapComputron,
314
- } = beansPerUnit;
315
- assert.typeof(blockComputeLimit, 'bigint');
316
- assert.typeof(vatCreation, 'bigint');
317
- assert.typeof(xsnapComputron, 'bigint');
318
-
319
- let totalBeans = 0n;
320
- const shouldRun = () => ignoreBlockLimit || totalBeans < blockComputeLimit;
321
-
322
- const remainingCleanups = { default: Infinity, ...vatCleanupBudget };
323
- const defaultCleanupBudget = remainingCleanups.default;
324
- let cleanupStarted = false;
325
- let cleanupDone = false;
326
- const cleanupPossible =
327
- Object.values(remainingCleanups).length > 0
328
- ? Object.values(remainingCleanups).some(n => n > 0)
329
- : defaultCleanupBudget > 0;
330
- if (!cleanupPossible) cleanupDone = true;
331
- /** @type {() => (false | import('@agoric/swingset-vat').CleanupBudget)} */
332
- const allowCleanup = () =>
333
- cleanupStarted && !cleanupDone && { ...remainingCleanups };
334
- const startCleanup = () => {
335
- assert(!cleanupStarted);
336
- cleanupStarted = true;
337
- return totalBeans === 0n && !cleanupDone;
338
- };
339
- const didCleanup = details => {
340
- for (const [phase, count] of Object.entries(details.cleanups)) {
341
- if (phase === 'total') continue;
342
- if (!hasOwn(remainingCleanups, phase)) {
343
- // TODO: log unknown phases?
344
- remainingCleanups[phase] = defaultCleanupBudget;
345
- }
346
- remainingCleanups[phase] -= count;
347
- if (remainingCleanups[phase] <= 0) cleanupDone = true;
348
- }
349
- // We return true to allow processing of any BOYD/GC prompted by cleanup,
350
- // even if cleanup as such is now done.
351
- return true;
352
- };
353
-
354
- const policy = harden({
355
- vatCreated() {
356
- totalBeans += vatCreation;
357
- return shouldRun();
358
- },
359
- crankComplete(details = {}) {
360
- assert.typeof(details, 'object');
361
- if (details.computrons) {
362
- assert.typeof(details.computrons, 'bigint');
363
-
364
- // TODO: xsnapComputron should not be assumed here.
365
- // Instead, SwingSet should describe the computron model it uses.
366
- totalBeans += details.computrons * xsnapComputron;
367
- }
368
- return shouldRun();
369
- },
370
- crankFailed() {
371
- const failedComputrons = 1000000n; // who knows, 1M is as good as anything
372
- totalBeans += failedComputrons * xsnapComputron;
373
- return shouldRun();
374
- },
375
- emptyCrank() {
376
- return shouldRun();
377
- },
378
- allowCleanup,
379
- didCleanup,
380
-
381
- shouldRun,
382
- remainingBeans: () =>
383
- ignoreBlockLimit ? undefined : blockComputeLimit - totalBeans,
384
- totalBeans: () => totalBeans,
385
- startCleanup,
386
- });
387
- return policy;
388
- }
389
-
390
279
  /**
391
280
  * @template [T=unknown]
392
281
  * @typedef {object} LaunchOptions