Skip to content

Commit

Permalink
Merge pull request #8153 from Agoric/4645-end-cycles
Browse files Browse the repository at this point in the history
end package cycles
  • Loading branch information
turadg authored Aug 13, 2023
2 parents 6de5f1d + 7453fa3 commit 8169e6c
Show file tree
Hide file tree
Showing 46 changed files with 337 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: sudo apt install -y graphviz

- name: Check for cycles
run: scripts/check-dependency-cycles.sh 1
run: scripts/check-dependency-cycles.sh

##################
# Lint tests
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"packages/*",
"packages/wallet/*"
],
"rejectCycles": true,
"useWorkspaces": true,
"version": "independent"
}
1 change: 1 addition & 0 deletions packages/SwingSet/src/controller/initializeSwingset.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export async function loadSwingsetConfigFile(configPath) {
Fail`bootstrap vat ${config.bootstrap} not found in ${configPath}`;
return config;
} catch (e) {
console.error(`failed to load ${configPath}`);
if (e.code === 'ENOENT') {
return null;
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/builders/scripts/inter-protocol/init-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from '@agoric/inter-protocol/src/proposals/core-proposal.js';
import { makeInstallCache } from '@agoric/inter-protocol/src/proposals/utils.js';

// TODO end inter-package filesystem references https://github.com/Agoric/agoric-sdk/issues/8178

/** @type {Record<string, Record<string, [string, string]>>} */
const installKeyGroups = {
econCommittee: {
Expand Down
2 changes: 1 addition & 1 deletion packages/builders/scripts/vats/init-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const defaultProposalBuilder = async ({ publishRef, install }) =>
installKeys: {
provisionPool: publishRef(
install(
'@agoric/vats/src/provisionPool.js',
'@agoric/inter-protocol/src/provisionPool.js',
'../bundles/bundle-provisionPool.js',
),
),
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy-script-support/src/externalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export {};
* @param {string} srcSpec
* @param {string} bundlePath
* @param {any} [opts]
* @returns {ManifestBundleRef}
* @returns {Promise<ManifestBundleRef>}
*/

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/deploy-script-support/src/getBundlerMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import { E } from '@endo/far';
import url from 'url';

/** @typedef {ReturnType<import('./endo-pieces-contract.js')['start']>['publicFacet']} BundleMaker */

export const makeGetBundlerMaker =
(homeP, { lookup, bundleSource }) =>
async ({
BUNDLER_MAKER_LOOKUP = JSON.stringify(['scratch', 'bundlerMaker']),
log = console.log,
} = {}) => {
const { board: optionalBoard, zoe, scratch } = await homeP;
/** @type {() => Promise<BundleMaker>} */
const lookupOrCreate = async () => {
// Locate the bundler maker if any already exists at the given path.
let bundlerMaker = await lookup(JSON.parse(BUNDLER_MAKER_LOOKUP));
Expand Down
41 changes: 39 additions & 2 deletions packages/deploy-script-support/src/writeCoreProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ import { createBundles } from '@agoric/internal/src/node/createBundles.js';
import { defangAndTrim, mergePermits, stringify } from './code-gen.js';
import { makeCoreProposalBehavior, permits } from './coreProposalBehavior.js';

/**
* @callback WriteCoreProposal
* @param {string} filePrefix
* @param {import('./externalTypes.js').ProposalBuilder} proposalBuilder
* @returns {Promise<void>}
*/

/**
*
* @param {*} homeP
* @param {*} endowments
* @param {{
* getBundlerMaker: () => Promise<import('./getBundlerMaker.js').BundleMaker>,
* getBundleSpec: (...args: *) => Promise<import('./externalTypes.js').ManifestBundleRef>,
* log?: typeof console.log,
* writeFile?: typeof fs.promises.writeFile
* }} io
* @returns {WriteCoreProposal}
*/
export const makeWriteCoreProposal = (
homeP,
endowments,
Expand Down Expand Up @@ -50,8 +69,18 @@ export const makeWriteCoreProposal = (
};
};

let mutex = Promise.resolve();
let mutex =
/** @type {Promise<import('./externalTypes.js').ManifestBundleRef | undefined>} */ (
Promise.resolve()
);
/** @type {WriteCoreProposal} */
const writeCoreProposal = async (filePrefix, proposalBuilder) => {
/**
*
* @param {string} entrypoint
* @param {string} [bundlePath]
* @returns {Promise<NodeModule>}
*/
const getBundle = async (entrypoint, bundlePath) => {
if (!bundlePath) {
return bundleSource(pathResolve(entrypoint));
Expand All @@ -62,7 +91,14 @@ export const makeWriteCoreProposal = (
return ns.default;
};

// Install an entrypoint.
/**
* Install an entrypoint.
*
* @param {string} entrypoint
* @param {string} [bundlePath]
* @param [opts]
* @returns {Promise<import('./externalTypes.js').ManifestBundleRef>}
*/
const install = async (entrypoint, bundlePath, opts) => {
const bundle = getBundle(entrypoint, bundlePath);

Expand All @@ -71,6 +107,7 @@ export const makeWriteCoreProposal = (
// console.log('installing', { filePrefix, entrypoint, bundlePath });
return getBundleSpec(bundle, getBundler, opts);
});
// @ts-expect-error xxx mutex type narrowing
return mutex;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ test('getBundlerMaker - already made', async t => {
const getBundlerMaker = makeGetBundlerMaker({}, { lookup });

const bundler = await getBundlerMaker({ log: t.log });
// @ts-expect-error mock lookup result
t.is(bundler, 'BUNDLER_MAKER_FOUND');
});

test('getBundlerMaker - not yet made', async t => {
/** @type {any} */
let bundlerMaker;
const zoe = {
install: async b => {
Expand Down
1 change: 0 additions & 1 deletion packages/governance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"import-meta-resolve": "^2.2.1"
},
"devDependencies": {
"@agoric/vats": "^0.15.1",
"@endo/bundle-source": "^2.5.2",
"@endo/init": "^0.5.57",
"ava": "^5.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';

import {
ChoiceMethod,
QuorumRule,
ElectionType,
QuorumRule,
coerceQuestionSpec,
} from '../../../src/index.js';
import { remoteNullMarshaller } from '../utils.js';

const { quote: q } = assert;

Expand Down Expand Up @@ -65,7 +65,7 @@ const committeeBinaryStart = async (
const { creatorFacet: electorateFacet, instance: electorateInstance } =
await E(zoe).startInstance(installations.committee, {}, electorateTerms, {
storageNode: makeMockChainStorageRoot().makeChildNode('thisElectorate'),
marshaller: makeFakeBoard().getReadonlyMarshaller(),
marshaller: remoteNullMarshaller,
});

const choose = { text: 'Choose' };
Expand Down Expand Up @@ -128,7 +128,7 @@ const committeeBinaryTwoQuestions = async (
const { creatorFacet: electorateFacet, instance: electorateInstance } =
await E(zoe).startInstance(installations.committee, {}, electorateTerms, {
storageNode: makeMockChainStorageRoot().makeChildNode('thisElectorate'),
marshaller: makeFakeBoard().getReadonlyMarshaller(),
marshaller: remoteNullMarshaller,
});

const invitations = await E(electorateFacet).getVoterInvitations();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';
import { observeIteration, subscribeEach } from '@agoric/notifier';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { observeIteration, subscribeEach } from '@agoric/notifier';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';

import { makeTerms, MALLEABLE_NUMBER } from './governedContract.js';
import {
CONTRACT_ELECTORATE,
assertContractElectorate,
CONTRACT_ELECTORATE,
} from '../../../src/index.js';
import { remoteNullMarshaller } from '../utils.js';
import { makeTerms, MALLEABLE_NUMBER } from './governedContract.js';

const { quote: q } = assert;

Expand Down Expand Up @@ -79,7 +79,7 @@ const startElectorate = async (zoe, installations, electorateTerms) => {
const { creatorFacet: electorateCreatorFacet, instance: electorateInstance } =
await E(zoe).startInstance(installations.committee, {}, electorateTerms, {
storageNode: makeMockChainStorageRoot().makeChildNode('thisElectorate'),
marshaller: makeFakeBoard().getReadonlyMarshaller(),
marshaller: remoteNullMarshaller,
});
return { electorateCreatorFacet, electorateInstance };
};
Expand Down
12 changes: 12 additions & 0 deletions packages/governance/test/swingsetTests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Far, makeMarshal } from '@endo/marshal';
import { makeExo } from '@agoric/store';

const nullMarshaller = makeMarshal(
_ => null,
_ => Far('dummy'),
);

export const remoteNullMarshaller = makeExo('nullMarshaller', undefined, {
toCapData: val => nullMarshaller.toCapData(val),
fromCapData: slot => nullMarshaller.fromCapData(slot),
});
16 changes: 8 additions & 8 deletions packages/governance/test/unitTests/test-committee.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import '@agoric/zoe/exported.js';

import path from 'path';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/far';
import { makeZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
import bundleSource from '@endo/bundle-source';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { makeZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
import bundleSource from '@endo/bundle-source';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/far';
import path from 'path';

import {
ChoiceMethod,
Expand All @@ -19,6 +18,7 @@ import {
coerceQuestionSpec,
} from '../../src/index.js';
import { documentStorageSchema } from '../../tools/storageDoc.js';
import { remoteNullMarshaller } from '../swingsetTests/utils.js';

const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);
Expand Down Expand Up @@ -51,7 +51,7 @@ const setupContract = async () => {
terms,
{
storageNode: mockChainStorageRoot.makeChildNode('thisElectorate'),
marshaller: makeFakeBoard().getReadonlyMarshaller(),
marshaller: remoteNullMarshaller,
},
);

Expand Down
14 changes: 7 additions & 7 deletions packages/governance/test/unitTests/test-paramGovernance.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import '@agoric/zoe/exported.js';
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';
import { makeNotifierFromAsyncIterable } from '@agoric/notifier';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { makeZoeForTest } from '@agoric/zoe/tools/setup-zoe.js';
import bundleSource from '@endo/bundle-source';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { E } from '@endo/eventual-send';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js';

import { resolve as importMetaResolve } from 'import-meta-resolve';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { MALLEABLE_NUMBER } from '../swingsetTests/contractGovernor/governedContract.js';
import { resolve as importMetaResolve } from 'import-meta-resolve';
import { CONTRACT_ELECTORATE, ParamTypes } from '../../src/index.js';
import { MALLEABLE_NUMBER } from '../swingsetTests/contractGovernor/governedContract.js';
import { remoteNullMarshaller } from '../swingsetTests/utils.js';

const voteCounterRoot = '../../src/binaryVoteCounter.js';
const governedRoot = '../swingsetTests/contractGovernor/governedContract.js';
Expand Down Expand Up @@ -61,7 +61,7 @@ const setUpGovernedContract = async (zoe, electorateTerms, timer) => {
electorateTerms,
{
storageNode: makeMockChainStorageRoot().makeChildNode('thisElectorate'),
marshaller: makeFakeBoard().getReadonlyMarshaller(),
marshaller: remoteNullMarshaller,
},
);

Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/docs/governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ for this contract.

### Provision Pool

In `packages/vats/src/provisionPool.js`:
In `packages/inter-protocol/src/provisionPool.js`:

| Governance Key | Type | WP? |
| ----------------------- | :------ | --- |
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@agoric/store": "^0.9.2",
"@agoric/time": "^0.3.2",
"@agoric/vat-data": "^0.5.2",
"@agoric/vats": "^0.15.1",
"@agoric/zoe": "^0.26.2",
"@endo/captp": "^3.1.2",
"@endo/eventual-send": "^0.17.3",
Expand All @@ -51,7 +52,6 @@
"@agoric/smart-wallet": "^0.5.3",
"@agoric/swingset-liveslots": "^0.10.2",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/vats": "^0.15.1",
"@agoric/zone": "^0.2.2",
"@endo/bundle-source": "^2.5.2",
"@endo/init": "^0.5.57",
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/price/roundsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { isNat, Nat } from '@endo/nat';
import { UnguardedHelperI } from '../typeGuards.js';
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';

const { add, subtract, multiply, floorDivide, ceilDivide, isGTE } = natSafeMath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ harden(meta);
* TODO: ERef<GovernedCreatorFacet<ProvisionCreator>>
* @param {ZCF<ProvisionTerms>} zcf
* @param {{
* poolBank: import('@endo/far').ERef<import('./vat-bank.js').Bank>;
* poolBank: import('@endo/far').ERef<
* import('@agoric/vats/src/vat-bank.js').Bank
* >;
* initialPoserInvitation: Invitation;
* storageNode: StorageNode;
* marshaller: Marshaller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { AmountMath, BrandShape } from '@agoric/ertp';
import { UnguardedHelperI } from '@agoric/inter-protocol/src/typeGuards.js';
import { UnguardedHelperI } from '@agoric/internal/src/typeGuards.js';
import {
observeIteration,
observeNotifier,
Expand All @@ -12,14 +12,14 @@ import {
makeScalarBigSetStore,
prepareExoClassKit,
} from '@agoric/vat-data';
import { PowerFlags } from '@agoric/vats/src/walletFlags.js';
import {
makeRecorderTopic,
PublicTopicShape,
makeRecorderTopic,
} from '@agoric/zoe/src/contractSupport/topics.js';
import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
import { E } from '@endo/far';
import { deeplyFulfilled, Far } from '@endo/marshal';
import { PowerFlags } from './walletFlags.js';
import { Far, deeplyFulfilled } from '@endo/marshal';

const { details: X, quote: q, Fail } = assert;

Expand Down Expand Up @@ -55,7 +55,7 @@ const { details: X, quote: q, Fail } = assert;
* @param {(depositBank: ERef<Bank>) => Promise<void>} sendInitialPayment
* @param {() => void} onProvisioned
*
* @typedef {import('./vat-bank.js').Bank} Bank
* @typedef {import('@agoric/vats/src/vat-bank.js').Bank} Bank
*/
export const makeBridgeProvisionTool = (sendInitialPayment, onProvisioned) => {
/** @param {ProvisionPoolKitReferences} refs */
Expand Down
Loading

0 comments on commit 8169e6c

Please sign in to comment.