@agoric/cosmic-swingset 0.41.4-dev-0cc126e.0 → 0.41.4-dev-52bc8ec.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-0cc126e.0+0cc126e",
3
+ "version": "0.41.4-dev-52bc8ec.0+52bc8ec",
4
4
  "description": "Agoric's Cosmos blockchain integration",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,16 +22,16 @@
22
22
  "author": "Agoric",
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@agoric/assert": "0.6.1-dev-0cc126e.0+0cc126e",
26
- "@agoric/builders": "0.1.1-dev-0cc126e.0+0cc126e",
27
- "@agoric/cosmos": "0.34.2-dev-0cc126e.0+0cc126e",
28
- "@agoric/deploy-script-support": "0.10.4-dev-0cc126e.0+0cc126e",
29
- "@agoric/internal": "0.3.3-dev-0cc126e.0+0cc126e",
30
- "@agoric/store": "0.9.3-dev-0cc126e.0+0cc126e",
31
- "@agoric/swing-store": "0.9.2-dev-0cc126e.0+0cc126e",
32
- "@agoric/swingset-vat": "0.32.3-dev-0cc126e.0+0cc126e",
33
- "@agoric/telemetry": "0.6.3-dev-0cc126e.0+0cc126e",
34
- "@agoric/vm-config": "0.1.1-dev-0cc126e.0+0cc126e",
25
+ "@agoric/assert": "0.6.1-dev-52bc8ec.0+52bc8ec",
26
+ "@agoric/builders": "0.1.1-dev-52bc8ec.0+52bc8ec",
27
+ "@agoric/cosmos": "0.34.2-dev-52bc8ec.0+52bc8ec",
28
+ "@agoric/deploy-script-support": "0.10.4-dev-52bc8ec.0+52bc8ec",
29
+ "@agoric/internal": "0.3.3-dev-52bc8ec.0+52bc8ec",
30
+ "@agoric/store": "0.9.3-dev-52bc8ec.0+52bc8ec",
31
+ "@agoric/swing-store": "0.9.2-dev-52bc8ec.0+52bc8ec",
32
+ "@agoric/swingset-vat": "0.32.3-dev-52bc8ec.0+52bc8ec",
33
+ "@agoric/telemetry": "0.6.3-dev-52bc8ec.0+52bc8ec",
34
+ "@agoric/vm-config": "0.1.1-dev-52bc8ec.0+52bc8ec",
35
35
  "@endo/bundle-source": "^2.5.2",
36
36
  "@endo/far": "^0.2.19",
37
37
  "@endo/import-bundle": "^0.3.5",
@@ -66,5 +66,5 @@
66
66
  ],
67
67
  "timeout": "20m"
68
68
  },
69
- "gitHead": "0cc126ec803bb3eeff9c94d950e679dfa3db4d6a"
69
+ "gitHead": "52bc8ecaca025779a026d0396e07c4f620ef3a0a"
70
70
  }
@@ -44,7 +44,7 @@ import {
44
44
  BeansPerXsnapComputron,
45
45
  } from './sim-params.js';
46
46
  import { parseParams } from './params.js';
47
- import { makeQueue } from './helpers/make-queue.js';
47
+ import { makeQueue, makeQueueStorageMock } from './helpers/make-queue.js';
48
48
  import { exportStorage } from './export-storage.js';
49
49
  import { parseLocatedJson } from './helpers/json.js';
50
50
 
@@ -202,7 +202,8 @@ export async function buildSwingset(
202
202
  /**
203
203
  * @typedef {import('@agoric/swingset-vat').RunPolicy & {
204
204
  * shouldRun(): boolean;
205
- * remainingBeans(): bigint;
205
+ * remainingBeans(): bigint | undefined;
206
+ * totalBeans(): bigint;
206
207
  * }} ChainRunPolicy
207
208
  */
208
209
 
@@ -215,19 +216,24 @@ export async function buildSwingset(
215
216
 
216
217
  /**
217
218
  * @param {BeansPerUnit} beansPerUnit
219
+ * @param {boolean} [ignoreBlockLimit]
218
220
  * @returns {ChainRunPolicy}
219
221
  */
220
- function computronCounter({
221
- [BeansPerBlockComputeLimit]: blockComputeLimit,
222
- [BeansPerVatCreation]: vatCreation,
223
- [BeansPerXsnapComputron]: xsnapComputron,
224
- }) {
222
+ function computronCounter(
223
+ {
224
+ [BeansPerBlockComputeLimit]: blockComputeLimit,
225
+ [BeansPerVatCreation]: vatCreation,
226
+ [BeansPerXsnapComputron]: xsnapComputron,
227
+ },
228
+ ignoreBlockLimit = false,
229
+ ) {
225
230
  assert.typeof(blockComputeLimit, 'bigint');
226
231
  assert.typeof(vatCreation, 'bigint');
227
232
  assert.typeof(xsnapComputron, 'bigint');
228
233
  let totalBeans = 0n;
229
- const shouldRun = () => totalBeans < blockComputeLimit;
230
- const remainingBeans = () => blockComputeLimit - totalBeans;
234
+ const shouldRun = () => ignoreBlockLimit || totalBeans < blockComputeLimit;
235
+ const remainingBeans = () =>
236
+ ignoreBlockLimit ? undefined : blockComputeLimit - totalBeans;
231
237
 
232
238
  const policy = harden({
233
239
  vatCreated() {
@@ -251,23 +257,17 @@ function computronCounter({
251
257
  return shouldRun();
252
258
  },
253
259
  emptyCrank() {
254
- return true;
260
+ return shouldRun();
255
261
  },
256
262
  shouldRun,
257
263
  remainingBeans,
264
+ totalBeans() {
265
+ return totalBeans;
266
+ },
258
267
  });
259
268
  return policy;
260
269
  }
261
270
 
262
- function neverStop() {
263
- return harden({
264
- vatCreated: () => true,
265
- crankComplete: () => true,
266
- crankFailed: () => true,
267
- emptyCrank: () => true,
268
- });
269
- }
270
-
271
271
  export async function launch({
272
272
  actionQueueStorage,
273
273
  highPriorityQueueStorage,
@@ -316,6 +316,14 @@ export async function launch({
316
316
  const actionQueue = makeQueue(actionQueueStorage);
317
317
  /** @type {InboundQueue} */
318
318
  const highPriorityQueue = makeQueue(highPriorityQueueStorage);
319
+ /**
320
+ * In memory queue holding actions that must be consumed entirely
321
+ * during the block. If it's not drained, we open the gates to
322
+ * hangover hell.
323
+ *
324
+ * @type {InboundQueue}
325
+ */
326
+ const runThisBlock = makeQueue(makeQueueStorageMock().storage);
319
327
 
320
328
  // Not to be confused with the gas model, this meter is for OpenTelemetry.
321
329
  const metricMeter = metricsProvider.getMeter('ag-chain-cosmos');
@@ -357,14 +365,55 @@ export async function launch({
357
365
  inboundQueueMetrics,
358
366
  });
359
367
 
360
- async function bootstrapBlock(_blockHeight, blockTime) {
368
+ /**
369
+ * @param {number} blockHeight
370
+ * @param {ChainRunPolicy} runPolicy
371
+ */
372
+ function makeRunSwingset(blockHeight, runPolicy) {
373
+ let runNum = 0;
374
+ async function runSwingset() {
375
+ const startBeans = runPolicy.totalBeans();
376
+ controller.writeSlogObject({
377
+ type: 'cosmic-swingset-run-start',
378
+ blockHeight,
379
+ runNum,
380
+ startBeans,
381
+ remainingBeans: runPolicy.remainingBeans(),
382
+ });
383
+ // TODO: crankScheduler does a schedulerBlockTimeHistogram thing
384
+ // that needs to be revisited, it used to be called once per
385
+ // block, now it's once per processed inbound queue item
386
+ await crankScheduler(runPolicy);
387
+ const finishBeans = runPolicy.totalBeans();
388
+ controller.writeSlogObject({
389
+ type: 'kernel-stats',
390
+ stats: controller.getStats(),
391
+ });
392
+ controller.writeSlogObject({
393
+ type: 'cosmic-swingset-run-finish',
394
+ blockHeight,
395
+ runNum,
396
+ startBeans,
397
+ finishBeans,
398
+ usedBeans: finishBeans - startBeans,
399
+ remainingBeans: runPolicy.remainingBeans(),
400
+ });
401
+ runNum += 1;
402
+ return runPolicy.shouldRun();
403
+ }
404
+ return runSwingset;
405
+ }
406
+
407
+ async function bootstrapBlock(blockHeight, blockTime, params) {
361
408
  // We need to let bootstrap know of the chain time. The time of the first
362
409
  // block may be the genesis time, or the block time of the upgrade block.
363
410
  timer.poll(blockTime);
364
411
  // This is before the initial block, we need to finish processing the
365
412
  // entire bootstrap before opening for business.
366
- const policy = neverStop();
367
- await crankScheduler(policy);
413
+ const runPolicy = computronCounter(params.beansPerUnit, true);
414
+ const runSwingset = makeRunSwingset(blockHeight, runPolicy);
415
+
416
+ await runSwingset();
368
417
  }
369
418
 
370
419
  async function saveChainState() {
@@ -511,66 +560,45 @@ export async function launch({
511
560
  return p;
512
561
  }
513
562
 
514
- async function runKernel(runPolicy, blockHeight, blockTime) {
515
- let runNum = 0;
516
- async function runSwingset() {
517
- const initialBeans = runPolicy.remainingBeans();
518
- controller.writeSlogObject({
519
- type: 'cosmic-swingset-run-start',
520
- blockHeight,
521
- runNum,
522
- initialBeans,
523
- });
524
- // TODO: crankScheduler does a schedulerBlockTimeHistogram thing
525
- // that needs to be revisited, it used to be called once per
526
- // block, now it's once per processed inbound queue item
527
- await crankScheduler(runPolicy);
528
- const remainingBeans = runPolicy.remainingBeans();
529
- controller.writeSlogObject({
530
- type: 'kernel-stats',
531
- stats: controller.getStats(),
532
- });
533
- controller.writeSlogObject({
534
- type: 'cosmic-swingset-run-finish',
535
- blockHeight,
536
- runNum,
537
- remainingBeans,
538
- usedBeans: initialBeans - remainingBeans,
539
- });
540
- runNum += 1;
541
- return runPolicy.shouldRun();
542
- }
543
-
544
- /**
545
- * Process as much as we can from an inbound queue, which contains
546
- * first the old actions not previously processed, followed by actions
547
- * newly added, running the kernel to completion after each.
548
- *
549
- * @param {InboundQueue} inboundQueue
550
- */
551
- async function processActions(inboundQueue) {
552
- let keepGoing = true;
553
- await null;
554
- for (const { action, context } of inboundQueue.consumeAll()) {
555
- const inboundNum = `${context.blockHeight}-${context.txHash}-${context.msgIdx}`;
556
- inboundQueueMetrics.decStat();
557
- await performAction(action, inboundNum);
558
- keepGoing = await runSwingset();
559
- if (!keepGoing) {
560
- // any leftover actions will remain on the inbound queue for possible
561
- // processing in the next block
562
- break;
563
- }
563
+ /**
564
+ * Process as much as we can from an inbound queue, which contains
565
+ * first the old actions not previously processed, followed by actions
566
+ * newly added, running the kernel to completion after each.
567
+ *
568
+ * @param {InboundQueue} inboundQueue
569
+ * @param {ReturnType<typeof makeRunSwingset>} runSwingset
570
+ */
571
+ async function processActions(inboundQueue, runSwingset) {
572
+ let keepGoing = true;
573
+ await null;
574
+ for (const { action, context } of inboundQueue.consumeAll()) {
575
+ const inboundNum = `${context.blockHeight}-${context.txHash}-${context.msgIdx}`;
576
+ inboundQueueMetrics.decStat();
577
+ await performAction(action, inboundNum);
578
+ keepGoing = await runSwingset();
579
+ if (!keepGoing) {
580
+ // any leftover actions will remain on the inbound queue for possible
581
+ // processing in the next block
582
+ break;
564
583
  }
565
- return keepGoing;
566
584
  }
585
+ return keepGoing;
586
+ }
567
587
 
588
+ async function runKernel(runSwingset, blockHeight, blockTime) {
568
589
  // First, complete leftover work, if any
569
590
  let keepGoing = await runSwingset();
570
591
  if (!keepGoing) return;
571
592
 
593
+ // Then, if we have anything in the special runThisBlock queue, process
594
+ // it and do no further work.
595
+ if (runThisBlock.size()) {
596
+ await processActions(runThisBlock, runSwingset);
597
+ return;
598
+ }
599
+
572
600
  // Then, process as much as we can from the priorityQueue.
573
- keepGoing = await processActions(highPriorityQueue);
601
+ keepGoing = await processActions(highPriorityQueue, runSwingset);
574
602
  if (!keepGoing) return;
575
603
 
576
604
  // Then, update the timer device with the new external time, which might
@@ -587,7 +615,7 @@ export async function launch({
587
615
  if (!keepGoing) return;
588
616
 
589
617
  // Finally, process as much as we can from the actionQueue.
590
- await processActions(actionQueue);
618
+ await processActions(actionQueue, runSwingset);
591
619
  }
592
620
 
593
621
  async function endBlock(blockHeight, blockTime, params) {
@@ -598,13 +626,18 @@ export async function launch({
598
626
  // First, record new actions (bridge/mailbox/etc events that cosmos
599
627
  // added up for delivery to swingset) into our inboundQueue metrics
600
628
  inboundQueueMetrics.updateLength(
601
- actionQueue.size() + highPriorityQueue.size(),
629
+ actionQueue.size() + highPriorityQueue.size() + runThisBlock.size(),
602
630
  );
603
631
 
632
+ // If we have work to complete this block, it needs to run to completion.
633
+ // It will also run to completion any work that swingset still had pending.
634
+ const neverStop = runThisBlock.size() > 0;
635
+
604
636
  // make a runPolicy that will be shared across all cycles
605
- const runPolicy = computronCounter(params.beansPerUnit);
637
+ const runPolicy = computronCounter(params.beansPerUnit, neverStop);
638
+ const runSwingset = makeRunSwingset(blockHeight, runPolicy);
606
639
 
607
- await runKernel(runPolicy, blockHeight, blockTime);
640
+ await runKernel(runSwingset, blockHeight, blockTime);
608
641
 
609
642
  if (END_BLOCK_SPIN_MS) {
610
643
  // Introduce a busy-wait to artificially put load on the chain.
@@ -703,31 +736,21 @@ export async function launch({
703
736
  // );
704
737
  switch (action.type) {
705
738
  case ActionType.AG_COSMOS_INIT: {
706
- const { isBootstrap, upgradePlan, blockTime } = action;
739
+ const { isBootstrap, upgradePlan, blockTime, params } = action;
707
740
  // This only runs for the very first block on the chain.
708
741
  if (isBootstrap) {
709
742
  verboseBlocks && blockManagerConsole.info('block bootstrap');
710
743
  savedHeight === 0 ||
711
744
  Fail`Cannot run a bootstrap block at height ${savedHeight}`;
745
+ const bootstrapBlockParams = parseParams(params);
712
746
  const blockHeight = 0;
713
- const runNum = 0;
714
747
  controller.writeSlogObject({
715
748
  type: 'cosmic-swingset-bootstrap-block-start',
716
749
  blockTime,
717
750
  });
718
- controller.writeSlogObject({
719
- type: 'cosmic-swingset-run-start',
720
- blockHeight,
721
- runNum,
722
- });
723
751
  await processAction(action.type, async () =>
724
- bootstrapBlock(blockHeight, blockTime),
752
+ bootstrapBlock(blockHeight, blockTime, bootstrapBlockParams),
725
753
  );
726
- controller.writeSlogObject({
727
- type: 'cosmic-swingset-run-finish',
728
- blockHeight,
729
- runNum,
730
- });
731
754
  controller.writeSlogObject({
732
755
  type: 'cosmic-swingset-bootstrap-block-finish',
733
756
  blockTime,
@@ -735,38 +758,36 @@ export async function launch({
735
758
  }
736
759
  if (upgradePlan) {
737
760
  const blockHeight = upgradePlan.height;
738
- if (blockNeedsExecution(blockHeight)) {
739
- controller.writeSlogObject({
740
- type: 'cosmic-swingset-upgrade-start',
741
- blockHeight,
742
- blockTime,
743
- upgradePlan,
744
- });
745
- // Process upgrade plan
746
- const upgradedAction = {
747
- type: ActionType.ENACTED_UPGRADE,
748
- upgradePlan,
749
- blockHeight,
750
- blockTime,
751
- };
752
- await doBlockingSend(upgradedAction);
753
- controller.writeSlogObject({
754
- type: 'cosmic-swingset-upgrade-finish',
755
- blockHeight,
756
- blockTime,
757
- });
758
- }
761
+
762
+ // Process upgrade plan
763
+ const upgradedAction = {
764
+ type: ActionType.ENACTED_UPGRADE,
765
+ upgradePlan,
766
+ blockHeight,
767
+ blockTime,
768
+ };
769
+ await doBlockingSend(upgradedAction);
759
770
  }
760
771
  return true;
761
772
  }
762
773
 
763
774
  case ActionType.ENACTED_UPGRADE: {
764
775
  // Install and execute new core proposals.
765
- const {
766
- upgradePlan: { info: upgradeInfoJson = null } = {},
776
+ const { upgradePlan, blockHeight, blockTime } = action;
777
+
778
+ if (!blockNeedsExecution(blockHeight)) {
779
+ return undefined;
780
+ }
781
+
782
+ controller.writeSlogObject({
783
+ type: 'cosmic-swingset-upgrade-start',
767
784
  blockHeight,
768
785
  blockTime,
769
- } = action;
786
+ upgradePlan,
787
+ });
788
+
789
+ const { info: upgradeInfoJson = null } = upgradePlan || {};
790
+
770
791
  const upgradePlanInfo =
771
792
  upgradeInfoJson &&
772
793
  parseLocatedJson(upgradeInfoJson, 'ENACTED_UPGRADE upgradePlan.info');
@@ -800,9 +821,6 @@ export async function launch({
800
821
  }
801
822
 
802
823
  // Now queue the code for evaluation.
803
- //
804
- // TODO: Once SwingSet sprouts some tools for preemption, we should use
805
- // them to help the upgrade process finish promptly.
806
824
  const coreEvalAction = {
807
825
  type: ActionType.CORE_EVAL,
808
826
  blockHeight,
@@ -814,7 +832,7 @@ export async function launch({
814
832
  },
815
833
  ],
816
834
  };
817
- highPriorityQueue.push({
835
+ runThisBlock.push({
818
836
  context: {
819
837
  blockHeight,
820
838
  txHash: 'x/upgrade',
@@ -823,6 +841,12 @@ export async function launch({
823
841
  action: coreEvalAction,
824
842
  });
825
843
 
844
+ controller.writeSlogObject({
845
+ type: 'cosmic-swingset-upgrade-finish',
846
+ blockHeight,
847
+ blockTime,
848
+ });
849
+
826
850
  return undefined;
827
851
  }
828
852
 
@@ -836,6 +860,9 @@ export async function launch({
836
860
  );
837
861
  }
838
862
 
863
+ runThisBlock.size() === 0 ||
864
+ Fail`We didn't process all "run this block" actions`;
865
+
839
866
  controller.writeSlogObject({
840
867
  type: 'cosmic-swingset-commit-block-start',
841
868
  blockHeight,
package/src/sim-chain.js CHANGED
@@ -215,6 +215,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
215
215
  type: 'AG_COSMOS_INIT',
216
216
  blockTime: scaleBlockTime(Date.now()),
217
217
  isBootstrap: true,
218
+ params: DEFAULT_SIM_SWINGSET_PARAMS,
218
219
  });
219
220
  blockHeight = initialHeight;
220
221
  };