Skip to content

Commit

Permalink
fix(cosmic-swingset): Publish installation success and failure topic
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Sep 8, 2022
1 parent b8841a4 commit 6a9f533
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions golang/cosmos/x/swingset/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
StoragePathEgress = "egress"
StoragePathMailbox = "mailbox"
StoragePathCustom = "published"
StoragePathBundles = "bundles"
)

// Keeper maintains the link to data vstorage and exposes getter/setter methods for the various parts of the state machine
Expand Down
2 changes: 2 additions & 0 deletions packages/cosmic-swingset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@agoric/deploy-script-support": "^0.9.0",
"@agoric/internal": "^0.1.0",
"@agoric/nat": "^4.1.0",
"@agoric/notifier": "^0.4.0",
"@agoric/store": "^0.7.2",
"@agoric/swing-store": "^0.7.0",
"@agoric/swingset-vat": "^0.28.0",
Expand All @@ -36,6 +37,7 @@
"@endo/far": "^0.2.9",
"@endo/import-bundle": "^0.2.51",
"@endo/init": "^0.5.47",
"@endo/marshal": "^0.7.3",
"@iarna/toml": "^2.2.3",
"@opentelemetry/sdk-metrics-base": "^0.27.0",
"agoric": "^0.16.0",
Expand Down
43 changes: 38 additions & 5 deletions packages/cosmic-swingset/src/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
/* global process */
import anylogger from 'anylogger';

import { makeMarshal } from '@endo/marshal';
import { assert, details as X } from '@agoric/assert';
import { BridgeId as BRIDGE_ID } from '@agoric/internal';

import { makeStoredSubscriber, makePublishKit } from '@agoric/notifier';
import * as ActionType from './action-types.js';
import { parseParams } from './params.js';

import '@agoric/notifier/exported.js';

const console = anylogger('block-manager');

// Artificially create load if set.
const END_BLOCK_SPIN_MS = process.env.END_BLOCK_SPIN_MS
? parseInt(process.env.END_BLOCK_SPIN_MS, 10)
: 0;

/** @typedef {Record<string, unknown>} InstallationNotification */

export default function makeBlockManager({
actionQueue,
deliverInbound,
Expand All @@ -27,6 +32,7 @@ export default function makeBlockManager({
saveOutsideState,
savedHeight,
validateAndInstallBundle,
installationStorageNode = undefined,
verboseBlocks = false,
}) {
let computedHeight = savedHeight;
Expand All @@ -35,6 +41,9 @@ export default function makeBlockManager({
let latestParams;
let beginBlockAction;

/** @type {PublishKit<unknown>['publisher'] | undefined} */
let installationPublisher;

async function processAction(action) {
const start = Date.now();
const finish = res => {
Expand All @@ -43,6 +52,16 @@ export default function makeBlockManager({
return res;
};

if (
installationPublisher === undefined &&
installationStorageNode !== undefined
) {
const marshaller = makeMarshal();
const { publisher, subscriber } = makePublishKit();
makeStoredSubscriber(subscriber, installationStorageNode, marshaller);
installationPublisher = publisher;
}

// console.error('Performing action', action);
let p;
switch (action.type) {
Expand Down Expand Up @@ -83,10 +102,24 @@ export default function makeBlockManager({
p = (async () => {
const bundle = JSON.parse(action.bundle);
harden(bundle);
return validateAndInstallBundle(bundle);
})().catch(error => {
console.error(error);
});

const error = await validateAndInstallBundle(bundle).then(
() => null,
(/** @type {unknown} */ errorValue) => errorValue,
);

const { endoZipBase64Sha512 } = bundle;

if (installationPublisher !== undefined) {
installationPublisher.publish(
harden({
endoZipBase64Sha512,
installed: error === null,
error,
}),
);
}
})();
break;
}

Expand Down
16 changes: 16 additions & 0 deletions packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { makeBufferedStorage } from '@agoric/swingset-vat/src/lib/storageAPI.js'
import { assert, details as X } from '@agoric/assert';
import { makeSlogSenderFromModule } from '@agoric/telemetry';

import { makeChainStorageRoot } from '@agoric/vats/src/lib-chainStorage.js';

import * as STORAGE_PATH from '@agoric/vats/src/chain-storage-paths.js';
import { BridgeId as BRIDGE_ID } from '@agoric/internal';
import stringify from './json-stable-stringify.js';
import { launch } from './launch-chain.js';
import makeBlockManager from './block-manager.js';
Expand Down Expand Up @@ -502,14 +505,27 @@ export default async function main(progname, args, { env, homedir, agcc }) {
portNums.lien = action.lienPort;
}

// Ensure that initialization has completed.
if (!blockingSend) {
const { savedChainSends: scs, ...fns } =
await launchAndInitializeSwingSet(action);

const toStorage = message => {
return fns.bridgeOutbound(BRIDGE_ID.STORAGE, message);
};
const installationStorageNode = makeChainStorageRoot(
toStorage,
'swingset',
STORAGE_PATH.BUNDLES,
{ sequence: true },
);

savedChainSends = scs;
blockingSend = makeBlockManager({
...fns,
flushChainSends,
verboseBlocks: true,
installationStorageNode,
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export async function launch({
actionQueue,
deliverInbound,
doBridgeInbound,
// bridgeOutbound,
bridgeOutbound,
bootstrapBlock,
beginBlock,
endBlock,
Expand Down
1 change: 1 addition & 0 deletions packages/vats/src/chain-storage-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const ACTIVITYHASH = 'activityhash';
export const BEANSOWING = 'beansOwing';
export const EGRESS = 'egress';
export const MAILBOX = 'mailbox';
export const BUNDLES = 'bundles';
export const CUSTOM = 'published';

0 comments on commit 6a9f533

Please sign in to comment.