@agoric/cosmic-swingset 0.41.4-dev-02c06c4.0 → 0.41.4-dev-2837beb.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/chain-main.js +5 -30
- package/src/helpers/bufferedStorage.js +182 -8
- package/src/helpers/json-stable-stringify.js +11 -4
- package/src/launch-chain.js +202 -54
- package/src/params.js +52 -12
- package/src/sim-chain.js +5 -5
- package/src/sim-params.js +41 -2
- package/tools/test-kit.js +392 -0
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-2837beb.0+2837beb",
|
|
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-2837beb.0+2837beb",
|
|
26
|
+
"@agoric/cosmos": "0.34.2-dev-2837beb.0+2837beb",
|
|
27
|
+
"@agoric/deploy-script-support": "0.10.4-dev-2837beb.0+2837beb",
|
|
28
|
+
"@agoric/internal": "0.3.3-dev-2837beb.0+2837beb",
|
|
29
|
+
"@agoric/store": "0.9.3-dev-2837beb.0+2837beb",
|
|
30
|
+
"@agoric/swing-store": "0.9.2-dev-2837beb.0+2837beb",
|
|
31
|
+
"@agoric/swingset-vat": "0.32.3-dev-2837beb.0+2837beb",
|
|
32
|
+
"@agoric/telemetry": "0.6.3-dev-2837beb.0+2837beb",
|
|
33
|
+
"@agoric/vm-config": "0.1.1-dev-2837beb.0+2837beb",
|
|
34
34
|
"@endo/bundle-source": "^3.4.2",
|
|
35
35
|
"@endo/env-options": "^1.1.7",
|
|
36
36
|
"@endo/errors": "^1.2.7",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"typeCoverage": {
|
|
72
72
|
"atLeast": 80.52
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "2837beb6d7350aa6976923f1dbbb35edfa8906d6"
|
|
75
75
|
}
|
package/src/chain-main.js
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
} from '@agoric/internal/src/lib-chainStorage.js';
|
|
31
31
|
import { makeShutdown } from '@agoric/internal/src/node/shutdown.js';
|
|
32
32
|
|
|
33
|
+
import { makeInitMsg } from '@agoric/internal/src/chain-utils.js';
|
|
33
34
|
import * as STORAGE_PATH from '@agoric/internal/src/chain-storage-paths.js';
|
|
34
35
|
import * as ActionType from '@agoric/internal/src/action-types.js';
|
|
35
36
|
import { BridgeId, CosmosInitKeyToBridgeId } from '@agoric/internal';
|
|
@@ -104,32 +105,6 @@ const validateSwingsetConfig = swingsetConfig => {
|
|
|
104
105
|
Fail`maxVatsOnline must be a positive integer`;
|
|
105
106
|
};
|
|
106
107
|
|
|
107
|
-
/**
|
|
108
|
-
* A boot message consists of cosmosInitAction fields that are subject to
|
|
109
|
-
* consensus. See cosmosInitAction in {@link ../../../golang/cosmos/app/app.go}.
|
|
110
|
-
*
|
|
111
|
-
* @param {any} initAction
|
|
112
|
-
*/
|
|
113
|
-
const makeBootMsg = initAction => {
|
|
114
|
-
const {
|
|
115
|
-
type,
|
|
116
|
-
blockTime,
|
|
117
|
-
blockHeight,
|
|
118
|
-
chainID,
|
|
119
|
-
params,
|
|
120
|
-
// NB: resolvedConfig is independent of consensus and MUST NOT be included
|
|
121
|
-
supplyCoins,
|
|
122
|
-
} = initAction;
|
|
123
|
-
return {
|
|
124
|
-
type,
|
|
125
|
-
blockTime,
|
|
126
|
-
blockHeight,
|
|
127
|
-
chainID,
|
|
128
|
-
params,
|
|
129
|
-
supplyCoins,
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
|
|
133
108
|
/**
|
|
134
109
|
* @template {unknown} [T=unknown]
|
|
135
110
|
* @param {(req: string) => string} call
|
|
@@ -454,16 +429,16 @@ export default async function main(progname, args, { env, homedir, agcc }) {
|
|
|
454
429
|
};
|
|
455
430
|
|
|
456
431
|
const argv = {
|
|
457
|
-
bootMsg:
|
|
432
|
+
bootMsg: makeInitMsg(initAction),
|
|
458
433
|
};
|
|
459
434
|
const getVatConfig = async () => {
|
|
460
|
-
const
|
|
435
|
+
const href = await importMetaResolve(
|
|
461
436
|
env.CHAIN_BOOTSTRAP_VAT_CONFIG ||
|
|
462
437
|
argv.bootMsg.params.bootstrap_vat_config,
|
|
463
438
|
import.meta.url,
|
|
464
439
|
);
|
|
465
|
-
const
|
|
466
|
-
return
|
|
440
|
+
const { pathname } = new URL(href);
|
|
441
|
+
return pathname;
|
|
467
442
|
};
|
|
468
443
|
|
|
469
444
|
// Delay makeShutdown to override the golang interrupts
|
|
@@ -15,6 +15,11 @@ import { assert, Fail } from '@endo/errors';
|
|
|
15
15
|
* }} KVStore
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @template {unknown} [T=unknown]
|
|
20
|
+
* @typedef {KVStore<T> & {commit: () => void, abort: () => void}} BufferedKVStore
|
|
21
|
+
*/
|
|
22
|
+
|
|
18
23
|
/**
|
|
19
24
|
* Assert function to ensure that an object implements the StorageAPI
|
|
20
25
|
* interface: methods { has, getNextKey, get, set, delete }
|
|
@@ -33,21 +38,188 @@ export function insistStorageAPI(kvStore) {
|
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
|
|
41
|
+
// TODO: Replace compareByCodePoints and makeKVStoreFromMap and
|
|
42
|
+
// provideEnhancedKVStore with imports when
|
|
43
|
+
// available.
|
|
44
|
+
// https://github.com/Agoric/agoric-sdk/pull/10299
|
|
45
|
+
|
|
46
|
+
const compareByCodePoints = (left, right) => {
|
|
47
|
+
const leftIter = left[Symbol.iterator]();
|
|
48
|
+
const rightIter = right[Symbol.iterator]();
|
|
49
|
+
for (;;) {
|
|
50
|
+
const { value: leftChar } = leftIter.next();
|
|
51
|
+
const { value: rightChar } = rightIter.next();
|
|
52
|
+
if (leftChar === undefined && rightChar === undefined) {
|
|
53
|
+
return 0;
|
|
54
|
+
} else if (leftChar === undefined) {
|
|
55
|
+
// left is a prefix of right.
|
|
56
|
+
return -1;
|
|
57
|
+
} else if (rightChar === undefined) {
|
|
58
|
+
// right is a prefix of left.
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
const leftCodepoint = /** @type {number} */ (leftChar.codePointAt(0));
|
|
62
|
+
const rightCodepoint = /** @type {number} */ (rightChar.codePointAt(0));
|
|
63
|
+
if (leftCodepoint < rightCodepoint) return -1;
|
|
64
|
+
if (leftCodepoint > rightCodepoint) return 1;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @template [T=unknown]
|
|
70
|
+
* @param {Map<string, T>} map
|
|
71
|
+
* @returns {KVStore<T>}
|
|
72
|
+
*/
|
|
73
|
+
export const makeKVStoreFromMap = map => {
|
|
74
|
+
let sortedKeys;
|
|
75
|
+
let priorKeyReturned;
|
|
76
|
+
let priorKeyIndex;
|
|
77
|
+
|
|
78
|
+
const ensureSorted = () => {
|
|
79
|
+
if (!sortedKeys) {
|
|
80
|
+
sortedKeys = [...map.keys()];
|
|
81
|
+
sortedKeys.sort(compareByCodePoints);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const clearGetNextKeyCache = () => {
|
|
86
|
+
priorKeyReturned = undefined;
|
|
87
|
+
priorKeyIndex = -1;
|
|
88
|
+
};
|
|
89
|
+
clearGetNextKeyCache();
|
|
90
|
+
|
|
91
|
+
const clearSorted = () => {
|
|
92
|
+
sortedKeys = undefined;
|
|
93
|
+
clearGetNextKeyCache();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** @type {KVStore<T>} */
|
|
97
|
+
const fakeStore = harden({
|
|
98
|
+
has: key => map.has(key),
|
|
99
|
+
get: key => map.get(key),
|
|
100
|
+
getNextKey: priorKey => {
|
|
101
|
+
assert.typeof(priorKey, 'string');
|
|
102
|
+
ensureSorted();
|
|
103
|
+
const start =
|
|
104
|
+
compareByCodePoints(priorKeyReturned, priorKey) <= 0
|
|
105
|
+
? priorKeyIndex + 1
|
|
106
|
+
: 0;
|
|
107
|
+
for (let i = start; i < sortedKeys.length; i += 1) {
|
|
108
|
+
const key = sortedKeys[i];
|
|
109
|
+
if (compareByCodePoints(key, priorKey) <= 0) continue;
|
|
110
|
+
priorKeyReturned = key;
|
|
111
|
+
priorKeyIndex = i;
|
|
112
|
+
return key;
|
|
113
|
+
}
|
|
114
|
+
// reached end without finding the key, so clear our cache
|
|
115
|
+
clearGetNextKeyCache();
|
|
116
|
+
return undefined;
|
|
117
|
+
},
|
|
118
|
+
set: (key, value) => {
|
|
119
|
+
if (!map.has(key)) clearSorted();
|
|
120
|
+
map.set(key, value);
|
|
121
|
+
},
|
|
122
|
+
delete: key => {
|
|
123
|
+
if (map.has(key)) clearSorted();
|
|
124
|
+
map.delete(key);
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
return fakeStore;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Return an object representing KVStore contents as both a KVStore and a Map.
|
|
132
|
+
*
|
|
133
|
+
* Iterating over the map while mutating it is "unsupported" (entries inserted
|
|
134
|
+
* that sort before the current iteration point will be skipped).
|
|
135
|
+
*
|
|
136
|
+
* The `size` property is not supported.
|
|
137
|
+
*
|
|
138
|
+
* @template [T=unknown]
|
|
139
|
+
* @param {Map<string, T> | KVStore<T>} [mapOrKvStore]
|
|
140
|
+
*/
|
|
141
|
+
export function provideEnhancedKVStore(mapOrKvStore = new Map()) {
|
|
142
|
+
if (!('getNextKey' in mapOrKvStore)) {
|
|
143
|
+
mapOrKvStore = makeKVStoreFromMap(mapOrKvStore);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!('keys' in mapOrKvStore)) {
|
|
147
|
+
const kvStore = mapOrKvStore;
|
|
148
|
+
const map = harden({
|
|
149
|
+
...mapOrKvStore,
|
|
150
|
+
set(key, value) {
|
|
151
|
+
kvStore.set(key, value);
|
|
152
|
+
return map;
|
|
153
|
+
},
|
|
154
|
+
delete(key) {
|
|
155
|
+
const had = kvStore.has(key);
|
|
156
|
+
kvStore.delete(key);
|
|
157
|
+
return had;
|
|
158
|
+
},
|
|
159
|
+
clear() {
|
|
160
|
+
for (const key of map.keys()) {
|
|
161
|
+
kvStore.delete(key);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
/** @returns {number} */
|
|
165
|
+
get size() {
|
|
166
|
+
throw new Error('size not implemented.');
|
|
167
|
+
},
|
|
168
|
+
*entries() {
|
|
169
|
+
for (const key of map.keys()) {
|
|
170
|
+
yield [key, /** @type {string} */ (kvStore.get(key))];
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
*keys() {
|
|
174
|
+
/** @type {string | undefined} */
|
|
175
|
+
let key = '';
|
|
176
|
+
if (kvStore.has(key)) {
|
|
177
|
+
yield key;
|
|
178
|
+
}
|
|
179
|
+
// eslint-disable-next-line no-cond-assign
|
|
180
|
+
while ((key = kvStore.getNextKey(key))) {
|
|
181
|
+
yield key;
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
*values() {
|
|
185
|
+
for (const key of map.keys()) {
|
|
186
|
+
yield /** @type {string} */ (kvStore.get(key));
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
forEach(callbackfn, thisArg) {
|
|
190
|
+
for (const key of map.keys()) {
|
|
191
|
+
Reflect.apply(callbackfn, thisArg, [
|
|
192
|
+
/** @type {string} */ (kvStore.get(key)),
|
|
193
|
+
key,
|
|
194
|
+
map,
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
[Symbol.iterator]() {
|
|
199
|
+
return map.entries();
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
mapOrKvStore = map;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return /** @type {Map<string, T> & KVStore<T>} */ (mapOrKvStore);
|
|
206
|
+
}
|
|
207
|
+
|
|
36
208
|
/**
|
|
37
209
|
* Create a StorageAPI object that buffers writes to a wrapped StorageAPI object
|
|
38
210
|
* until told to commit (or abort) them.
|
|
39
211
|
*
|
|
40
|
-
* @template
|
|
212
|
+
* @template [T=unknown]
|
|
41
213
|
* @param {KVStore<T>} kvStore The StorageAPI object to wrap
|
|
42
214
|
* @param {{
|
|
43
|
-
* onGet?: (key: string, value: T) => void, // a callback invoked after getting a value from kvStore
|
|
215
|
+
* onGet?: (key: string, value: T | undefined) => void, // a callback invoked after getting a value from kvStore
|
|
44
216
|
* onPendingSet?: (key: string, value: T) => void, // a callback invoked after a new uncommitted value is set
|
|
45
217
|
* onPendingDelete?: (key: string) => void, // a callback invoked after a new uncommitted delete
|
|
46
218
|
* onCommit?: () => void, // a callback invoked after pending operations have been committed
|
|
47
219
|
* onAbort?: () => void, // a callback invoked after pending operations have been aborted
|
|
48
220
|
* }} listeners Optional callbacks to be invoked when respective events occur
|
|
49
221
|
*
|
|
50
|
-
* @returns {{kvStore: KVStore<T>, commit
|
|
222
|
+
* @returns {{kvStore: KVStore<T>} & Pick<BufferedKVStore<T>, 'commit' | 'abort'>}
|
|
51
223
|
*/
|
|
52
224
|
export function makeBufferedStorage(kvStore, listeners = {}) {
|
|
53
225
|
insistStorageAPI(kvStore);
|
|
@@ -59,6 +231,7 @@ export function makeBufferedStorage(kvStore, listeners = {}) {
|
|
|
59
231
|
const additions = new Map();
|
|
60
232
|
const deletions = new Set();
|
|
61
233
|
|
|
234
|
+
/** @type {KVStore<T>} */
|
|
62
235
|
const buffered = {
|
|
63
236
|
has(key) {
|
|
64
237
|
assert.typeof(key, 'string');
|
|
@@ -71,7 +244,6 @@ export function makeBufferedStorage(kvStore, listeners = {}) {
|
|
|
71
244
|
if (additions.has(key)) return additions.get(key);
|
|
72
245
|
if (deletions.has(key)) return undefined;
|
|
73
246
|
const value = kvStore.get(key);
|
|
74
|
-
// @ts-expect-error value may be undefined
|
|
75
247
|
if (onGet !== undefined) onGet(key, value);
|
|
76
248
|
return value;
|
|
77
249
|
},
|
|
@@ -118,19 +290,21 @@ export function makeBufferedStorage(kvStore, listeners = {}) {
|
|
|
118
290
|
/**
|
|
119
291
|
* @template {unknown} [T=unknown]
|
|
120
292
|
* @param {KVStore<T>} kvStore
|
|
293
|
+
* @returns {BufferedKVStore<T>}
|
|
121
294
|
*/
|
|
122
295
|
export const makeReadCachingStorage = kvStore => {
|
|
123
296
|
// In addition to the wrapping write buffer, keep a simple cache of
|
|
124
297
|
// read values for has and get.
|
|
298
|
+
const deleted = Symbol('deleted');
|
|
299
|
+
const undef = Symbol('undefined');
|
|
300
|
+
/** @typedef {(typeof deleted) | (typeof undef)} ReadCacheSentinel */
|
|
301
|
+
/** @type {Map<string, T | ReadCacheSentinel>} */
|
|
125
302
|
let cache;
|
|
126
303
|
function resetCache() {
|
|
127
304
|
cache = new Map();
|
|
128
305
|
}
|
|
129
306
|
resetCache();
|
|
130
307
|
|
|
131
|
-
const deleted = Symbol('deleted');
|
|
132
|
-
const undef = Symbol('undefined');
|
|
133
|
-
|
|
134
308
|
/** @type {KVStore<T>} */
|
|
135
309
|
const storage = harden({
|
|
136
310
|
has(key) {
|
|
@@ -190,5 +364,5 @@ export const makeReadCachingStorage = kvStore => {
|
|
|
190
364
|
onCommit: resetCache,
|
|
191
365
|
onAbort: resetCache,
|
|
192
366
|
});
|
|
193
|
-
return harden({
|
|
367
|
+
return harden({ .../** @type {KVStore<T>} */ (buffered), commit, abort });
|
|
194
368
|
};
|
|
@@ -47,12 +47,18 @@ export default function stableStringify(obj, opts) {
|
|
|
47
47
|
})(opts.cmp);
|
|
48
48
|
|
|
49
49
|
const seen = [];
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* @param {object | unknown[]} parent
|
|
52
|
+
* @param {PropertyKey} key
|
|
53
|
+
* @param {unknown} node
|
|
54
|
+
* @param {number} level
|
|
55
|
+
*/
|
|
56
|
+
const stringify = (parent, key, node, level) => {
|
|
51
57
|
const indent = space ? `\n${new Array(level + 1).join(space)}` : '';
|
|
52
58
|
const colonSeparator = space ? ': ' : ':';
|
|
53
59
|
|
|
54
|
-
if (node &&
|
|
55
|
-
node = node.toJSON();
|
|
60
|
+
if (node && typeof node === 'object' && 'toJSON' in node) {
|
|
61
|
+
if (typeof node.toJSON === 'function') node = node.toJSON();
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
node = replacer.call(parent, key, node);
|
|
@@ -90,5 +96,6 @@ export default function stableStringify(obj, opts) {
|
|
|
90
96
|
}
|
|
91
97
|
seen.splice(seen.indexOf(node), 1);
|
|
92
98
|
return `{${out.join(',')}${indent}}`;
|
|
93
|
-
}
|
|
99
|
+
};
|
|
100
|
+
return stringify({ '': obj }, '', obj, 0);
|
|
94
101
|
}
|