Skip to content

Commit

Permalink
fix(types): board values (#9332)
Browse files Browse the repository at this point in the history
## Description

Follow up to #8774

Fix the Board types

### Security Considerations

<!-- Does this change introduce new assumptions or dependencies that, if
violated, could introduce security vulnerabilities? How does this PR
change the boundaries between mutually-suspicious components? What new
authorities are introduced by this change, perhaps by new API calls?
-->

### Scaling Considerations

<!-- Does this change require or encourage significant increase in
consumption of CPU cycles, RAM, on-chain storage, message exchanges, or
other scarce resources? If so, can that be prevented or mitigated? -->

### Documentation Considerations

<!-- Give our docs folks some hints about what needs to be described to
downstream users.

Backwards compatibility: what happens to existing data or deployments
when this code is shipped? Do we need to instruct users to do something
to upgrade their saved data? If there is no upgrade path possible, how
bad will that be for users?

-->

### Testing Considerations

<!-- Every PR should of course come with tests of its own functionality.
What additional tests are still needed beyond those unit tests? How does
this affect CI, other test automation, or the testnet?
-->

### Upgrade Considerations

The one behavior change is to omit non-remotables from the board, but
nothing should have been doing that and if it was this error will help.

Of course that doesn't need to go out in any particular chain upgrade,
but it could to minimize divergence from master until,
- #9252
  • Loading branch information
mergify[bot] committed May 10, 2024
2 parents 4685ea9 + 4196da3 commit 9b5b61a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/inter-protocol/src/proposals/addAssetToVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const publishInterchainAssetFromBoardId = async (
assert.typeof(issuerBoardId, 'string');
assert.typeof(issuerName, 'string');

const issuer = await E(board).getValue(issuerBoardId);
const issuer = /** @type {Issuer} */ (await E(board).getValue(issuerBoardId));
const brand = await E(issuer).getBrand();

return Promise.all([
Expand Down
6 changes: 3 additions & 3 deletions packages/smart-wallet/src/marshal-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DEFAULT_PREFIX } from '@agoric/vats/src/lib-board.js';
const { Fail, quote: q } = assert;

/**
* @import {PassableCap} from '@endo/marshal';
* @import {PassableCap, RemotableObject} from '@endo/marshal';
* @import {Key} from '@endo/patterns';
* @import {BoardId} from '@agoric/vats/src/lib-board.js';
*/
Expand Down Expand Up @@ -212,14 +212,14 @@ export const makeExportContext = () => {
purseEntries: walletObjects.purse.bySlot.entries,
/**
* @param {BoardId} id
* @param {PassableCap} val
* @param {RemotableObject} val
*/
initBoardId: (id, val) => {
initSlotVal(boardObjects, id, val);
},
/**
* @param {BoardId} id
* @param {PassableCap} val
* @param {RemotableObject} val
*/
ensureBoardId: (id, val) => {
if (boardObjects.byVal.has(val)) {
Expand Down
1 change: 0 additions & 1 deletion packages/smart-wallet/test/marshal-contexts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const makeOnChainWallet = board => {
getCurrentAmount: () => harden({ brand, value: 100 }),
});
// only for private brands
// context.initBrandId(boardId, brand);
context.initBoardId(boardId, brand);
// @ts-expect-error mock purse
context.initPurseId(name, purse); // TODO: strong id rather than name?
Expand Down
18 changes: 10 additions & 8 deletions packages/vats/src/lib-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
prepareRecorder,
} from '@agoric/zoe/src/contractSupport/recorder.js';
import { E, Far } from '@endo/far';
import { makeMarshal } from '@endo/marshal';
import { isRemotable, makeMarshal } from '@endo/marshal';

import { crc6 } from './crc.js';

/**
* @import {PassableCap} from '@endo/marshal';
* @import {RemotableObject} from '@endo/pass-style';
* @import {Key} from '@endo/patterns');
*/

Expand Down Expand Up @@ -102,13 +102,13 @@ const initDurableBoardState = (
const immutable = { prefix, crcDigits };

const lastSequence = BigInt(initSequence);
/** @type {MapStore<BoardId, PassableCap>} */
/** @type {MapStore<BoardId, RemotableObject>} */
const idToVal = makeScalarBigMapStore('idToVal', {
durable: true,
keyShape: IdShape,
valueShape: ValShape,
});
/** @type {MapStore<PassableCap, BoardId>} */
/** @type {MapStore<RemotableObject, BoardId>} */
const valToId = makeScalarBigMapStore('valToId', {
durable: true,
keyShape: ValShape,
Expand All @@ -130,11 +130,14 @@ const initDurableBoardState = (
// transient marshallers that get GCed when the function completes.

/**
* @param {PassableCap} value
* @param {RemotableObject} value
* @param {BoardState} state
*/
const getId = (value, state) => {
const { idToVal, valToId, prefix, crcDigits } = state;
if (!isRemotable(value)) {
Fail`Board cannot create id for non-remotable`;
}

if (valToId.has(value)) {
return valToId.get(value);
Expand Down Expand Up @@ -267,8 +270,7 @@ export const prepareBoardKit = baggage => {
* `value` for its entire lifetime. For a well-known board, this is
* essentially forever.
*
* @param {PassableCap} value
* @throws if `value` is not a Key in the @agoric/store sense
* @param {RemotableObject} value
*/
getId(value) {
return getId(value, this.state);
Expand Down Expand Up @@ -305,7 +307,7 @@ export const prepareBoardKit = baggage => {
}
return E(firstValue).lookup(...rest);
},
/** @param {PassableCap} val */
/** @param {RemotableObject} val */
has(val) {
const { state } = this;
return state.valToId.has(val);
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet/api/src/findOrMakeInvitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ const makeInvitation = async (
board,
zoe,
) => {
const instance = E(board).getValue(instanceHandleBoardId);
const instance = /** @type {Promise<Instance>} */ (
E(board).getValue(instanceHandleBoardId)
);
const publicFacet = E(zoe).getPublicFacet(instance);
const { method, args = [] } = invitationMaker;

Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/api/test/lib-wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t
const {
board,
automaticRefundInvitation,
autoswapInstallationHandle,
automaticRefundInstance,
wallet,
pursesStateChangeLog,
inboxStateChangeLog,
} = await setupTest(t, { autoswap: true, automaticRefund: true });
const { autoswapInstallation: autoswapInstallationHandle } = t.context;

const { issuer: bucksIssuer } = makeIssuerKit('bucks');
const bucksIssuerBoardId = await E(board).getId(bucksIssuer);
Expand Down

0 comments on commit 9b5b61a

Please sign in to comment.