@agoric/cosmic-swingset 0.41.4-dev-e68f280.0 → 0.41.4-dev-6f05870.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-e68f280.0+e68f280",
3
+ "version": "0.41.4-dev-6f05870.0+6f05870",
4
4
  "description": "Agoric's Cosmos blockchain integration",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,14 +22,14 @@
22
22
  "author": "Agoric",
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@agoric/assert": "0.6.1-dev-e68f280.0+e68f280",
26
- "@agoric/cosmos": "0.34.2-dev-e68f280.0+e68f280",
27
- "@agoric/deploy-script-support": "0.10.4-dev-e68f280.0+e68f280",
28
- "@agoric/internal": "0.3.3-dev-e68f280.0+e68f280",
29
- "@agoric/store": "0.9.3-dev-e68f280.0+e68f280",
30
- "@agoric/swing-store": "0.9.2-dev-e68f280.0+e68f280",
31
- "@agoric/swingset-vat": "0.32.3-dev-e68f280.0+e68f280",
32
- "@agoric/telemetry": "0.6.3-dev-e68f280.0+e68f280",
25
+ "@agoric/assert": "0.6.1-dev-6f05870.0+6f05870",
26
+ "@agoric/cosmos": "0.34.2-dev-6f05870.0+6f05870",
27
+ "@agoric/deploy-script-support": "0.10.4-dev-6f05870.0+6f05870",
28
+ "@agoric/internal": "0.3.3-dev-6f05870.0+6f05870",
29
+ "@agoric/store": "0.9.3-dev-6f05870.0+6f05870",
30
+ "@agoric/swing-store": "0.9.2-dev-6f05870.0+6f05870",
31
+ "@agoric/swingset-vat": "0.32.3-dev-6f05870.0+6f05870",
32
+ "@agoric/telemetry": "0.6.3-dev-6f05870.0+6f05870",
33
33
  "@endo/far": "^0.2.19",
34
34
  "@endo/import-bundle": "^0.3.5",
35
35
  "@endo/init": "^0.5.57",
@@ -60,5 +60,5 @@
60
60
  ],
61
61
  "timeout": "20m"
62
62
  },
63
- "gitHead": "e68f2805dde79871d1421e50c60f08e854e1851d"
63
+ "gitHead": "6f05870eef00470eb99022513e2df5ff62e81785"
64
64
  }
package/src/chain-main.js CHANGED
@@ -39,8 +39,14 @@ import stringify from './helpers/json-stable-stringify.js';
39
39
  import { launch } from './launch-chain.js';
40
40
  import { getTelemetryProviders } from './kernel-stats.js';
41
41
  import { makeProcessValue } from './helpers/process-value.js';
42
- import { spawnSwingStoreExport } from './export-kernel-db.js';
43
- import { performStateSyncImport } from './import-kernel-db.js';
42
+ import {
43
+ spawnSwingStoreExport,
44
+ validateExporterOptions,
45
+ } from './export-kernel-db.js';
46
+ import {
47
+ performStateSyncImport,
48
+ validateImporterOptions,
49
+ } from './import-kernel-db.js';
44
50
 
45
51
  // eslint-disable-next-line no-unused-vars
46
52
  let whenHellFreezesOver = null;
@@ -497,30 +503,48 @@ export default async function main(progname, args, { env, homedir, agcc }) {
497
503
  /** @type {Awaited<ReturnType<typeof launch>>['blockingSend'] | undefined} */
498
504
  let blockingSend;
499
505
 
500
- async function handleCosmosSnapshot(blockHeight, request, requestArgs) {
506
+ async function handleSwingStoreExport(blockHeight, request, requestArgs) {
501
507
  await null;
502
508
  switch (request) {
503
509
  case 'restore': {
504
- const exportDir = requestArgs[0];
505
- if (typeof exportDir !== 'string') {
506
- throw Fail`Invalid exportDir argument ${q(exportDir)}`;
507
- }
510
+ const requestOptions =
511
+ typeof requestArgs[0] === 'string'
512
+ ? { exportDir: requestArgs[0] }
513
+ : requestArgs[0] || {};
514
+ const options = {
515
+ ...requestOptions,
516
+ stateDir: stateDBDir,
517
+ blockHeight,
518
+ };
519
+ validateImporterOptions(options);
508
520
  !stateSyncExport ||
509
521
  Fail`Snapshot already in progress for ${stateSyncExport.blockHeight}`;
510
522
  !blockingSend || Fail`Cannot restore snapshot after init`;
511
523
  console.info(
512
524
  'Restoring SwingSet state from snapshot at block height',
513
525
  blockHeight,
526
+ 'with options',
527
+ JSON.stringify(requestOptions),
514
528
  );
515
- return performStateSyncImport(
516
- { exportDir, stateDir: stateDBDir, blockHeight },
517
- { fs: { ...fs, ...fsPromises }, pathResolve, log: null },
518
- );
529
+ return performStateSyncImport(options, {
530
+ fs: { ...fs, ...fsPromises },
531
+ pathResolve,
532
+ log: null,
533
+ });
519
534
  }
520
535
  case 'initiate': {
521
536
  !stateSyncExport ||
522
537
  Fail`Snapshot already in progress for ${stateSyncExport.blockHeight}`;
523
538
 
539
+ const requestOptions = requestArgs[0] || {};
540
+
541
+ validateExporterOptions({
542
+ ...requestOptions,
543
+ stateDir: stateDBDir,
544
+ exportDir: '',
545
+ blockHeight,
546
+ });
547
+
524
548
  const exportData =
525
549
  /** @type {Required<NonNullable<typeof stateSyncExport>>} */ ({
526
550
  blockHeight,
@@ -563,9 +587,12 @@ export default async function main(progname, args, { env, homedir, agcc }) {
563
587
  console.info(
564
588
  'Initiating SwingSet state snapshot at block height',
565
589
  blockHeight,
590
+ 'with options',
591
+ JSON.stringify(requestOptions),
566
592
  );
567
593
  exportData.exporter = spawnSwingStoreExport(
568
594
  {
595
+ ...requestOptions,
569
596
  stateDir: stateDBDir,
570
597
  exportDir: exportData.exportDir,
571
598
  blockHeight,
@@ -649,7 +676,7 @@ export default async function main(progname, args, { env, homedir, agcc }) {
649
676
  }
650
677
 
651
678
  // Snapshot actions are specific to cosmos chains and handled here
652
- case ActionType.COSMOS_SNAPSHOT: {
679
+ case ActionType.SWING_STORE_EXPORT: {
653
680
  const { blockHeight, request, args: requestArgs } = action;
654
681
  writeSlogObject?.({
655
682
  type: 'cosmic-swingset-snapshot-start',
@@ -658,7 +685,11 @@ export default async function main(progname, args, { env, homedir, agcc }) {
658
685
  args: requestArgs,
659
686
  });
660
687
 
661
- const resultP = handleCosmosSnapshot(blockHeight, request, requestArgs);
688
+ const resultP = handleSwingStoreExport(
689
+ blockHeight,
690
+ request,
691
+ requestArgs,
692
+ );
662
693
 
663
694
  resultP.then(
664
695
  result => {
@@ -21,6 +21,10 @@ import { makeProcessValue } from './helpers/process-value.js';
21
21
 
22
22
  /** @typedef {'current' | 'archival' | 'debug'} SwingStoreExportMode */
23
23
 
24
+ // ExportManifestFilename is the manifest filename which must be synchronized
25
+ // with the golang SwingStoreExportsHandler in golang/cosmos/x/swingset/keeper/swing_store_exports_handler.go
26
+ export const ExportManifestFileName = 'export-manifest.json';
27
+
24
28
  // eslint-disable-next-line jsdoc/require-returns-check
25
29
  /**
26
30
  * @param {string | undefined} mode
@@ -73,6 +77,25 @@ const checkExportMode = mode => {
73
77
  * @property {boolean} [includeExportData] whether to include an artifact for the export data in the export
74
78
  */
75
79
 
80
+ /**
81
+ * @param {object} options
82
+ * @returns {asserts options is StateSyncExporterOptions}
83
+ */
84
+ export const validateExporterOptions = options => {
85
+ typeof options === 'object' || Fail`options is not an object`;
86
+ typeof options.stateDir === 'string' ||
87
+ Fail`required stateDir option not a string`;
88
+ typeof options.exportDir === 'string' ||
89
+ Fail`required exportDir option not a string`;
90
+ options.blockHeight == null ||
91
+ typeof options.blockHeight === 'number' ||
92
+ Fail`optional blockHeight option not a number`;
93
+ checkExportMode(options.exportMode);
94
+ options.includeExportData == null ||
95
+ typeof options.includeExportData === 'boolean' ||
96
+ Fail`optional includeExportData option not a boolean`;
97
+ };
98
+
76
99
  /**
77
100
  * @param {StateSyncExporterOptions} options
78
101
  * @param {object} powers
@@ -113,7 +136,7 @@ export const initiateSwingStoreExport = (
113
136
  const cleanup = [];
114
137
 
115
138
  const exportDone = (async () => {
116
- const manifestPath = pathResolve(exportDir, 'export-manifest.json');
139
+ const manifestPath = pathResolve(exportDir, ExportManifestFileName);
117
140
  const manifestFile = await open(manifestPath, 'wx');
118
141
  cleanup.push(async () => manifestFile.close());
119
142
 
@@ -17,6 +17,7 @@ import { importSwingStore } from '@agoric/swing-store';
17
17
 
18
18
  import { isEntrypoint } from './helpers/is-entrypoint.js';
19
19
  import { makeProcessValue } from './helpers/process-value.js';
20
+ import { ExportManifestFileName } from './export-kernel-db.js';
20
21
 
21
22
  /**
22
23
  * @typedef {object} StateSyncImporterOptions
@@ -26,6 +27,24 @@ import { makeProcessValue } from './helpers/process-value.js';
26
27
  * @property {boolean} [includeHistorical] whether to include historical artifacts in the export
27
28
  */
28
29
 
30
+ /**
31
+ * @param {object} options
32
+ * @returns {asserts options is StateSyncImporterOptions}
33
+ */
34
+ export const validateImporterOptions = options => {
35
+ typeof options === 'object' || Fail`options is not an object`;
36
+ typeof options.stateDir === 'string' ||
37
+ Fail`required stateDir option not a string`;
38
+ typeof options.exportDir === 'string' ||
39
+ Fail`required exportDir option not a string`;
40
+ options.blockHeight == null ||
41
+ typeof options.blockHeight === 'number' ||
42
+ Fail`optional blockHeight option not a number`;
43
+ options.includeHistorical == null ||
44
+ typeof options.includeHistorical === 'boolean' ||
45
+ Fail`optional includeHistorical option not a boolean`;
46
+ };
47
+
29
48
  /**
30
49
  * @param {StateSyncImporterOptions} options
31
50
  * @param {object} powers
@@ -52,7 +71,7 @@ export const performStateSyncImport = async (
52
71
  return resolvedPath;
53
72
  };
54
73
 
55
- const manifestPath = safeExportFileResolve('export-manifest.json');
74
+ const manifestPath = safeExportFileResolve(ExportManifestFileName);
56
75
  /** @type {Readonly<import('./export-kernel-db.js').StateSyncManifest>} */
57
76
  const manifest = await readFile(manifestPath, { encoding: 'utf-8' }).then(
58
77
  data => JSON.parse(data),
@@ -683,7 +683,7 @@ export async function launch({
683
683
 
684
684
  // Handle block related actions
685
685
  // Some actions that are integration specific may be handled by the caller
686
- // For example COSMOS_SNAPSHOT is handled in chain-main.js
686
+ // For example SWING_STORE_EXPORT is handled in chain-main.js
687
687
  async function doBlockingSend(action) {
688
688
  await null;
689
689
  // blockManagerConsole.warn(