-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(spawner): rewrite to use createVat, strip down to bare minimum API
This removes all zoe-like functionality from the spawner, leaving a bare install() and spawn() API. This is now effectively a wrapper around createVat(), except that it accepts source code which exports a default function, rather than an export named `buildRootObject`, and it does not return the control facet (`adminNode`) to the caller. Our two cosmic-swingset applications (chain and ag-solo) are updated to create the spawner correctly. Dapps can continue to use the existing API without changes. closes #1343
- Loading branch information
Showing
30 changed files
with
253 additions
and
1,985 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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
// Copyright (C) 2018 Agoric, under Apache License 2.0 | ||
import { Far } from '@agoric/marshal'; | ||
import { makeSpawner } from '@agoric/spawner'; | ||
|
||
function buildRootObject() { | ||
return Far('root', { | ||
buildSpawner(vatAdminSvc) { | ||
return makeSpawner(vatAdminSvc); | ||
}, | ||
}); | ||
} | ||
harden(buildRootObject); | ||
export { buildRootObject }; |
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 |
---|---|---|
@@ -1,4 +1,56 @@ | ||
# Spawner | ||
|
||
The original contractHost, which will be turned into a general purpose | ||
vat spawner now that we have Zoe for most smart contracts. | ||
The "spawner" was the original method for instantiating contract code within | ||
the chain's swingset. This on-chain usage has been entirely superceded by | ||
Zoe, and the chain swingset no longer includes a spawner. | ||
|
||
However, it was also pressed into service in the ag-solo swingset for | ||
executing deploy scripts that need to leave code running after the script | ||
finishes, such as an HTTP API handler. This use case is still active, but | ||
none of the callers need the zoe-like features (comparable contract identity, | ||
source retrieval, issuers, invitations, or seats). These callers now do | ||
something like: | ||
|
||
```js | ||
const bundle = await bundleSource(pathResolve(__dirname, './src/wallet.js')); | ||
const walletInstall = E(spawner).install(bundle); | ||
const walletVat = await E(walletInstall).spawn(args); | ||
``` | ||
|
||
So the spawner is now a stripped-down dynamic-vat creation frontend with the | ||
minimal code necessary to satisfy those callers. | ||
|
||
The spawner expects to be running in a vat. It used to evaluate the submitted | ||
code in its own vat, under "within-vat" metering to protect itself from | ||
runaway guest code. It has been rewritten to evaluate the guest in a new | ||
dynamic vat instead. | ||
|
||
To support a spawner, your swingset must provide it with the `vatAdmin` facet | ||
(to create new vats), and a copy of the `vat-spawned.js` bundle (to install | ||
in the new vat). Your `vat-spawner.js` should look like: | ||
|
||
```js | ||
import { Far } from '@agoric/marshal'; | ||
import { makeSpawner } from '@agoric/spawner'; | ||
function buildRootObject() { | ||
return Far('root', { | ||
buildSpawner(vatAdminSvc) { | ||
return makeSpawner(vatAdminSvc); | ||
} | ||
}); | ||
} | ||
harden(buildRootObject); | ||
export { buildRootObject }; | ||
``` | ||
|
||
And your bootstrap function needs something like this: | ||
|
||
```js | ||
return Far('root', { | ||
async bootstrap(vats, devices) { | ||
const vatAdminSvc = await E(vats.vatAdmin).createVatAdminService( | ||
devices.vatAdmin, | ||
); | ||
const spawner = await E(vats.spawner).buildSpawner(vatAdminSvc); | ||
// ... | ||
``` |
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,33 @@ | ||
/* global __dirname */ | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import 'ses'; | ||
import fs from 'fs'; | ||
import process from 'process'; | ||
import bundleSource from '@agoric/bundle-source'; | ||
|
||
async function writeSourceBundle(contractFilename, outputPath) { | ||
await bundleSource(contractFilename).then(bundle => { | ||
// TODO: fix | ||
// @ts-ignore mkdirSync believes it only accepts 2 arguments. | ||
fs.mkdirSync(`${__dirname}/../bundles`, { recursive: true }, err => { | ||
if (err) throw err; | ||
}); | ||
fs.writeFileSync(outputPath, `export default ${JSON.stringify(bundle)};`); | ||
}); | ||
} | ||
|
||
async function main() { | ||
const contractFilename = `${__dirname}/../src/vat-spawned.js`; | ||
const outputPath = `${__dirname}/../bundles/bundle-spawn.js`; | ||
await writeSourceBundle(contractFilename, outputPath); | ||
} | ||
|
||
main().then( | ||
_ => process.exit(0), | ||
err => { | ||
console.log('error creating spawn bundle:'); | ||
console.log(err); | ||
process.exit(1); | ||
}, | ||
); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.