Skip to content

Commit

Permalink
feat(cosmic-swingset): add JS upgrade plan handler stub
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Jul 28, 2023
1 parent e7cd762 commit 655133e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
74 changes: 44 additions & 30 deletions packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,39 +688,53 @@ export async function launch({
// );
switch (action.type) {
case ActionType.AG_COSMOS_INIT: {
const { isBootstrap, blockTime } = action;
const { isBootstrap, upgradePlan, blockTime } = action;
// This only runs for the very first block on the chain.
if (!isBootstrap) {
return true;
if (isBootstrap) {
verboseBlocks && blockManagerConsole.info('block bootstrap');
savedHeight === 0 ||
Fail`Cannot run a bootstrap block at height ${savedHeight}`;
const blockHeight = 0;
const runNum = 0;
controller.writeSlogObject({
type: 'cosmic-swingset-bootstrap-block-start',
blockTime,
});
controller.writeSlogObject({
type: 'cosmic-swingset-run-start',
blockHeight,
runNum,
});
await processAction(action.type, async () =>
bootstrapBlock(blockHeight, blockTime),
);
controller.writeSlogObject({
type: 'cosmic-swingset-run-finish',
blockHeight,
runNum,
});
controller.writeSlogObject({
type: 'cosmic-swingset-bootstrap-block-finish',
blockTime,
});
}
verboseBlocks && blockManagerConsole.info('block bootstrap');
if (savedHeight !== 0) {
throw Error(`Cannot run a bootstrap block at height ${savedHeight}`);
if (upgradePlan) {
const blockHeight = upgradePlan.height;
if (blockNeedsExecution(blockHeight)) {
controller.writeSlogObject({
type: 'cosmic-swingset-upgrade-start',
blockHeight,
blockTime,
upgradePlan,
});
// TODO: Process upgrade plan
controller.writeSlogObject({
type: 'cosmic-swingset-upgrade-finish',
blockHeight,
blockTime,
});
}
}
const blockHeight = 0;
const runNum = 0;
controller.writeSlogObject({
type: 'cosmic-swingset-bootstrap-block-start',
blockTime,
});
controller.writeSlogObject({
type: 'cosmic-swingset-run-start',
blockHeight,
runNum,
});
await processAction(action.type, async () =>
bootstrapBlock(blockHeight, blockTime),
);
controller.writeSlogObject({
type: 'cosmic-swingset-run-finish',
blockHeight,
runNum,
});
await pendingSwingStoreExport;
controller.writeSlogObject({
type: 'cosmic-swingset-bootstrap-block-finish',
blockTime,
});
return true;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/telemetry/src/slog-to-otel.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,17 @@ export const makeSlogToOtelKit = (tracer, overrideAttrs = {}) => {
dbTransactionManager.end();
break;
}
case 'cosmic-swingset-upgrade-start': {
dbTransactionManager.begin();
assert(!spans.top());
spans.push(['upgrade', slogAttrs.blockHeight]);
break;
}
case 'cosmic-swingset-upgrade-finish': {
spans.pop(['slogAttrs.blockHeight', slogAttrs.blockHeight]);
dbTransactionManager.end();
break;
}
case 'cosmic-swingset-begin-block': {
if (spans.topKind() === 'intra-block') {
spans.pop('intra-block');
Expand Down

0 comments on commit 655133e

Please sign in to comment.