@agoric/cosmic-swingset 0.41.4-dev-9d6cff1.0 → 0.41.4-dev-0105e1a.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/anylogger-agoric.js +2 -2
- package/src/chain-main.js +6 -2
- package/src/entrypoint.js +2 -2
- package/src/helpers/bufferedStorage.js +9 -11
- package/src/sim-chain.js +35 -19
- package/tools/test-kit.js +2 -0
- package/tsconfig.json +0 -3
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-0105e1a.0+0105e1a",
|
|
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-0105e1a.0+0105e1a",
|
|
26
|
+
"@agoric/cosmos": "0.34.2-dev-0105e1a.0+0105e1a",
|
|
27
|
+
"@agoric/deploy-script-support": "0.10.4-dev-0105e1a.0+0105e1a",
|
|
28
|
+
"@agoric/internal": "0.3.3-dev-0105e1a.0+0105e1a",
|
|
29
|
+
"@agoric/store": "0.9.3-dev-0105e1a.0+0105e1a",
|
|
30
|
+
"@agoric/swing-store": "0.9.2-dev-0105e1a.0+0105e1a",
|
|
31
|
+
"@agoric/swingset-vat": "0.32.3-dev-0105e1a.0+0105e1a",
|
|
32
|
+
"@agoric/telemetry": "0.6.3-dev-0105e1a.0+0105e1a",
|
|
33
|
+
"@agoric/vm-config": "0.1.1-dev-0105e1a.0+0105e1a",
|
|
34
34
|
"@endo/bundle-source": "^3.5.0",
|
|
35
35
|
"@endo/env-options": "^1.1.8",
|
|
36
36
|
"@endo/errors": "^1.2.8",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"typeCoverage": {
|
|
72
72
|
"atLeast": 82.83
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "0105e1ac69b66895872c2e3243f8162069491208"
|
|
75
75
|
}
|
package/src/anylogger-agoric.js
CHANGED
|
@@ -32,8 +32,8 @@ const selectedCode = anylogger.levels[selectedLevel];
|
|
|
32
32
|
const globalCode = selectedCode === undefined ? -Infinity : selectedCode;
|
|
33
33
|
|
|
34
34
|
const oldExt = anylogger.ext;
|
|
35
|
-
anylogger.ext =
|
|
36
|
-
l = oldExt(
|
|
35
|
+
anylogger.ext = logger => {
|
|
36
|
+
const l = oldExt(logger);
|
|
37
37
|
l.enabledFor = lvl => globalCode >= anylogger.levels[lvl];
|
|
38
38
|
|
|
39
39
|
const prefix = l.name.replace(/:/g, ': ');
|
package/src/chain-main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import nativePath from 'node:path';
|
|
4
4
|
import v8 from 'node:v8';
|
|
5
5
|
import process from 'node:process';
|
|
6
6
|
import fs from 'node:fs';
|
|
@@ -167,7 +167,11 @@ const makePrefixedBridgeStorage = (
|
|
|
167
167
|
});
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
export default async function main(
|
|
170
|
+
export default async function main(
|
|
171
|
+
progname,
|
|
172
|
+
args,
|
|
173
|
+
{ env, homedir, path = nativePath, agcc },
|
|
174
|
+
) {
|
|
171
175
|
const portNums = {};
|
|
172
176
|
|
|
173
177
|
// TODO: use the 'basedir' pattern
|
package/src/entrypoint.js
CHANGED
|
@@ -18,9 +18,9 @@ import main from './chain-main.js';
|
|
|
18
18
|
const log = anylogger('ag-chain-cosmos');
|
|
19
19
|
|
|
20
20
|
main(process.argv[1], process.argv.splice(2), {
|
|
21
|
-
path,
|
|
22
|
-
homedir: os.homedir(),
|
|
23
21
|
env: process.env,
|
|
22
|
+
homedir: os.homedir(),
|
|
23
|
+
path,
|
|
24
24
|
agcc,
|
|
25
25
|
}).then(
|
|
26
26
|
_res => 0,
|
|
@@ -5,7 +5,7 @@ import { assert, Fail } from '@endo/errors';
|
|
|
5
5
|
// XXX Do these "StorageAPI" functions belong in their own package?
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @template
|
|
8
|
+
* @template [T=unknown]
|
|
9
9
|
* @typedef {{
|
|
10
10
|
* has: (key: string) => boolean,
|
|
11
11
|
* get: (key: string) => T | undefined,
|
|
@@ -16,7 +16,7 @@ import { assert, Fail } from '@endo/errors';
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @template
|
|
19
|
+
* @template [T=unknown]
|
|
20
20
|
* @typedef {KVStore<T> & {commit: () => void, abort: () => void}} BufferedKVStore
|
|
21
21
|
*/
|
|
22
22
|
|
|
@@ -210,15 +210,13 @@ export function provideEnhancedKVStore(mapOrKvStore = new Map()) {
|
|
|
210
210
|
* until told to commit (or abort) them.
|
|
211
211
|
*
|
|
212
212
|
* @template [T=unknown]
|
|
213
|
-
* @param {KVStore<T>} kvStore
|
|
214
|
-
* @param {
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* }} listeners Optional callbacks to be invoked when respective events occur
|
|
221
|
-
*
|
|
213
|
+
* @param {KVStore<T>} kvStore the StorageAPI object to wrap
|
|
214
|
+
* @param {object} [listeners] optional callbacks to be invoked when respective events occur
|
|
215
|
+
* @param {(key: string, value: T | undefined) => void} [listeners.onGet] a callback invoked after getting a value from kvStore
|
|
216
|
+
* @param {(key: string, value: T) => void} [listeners.onPendingSet] a callback invoked after a new uncommitted value is set
|
|
217
|
+
* @param {(key: string) => void} [listeners.onPendingDelete] a callback invoked after a new uncommitted delete
|
|
218
|
+
* @param {() => void} [listeners.onCommit] a callback invoked after pending operations have been committed
|
|
219
|
+
* @param {() => void} [listeners.onAbort] a callback invoked after pending operations have been aborted
|
|
222
220
|
* @returns {{kvStore: KVStore<T>} & Pick<BufferedKVStore<T>, 'commit' | 'abort'>}
|
|
223
221
|
*/
|
|
224
222
|
export function makeBufferedStorage(kvStore, listeners = {}) {
|
package/src/sim-chain.js
CHANGED
|
@@ -19,8 +19,11 @@ import { launch } from './launch-chain.js';
|
|
|
19
19
|
import { getTelemetryProviders } from './kernel-stats.js';
|
|
20
20
|
import { DEFAULT_SIM_SWINGSET_PARAMS, QueueInbound } from './sim-params.js';
|
|
21
21
|
import { parseQueueSizes } from './params.js';
|
|
22
|
+
import { makeKVStoreFromMap } from './helpers/bufferedStorage.js';
|
|
22
23
|
import { makeQueue, makeQueueStorageMock } from './helpers/make-queue.js';
|
|
23
24
|
|
|
25
|
+
/** @import { Mailbox } from '@agoric/swingset-vat' */
|
|
26
|
+
|
|
24
27
|
const console = anylogger('fake-chain');
|
|
25
28
|
|
|
26
29
|
const TELEMETRY_SERVICE_NAME = 'sim-cosmos';
|
|
@@ -28,10 +31,11 @@ const TELEMETRY_SERVICE_NAME = 'sim-cosmos';
|
|
|
28
31
|
const PRETEND_BLOCK_DELAY = 5;
|
|
29
32
|
const scaleBlockTime = ms => Math.floor(ms / 1000);
|
|
30
33
|
|
|
31
|
-
async function
|
|
32
|
-
|
|
34
|
+
async function makeMailboxStorageFromFile(file) {
|
|
35
|
+
/** @type {Map<string, Mailbox>} */
|
|
33
36
|
const map = new Map();
|
|
34
|
-
|
|
37
|
+
const kvStore = makeKVStoreFromMap(map);
|
|
38
|
+
const commit = async () => {
|
|
35
39
|
const obj = {};
|
|
36
40
|
for (const [k, v] of map.entries()) {
|
|
37
41
|
obj[k] = exportMailbox(v);
|
|
@@ -39,20 +43,24 @@ async function makeMapStorage(file) {
|
|
|
39
43
|
const json = stringify(obj);
|
|
40
44
|
await fs.promises.writeFile(file, json);
|
|
41
45
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
content = await fs.promises.readFile(file);
|
|
46
|
+
const read = async () => {
|
|
47
|
+
const content = await fs.promises.readFile(file, 'utf8');
|
|
45
48
|
return JSON.parse(content);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
)
|
|
49
|
+
};
|
|
50
|
+
const load = async obj => {
|
|
51
|
+
map.clear();
|
|
52
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
53
|
+
map.set(k, importMailbox(v));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const reset = async () => {
|
|
57
|
+
const obj = await read();
|
|
58
|
+
await load(obj);
|
|
59
|
+
};
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
await read().then(load, () => {});
|
|
62
|
+
|
|
63
|
+
return { ...kvStore, commit, abort: reset };
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
export async function connectToFakeChain(basedir, GCI, delay, inbound) {
|
|
@@ -61,7 +69,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
|
|
|
61
69
|
const mailboxFile = path.join(basedir, `fake-chain-${GCI}-mailbox.json`);
|
|
62
70
|
const bootAddress = `${GCI}-client`;
|
|
63
71
|
|
|
64
|
-
const mailboxStorage = await
|
|
72
|
+
const mailboxStorage = await makeMailboxStorageFromFile(mailboxFile);
|
|
65
73
|
|
|
66
74
|
const argv = {
|
|
67
75
|
giveMeAllTheAgoricPowers: true,
|
|
@@ -109,6 +117,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
|
|
|
109
117
|
const actionQueue = makeQueue(actionQueueStorage);
|
|
110
118
|
|
|
111
119
|
const s = await launch({
|
|
120
|
+
bridgeOutbound: /** @type {any} */ (undefined),
|
|
112
121
|
actionQueueStorage,
|
|
113
122
|
highPriorityQueueStorage,
|
|
114
123
|
kernelStateDBDir: stateDBdir,
|
|
@@ -120,13 +129,20 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
|
|
|
120
129
|
debugName: GCI,
|
|
121
130
|
metricsProvider,
|
|
122
131
|
slogSender,
|
|
132
|
+
swingsetConfig: {},
|
|
123
133
|
});
|
|
124
134
|
|
|
125
135
|
const { blockingSend, savedHeight } = s;
|
|
126
136
|
|
|
127
137
|
let blockHeight = savedHeight;
|
|
128
138
|
const intoChain = [];
|
|
129
|
-
|
|
139
|
+
/** @type {undefined | ReturnType<typeof setTimeout>} */
|
|
140
|
+
let nextBlockTimeout;
|
|
141
|
+
const resetNextBlockTimeout = () => {
|
|
142
|
+
if (nextBlockTimeout === undefined) return;
|
|
143
|
+
clearTimeout(nextBlockTimeout);
|
|
144
|
+
nextBlockTimeout = undefined;
|
|
145
|
+
};
|
|
130
146
|
|
|
131
147
|
const maximumDelay = (delay || PRETEND_BLOCK_DELAY) * 1000;
|
|
132
148
|
|
|
@@ -172,7 +188,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
|
|
|
172
188
|
// Done processing, "commit the block".
|
|
173
189
|
await blockingSend({ type: 'COMMIT_BLOCK', blockHeight, blockTime });
|
|
174
190
|
|
|
175
|
-
|
|
191
|
+
resetNextBlockTimeout();
|
|
176
192
|
nextBlockTimeout = setTimeout(simulateBlock, maximumDelay);
|
|
177
193
|
|
|
178
194
|
// TODO: maybe add latency to the inbound messages.
|
|
@@ -197,7 +213,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
|
|
|
197
213
|
// Only actually simulate a block if we're not in bootstrap.
|
|
198
214
|
let p;
|
|
199
215
|
if (blockHeight && !delay) {
|
|
200
|
-
|
|
216
|
+
resetNextBlockTimeout();
|
|
201
217
|
p = simulateBlock();
|
|
202
218
|
}
|
|
203
219
|
await p;
|
package/tools/test-kit.js
CHANGED
|
@@ -35,6 +35,7 @@ const stripUndefined = obj =>
|
|
|
35
35
|
Object.entries(obj).filter(([_key, value]) => value !== undefined),
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
+
/** @type {InitMsg} */
|
|
38
39
|
export const defaultInitMessage = harden(
|
|
39
40
|
makeInitMsg({
|
|
40
41
|
type: SwingsetMessageType.AG_COSMOS_INIT,
|
|
@@ -59,6 +60,7 @@ export const defaultInitMessage = harden(
|
|
|
59
60
|
),
|
|
60
61
|
}),
|
|
61
62
|
);
|
|
63
|
+
/** @type {InitMsg} */
|
|
62
64
|
export const defaultBootstrapMessage = harden({
|
|
63
65
|
...deepCopyJsonable(defaultInitMessage),
|
|
64
66
|
blockHeight: 1,
|