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

use contract "start" consistently #8045

Merged
merged 3 commits into from
Jul 26, 2023
Merged

use contract "start" consistently #8045

merged 3 commits into from
Jul 26, 2023

Conversation

turadg
Copy link
Member

@turadg turadg commented Jul 12, 2023

Description

While describing contract upgrade to @carlos-kryha I couldn't come up with a good explanation for why upgradable contracts name the start functionprepare.

This keeps the start name and makes an explicit declaration under meta of the upgradability the contract claims.

Security Considerations

n/a

Scaling Considerations

n/a

Documentation Considerations

Any other docs about "prepare" will need to be updated.

This is a breaking change to downstream consumers, but will appear in the changelogs and is trivial to comply with.

Testing Considerations

CI

@turadg turadg changed the title ta/contract start use contract "start" consistently Jul 12, 2023
@turadg turadg force-pushed the ta/contract-start branch 2 times, most recently from 37aa6be to 5fe5330 Compare July 12, 2023 18:42
buildRootObject === undefined ||
Fail`Did you provide a vat bundle instead of a contract bundle?`;
Fail`contract exports missing start/prepare`;
Fail`contract exports missing start`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this break current users of agoric using prepare? Should we communicate this change to our partners?


const areDurable = objectMap(
{ creatorFacet, publicFacet, creatorInvitation },
canBeDurable,
);
const allDurable = Object.values(areDurable).every(Boolean);
if (prepare) {
if (takesBaggage) {
allDurable ||
Fail`values from prepare() must be durable ${areDurable}`;
Copy link
Contributor

@toliaqat toliaqat Jul 12, 2023

Choose a reason for hiding this comment

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

Replace prepare with start in the error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -147,7 +147,7 @@ harden(validateQuestionFromCounter);
* }>}
* @param {import('@agoric/vat-data').Baggage} baggage
*/
export const prepare = async (zcf, privateArgs, baggage) => {
export const start = async (zcf, privateArgs, baggage) => {
trace('prepare');
Copy link
Contributor

Choose a reason for hiding this comment

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

replace prepare with start in trace statements here and bellow in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@turadg
Copy link
Member Author

turadg commented Jul 12, 2023

Closing as we need to support the case of a contract that will eventually be upgradable but isn't already. That is, it takes baggage but doesn't yet return durable facets. Fortunately this was detected in CI because auctioneer.js contract works that way.

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

This works for me.

packages/zoe/src/contractFacet/zcfZygote.js Outdated Show resolved Hide resolved
@turadg turadg force-pushed the ta/contract-start branch 3 times, most recently from 3bd57b9 to f846088 Compare July 24, 2023 16:20
@turadg turadg marked this pull request as ready for review July 24, 2023 21:19
Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

@toliaqat's comments merit a response.

LGTM.

export const meta = {
upgradability: 'canUpgrade',
};

Copy link
Contributor

Choose a reason for hiding this comment

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

harden(meta);

Comment on lines 48 to 62
export const meta = {
privateArgsShape: M.splitRecord(
harden({
marshaller: M.remotable('Marshaller'),
storageNode: StorageNodeShape,
}),
harden({
// only necessary on first invocation, not subsequent
feeMintAccess: FeeMintAccessShape,
initialPoserInvitation: InvitationShape,
initialShortfallInvitation: InvitationShape,
}),
),
upgradability: 'canUpgrade',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const meta = {
privateArgsShape: M.splitRecord(
harden({
marshaller: M.remotable('Marshaller'),
storageNode: StorageNodeShape,
}),
harden({
// only necessary on first invocation, not subsequent
feeMintAccess: FeeMintAccessShape,
initialPoserInvitation: InvitationShape,
initialShortfallInvitation: InvitationShape,
}),
),
upgradability: 'canUpgrade',
};
export const meta = {
privateArgsShape: M.splitRecord(
{
marshaller: M.remotable('Marshaller'),
storageNode: StorageNodeShape,
},
{
// only necessary on first invocation, not subsequent
feeMintAccess: FeeMintAccessShape,
initialPoserInvitation: InvitationShape,
initialShortfallInvitation: InvitationShape,
},
),
upgradability: 'canUpgrade',
};

Copy link
Member Author

@turadg turadg Jul 24, 2023

Choose a reason for hiding this comment

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

thanks. I thought splitRecord required hardened args

Comment on lines 90 to 100
privateArgsShape: M.splitRecord(
harden({
marshaller: M.remotable('Marshaller'),
storageNode: StorageNodeShape,
}),
harden({
// only necessary on first invocation, not subsequent
feeMintAccess: FeeMintAccessShape,
initialPoserInvitation: InvitationShape,
}),
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
privateArgsShape: M.splitRecord(
harden({
marshaller: M.remotable('Marshaller'),
storageNode: StorageNodeShape,
}),
harden({
// only necessary on first invocation, not subsequent
feeMintAccess: FeeMintAccessShape,
initialPoserInvitation: InvitationShape,
}),
),
privateArgsShape: M.splitRecord(
{
marshaller: M.remotable('Marshaller'),
storageNode: StorageNodeShape,
},
{
// only necessary on first invocation, not subsequent
feeMintAccess: FeeMintAccessShape,
initialPoserInvitation: InvitationShape,
},
),

Comment on lines 449 to 450
/** @typedef {Awaited<ReturnType<typeof start>>['publicFacet']} PsmPublicFacet */
harden(start);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** @typedef {Awaited<ReturnType<typeof start>>['publicFacet']} PsmPublicFacet */
harden(start);
harden(start);
/** @typedef {Awaited<ReturnType<typeof start>>['publicFacet']} PsmPublicFacet */

Comment on lines 18 to 32
export const meta = {
privateArgsShape: M.splitRecord(
harden({
poolBank: M.eref(M.remotable('bank')),
storageNode: M.eref(M.remotable('storageNode')),
marshaller: M.eref(M.remotable('marshaller')),
}),
harden({
// only necessary on first invocation, not subsequent
initialPoserInvitation: InvitationShape,
metricsOverride: M.recordOf(M.string()),
}),
),
upgradability: 'canUpgrade',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const meta = {
privateArgsShape: M.splitRecord(
harden({
poolBank: M.eref(M.remotable('bank')),
storageNode: M.eref(M.remotable('storageNode')),
marshaller: M.eref(M.remotable('marshaller')),
}),
harden({
// only necessary on first invocation, not subsequent
initialPoserInvitation: InvitationShape,
metricsOverride: M.recordOf(M.string()),
}),
),
upgradability: 'canUpgrade',
};
export const meta = {
privateArgsShape: M.splitRecord(
{
poolBank: M.eref(M.remotable('bank')),
storageNode: M.eref(M.remotable('storageNode')),
marshaller: M.eref(M.remotable('marshaller')),
},
{
// only necessary on first invocation, not subsequent
initialPoserInvitation: InvitationShape,
metricsOverride: M.recordOf(M.string()),
},
),
upgradability: 'canUpgrade',
};

* buildRootObject: undefined,
* start: ContractStartFn,
* meta?: ContractMeta,
}>} */
Copy link
Contributor

Choose a reason for hiding this comment

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

The formatting looks broken here. Is github confused?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is janky. I must have messed it up.

prettier-plugin-jsdoc would format it as,

  /**
   * @type {() => Promise<
   *   | {
   *       buildRootObject: any;
   *       start: undefined;
   *       meta: undefined;
   *     }
   *   | {
   *       buildRootObject: undefined;
   *       start: ContractStartFn;
   *       meta?: ContractMeta;
   *     }
   * >}
   */

Since that automated our whitespace, I'll address this when we opt packages/zoe into pretty jsdoc

Copy link
Contributor

Choose a reason for hiding this comment

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

I started noticing that VS code is not auto formatting for some packages (i.e. cosmic-swingset). It does for SwingSet. Maybe I started noticing this in cosmic-swingset because I just now made some changes in it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please ignore my comment. I was missing settings file for cosmic-swingset in my project.

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

The formatting of one comment in zcfZygote looks broken. otherwise, looks great.

@turadg turadg added this pull request to the merge queue Jul 26, 2023
Merged via the queue into master with commit ad3aa42 Jul 26, 2023
@turadg turadg deleted the ta/contract-start branch July 26, 2023 19:09
mhofman pushed a commit that referenced this pull request Aug 7, 2023
use contract "start" consistently
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants