@agoric/swingset-vat 0.32.3-dev-55a8847.0 → 0.32.3-dev-d322e42.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 +12 -12
- package/src/devices/mailbox/mailbox.js +76 -43
- package/src/index.js +2 -0
- package/src/types-external.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/swingset-vat",
|
|
3
|
-
"version": "0.32.3-dev-
|
|
3
|
+
"version": "0.32.3-dev-d322e42.0+d322e42",
|
|
4
4
|
"description": "Vat/Container Launcher",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"@types/yargs-parser": "^21.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@agoric/internal": "0.3.3-dev-
|
|
31
|
-
"@agoric/kmarshal": "0.1.1-dev-
|
|
32
|
-
"@agoric/store": "0.9.3-dev-
|
|
33
|
-
"@agoric/swing-store": "0.9.2-dev-
|
|
34
|
-
"@agoric/swingset-liveslots": "0.10.3-dev-
|
|
35
|
-
"@agoric/swingset-xsnap-supervisor": "0.10.3-dev-
|
|
36
|
-
"@agoric/time": "0.3.3-dev-
|
|
37
|
-
"@agoric/vat-data": "0.5.3-dev-
|
|
38
|
-
"@agoric/xsnap": "0.14.3-dev-
|
|
39
|
-
"@agoric/xsnap-lockdown": "0.14.1-dev-
|
|
30
|
+
"@agoric/internal": "0.3.3-dev-d322e42.0+d322e42",
|
|
31
|
+
"@agoric/kmarshal": "0.1.1-dev-d322e42.0+d322e42",
|
|
32
|
+
"@agoric/store": "0.9.3-dev-d322e42.0+d322e42",
|
|
33
|
+
"@agoric/swing-store": "0.9.2-dev-d322e42.0+d322e42",
|
|
34
|
+
"@agoric/swingset-liveslots": "0.10.3-dev-d322e42.0+d322e42",
|
|
35
|
+
"@agoric/swingset-xsnap-supervisor": "0.10.3-dev-d322e42.0+d322e42",
|
|
36
|
+
"@agoric/time": "0.3.3-dev-d322e42.0+d322e42",
|
|
37
|
+
"@agoric/vat-data": "0.5.3-dev-d322e42.0+d322e42",
|
|
38
|
+
"@agoric/xsnap": "0.14.3-dev-d322e42.0+d322e42",
|
|
39
|
+
"@agoric/xsnap-lockdown": "0.14.1-dev-d322e42.0+d322e42",
|
|
40
40
|
"@endo/base64": "^1.0.8",
|
|
41
41
|
"@endo/bundle-source": "^3.4.1",
|
|
42
42
|
"@endo/captp": "^4.4.0",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"typeCoverage": {
|
|
104
104
|
"atLeast": 75.82
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "d322e42bcb8bf53aba0468f67907464b34d9e937"
|
|
107
107
|
}
|
|
@@ -71,6 +71,23 @@ import { Nat } from '@endo/nat';
|
|
|
71
71
|
// replace it with one that tracks which parts of the state have been
|
|
72
72
|
// modified, to build more efficient Merkle proofs.
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {object} Mailbox
|
|
76
|
+
* @property {bigint} ack
|
|
77
|
+
* @property {Map<bigint, unknown>} outbox
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @typedef {object} MailboxExport
|
|
82
|
+
* @property {number} ack
|
|
83
|
+
* @property {Array<[number, unknown]>} outbox
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @param {MailboxExport} data
|
|
88
|
+
* @param {Partial<Mailbox>} [inout]
|
|
89
|
+
* @returns {Mailbox}
|
|
90
|
+
*/
|
|
74
91
|
export function importMailbox(data, inout = {}) {
|
|
75
92
|
const outbox = new Map();
|
|
76
93
|
for (const m of data.outbox) {
|
|
@@ -78,10 +95,15 @@ export function importMailbox(data, inout = {}) {
|
|
|
78
95
|
}
|
|
79
96
|
inout.ack = Nat(data.ack);
|
|
80
97
|
inout.outbox = outbox;
|
|
81
|
-
return inout;
|
|
98
|
+
return /** @type {Mailbox} */ (inout);
|
|
82
99
|
}
|
|
83
100
|
|
|
101
|
+
/**
|
|
102
|
+
* @param {Mailbox} inout
|
|
103
|
+
* @returns {MailboxExport}
|
|
104
|
+
*/
|
|
84
105
|
export function exportMailbox(inout) {
|
|
106
|
+
/** @type {MailboxExport['outbox']} */
|
|
85
107
|
const messages = [];
|
|
86
108
|
for (const [msgnum, body] of inout.outbox) {
|
|
87
109
|
messages.push([Number(msgnum), body]);
|
|
@@ -93,64 +115,75 @@ export function exportMailbox(inout) {
|
|
|
93
115
|
};
|
|
94
116
|
}
|
|
95
117
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
/**
|
|
119
|
+
* @param {Map<string, Mailbox>} state
|
|
120
|
+
*/
|
|
121
|
+
export function exportMailboxData(state) {
|
|
122
|
+
/** @type {Record<string, {inboundAck: MailboxExport['ack'], outbox: MailboxExport['outbox']}>} */
|
|
123
|
+
const data = {};
|
|
124
|
+
for (const [peer, inout] of state.entries()) {
|
|
125
|
+
const exported = exportMailbox(inout);
|
|
126
|
+
data[peer] = {
|
|
127
|
+
inboundAck: exported.ack,
|
|
128
|
+
outbox: exported.outbox,
|
|
129
|
+
};
|
|
106
130
|
}
|
|
131
|
+
return harden(data);
|
|
132
|
+
}
|
|
107
133
|
|
|
108
|
-
|
|
109
|
-
|
|
134
|
+
function getOrCreatePeer(state, peer) {
|
|
135
|
+
if (!state.has(peer)) {
|
|
136
|
+
const inout = {
|
|
137
|
+
outbox: harden(new Map()),
|
|
138
|
+
ack: 0n,
|
|
139
|
+
};
|
|
140
|
+
state.set(peer, inout);
|
|
110
141
|
}
|
|
142
|
+
return state.get(peer);
|
|
143
|
+
}
|
|
111
144
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
145
|
+
/**
|
|
146
|
+
* @param {ReturnType<exportMailboxData>} data
|
|
147
|
+
* @returns {Map<string, Mailbox>}
|
|
148
|
+
*/
|
|
149
|
+
export function makeEphemeralMailboxStorage(data) {
|
|
150
|
+
const state = harden(new Map());
|
|
151
|
+
for (const peer of Object.getOwnPropertyNames(data)) {
|
|
152
|
+
const inout = getOrCreatePeer(state, peer);
|
|
153
|
+
const d = data[peer];
|
|
154
|
+
importMailbox(
|
|
155
|
+
{
|
|
156
|
+
ack: d.inboundAck,
|
|
157
|
+
outbox: d.outbox,
|
|
158
|
+
},
|
|
159
|
+
inout,
|
|
160
|
+
);
|
|
115
161
|
}
|
|
162
|
+
return state;
|
|
163
|
+
}
|
|
116
164
|
|
|
117
|
-
|
|
118
|
-
|
|
165
|
+
/**
|
|
166
|
+
* @template [T=unknown]
|
|
167
|
+
* @param {Pick<Map<string, T>, 'has' | 'get'> & {set: (key: string, value: T) => void}} [state]
|
|
168
|
+
*/
|
|
169
|
+
export function buildMailboxStateMap(state = harden(new Map())) {
|
|
170
|
+
function add(peer, msgnum, body) {
|
|
171
|
+
getOrCreatePeer(state, `${peer}`).outbox.set(Nat(msgnum), `${body}`);
|
|
119
172
|
}
|
|
120
173
|
|
|
121
|
-
function
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const exported = exportMailbox(inout);
|
|
125
|
-
data[peer] = {
|
|
126
|
-
inboundAck: exported.ack,
|
|
127
|
-
outbox: exported.outbox,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
return harden(data);
|
|
174
|
+
function remove(peer, msgnum) {
|
|
175
|
+
const messages = getOrCreatePeer(state, `${peer}`).outbox;
|
|
176
|
+
messages.delete(Nat(msgnum));
|
|
131
177
|
}
|
|
132
178
|
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
for (const peer of Object.getOwnPropertyNames(data)) {
|
|
136
|
-
const inout = getOrCreatePeer(peer);
|
|
137
|
-
const d = data[peer];
|
|
138
|
-
importMailbox(
|
|
139
|
-
{
|
|
140
|
-
ack: d.inboundAck,
|
|
141
|
-
outbox: d.outbox,
|
|
142
|
-
},
|
|
143
|
-
inout,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
179
|
+
function setAcknum(peer, msgnum) {
|
|
180
|
+
getOrCreatePeer(state, `${peer}`).ack = Nat(msgnum);
|
|
146
181
|
}
|
|
147
182
|
|
|
148
183
|
return harden({
|
|
149
184
|
add,
|
|
150
185
|
remove,
|
|
151
186
|
setAcknum,
|
|
152
|
-
exportToData,
|
|
153
|
-
populateFromData,
|
|
154
187
|
});
|
|
155
188
|
}
|
|
156
189
|
|
package/src/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export { upgradeSwingset } from './controller/upgradeSwingset.js';
|
|
|
13
13
|
export {
|
|
14
14
|
buildMailboxStateMap,
|
|
15
15
|
buildMailbox,
|
|
16
|
+
exportMailboxData,
|
|
17
|
+
makeEphemeralMailboxStorage,
|
|
16
18
|
} from './devices/mailbox/mailbox.js';
|
|
17
19
|
export { buildTimer } from './devices/timer/timer.js';
|
|
18
20
|
export { buildBridge } from './devices/bridge/bridge.js';
|
package/src/types-external.js
CHANGED
|
@@ -283,6 +283,13 @@ export {};
|
|
|
283
283
|
* @property { boolean } [restartWorkerOnSnapshot] Reload worker immediately upon snapshot creation
|
|
284
284
|
*/
|
|
285
285
|
|
|
286
|
+
/**
|
|
287
|
+
* @typedef { import('./devices/mailbox/mailbox.js').Mailbox } Mailbox
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
* @typedef { import('./devices/mailbox/mailbox.js').MailboxExport } MailboxExport
|
|
291
|
+
*/
|
|
292
|
+
|
|
286
293
|
/**
|
|
287
294
|
* Vat Creation and Management
|
|
288
295
|
*
|