Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 26, 2023
1 parent eac3aa8 commit e7868f7
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/builders/restart-kread-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"evals": [
{
"permit": "restart-kread-permit.json",
"script": "restart-kread.js"
}
],
"bundles": [
"/Users/turadg/.agoric/cache/b1-1711dfe7b92654ebfcce3a700736d66f51a6b1d401c14eefda9e8acc7eb04cd28ced726a63117f629e94bdc1421b30fdef53dd34773ac5a4958bcb17e8f78102.json"
]
}
21 changes: 21 additions & 0 deletions packages/builders/restart-kread-permit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"consume": {
"chainTimerService": true,
"chainStorage": true,
"board": true,
"kreadKit": true,
"agoricNamesAdmin": "makeCoreProposalBehavior",
"vatAdminSvc": "makeCoreProposalBehavior",
"zoe": "makeCoreProposalBehavior"
},
"produce": {},
"evaluateBundleCap": "makeCoreProposalBehavior",
"installation": {
"produce": "makeCoreProposalBehavior"
},
"modules": {
"utils": {
"runModuleBehaviors": "makeCoreProposalBehavior"
}
}
}
131 changes: 131 additions & 0 deletions packages/builders/restart-kread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// This is generated by writeCoreProposal; please edit!
/* eslint-disable */

const manifestBundleRef = {bundleID:"b1-1711dfe7b92654ebfcce3a700736d66f51a6b1d401c14eefda9e8acc7eb04cd28ced726a63117f629e94bdc1421b30fdef53dd34773ac5a4958bcb17e8f78102"};
const getManifestCall = harden([
"getManifestForRestart",
]);
const overrideManifest = {
restartKread: {
consume: {
board: true,
chainStorage: true,
chainTimerService: true,
kreadKit: true,
},
produce: {},
},
};

// Make the behavior the completion value.
(({
manifestBundleRef,
getManifestCall,
overrideManifest,
E,
log = console.info,
restoreRef: overrideRestoreRef,
}) => {
const { entries, fromEntries } = Object;

// deeplyFulfilled is a bit overkill for what we need.
const shallowlyFulfilled = async obj => {
if (!obj) {
return obj;
}
const ents = await Promise.all(
entries(obj).map(async ([key, valueP]) => {
const value = await valueP;
return [key, value];
}),
);
return fromEntries(ents);
};

/** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} allPowers */
const behavior = async allPowers => {
// NOTE: If updating any of these names extracted from `allPowers`, you must
// change `permits` above to reflect their accessibility.
const {
consume: { vatAdminSvc, zoe, agoricNamesAdmin },
evaluateBundleCap,
installation: { produce: produceInstallations },
modules: {
utils: { runModuleBehaviors },
},
} = allPowers;
const [exportedGetManifest, ...manifestArgs] = getManifestCall;

/** @type {(ref: import\('./externalTypes.js').ManifestBundleRef) => Promise<Installation<unknown>>} */
const defaultRestoreRef = async ref => {
// extract-proposal.js creates these records, and bundleName is
// the name under which the bundle was installed into
// config.bundles
const p =
'bundleName' in ref
? E(vatAdminSvc).getBundleIDByName(ref.bundleName)
: ref.bundleID;
const bundleID = await p;
const label = bundleID.slice(0, 8);
return E(zoe).installBundleID(bundleID, label);
};
const restoreRef = overrideRestoreRef || defaultRestoreRef;

// Get the on-chain installation containing the manifest and behaviors.
console.info('evaluateBundleCap', {
manifestBundleRef,
exportedGetManifest,
vatAdminSvc,
});
let bcapP;
if ('bundleName' in manifestBundleRef) {
bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName);
} else {
bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID);
}
const bundleCap = await bcapP;

const manifestNS = await evaluateBundleCap(bundleCap);

console.error('execute', {
exportedGetManifest,
behaviors: Object.keys(manifestNS),
});
const {
manifest,
options: rawOptions,
installations: rawInstallations,
} = await manifestNS[exportedGetManifest](
harden({ restoreRef }),
...manifestArgs,
);

// Await references in the options or installations.
const [options, installations] = await Promise.all(
[rawOptions, rawInstallations].map(shallowlyFulfilled),
);

// Publish the installations for behavior dependencies.
const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation');
await Promise.all(
entries(installations || {}).map(([key, value]) => {
produceInstallations[key].resolve(value);
return E(installAdmin).update(key, value);
}),
);

// Evaluate the manifest for our behaviors.
return runModuleBehaviors({
allPowers,
behaviors: manifestNS,
manifest: overrideManifest || manifest,
makeConfig: (name, _permit) => {
log('coreProposal:', name);
return { options };
},
});
};

// Make the behavior the completion value.
return behavior;
})({ manifestBundleRef, getManifestCall, overrideManifest, E });
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ const readBundleSizes = async proposalDir => {
const ensureISTForInstall = async (agd, config, { log }) => {
const { proposalDir, installer } = config;
const { bundleSizes, totalSize } = await readBundleSizes(proposalDir);
// XXX multiply for huge fudge factor
const cost = importBundleCost(sum(bundleSizes)) * 10;
const cost = importBundleCost(sum(bundleSizes));
log({ bundleSizes, totalSize, cost });

const addr = agd.lookup(installer);
Expand Down Expand Up @@ -438,7 +437,7 @@ test.serial('core eval prereqs: provision royalty, gov, ...', async t => {
t.pass();
});

test.serial('core eval proposal passes', async t => {
test.serial.skip('core eval proposal passes', async t => {
const { agd, swingstore, config } = t.context;
const from = agd.lookup(config.proposer);
const { chainId, deposit, proposalDir, instance } = config;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"evals": [
{
"permit": "restart-kread-permit.json",
"script": "restart-kread.js"
}
],
"bundles": [
"/Users/turadg/.agoric/cache/b1-1711dfe7b92654ebfcce3a700736d66f51a6b1d401c14eefda9e8acc7eb04cd28ced726a63117f629e94bdc1421b30fdef53dd34773ac5a4958bcb17e8f78102.json"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"consume": {
"chainTimerService": true,
"chainStorage": true,
"board": true,
"kreadKit": true,
"agoricNamesAdmin": "makeCoreProposalBehavior",
"vatAdminSvc": "makeCoreProposalBehavior",
"zoe": "makeCoreProposalBehavior"
},
"produce": {},
"evaluateBundleCap": "makeCoreProposalBehavior",
"installation": {
"produce": "makeCoreProposalBehavior"
},
"modules": {
"utils": {
"runModuleBehaviors": "makeCoreProposalBehavior"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// This is generated by writeCoreProposal; please edit!
/* eslint-disable */

const manifestBundleRef = {bundleID:"b1-1711dfe7b92654ebfcce3a700736d66f51a6b1d401c14eefda9e8acc7eb04cd28ced726a63117f629e94bdc1421b30fdef53dd34773ac5a4958bcb17e8f78102"};
const getManifestCall = harden([
"getManifestForRestart",
]);
const overrideManifest = {
restartKread: {
consume: {
board: true,
chainStorage: true,
chainTimerService: true,
kreadKit: true,
},
produce: {},
},
};

// Make the behavior the completion value.
(({
manifestBundleRef,
getManifestCall,
overrideManifest,
E,
log = console.info,
restoreRef: overrideRestoreRef,
}) => {
const { entries, fromEntries } = Object;

// deeplyFulfilled is a bit overkill for what we need.
const shallowlyFulfilled = async obj => {
if (!obj) {
return obj;
}
const ents = await Promise.all(
entries(obj).map(async ([key, valueP]) => {
const value = await valueP;
return [key, value];
}),
);
return fromEntries(ents);
};

/** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} allPowers */
const behavior = async allPowers => {
// NOTE: If updating any of these names extracted from `allPowers`, you must
// change `permits` above to reflect their accessibility.
const {
consume: { vatAdminSvc, zoe, agoricNamesAdmin },
evaluateBundleCap,
installation: { produce: produceInstallations },
modules: {
utils: { runModuleBehaviors },
},
} = allPowers;
const [exportedGetManifest, ...manifestArgs] = getManifestCall;

/** @type {(ref: import\('./externalTypes.js').ManifestBundleRef) => Promise<Installation<unknown>>} */
const defaultRestoreRef = async ref => {
// extract-proposal.js creates these records, and bundleName is
// the name under which the bundle was installed into
// config.bundles
const p =
'bundleName' in ref
? E(vatAdminSvc).getBundleIDByName(ref.bundleName)
: ref.bundleID;
const bundleID = await p;
const label = bundleID.slice(0, 8);
return E(zoe).installBundleID(bundleID, label);
};
const restoreRef = overrideRestoreRef || defaultRestoreRef;

// Get the on-chain installation containing the manifest and behaviors.
console.info('evaluateBundleCap', {
manifestBundleRef,
exportedGetManifest,
vatAdminSvc,
});
let bcapP;
if ('bundleName' in manifestBundleRef) {
bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName);
} else {
bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID);
}
const bundleCap = await bcapP;

const manifestNS = await evaluateBundleCap(bundleCap);

console.error('execute', {
exportedGetManifest,
behaviors: Object.keys(manifestNS),
});
const {
manifest,
options: rawOptions,
installations: rawInstallations,
} = await manifestNS[exportedGetManifest](
harden({ restoreRef }),
...manifestArgs,
);

// Await references in the options or installations.
const [options, installations] = await Promise.all(
[rawOptions, rawInstallations].map(shallowlyFulfilled),
);

// Publish the installations for behavior dependencies.
const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation');
await Promise.all(
entries(installations || {}).map(([key, value]) => {
produceInstallations[key].resolve(value);
return E(installAdmin).update(key, value);
}),
);

// Evaluate the manifest for our behaviors.
return runModuleBehaviors({
allPowers,
behaviors: manifestNS,
manifest: overrideManifest || manifest,
makeConfig: (name, _permit) => {
log('coreProposal:', name);
return { options };
},
});
};

// Make the behavior the completion value.
return behavior;
})({ manifestBundleRef, getManifestCall, overrideManifest, E });

0 comments on commit e7868f7

Please sign in to comment.