-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8801 from Agoric/ta/a3p-coreeval
add a CoreEval proposal to a3p-integration
- Loading branch information
Showing
12 changed files
with
2,529 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
5 changes: 5 additions & 0 deletions
5
...dbc7f3ff7f1f05725d01ba9b3de4a06f937b1834622cb4b45485d2610a3e6cc7f6e5bbf7b57311f91dc1.json
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
a3p-integration/proposals/b:restart-vats/submission/restart-vats-permit.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
a3p-integration/proposals/b:restart-vats/submission/restart-vats-plan.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
176 changes: 176 additions & 0 deletions
176
a3p-integration/proposals/b:restart-vats/submission/restart-vats.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
echo TODO test of restart-vats |
Oops, something went wrong.