-
Notifications
You must be signed in to change notification settings - Fork 212
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
add a CoreEval proposal to a3p-integration #8801
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
A demonstration of how to declare a CoreEvalProposal | ||
|
||
The console output will show errors, because the `restart-vats` proposal is not well maintained. | ||
|
||
Requires manually and checking in the submiission, until https://github.com/Agoric/agoric-3-proposals/issues/87 | ||
```sh | ||
agoric run packages/builders/scripts/vats/restart-vats.js | ||
mkdir a3p-integration/proposals/b:restart-vats/submission | ||
mv restart-vats* a3p-integration/proposals/b:restart-vats/submission | ||
cp $(grep -oh '/.*b1-.*.json' restart-vats*) a3p-integration/proposals/b:restart-vats/submission | ||
git add a3p-integration/proposals/b:restart-vats/submission | ||
``` | ||
|
||
Then look in the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"agoricProposal": { | ||
"type": "/agoric.swingset.CoreEvalProposal", | ||
"source": "subdir" | ||
}, | ||
"type": "module", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@agoric/synthetic-chain": "^0.0.6-4", | ||
"ava": "^5.3.1" | ||
}, | ||
"packageManager": "yarn@4.1.0" | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"consume": { | ||
"contractKits": true, | ||
"governedContractKits": true, | ||
"instancePrivateArgs": true, | ||
"loadCriticalVat": true, | ||
"psmKit": true, | ||
"vatStore": true, | ||
"zoe": "zoe", | ||
"provisioning": "provisioning", | ||
"vaultFactoryKit": true, | ||
"agoricNamesAdmin": "makeCoreProposalBehavior", | ||
"vatAdminSvc": "makeCoreProposalBehavior" | ||
}, | ||
"produce": {}, | ||
"evaluateBundleCap": "makeCoreProposalBehavior", | ||
"installation": { | ||
"produce": "makeCoreProposalBehavior" | ||
}, | ||
"modules": { | ||
"utils": { | ||
"runModuleBehaviors": "makeCoreProposalBehavior" | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. github flags lack of a newline at end of file here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a file move of the output from |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "restart-vats", | ||
"script": "restart-vats.js", | ||
"permit": "restart-vats-permit.json", | ||
"bundles": [ | ||
{ | ||
"entrypoint": "@agoric/vats/src/proposals/restart-vats-proposal.js", | ||
"bundleID": "b1-23367331a30b300c84bc01bccaab0c30ad71bef57308dbc7f3ff7f1f05725d01ba9b3de4a06f937b1834622cb4b45485d2610a3e6cc7f6e5bbf7b57311f91dc1", | ||
"fileName": "/Users/turadg/.agoric/cache/b1-23367331a30b300c84bc01bccaab0c30ad71bef57308dbc7f3ff7f1f05725d01ba9b3de4a06f937b1834622cb4b45485d2610a3e6cc7f6e5bbf7b57311f91dc1.json" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// This is generated by writeCoreProposal; please edit! | ||
/* eslint-disable */ | ||
|
||
const manifestBundleRef = {bundleID:"b1-23367331a30b300c84bc01bccaab0c30ad71bef57308dbc7f3ff7f1f05725d01ba9b3de4a06f937b1834622cb4b45485d2610a3e6cc7f6e5bbf7b57311f91dc1"}; | ||
const getManifestCall = harden([ | ||
"getManifestForRestart", | ||
{ | ||
skip: [ | ||
"auctioneer", | ||
"feeDistributor", | ||
"scaledPriceAuthority-ATOM", | ||
"ATOM-USD_price_feed", | ||
], | ||
}, | ||
]); | ||
const customManifest = { | ||
restartVats: { | ||
consume: { | ||
contractKits: true, | ||
governedContractKits: true, | ||
instancePrivateArgs: true, | ||
loadCriticalVat: true, | ||
provisioning: "provisioning", | ||
psmKit: true, | ||
vatStore: true, | ||
vaultFactoryKit: true, | ||
zoe: "zoe", | ||
}, | ||
produce: {}, | ||
}, | ||
}; | ||
|
||
// Make a behavior function and "export" it by way of script completion value. | ||
// It is constructed by an anonymous invocation to ensure the absence of a global binding | ||
// for makeCoreProposalBehavior, which may not be necessary but preserves behavior pre-dating | ||
// https://github.com/Agoric/agoric-sdk/pull/8712 . | ||
const behavior = (({ | ||
manifestBundleRef, | ||
getManifestCall: [manifestGetterName, ...manifestGetterArgs], | ||
customManifest, | ||
E, | ||
log = console.info, | ||
customRestoreRef, | ||
}) => { | ||
const { entries, fromEntries } = Object; | ||
|
||
/** | ||
* Given an object whose properties may be promise-valued, return a promise | ||
* for an analogous object in which each such value has been replaced with its | ||
* fulfillment. | ||
* This is a non-recursive form of endo `deeplyFulfilled`. | ||
* | ||
* @template T | ||
* @param {{[K in keyof T]: (T[K] | Promise<T[K]>)}} obj | ||
* @returns {Promise<T>} | ||
*/ | ||
const shallowlyFulfilled = async obj => { | ||
if (!obj) { | ||
return obj; | ||
} | ||
const awaitedEntries = await Promise.all( | ||
entries(obj).map(async ([key, valueP]) => { | ||
const value = await valueP; | ||
return [key, value]; | ||
}), | ||
); | ||
return fromEntries(awaitedEntries); | ||
}; | ||
|
||
const makeRestoreRef = (vatAdminSvc, zoe) => { | ||
/** @type {(ref: import\('./externalTypes.js').ManifestBundleRef) => Promise<Installation<unknown>>} */ | ||
const defaultRestoreRef = async bundleRef => { | ||
// extract-proposal.js creates these records, and bundleName is | ||
// the optional name under which the bundle was installed into | ||
// config.bundles | ||
const bundleIdP = | ||
'bundleName' in bundleRef | ||
? E(vatAdminSvc).getBundleIDByName(bundleRef.bundleName) | ||
: bundleRef.bundleID; | ||
const bundleID = await bundleIdP; | ||
const label = bundleID.slice(0, 8); | ||
return E(zoe).installBundleID(bundleID, label); | ||
}; | ||
return defaultRestoreRef; | ||
}; | ||
|
||
/** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} powers */ | ||
const coreProposalBehavior = async powers => { | ||
// NOTE: `powers` is expected to match or be a superset of the above `permits` export, | ||
// which should therefore be kept in sync with this deconstruction code. | ||
// HOWEVER, do note that this function is invoked with at least the *union* of powers | ||
// required by individual moduleBehaviors declared by the manifest getter, which is | ||
// necessary so it can use `runModuleBehaviors` to provide the appropriate subset to | ||
// each one (see ./writeCoreProposal.js). | ||
// Handle `powers` with the requisite care. | ||
const { | ||
consume: { vatAdminSvc, zoe, agoricNamesAdmin }, | ||
evaluateBundleCap, | ||
installation: { produce: produceInstallations }, | ||
modules: { | ||
utils: { runModuleBehaviors }, | ||
}, | ||
} = powers; | ||
|
||
// Get the on-chain installation containing the manifest and behaviors. | ||
log('evaluateBundleCap', { | ||
manifestBundleRef, | ||
manifestGetterName, | ||
vatAdminSvc, | ||
}); | ||
let bcapP; | ||
if ('bundleName' in manifestBundleRef) { | ||
bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName); | ||
} else if ('bundleID' in manifestBundleRef) { | ||
bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID); | ||
} else { | ||
const keys = Reflect.ownKeys(manifestBundleRef).map(key => | ||
typeof key === 'string' ? JSON.stringify(key) : String(key), | ||
); | ||
const keysStr = `[${keys.join(', ')}]`; | ||
throw Error( | ||
`bundleRef must have own bundleName or bundleID, missing in ${keysStr}`, | ||
); | ||
} | ||
const bundleCap = await bcapP; | ||
|
||
const proposalNS = await evaluateBundleCap(bundleCap); | ||
|
||
// Get the manifest and its metadata. | ||
log('execute', { | ||
manifestGetterName, | ||
bundleExports: Object.keys(proposalNS), | ||
}); | ||
const restoreRef = customRestoreRef || makeRestoreRef(vatAdminSvc, zoe); | ||
const { | ||
manifest, | ||
options: rawOptions, | ||
installations: rawInstallations, | ||
} = await proposalNS[manifestGetterName]( | ||
harden({ restoreRef }), | ||
...manifestGetterArgs, | ||
); | ||
|
||
// Await promises in the returned options and installations records. | ||
const [options, installations] = await Promise.all( | ||
[rawOptions, rawInstallations].map(shallowlyFulfilled), | ||
); | ||
|
||
// Publish the installations for our dependencies. | ||
const installationEntries = entries(installations || {}); | ||
if (installationEntries.length > 0) { | ||
const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation'); | ||
await Promise.all( | ||
installationEntries.map(([key, value]) => { | ||
produceInstallations[key].resolve(value); | ||
return E(installAdmin).update(key, value); | ||
}), | ||
); | ||
} | ||
|
||
// Evaluate the manifest. | ||
return runModuleBehaviors({ | ||
// Remember that `powers` may be arbitrarily broad. | ||
allPowers: powers, | ||
behaviors: proposalNS, | ||
manifest: customManifest || manifest, | ||
makeConfig: (name, _permit) => { | ||
log('coreProposal:', name); | ||
return { options }; | ||
}, | ||
}); | ||
}; | ||
|
||
return coreProposalBehavior; | ||
})({ manifestBundleRef, getManifestCall, customManifest, E }); | ||
behavior; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo TODO test of restart-vats |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subdir? not submission?
I'm a little surprised to see the bundle checked in, but I guess that's the current state of the art?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately yes