Skip to content

Commit

Permalink
feat(cosmic-swingset): Allow launch to accept an already-open swing…
Browse files Browse the repository at this point in the history
…Store

...exclusive with swingStoreExportCallback and kernelStateDBDir
  • Loading branch information
gibson042 committed Nov 9, 2024
1 parent b7ed256 commit c65e5b1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
29 changes: 20 additions & 9 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ function computronCounter(
* @typedef {object} LaunchOptions
* @property {import('./helpers/make-queue.js').QueueStorage} actionQueueStorage
* @property {import('./helpers/make-queue.js').QueueStorage} highPriorityQueueStorage
* @property {string} kernelStateDBDir
* @property {string} [kernelStateDBDir]
* @property {import('@agoric/swing-store').SwingStore} [swingStore]
* @property {BufferedKVStore<Mailbox>} mailboxStorage
* TODO: Merge together BufferedKVStore and QueueStorage (get/set/delete/commit/abort)
* @property {() => Promise<unknown>} clearChainSends
Expand Down Expand Up @@ -427,6 +428,7 @@ export async function launch({
actionQueueStorage,
highPriorityQueueStorage,
kernelStateDBDir,
swingStore,
mailboxStorage,
clearChainSends,
replayChainSends,
Expand Down Expand Up @@ -485,14 +487,23 @@ export async function launch({
};
})();

const { kernelStorage, hostStorage } = openSwingStore(kernelStateDBDir, {
traceFile: swingStoreTraceFile,
exportCallback: swingStoreExportSyncCallback,
keepSnapshots,
keepTranscripts,
archiveSnapshot,
archiveTranscript,
});
if (swingStore) {
!swingStoreExportCallback ||
Fail`swingStoreExportCallback is not compatible with a provided swingStore; either drop the former or allow launch to open the latter`;
kernelStateDBDir === undefined ||
kernelStateDBDir === swingStore.internal.dirPath ||
Fail`provided kernelStateDBDir does not match provided swingStore`;
}
const { kernelStorage, hostStorage } =
swingStore ||
openSwingStore(/** @type {string} */ (kernelStateDBDir), {
traceFile: swingStoreTraceFile,
exportCallback: swingStoreExportSyncCallback,
keepSnapshots,
keepTranscripts,
archiveSnapshot,
archiveTranscript,
});
const { kvStore, commit } = hostStorage;

/** @typedef {ReturnType<typeof makeQueue<{context: any, action: any}>>} InboundQueue */
Expand Down
2 changes: 1 addition & 1 deletion packages/swing-store/src/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function makeSwingStoreExporter(dirPath, options = {}) {
function getArtifactNames() {
if (artifactMode !== 'debug') {
// synchronously throw if this DB will not be able to yield all the desired artifacts
const internal = { snapStore, bundleStore, transcriptStore };
const internal = { dirPath, snapStore, bundleStore, transcriptStore };
assertComplete(internal, artifactMode);
}
return generateArtifactNames();
Expand Down
1 change: 1 addition & 0 deletions packages/swing-store/src/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Fail, q } from '@endo/errors';
* @typedef { import('./bundleStore.js').BundleStoreInternal } BundleStoreInternal
*
* @typedef {{
* dirPath: string | null,
* transcriptStore: TranscriptStoreInternal,
* snapStore: SnapStoreInternal,
* bundleStore: BundleStoreInternal,
Expand Down
1 change: 1 addition & 0 deletions packages/swing-store/src/swingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export function makeSwingStore(dirPath, forceReset, options = {}) {

/** @type {import('./internal.js').SwingStoreInternal} */
const internal = harden({
dirPath,
snapStore,
transcriptStore,
bundleStore,
Expand Down

0 comments on commit c65e5b1

Please sign in to comment.