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

reduce imports of @agoric/store #7949

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/ERTP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/notifier": "^0.6.2",
"@agoric/store": "^0.9.2",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/vat-data": "^0.5.2",
"@endo/eventual-send": "^0.17.2",
"@endo/far": "^0.2.18",
"@endo/marshal": "^0.8.5",
"@endo/nat": "^4.1.27",
"@endo/patterns": "^0.2.2",
"@endo/promise-kit": "^0.2.56"
},
"devDependencies": {
"@agoric/swingset-vat": "^0.32.2",
"@endo/bundle-source": "^2.5.1",
"@fast-check/ava": "^1.1.5",
"ava": "^5.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/amountMath.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { passStyleOf, assertRemotable, assertRecord } from '@endo/marshal';

import { M, matches } from '@agoric/store';
import { M, matches } from '@endo/patterns';
import { natMathHelpers } from './mathHelpers/natMathHelpers.js';
import { setMathHelpers } from './mathHelpers/setMathHelpers.js';
import { copySetMathHelpers } from './mathHelpers/copySetMathHelpers.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @jessie-check

import { Fail } from '@agoric/assert';
import { mustMatch } from '@agoric/store';
import { mustMatch } from '@endo/patterns';

import { DisplayInfoShape } from './typeGuards.js';

Expand Down
12 changes: 6 additions & 6 deletions packages/ERTP/src/issuerKit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @jessie-check

import { assert } from '@agoric/assert';
import { assertPattern } from '@agoric/store';
import { assertPattern } from '@endo/patterns';
import { makeScalarBigMapStore } from '@agoric/vat-data';

import { AssetKind, assertAssetKind } from './amountMath.js';
Expand Down Expand Up @@ -127,8 +127,8 @@ export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
*
* @param {Baggage} issuerBaggage
* @param {string} name
* @param {K} [assetKind=AssetKind.NAT]
* @param {AdditionalDisplayInfo} [displayInfo={}]
* @param {K} [assetKind]
* @param {AdditionalDisplayInfo} [displayInfo]
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
* in the middle of an atomic action (which btw should never happen), it
* potentially leaves its ledger in a corrupted state. If this function was
Expand All @@ -155,7 +155,7 @@ export const makeDurableIssuerKit = (
harden(makeDurableIssuerKit);

/**
* @template {AssetKind} [K='nat']
* @template {AssetKind} K
* The name becomes part of the brand in asset descriptions.
* The name is useful for debugging and double-checking
* assumptions, but should not be trusted wrt any external namespace.
Expand All @@ -170,8 +170,8 @@ harden(makeDurableIssuerKit);
* `displayInfo` gives information to the UI on how to display the amount.
*
* @param {string} name
* @param {K} [assetKind='nat']
* @param {AdditionalDisplayInfo} [displayInfo={}]
* @param {K} [assetKind]
* @param {AdditionalDisplayInfo} [displayInfo]
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails
* in the middle of an atomic action (which btw should never happen), it
* potentially leaves its ledger in a corrupted state. If this function was
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/legacy-payment-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check

import { mustMatch } from '@agoric/store';
import { mustMatch } from '@endo/patterns';
import { E } from '@endo/far';
import { AmountMath } from './amountMath.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/mathHelpers/copyBagMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
bagIsSuperbag,
bagUnion,
bagDisjointSubtract,
} from '@agoric/store';
} from '@endo/patterns';
import '../types-ambient.js';

/** @type {CopyBag} */
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/mathHelpers/copySetMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
setIsSuperset,
setDisjointUnion,
setDisjointSubtract,
} from '@agoric/store';
} from '@endo/patterns';
import '../types-ambient.js';

/** @type {CopySet} */
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/mathHelpers/setMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
elementsDisjointSubtract,
coerceToElements,
elementsCompare,
} from '@agoric/store';
} from '@endo/patterns';
import '../types-ambient.js';

// Operations for arrays with unique objects identifying and providing
Expand Down
3 changes: 1 addition & 2 deletions packages/ERTP/src/payment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @jessie-check

import { initEmpty } from '@agoric/store';
import { prepareExoClass } from '@agoric/vat-data';

/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
Expand All @@ -18,7 +17,7 @@ export const preparePaymentKind = (issuerBaggage, name, brand, PaymentI) => {
issuerBaggage,
`${name} payment`,
PaymentI,
initEmpty,
() => harden({}),
{
getAllegedBrand() {
return brand;
Expand Down
3 changes: 1 addition & 2 deletions packages/ERTP/src/paymentLedger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* eslint-disable no-use-before-define */
import { isPromise } from '@endo/promise-kit';
import { mustMatch, M, keyEQ } from '@agoric/store';
import { mustMatch, M, keyEQ } from '@endo/patterns';
import {
provideDurableWeakMapStore,
prepareExo,
Expand All @@ -12,7 +12,6 @@ import { AmountMath } from './amountMath.js';
import { preparePaymentKind } from './payment.js';
import { preparePurseKind } from './purse.js';

import '@agoric/store/exported.js';
import { BrandI, makeIssuerInterfaces } from './typeGuards.js';

/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/purse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { M } from '@agoric/store';
import { M } from '@endo/patterns';
import { prepareExoClassKit, makeScalarBigSetStore } from '@agoric/vat-data';
import { AmountMath } from './amountMath.js';
import { makeTransientNotifierKit } from './transientNotifier.js';
Expand Down
21 changes: 20 additions & 1 deletion packages/ERTP/src/transientNotifier.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
// @jessie-check

import { makeScalarBigWeakMapStore } from '@agoric/vat-data';
import { provideLazy } from '@agoric/store';
import { makeNotifierKit } from '@agoric/notifier';

/**
* Call `provideLazy` to get or make the value associated with the key.
* If there already is one, return that. Otherwise,
* call `makeValue(key)`, remember it as the value for
* that key, and return it.
*
* @template K,V
* @param {WeakMapStore<K,V>} mapStore
* @param {K} key
* @param {(key: K) => V} makeValue
* @returns {V}
*/
const provideLazy = (mapStore, key, makeValue) => {
if (!mapStore.has(key)) {
mapStore.init(key, makeValue(key));
}
return mapStore.get(key);
};
harden(provideLazy);

// Note: Virtual for high cardinality, but *not* durable, and so
// broken across an upgrade.
export const makeTransientNotifierKit = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ERTP/src/typeGuards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check

import { M, matches } from '@agoric/store';
import { M, matches } from '@endo/patterns';

export const BrandShape = M.remotable('Brand');
export const IssuerShape = M.remotable('Issuer');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
import { M } from '@agoric/store';
import { M } from '@endo/patterns';

import { Far } from '@endo/marshal';
import { AmountMath as m, AssetKind } from '../../../src/index.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/docs/vat-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ To enable upgrade, the v1 code must stash important data in durable storage, and
For durable objects, the v1 code must store the "durable kind handle" in durable storage. This is done automatically by `prepareExoClass()` and `prepareExoClassKit()`, but can also be done manually (see [Virtual and Durable Objects](./virtual-objects.md#virtual-and-durable-objects)).

```js
import { M } from '@agoric/store';
import { M } from '@endo/patterns';
const FooI = M.interface('foo', fooMethodGuards);
// someDurableMap should generally be reachable from baggage.
const makeFoo = prepareExoClass(someDurableMap, 'foo', fooI, initFoo, fooMethods);
Expand Down Expand Up @@ -201,7 +201,7 @@ The v2 code wakes up inside the upgrade phase when `buildRootObject(vatPowers, v
Before completion of `buildRootObject()` is indicated (either by returning a non-promise or by fulfilling a returned promise), the v2 code is obligated to redefine every Kind that was created by the v1 code. If any durable Kinds are defined incompletely or left undefined by the time of that indication, the upgrade fails and the vat is rolled back to v1.

```js
import { M } from '@agoric/store';
import { M } from '@endo/patterns';
// fooMethodGuards and fooMethods must match or be a superset of their v1 analogs.
const FooI = M.interface('foo', fooMethodGuards);
// someDurableMap is `baggage` or was retrieved from it.
Expand Down
1 change: 1 addition & 0 deletions packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@endo/init": "^0.5.56",
"@endo/marshal": "^0.8.5",
"@endo/nat": "^4.1.27",
"@endo/patterns": "^0.2.2",
"@endo/promise-kit": "^0.2.56",
"@endo/ses-ava": "^0.2.40",
"@endo/zip": "^0.2.31",
Expand Down
14 changes: 9 additions & 5 deletions packages/SwingSet/src/kernel/state/kernelKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export function commaSplit(s) {
return s.split(',');
}

/**
* @param {unknown} m
* @returns {asserts m is string}
*/
function insistMeterID(m) {
assert.typeof(m, 'string');
assert.equal(m[0], 'm');
Expand Down Expand Up @@ -553,14 +557,16 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {
* Allocate a new koid.
*
* @param {string} ownerID
* @param {undefined | bigint} id
erights marked this conversation as resolved.
Show resolved Hide resolved
* @param {bigint} [id]
* @returns {string}
*/
function addKernelObject(ownerID, id = undefined) {
// providing id= is only for unit tests
insistVatID(ownerID);
if (id === undefined) {
id = Nat(BigInt(getRequired('ko.nextID')));
// XXX https://github.com/Agoric/agoric-sdk/issues/4620
assert.typeof(id, 'bigint');
kvStore.set('ko.nextID', `${id + 1n}`);
}
kdebug(`Adding kernel object ko${id} for ${ownerID}`);
Expand Down Expand Up @@ -988,11 +994,9 @@ export default function makeKernelKeeper(kernelStorage, kernelSlog) {
insistMeterID(meterID);
assert.typeof(delta, 'bigint');
Nat(delta);
/** @type { bigint | string } */
let remaining = getRequired(`${meterID}.remaining`);
const remaining = getRequired(`${meterID}.remaining`);
if (remaining !== 'unlimited') {
remaining = Nat(BigInt(remaining));
kvStore.set(`${meterID}.remaining`, `${remaining + delta}`);
kvStore.set(`${meterID}.remaining`, `${Nat(BigInt(remaining)) + delta}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/typeGuards.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @jessie-check
import { M } from '@agoric/store';
import { M } from '@endo/patterns';

export const ManagerType = M.or(
'xsnap',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line import/order
import { test } from '../../tools/prepare-test-env-ava.js';

import { M } from '@agoric/store';
import { M } from '@endo/patterns';
import { initSwingStore } from '@agoric/swing-store';
import {
buildVatController,
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@agoric/inter-protocol": "^0.16.1",
"@agoric/internal": "^0.3.2",
"@agoric/smart-wallet": "^0.5.3",
"@agoric/store": "^0.9.2",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/vats": "^0.15.1",
"@agoric/zoe": "^0.26.2",
Expand All @@ -61,6 +60,7 @@
"@endo/init": "^0.5.56",
"@endo/marshal": "^0.8.5",
"@endo/nat": "^4.1.27",
"@endo/patterns": "^0.2.2",
"@endo/promise-kit": "^0.2.56",
"@iarna/toml": "^2.2.3",
"anylogger": "^0.21.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CommanderError, InvalidArgumentError } from 'commander';
import { makeOfferSpecShape } from '@agoric/inter-protocol/src/auction/auctionBook.js';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { objectMap } from '@agoric/internal';
import { M, matches } from '@agoric/store';
import { M, matches } from '@endo/patterns';

// XXX scare away ambient type zombies to fix ScheduleNotification.activeStartTime etc.
// https://github.com/Agoric/agoric-sdk/issues/6512
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ backend. Any passable object can be a cache key or a cache value.

```js
import { makeCache, makeScalarStoreCoordinator } from '@agoric/cache';
import { M } from '@agoric/store';
import { M } from '@endo/patterns';
import { makeScalarBigMapStore } from '@agoric/vat-data';

const store = makeScalarBigMapStore('cache');
Expand Down
3 changes: 2 additions & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"@agoric/swingset-vat": "^0.32.2",
"@agoric/vat-data": "^0.5.2",
"@endo/far": "^0.2.18",
"@endo/marshal": "^0.8.5"
"@endo/marshal": "^0.8.5",
"@endo/patterns": "^0.2.2"
},
"devDependencies": {
"@agoric/zoe": "^0.26.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/test-mvp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Must be first to set up globals
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { M } from '@agoric/store';
import { M } from '@endo/patterns';
import { makeScalarBigMapStore } from '@agoric/vat-data';

import { makeCache } from '../src/cache.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/test-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import test from 'ava';
import { makeChainStorageRoot } from '@agoric/internal/src/lib-chainStorage.js';

import { Far, makeMarshal } from '@endo/marshal';
import { M } from '@agoric/store';
import { M } from '@endo/patterns';
import { makeCache } from '../src/cache.js';
import { makeChainStorageCoordinator } from '../src/store.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/casting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@agoric/internal": "^0.3.2",
"@agoric/notifier": "^0.6.2",
"@agoric/spawner": "^0.6.8",
"@agoric/store": "^0.9.2",
"@cosmjs/encoding": "^0.30.1",
"@cosmjs/proto-signing": "^0.30.1",
"@cosmjs/stargate": "^0.30.1",
Expand All @@ -34,6 +33,7 @@
"@endo/init": "^0.5.56",
"@endo/lockdown": "^0.1.28",
"@endo/marshal": "^0.8.5",
"@endo/patterns": "^0.2.2",
"@endo/promise-kit": "^0.2.56",
"node-fetch": "^2.6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/casting/src/netconfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check

import { mustMatch, M } from '@agoric/store';
import { mustMatch, M } from '@endo/patterns';

// NB: keep type and shape in sync manually until https://github.com/Agoric/agoric-sdk/issues/6160
/**
Expand Down
2 changes: 2 additions & 0 deletions packages/governance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
"@endo/bundle-source": "^2.5.1",
"@endo/captp": "^3.1.1",
"@endo/eventual-send": "^0.17.2",
"@endo/exo": "^0.2.2",
"@endo/far": "^0.2.18",
"@endo/marshal": "^0.8.5",
"@endo/nat": "^4.1.27",
"@endo/patterns": "^0.2.2",
"@endo/promise-kit": "^0.2.56",
"import-meta-resolve": "^2.2.1"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/governance/src/binaryVoteCounter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { makePromiseKit } from '@endo/promise-kit';
import { makeExo, keyEQ, makeScalarMapStore } from '@agoric/store';
import { keyEQ } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { makeScalarMapStore } from '@agoric/vat-data';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { makeScalarMapStore } from '@agoric/vat-data';
import { makeScalarMapStore } from '@agoric/store';

IIUC the purpose of this PR, I'd expect you to prefer to import makeScalarMapStore from @agoric/store, where it originates, rather than @agoric/vat-data which imports and re-exports it. This seems more consistent with your preference (which I share) to import, for example, makeExo from @endo/exo where it originates, rather than @agoric/store, which imports and re-exports it.

Likewise for other similar changes from @agoric/store to @agoric/vat-data below.

FWIW, I plan to migrate @agoric/store to become @endo/store, and to move most of @agoric/zone to @endo/zone. Longer term, I expect such manual use of makeExo and makeScalarMapStore to migrate to using the corresponding Zone APIs. Just FYI; doesn't affect this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I mistakenly had in mind that vat-data sourced the functionality from globalThis and thus didn't entail a package dependency on @agoric/store.

I'll revert the changes that preferred vat-data.

import { E } from '@endo/eventual-send';

import {
Expand Down
2 changes: 1 addition & 1 deletion packages/governance/src/committee.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeStoredPublishKit } from '@agoric/notifier';
import { M } from '@agoric/store';
import { M } from '@endo/patterns';
import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/eventual-send';

Expand Down
Loading
Loading