Skip to content

Commit

Permalink
feat(cosmic-swingset): remove unnecessary explicit activityhash
Browse files Browse the repository at this point in the history
The activityhash is now part of the swingstore export
  • Loading branch information
mhofman committed Apr 19, 2023
1 parent be68431 commit 5dcc44d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 61 deletions.
15 changes: 7 additions & 8 deletions golang/cosmos/x/swingset/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ import (
// Top-level paths for chain storage should remain synchronized with
// packages/internal/src/chain-storage-paths.js
const (
StoragePathActionQueue = "actionQueue"
StoragePathActivityhash = "activityhash"
StoragePathBeansOwing = "beansOwing"
StoragePathEgress = "egress"
StoragePathMailbox = "mailbox"
StoragePathCustom = "published"
StoragePathBundles = "bundles"
StoragePathSwingStore = "swingStore"
StoragePathActionQueue = "actionQueue"
StoragePathBeansOwing = "beansOwing"
StoragePathEgress = "egress"
StoragePathMailbox = "mailbox"
StoragePathCustom = "published"
StoragePathBundles = "bundles"
StoragePathSwingStore = "swingStore"
)

// 2 ** 256 - 1
Expand Down
9 changes: 0 additions & 9 deletions packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,6 @@ export default async function main(progname, args, { env, homedir, agcc }) {
}),
);
};
function setActivityhash(activityhash) {
const entry = [STORAGE_PATH.ACTIVITYHASH, activityhash];
const msg = stringify({
method: 'set',
args: [entry],
});
chainSend(portNums.storage, msg);
}
function doOutboundBridge(dstID, msg) {
const portNum = portNums[dstID];
if (portNum === undefined) {
Expand Down Expand Up @@ -427,7 +419,6 @@ export default async function main(progname, args, { env, homedir, agcc }) {
mailboxStorage,
clearChainSends,
replayChainSends,
setActivityhash,
bridgeOutbound: doOutboundBridge,
vatconfig,
argv,
Expand Down
72 changes: 30 additions & 42 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ export async function launch({
mailboxStorage,
clearChainSends,
replayChainSends,
setActivityhash,
bridgeOutbound,
makeInstallationPublisher,
vatconfig,
Expand Down Expand Up @@ -303,9 +302,6 @@ export async function launch({
// entire bootstrap before opening for business.
const policy = neverStop();
await crankScheduler(policy);
if (setActivityhash) {
setActivityhash(controller.getActivityhash());
}
}

async function saveChainState() {
Expand Down Expand Up @@ -482,47 +478,39 @@ export async function launch({
return runPolicy.shouldRun();
}

async function doRunKernel() {
// First, complete leftover work, if any
let keepGoing = await runSwingset();
if (!keepGoing) return;

// Then, update the timer device with the new external time, which might
// push work onto the kernel run-queue (if any timers were ready to wake).
const addedToQueue = timer.poll(blockTime);
console.debug(
`polled; blockTime:${blockTime}, h:${blockHeight}; ADDED =`,
addedToQueue,
);
// We must run the kernel even if nothing was added since the kernel
// only notes state exports and updates consistency hashes when attempting
// to perform a crank.
// First, complete leftover work, if any
let keepGoing = await runSwingset();
if (!keepGoing) return;

// Then, update the timer device with the new external time, which might
// push work onto the kernel run-queue (if any timers were ready to wake).
const addedToQueue = timer.poll(blockTime);
console.debug(
`polled; blockTime:${blockTime}, h:${blockHeight}; ADDED =`,
addedToQueue,
);
// We must run the kernel even if nothing was added since the kernel
// only notes state exports and updates consistency hashes when attempting
// to perform a crank.
keepGoing = await runSwingset();
if (!keepGoing) return;

// Finally, process as much as we can from the actionQueue, which contains
// first the old actions followed by the newActions, running the
// kernel to completion after each.
for (const { action, context } of actionQueue.consumeAll()) {
const inboundNum = `${context.blockHeight}-${context.txHash}-${context.msgIdx}`;
inboundQueueMetrics.decStat();
// eslint-disable-next-line no-await-in-loop
await performAction(action, inboundNum);
// eslint-disable-next-line no-await-in-loop
keepGoing = await runSwingset();
if (!keepGoing) return;

// Finally, process as much as we can from the actionQueue, which contains
// first the old actions followed by the newActions, running the
// kernel to completion after each.
for (const { action, context } of actionQueue.consumeAll()) {
const inboundNum = `${context.blockHeight}-${context.txHash}-${context.msgIdx}`;
inboundQueueMetrics.decStat();
// eslint-disable-next-line no-await-in-loop
await performAction(action, inboundNum);
// eslint-disable-next-line no-await-in-loop
keepGoing = await runSwingset();
if (!keepGoing) {
// any leftover actions will remain on the actionQueue for possible
// processing in the next block
return;
}
if (!keepGoing) {
// any leftover actions will remain on the actionQueue for possible
// processing in the next block
return;
}
}

await doRunKernel();

if (setActivityhash) {
setActivityhash(controller.getActivityhash());
}
}

async function endBlock(blockHeight, blockTime, params) {
Expand Down
3 changes: 1 addition & 2 deletions packages/internal/src/chain-storage-paths.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* These identify top-level paths for SwingSet chain storage
* (and serve as prefixes, with the exception of ACTIVITYHASH).
* (and serve as prefixes).
* To avoid collisions, they should remain synchronized with
* golang/cosmos/x/swingset/keeper/keeper.go
*/
export const ACTION_QUEUE = 'actionQueue';
export const ACTIVITYHASH = 'activityhash';
export const BEANSOWING = 'beansOwing';
export const EGRESS = 'egress';
export const MAILBOX = 'mailbox';
Expand Down

0 comments on commit 5dcc44d

Please sign in to comment.