Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cosmic-swingset): Introduce inquisitor.mjs #10807

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5296f2c
chore(swing-store): Fix documentation typos
gibson042 Dec 13, 2024
25998fb
chore(swing-store): Add type SwingStoreOptions
gibson042 Dec 13, 2024
06c6fc5
chore(swing-store): Narrow AnyIterableIterator to AnyIterable
gibson042 Dec 13, 2024
7396efd
feat(internal): Add `pick` utility
gibson042 Dec 16, 2024
712f5a5
refactor(swing-store): Use new `pick` utility
gibson042 Dec 16, 2024
70e0945
feat(cosmic-swingset): Expose a controller and associated helpers fro…
gibson042 Dec 16, 2024
dd54fd1
refactor(swing-store): Extract all makeSwingStore options up front
gibson042 Dec 16, 2024
59f669c
feat(swing-store): Add options for opening swing-stores
gibson042 Dec 16, 2024
1048a92
feat(cosmic-swingset): Add `getNextKey` support to BufferedStorage
gibson042 Jan 7, 2025
250c1dd
feat(internal): Add `defineName` utility
gibson042 Dec 16, 2024
4ceea26
feat(cosmic-swingset): Introduce inquisitor.mjs
gibson042 Jan 7, 2025
009b113
chore: Add lint coverage for tools/
gibson042 Jan 7, 2025
e39c802
feat(internal): Generalize single-level `pick` utility to recursive `…
gibson042 Feb 11, 2025
d255a98
fixup! feat(internal): Generalize single-level `pick` utility to recu…
gibson042 Feb 11, 2025
090a6c7
fixup! feat(internal): Generalize single-level `pick` utility to recu…
gibson042 Feb 14, 2025
c800d1c
fixup! feat(cosmic-swingset): Expose a controller and associated help…
gibson042 Feb 14, 2025
2f4ef9b
fixup! chore: Add lint coverage for tools/
gibson042 Feb 14, 2025
12e96c8
fixup! feat(cosmic-swingset): Expose a controller and associated help…
gibson042 Feb 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default [
},

tsconfigRootDir: __dirname,
extraFileExtensions: ['.cjs'],
extraFileExtensions: ['.cjs', '.mjs'],
},
},

Expand Down Expand Up @@ -182,6 +182,7 @@ export default [
files: [
'packages/*/src/**/*.js',
'packages/*/tools/**/*.js',
'packages/*/tools/**/*.mjs',
'packages/*/*.js',
'packages/wallet/api/src/**/*.js',
],
Expand Down
3 changes: 2 additions & 1 deletion packages/SwingSet/tools/run-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { makeQueue } from '@endo/stream';
*/
export const makeRunUtils = (controller, harness) => {
const mutex = makeQueue();
mutex.put('dummy result'); // so the first `await mutex.get()` doesn't hang

const logRunFailure = reason =>
console.log('controller.run() failure', reason);
mutex.put(controller.run().catch(logRunFailure));

/**
* Wait for exclusive access to the controller, then before relinquishing that access,
Expand Down
1 change: 1 addition & 0 deletions packages/boot/test/upgrading/upgrade-vats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const makeScenario = async (
t.teardown(c.shutdown);
c.pinVatRoot('bootstrap');

await c.run();
const runUtils = makeRunUtils(c);
return runUtils;
};
Expand Down
1 change: 1 addition & 0 deletions packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export const makeSwingsetTestKit = async (

console.timeLog('makeBaseSwingsetTestKit', 'buildSwingset');

await controller.run();
gibson042 marked this conversation as resolved.
Show resolved Hide resolved
const runUtils = makeBootstrapRunUtils(controller, harness);

const buildProposal = makeProposalExtractor({
Expand Down
6 changes: 5 additions & 1 deletion packages/cosmic-swingset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@
"tmp": "^0.2.1"
},
"devDependencies": {
"@agoric/kmarshal": "^0.1.0",
"@endo/eventual-send": "^1.2.8",
"ava": "^5.3.0",
"c8": "^10.1.2"
"better-sqlite3": "^9.1.1",
"c8": "^10.1.2",
"ses": "^1.10.0"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 6 additions & 2 deletions packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
makeReadCachingStorage,
} from './helpers/bufferedStorage.js';
import stringify from './helpers/json-stable-stringify.js';
import { launch } from './launch-chain.js';
import { launch, launchAndShareInternals } from './launch-chain.js';
import { makeProcessValue } from './helpers/process-value.js';
import {
spawnSwingStoreExport,
Expand Down Expand Up @@ -228,6 +228,7 @@ export const makeQueueStorage = (call, queuePath) => {
* slogSender?: ERef<EReturn<typeof makeSlogSender>>,
* swingStore?: import('@agoric/swing-store').SwingStore,
* vatconfig?: Parameters<typeof launch>[0]['vatconfig'],
* withInternals?: boolean,
gibson042 marked this conversation as resolved.
Show resolved Hide resolved
* }} [options.testingOverrides]
*/
export const makeLaunchChain = (
Expand Down Expand Up @@ -523,7 +524,10 @@ export const makeLaunchChain = (
? makeArchiveTranscript(vatTranscriptArchiveDir, fsPowers)
: undefined;

const s = await launch({
const launcher = testingOverrides.withInternals
? launchAndShareInternals
: launch;
const s = await launcher({
actionQueueStorage,
highPriorityQueueStorage,
swingStore: testingOverrides.swingStore,
Expand Down
37 changes: 24 additions & 13 deletions packages/cosmic-swingset/src/helpers/bufferedStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ export const makeKVStoreFromMap = map => {
let priorKeyIndex;

const ensureSorted = () => {
if (!sortedKeys) {
sortedKeys = [...map.keys()];
sortedKeys.sort(compareByCodePoints);
}
if (sortedKeys) return;
sortedKeys = [...map.keys()].sort(compareByCodePoints);
};

const clearGetNextKeyCache = () => {
Expand All @@ -101,9 +99,16 @@ export const makeKVStoreFromMap = map => {
assert.typeof(priorKey, 'string');
ensureSorted();
const start =
compareByCodePoints(priorKeyReturned, priorKey) <= 0
? priorKeyIndex + 1
: 0;
priorKeyReturned === undefined
? 0
: // If priorKeyReturned <= priorKey, start just after it.
(compareByCodePoints(priorKeyReturned, priorKey) <= 0 &&
priorKeyIndex + 1) ||
// Else if priorKeyReturned immediately follows priorKey, start at
// its index (and expect to return it again).
(sortedKeys.at(priorKeyIndex - 1) === priorKey && priorKeyIndex) ||
// Otherwise, start at the beginning.
0;
for (let i = start; i < sortedKeys.length; i += 1) {
const key = sortedKeys[i];
if (compareByCodePoints(key, priorKey) <= 0) continue;
Expand Down Expand Up @@ -226,7 +231,8 @@ export function makeBufferedStorage(kvStore, listeners = {}) {

// To avoid confusion, additions and deletions are prevented from sharing
// the same key at any given time.
const additions = new Map();
/** @type {Map<string, T> & KVStore<T>} */
const additions = provideEnhancedKVStore(makeKVStoreFromMap(new Map()));
const deletions = new Set();

/** @type {KVStore<T>} */
Expand Down Expand Up @@ -257,13 +263,18 @@ export function makeBufferedStorage(kvStore, listeners = {}) {
deletions.add(key);
if (onPendingDelete !== undefined) onPendingDelete(key);
},

/**
* @param {string} previousKey
*/
getNextKey(previousKey) {
assert.typeof(previousKey, 'string');
throw Error('not implemented');
const bufferedNextKey = additions.getNextKey(previousKey);
let nextKey = kvStore.getNextKey(previousKey);
while (nextKey !== undefined) {
if (bufferedNextKey !== undefined) {
if (compareByCodePoints(bufferedNextKey, nextKey) <= 0) break;
}
if (!deletions.has(nextKey)) return nextKey;
nextKey = kvStore.getNextKey(nextKey);
}
return bufferedNextKey;
},
};
function commit() {
Expand Down
25 changes: 23 additions & 2 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '@agoric/swingset-vat';
import { waitUntilQuiescent } from '@agoric/internal/src/lib-nodejs/waitUntilQuiescent.js';
import { openSwingStore } from '@agoric/swing-store';
import { BridgeId as BRIDGE_ID } from '@agoric/internal';
import { attenuate, BridgeId as BRIDGE_ID } from '@agoric/internal';
import { makeWithQueue } from '@agoric/internal/src/queue.js';
import * as ActionType from '@agoric/internal/src/action-types.js';

Expand Down Expand Up @@ -333,7 +333,7 @@ export async function buildSwingset(
/**
* @param {LaunchOptions} options
*/
export async function launch({
export async function launchAndShareInternals({
actionQueueStorage,
highPriorityQueueStorage,
kernelStateDBDir,
Expand Down Expand Up @@ -1263,5 +1263,26 @@ export async function launch({
writeSlogObject,
savedHeight,
savedChainSends: JSON.parse(kvStore.get(getHostKey('chainSends')) || '[]'),
// NOTE: to be used only for testing purposes!
internals: {
controller,
bridgeInbound,
timer,
},
};
}

/**
* @param {LaunchOptions} options
* @returns {Promise<Omit<Awaited<ReturnType<typeof launchAndShareInternals>>, 'internals'>>}
*/
export async function launch(options) {
const launchResult = await launchAndShareInternals(options);
return attenuate(launchResult, {
blockingSend: 'pick',
shutdown: 'pick',
writeSlogObject: 'pick',
savedHeight: 'pick',
savedChainSends: 'pick',
});
}
Loading
Loading