@agoric/cosmic-swingset 0.41.4-dev-07cb543.0 → 0.41.4-dev-2a71f04.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/launch-chain.js +170 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cosmic-swingset",
|
|
3
|
-
"version": "0.41.4-dev-
|
|
3
|
+
"version": "0.41.4-dev-2a71f04.0+2a71f04",
|
|
4
4
|
"description": "Agoric's Cosmos blockchain integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"author": "Agoric",
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@agoric/builders": "0.1.1-dev-
|
|
26
|
-
"@agoric/cosmos": "0.34.2-dev-
|
|
27
|
-
"@agoric/deploy-script-support": "0.10.4-dev-
|
|
28
|
-
"@agoric/internal": "0.3.3-dev-
|
|
29
|
-
"@agoric/store": "0.9.3-dev-
|
|
30
|
-
"@agoric/swing-store": "0.9.2-dev-
|
|
31
|
-
"@agoric/swingset-vat": "0.32.3-dev-
|
|
32
|
-
"@agoric/telemetry": "0.6.3-dev-
|
|
33
|
-
"@agoric/vm-config": "0.1.1-dev-
|
|
25
|
+
"@agoric/builders": "0.1.1-dev-2a71f04.0+2a71f04",
|
|
26
|
+
"@agoric/cosmos": "0.34.2-dev-2a71f04.0+2a71f04",
|
|
27
|
+
"@agoric/deploy-script-support": "0.10.4-dev-2a71f04.0+2a71f04",
|
|
28
|
+
"@agoric/internal": "0.3.3-dev-2a71f04.0+2a71f04",
|
|
29
|
+
"@agoric/store": "0.9.3-dev-2a71f04.0+2a71f04",
|
|
30
|
+
"@agoric/swing-store": "0.9.2-dev-2a71f04.0+2a71f04",
|
|
31
|
+
"@agoric/swingset-vat": "0.32.3-dev-2a71f04.0+2a71f04",
|
|
32
|
+
"@agoric/telemetry": "0.6.3-dev-2a71f04.0+2a71f04",
|
|
33
|
+
"@agoric/vm-config": "0.1.1-dev-2a71f04.0+2a71f04",
|
|
34
34
|
"@endo/bundle-source": "^3.5.1",
|
|
35
35
|
"@endo/env-options": "^1.1.8",
|
|
36
36
|
"@endo/errors": "^1.2.9",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"typeCoverage": {
|
|
74
74
|
"atLeast": 83.4
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "2a71f04176f1a27be8e0356595d3dcd62f6d9186"
|
|
77
77
|
}
|
package/src/launch-chain.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
import { waitUntilQuiescent } from '@agoric/internal/src/lib-nodejs/waitUntilQuiescent.js';
|
|
28
28
|
import { openSwingStore } from '@agoric/swing-store';
|
|
29
29
|
import { BridgeId as BRIDGE_ID } from '@agoric/internal';
|
|
30
|
+
import { objectMapMutable } from '@agoric/internal/src/js-utils.js';
|
|
30
31
|
import { makeWithQueue } from '@agoric/internal/src/queue.js';
|
|
31
32
|
import * as ActionType from '@agoric/internal/src/action-types.js';
|
|
32
33
|
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
mergeCoreProposals,
|
|
36
37
|
} from '@agoric/deploy-script-support/src/extract-proposal.js';
|
|
37
38
|
import { fileURLToPath } from 'url';
|
|
39
|
+
import { ValueType } from '@opentelemetry/api';
|
|
38
40
|
|
|
39
41
|
import {
|
|
40
42
|
makeDefaultMeterProvider,
|
|
@@ -54,9 +56,79 @@ import { computronCounter } from './computron-counter.js';
|
|
|
54
56
|
|
|
55
57
|
/** @typedef {ReturnType<typeof makeQueue<{context: any, action: any}>>} InboundQueue */
|
|
56
58
|
|
|
59
|
+
const { now } = Date;
|
|
60
|
+
/**
|
|
61
|
+
* Convert a milliseconds timestamp from `now()` into milliseconds since the
|
|
62
|
+
* POSIX epoch. The result will match (or approximately match) the input when
|
|
63
|
+
* `now` is `Date.now`, but may differ dramatically when it is `performance.now`
|
|
64
|
+
* or otherwise not already relative to the POSIX epoch.
|
|
65
|
+
*
|
|
66
|
+
* @param {ReturnType<typeof now>} nowMilliseconds
|
|
67
|
+
* @returns {number}
|
|
68
|
+
*/
|
|
69
|
+
const toPosix = nowMilliseconds => {
|
|
70
|
+
const offset = Date.now() - now();
|
|
71
|
+
return offset + nowMilliseconds;
|
|
72
|
+
};
|
|
73
|
+
|
|
57
74
|
const console = anylogger('launch-chain');
|
|
58
75
|
const blockManagerConsole = anylogger('block-manager');
|
|
59
76
|
|
|
77
|
+
const blockHistogramMetricDesc = {
|
|
78
|
+
valueType: ValueType.DOUBLE,
|
|
79
|
+
unit: 's',
|
|
80
|
+
advice: {
|
|
81
|
+
explicitBucketBoundaries: [
|
|
82
|
+
0.1, 0.2, 0.3, 0.4, 0.5, 1, 2, 3, 4, 5, 6, 7, 10, 15, 30,
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const BLOCK_HISTOGRAM_METRICS = /** @type {const} */ ({
|
|
87
|
+
swingsetRunSeconds: {
|
|
88
|
+
description: 'Per-block time spent executing SwingSet',
|
|
89
|
+
...blockHistogramMetricDesc,
|
|
90
|
+
},
|
|
91
|
+
swingsetChainSaveSeconds: {
|
|
92
|
+
description: 'Per-block time spent propagating SwingSet state into cosmos',
|
|
93
|
+
...blockHistogramMetricDesc,
|
|
94
|
+
},
|
|
95
|
+
swingsetCommitSeconds: {
|
|
96
|
+
description:
|
|
97
|
+
'Per-block time spent committing SwingSet state to host storage',
|
|
98
|
+
...blockHistogramMetricDesc,
|
|
99
|
+
},
|
|
100
|
+
cosmosCommitSeconds: {
|
|
101
|
+
description: 'Per-block time spent committing cosmos state',
|
|
102
|
+
...blockHistogramMetricDesc,
|
|
103
|
+
},
|
|
104
|
+
fullCommitSeconds: {
|
|
105
|
+
description:
|
|
106
|
+
'Per-block time spent committing state, inclusive of COMMIT_BLOCK processing plus time spent [outside of cosmic-swingset] before and after it',
|
|
107
|
+
...blockHistogramMetricDesc,
|
|
108
|
+
},
|
|
109
|
+
interBlockSeconds: {
|
|
110
|
+
description: 'Time spent idle between blocks',
|
|
111
|
+
...blockHistogramMetricDesc,
|
|
112
|
+
},
|
|
113
|
+
afterCommitHangoverSeconds: {
|
|
114
|
+
description:
|
|
115
|
+
'Per-block time spent waiting for previous-block afterCommit work',
|
|
116
|
+
...blockHistogramMetricDesc,
|
|
117
|
+
},
|
|
118
|
+
blockLagSeconds: {
|
|
119
|
+
description: 'The delay of each block from its expected begin time',
|
|
120
|
+
...blockHistogramMetricDesc,
|
|
121
|
+
// Add buckets for excessively long delays.
|
|
122
|
+
advice: {
|
|
123
|
+
...blockHistogramMetricDesc.advice,
|
|
124
|
+
explicitBucketBoundaries: /** @type {number[]} */ ([
|
|
125
|
+
...blockHistogramMetricDesc.advice.explicitBucketBoundaries,
|
|
126
|
+
...[60, 120, 180, 240, 300, 600, 3600],
|
|
127
|
+
]),
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
60
132
|
/**
|
|
61
133
|
* @param {{ info: string } | null | undefined} upgradePlan
|
|
62
134
|
* @param {string} prefix
|
|
@@ -318,7 +390,7 @@ export async function buildSwingset(
|
|
|
318
390
|
* @property {ReturnType<typeof import('./kernel-stats.js').makeDefaultMeterProvider>} [metricsProvider]
|
|
319
391
|
* @property {import('@agoric/telemetry').SlogSender} [slogSender]
|
|
320
392
|
* @property {string} [swingStoreTraceFile]
|
|
321
|
-
* @property {(...args: unknown[]) => void} [swingStoreExportCallback]
|
|
393
|
+
* @property {(...args: unknown[]) => Promise<void> | void} [swingStoreExportCallback]
|
|
322
394
|
* @property {boolean} [keepSnapshots]
|
|
323
395
|
* @property {boolean} [keepTranscripts]
|
|
324
396
|
* @property {ReturnType<typeof import('@agoric/swing-store').makeArchiveSnapshot>} [archiveSnapshot]
|
|
@@ -496,6 +568,10 @@ export async function launch({
|
|
|
496
568
|
initialQueueLengths,
|
|
497
569
|
});
|
|
498
570
|
|
|
571
|
+
const blockMetrics = objectMapMutable(BLOCK_HISTOGRAM_METRICS, (desc, name) =>
|
|
572
|
+
metricMeter.createHistogram(name, desc),
|
|
573
|
+
);
|
|
574
|
+
|
|
499
575
|
/**
|
|
500
576
|
* @param {number} blockHeight
|
|
501
577
|
* @param {ChainRunPolicy} runPolicy
|
|
@@ -661,15 +737,22 @@ export async function launch({
|
|
|
661
737
|
* once-per-chain bootstrap (the latter excluding "bridged" core proposals
|
|
662
738
|
* that run outside the bootstrap vat)
|
|
663
739
|
*/
|
|
664
|
-
let
|
|
740
|
+
let runDuration = NaN;
|
|
665
741
|
/** duration of the latest saveChainState(), which commits mailbox data to chain storage */
|
|
666
|
-
let
|
|
742
|
+
let chainSaveDuration = NaN;
|
|
667
743
|
/** duration of the latest saveOutsideState(), which commits to swing-store host storage */
|
|
668
|
-
let
|
|
669
|
-
let endBlockFinish = 0;
|
|
744
|
+
let swingsetCommitDuration = NaN;
|
|
670
745
|
let blockParams;
|
|
671
746
|
let decohered;
|
|
672
|
-
|
|
747
|
+
/** @type {undefined | Promise<void>} */
|
|
748
|
+
let afterCommitWorkDone;
|
|
749
|
+
/** Timestamps that are relevant across block lifecycle events. */
|
|
750
|
+
const times = {
|
|
751
|
+
endBlockDone: NaN,
|
|
752
|
+
commitBlockDone: NaN,
|
|
753
|
+
afterCommitBlockDone: NaN,
|
|
754
|
+
previousBeginBlockPosix: NaN,
|
|
755
|
+
};
|
|
673
756
|
|
|
674
757
|
/**
|
|
675
758
|
* Dispatch an action from an inbound queue to an appropriate handler based on
|
|
@@ -852,8 +935,8 @@ export async function launch({
|
|
|
852
935
|
|
|
853
936
|
if (END_BLOCK_SPIN_MS) {
|
|
854
937
|
// Introduce a busy-wait to artificially put load on the chain.
|
|
855
|
-
const startTime =
|
|
856
|
-
while (
|
|
938
|
+
const startTime = now();
|
|
939
|
+
while (now() - startTime < END_BLOCK_SPIN_MS);
|
|
857
940
|
}
|
|
858
941
|
}
|
|
859
942
|
|
|
@@ -909,6 +992,7 @@ export async function launch({
|
|
|
909
992
|
kvStore.set(getHostKey('beginHeight'), `${savedBeginHeight}`);
|
|
910
993
|
}
|
|
911
994
|
|
|
995
|
+
/** @type {(blockHeight: BlockInfo['blockHeight'], blockTime: BlockInfo['blockTime']) => Promise<void>} */
|
|
912
996
|
async function afterCommit(blockHeight, blockTime) {
|
|
913
997
|
await waitUntilQuiescent()
|
|
914
998
|
.then(afterCommitCallback)
|
|
@@ -939,12 +1023,12 @@ export async function launch({
|
|
|
939
1023
|
// Start a block transaction, but without changing state
|
|
940
1024
|
// for the upcoming begin block check
|
|
941
1025
|
saveBeginHeight(savedBeginHeight);
|
|
942
|
-
const start =
|
|
1026
|
+
const start = now();
|
|
943
1027
|
await withErrorLogging(
|
|
944
1028
|
action.type,
|
|
945
1029
|
() => bootstrapBlock(blockHeight, blockTime, bootstrapBlockParams),
|
|
946
1030
|
() => {
|
|
947
|
-
|
|
1031
|
+
runDuration += now() - start;
|
|
948
1032
|
},
|
|
949
1033
|
);
|
|
950
1034
|
} finally {
|
|
@@ -1103,45 +1187,94 @@ export async function launch({
|
|
|
1103
1187
|
});
|
|
1104
1188
|
|
|
1105
1189
|
// Save the kernel's computed state just before the chain commits.
|
|
1106
|
-
const start =
|
|
1190
|
+
const start = now();
|
|
1107
1191
|
await saveOutsideState(savedHeight);
|
|
1108
|
-
|
|
1192
|
+
swingsetCommitDuration = now() - start;
|
|
1109
1193
|
|
|
1110
1194
|
blockParams = undefined;
|
|
1111
1195
|
|
|
1112
1196
|
blockManagerConsole.debug(
|
|
1113
|
-
`wrote SwingSet checkpoint [run=${
|
|
1197
|
+
`wrote SwingSet checkpoint [run=${runDuration}ms, chainSave=${chainSaveDuration}ms, kernelSave=${swingsetCommitDuration}ms]`,
|
|
1114
1198
|
);
|
|
1115
1199
|
|
|
1200
|
+
times.commitBlockDone = now();
|
|
1201
|
+
|
|
1116
1202
|
return undefined;
|
|
1117
1203
|
}
|
|
1118
1204
|
|
|
1119
1205
|
case ActionType.AFTER_COMMIT_BLOCK: {
|
|
1120
1206
|
const { blockHeight, blockTime } = action;
|
|
1121
1207
|
|
|
1122
|
-
const
|
|
1208
|
+
const afterCommitStart = now();
|
|
1209
|
+
// Time spent since the end of COMMIT_BLOCK (which itself is dominated
|
|
1210
|
+
// by swingsetCommitDuration).
|
|
1211
|
+
const cosmosCommitDuration = afterCommitStart - times.commitBlockDone;
|
|
1212
|
+
// Time spent since the end of END_BLOCK (inclusive of COMMIT_BLOCK).
|
|
1213
|
+
const fullCommitDuration = afterCommitStart - times.endBlockDone;
|
|
1123
1214
|
|
|
1124
1215
|
controller.writeSlogObject({
|
|
1125
1216
|
type: 'cosmic-swingset-commit-block-finish',
|
|
1126
1217
|
blockHeight,
|
|
1127
1218
|
blockTime,
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1219
|
+
runSeconds: runDuration / 1000,
|
|
1220
|
+
// TODO: After preparing all known consumers, rename
|
|
1221
|
+
// {chain,save,fullSave}Time to
|
|
1222
|
+
// {chainSave,swingsetCommit,cosmosCommit}Seconds
|
|
1223
|
+
chainTime: chainSaveDuration / 1000,
|
|
1224
|
+
saveTime: swingsetCommitDuration / 1000,
|
|
1225
|
+
cosmosCommitSeconds: cosmosCommitDuration / 1000,
|
|
1226
|
+
fullSaveTime: fullCommitDuration / 1000,
|
|
1131
1227
|
});
|
|
1132
1228
|
|
|
1229
|
+
blockMetrics.swingsetRunSeconds.record(runDuration / 1000);
|
|
1230
|
+
blockMetrics.swingsetChainSaveSeconds.record(chainSaveDuration / 1000);
|
|
1231
|
+
blockMetrics.swingsetCommitSeconds.record(
|
|
1232
|
+
swingsetCommitDuration / 1000,
|
|
1233
|
+
);
|
|
1234
|
+
blockMetrics.cosmosCommitSeconds.record(cosmosCommitDuration / 1000);
|
|
1235
|
+
blockMetrics.fullCommitSeconds.record(fullCommitDuration / 1000);
|
|
1236
|
+
|
|
1133
1237
|
afterCommitWorkDone = afterCommit(blockHeight, blockTime);
|
|
1134
1238
|
|
|
1239
|
+
// In the expected case where afterCommit work finishes before the next
|
|
1240
|
+
// block starts, don't incorrectly attribute `await` time to it.
|
|
1241
|
+
const latestAfterCommitP = afterCommitWorkDone;
|
|
1242
|
+
void afterCommitWorkDone.then(() => {
|
|
1243
|
+
afterCommitWorkDone === latestAfterCommitP ||
|
|
1244
|
+
Fail`Unexpected afterCommit overlap`;
|
|
1245
|
+
afterCommitWorkDone = undefined;
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
times.afterCommitBlockDone = now();
|
|
1249
|
+
|
|
1135
1250
|
return undefined;
|
|
1136
1251
|
}
|
|
1137
1252
|
|
|
1138
1253
|
case ActionType.BEGIN_BLOCK: {
|
|
1254
|
+
const beginBlockTimestamp = now();
|
|
1255
|
+
const interBlockDuration =
|
|
1256
|
+
beginBlockTimestamp - times.afterCommitBlockDone;
|
|
1257
|
+
|
|
1258
|
+
// Awaiting completion of afterCommitWorkDone ensures that timings
|
|
1259
|
+
// correspond exclusively with work for a single block.
|
|
1260
|
+
let hangoverTimestamp = beginBlockTimestamp;
|
|
1261
|
+
if (afterCommitWorkDone) {
|
|
1262
|
+
await afterCommitWorkDone;
|
|
1263
|
+
hangoverTimestamp = now();
|
|
1264
|
+
}
|
|
1265
|
+
const afterCommitHangover = hangoverTimestamp - beginBlockTimestamp;
|
|
1266
|
+
|
|
1139
1267
|
allowExportCallback = true; // cleared by saveOutsideState in COMMIT_BLOCK
|
|
1140
1268
|
const { blockHeight, blockTime, params } = action;
|
|
1141
1269
|
blockParams = parseParams(params);
|
|
1142
1270
|
verboseBlocks &&
|
|
1143
1271
|
blockManagerConsole.info('block', blockHeight, 'begin');
|
|
1144
|
-
|
|
1272
|
+
runDuration = 0;
|
|
1273
|
+
// blockTime is decided in consensus when starting to execute the
|
|
1274
|
+
// *previous* block.
|
|
1275
|
+
// TODO: Link to documentation of this.
|
|
1276
|
+
const blockLag = times.previousBeginBlockPosix - blockTime * 1000;
|
|
1277
|
+
times.previousBeginBlockPosix = toPosix(beginBlockTimestamp);
|
|
1145
1278
|
|
|
1146
1279
|
if (blockNeedsExecution(blockHeight)) {
|
|
1147
1280
|
if (savedBeginHeight === blockHeight) {
|
|
@@ -1158,9 +1291,20 @@ export async function launch({
|
|
|
1158
1291
|
type: 'cosmic-swingset-begin-block',
|
|
1159
1292
|
blockHeight,
|
|
1160
1293
|
blockTime,
|
|
1294
|
+
interBlockSeconds: interBlockDuration / 1000,
|
|
1295
|
+
afterCommitHangoverSeconds: afterCommitHangover / 1000,
|
|
1296
|
+
blockLagSeconds: blockLag / 1000,
|
|
1161
1297
|
inboundQueueStats: inboundQueueMetrics.getStats(),
|
|
1162
1298
|
});
|
|
1163
1299
|
|
|
1300
|
+
Number.isNaN(interBlockDuration) ||
|
|
1301
|
+
blockMetrics.interBlockSeconds.record(interBlockDuration / 1000);
|
|
1302
|
+
blockMetrics.afterCommitHangoverSeconds.record(
|
|
1303
|
+
afterCommitHangover / 1000,
|
|
1304
|
+
);
|
|
1305
|
+
Number.isNaN(blockLag) ||
|
|
1306
|
+
blockMetrics.blockLagSeconds.record(blockLag / 1000);
|
|
1307
|
+
|
|
1164
1308
|
return undefined;
|
|
1165
1309
|
}
|
|
1166
1310
|
|
|
@@ -1203,19 +1347,22 @@ export async function launch({
|
|
|
1203
1347
|
|
|
1204
1348
|
provideInstallationPublisher();
|
|
1205
1349
|
|
|
1206
|
-
const start =
|
|
1350
|
+
const start = now();
|
|
1207
1351
|
await withErrorLogging(
|
|
1208
1352
|
action.type,
|
|
1209
1353
|
() => endBlock(blockHeight, blockTime, blockParams),
|
|
1210
1354
|
() => {
|
|
1211
|
-
|
|
1355
|
+
runDuration += now() - start;
|
|
1212
1356
|
},
|
|
1213
1357
|
);
|
|
1214
1358
|
|
|
1215
1359
|
// We write out our on-chain state as a number of chainSends.
|
|
1216
|
-
const start2 =
|
|
1360
|
+
const start2 = now();
|
|
1217
1361
|
await saveChainState();
|
|
1218
|
-
|
|
1362
|
+
// Not strictly necessary for correctness (the caller ensures this is
|
|
1363
|
+
// done before returning), but account for time taken to flush.
|
|
1364
|
+
await pendingSwingStoreExport;
|
|
1365
|
+
chainSaveDuration = now() - start2;
|
|
1219
1366
|
|
|
1220
1367
|
// Advance our saved state variables.
|
|
1221
1368
|
savedHeight = blockHeight;
|
|
@@ -1227,7 +1374,7 @@ export async function launch({
|
|
|
1227
1374
|
inboundQueueStats: inboundQueueMetrics.getStats(),
|
|
1228
1375
|
});
|
|
1229
1376
|
|
|
1230
|
-
|
|
1377
|
+
times.endBlockDone = now();
|
|
1231
1378
|
|
|
1232
1379
|
return undefined;
|
|
1233
1380
|
}
|
|
@@ -1242,8 +1389,6 @@ export async function launch({
|
|
|
1242
1389
|
throw decohered;
|
|
1243
1390
|
}
|
|
1244
1391
|
|
|
1245
|
-
await afterCommitWorkDone;
|
|
1246
|
-
|
|
1247
1392
|
return doBlockingSend(action).finally(() => pendingSwingStoreExport);
|
|
1248
1393
|
}
|
|
1249
1394
|
|