@agoric/swing-store 0.9.2-dev-3fd7a2b.0 → 0.9.2-dev-a0c5f45.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/docs/data-export.md +78 -51
- package/package.json +4 -4
package/docs/data-export.md
CHANGED
|
@@ -39,30 +39,41 @@ The exporter is created by calling `makeSwingStoreExporter(dirpath)`, passing it
|
|
|
39
39
|
After calling `hostStorage.commit()`, the host application can extract the first-stage export data, and then the second-stage export artifacts:
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (const [key, value] of exporter.getExportData()) {
|
|
56
|
-
exportData.set(key, value);
|
|
57
|
-
}
|
|
58
|
-
const exportArtifacts = new Map();
|
|
59
|
-
for (const name of exporter.getArtifactNames()) {
|
|
60
|
-
const reader = exporter.getArtifact(name);
|
|
61
|
-
// reader is an async iterable of Uint8Array, e.g. a stream
|
|
62
|
-
const data = await buffer(reader);
|
|
63
|
-
exportArtifacts.set(name, data);
|
|
42
|
+
const dirPath = '.../swing-store';
|
|
43
|
+
const swingStore = openSwingStore(dirPath);
|
|
44
|
+
...
|
|
45
|
+
await controller.run();
|
|
46
|
+
hostStorage.commit();
|
|
47
|
+
// spawn a child process and wait for it to open a transaction
|
|
48
|
+
const started = makePromiseKit();
|
|
49
|
+
const child = fork(path, args);
|
|
50
|
+
child.on('error', started.reject);
|
|
51
|
+
child.on('exit', started.reject);
|
|
52
|
+
child.on('message', msg => {
|
|
53
|
+
if (msg?.type === 'started') {
|
|
54
|
+
started.resolve();
|
|
64
55
|
}
|
|
65
|
-
|
|
56
|
+
});
|
|
57
|
+
await started.promise;
|
|
58
|
+
...
|
|
59
|
+
|
|
60
|
+
// child process does:
|
|
61
|
+
import { buffer } from 'node:stream/consumers';
|
|
62
|
+
const exporter = makeSwingStoreExporter(dirPath);
|
|
63
|
+
// exporter now has a txn, so parent process is free to proceed forward
|
|
64
|
+
process.send({ type: 'started' });
|
|
65
|
+
const exportData = new Map();
|
|
66
|
+
for (const [key, value] of exporter.getExportData()) {
|
|
67
|
+
exportData.set(key, value);
|
|
68
|
+
}
|
|
69
|
+
const exportArtifacts = new Map();
|
|
70
|
+
for (const name of exporter.getArtifactNames()) {
|
|
71
|
+
const reader = exporter.getArtifact(name);
|
|
72
|
+
// reader is an async iterable of Uint8Array, e.g. a stream
|
|
73
|
+
const data = await buffer(reader);
|
|
74
|
+
exportArtifacts.set(name, data);
|
|
75
|
+
}
|
|
76
|
+
// export is the combination of 'exportData' and 'exportArtifacts'
|
|
66
77
|
```
|
|
67
78
|
|
|
68
79
|

|
|
@@ -92,35 +103,51 @@ Then, on the few occasions when the application needs to build a full state-sync
|
|
|
92
103
|

|
|
93
104
|
|
|
94
105
|
```js
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
106
|
+
const dirPath = '.../swing-store';
|
|
107
|
+
const iavl = ...;
|
|
108
|
+
function exportCallback(key, value) {
|
|
109
|
+
const iavlKey = `ssed.${key}`; // 'ssed' is short for SwingStoreExportData
|
|
110
|
+
if (value === undefined) {
|
|
111
|
+
iavl.delete(iavlKey);
|
|
112
|
+
} else {
|
|
113
|
+
iavl.set(iavlKey, value);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const swingStore = openSwingStore(dirPath, { exportCallback });
|
|
117
|
+
...
|
|
118
|
+
await controller.run();
|
|
119
|
+
hostStorage.commit();
|
|
120
|
+
|
|
121
|
+
// now, if the validator is configured to publish state-sync snapshots,
|
|
122
|
+
// and if this block height is one of the publishing points,
|
|
123
|
+
// do the following:
|
|
124
|
+
|
|
125
|
+
// spawn a child process and wait for it to open a transaction
|
|
126
|
+
const started = makePromiseKit();
|
|
127
|
+
const child = fork(path, args);
|
|
128
|
+
child.on('error', started.reject);
|
|
129
|
+
child.on('exit', started.reject);
|
|
130
|
+
child.on('message', msg => {
|
|
131
|
+
if (msg?.type === 'started') {
|
|
132
|
+
started.resolve();
|
|
122
133
|
}
|
|
123
|
-
|
|
134
|
+
});
|
|
135
|
+
try {
|
|
136
|
+
await started.promise;
|
|
137
|
+
} catch (err) {
|
|
138
|
+
...
|
|
139
|
+
}
|
|
140
|
+
...
|
|
141
|
+
|
|
142
|
+
// child process does:
|
|
143
|
+
const exporter = makeSwingStoreExporter(dirPath);
|
|
144
|
+
process.send({ type: 'started' });
|
|
145
|
+
// note: no exporter.getExportData(), the first-stage data is already in IAVL
|
|
146
|
+
const artifacts = new Map();
|
|
147
|
+
for (const name of exporter.getArtifactNames()) {
|
|
148
|
+
artifacts.set(name, exporter.getArtifact(name));
|
|
149
|
+
}
|
|
150
|
+
// instruct cosmos-sdk to include 'artifacts' in the state-sync snapshot
|
|
124
151
|
```
|
|
125
152
|
|
|
126
153
|
## Import
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/swing-store",
|
|
3
|
-
"version": "0.9.2-dev-
|
|
3
|
+
"version": "0.9.2-dev-a0c5f45.0+a0c5f45",
|
|
4
4
|
"description": "Persistent storage for SwingSet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"lint:eslint": "eslint ."
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@agoric/assert": "0.6.1-dev-
|
|
25
|
-
"@agoric/internal": "0.3.3-dev-
|
|
24
|
+
"@agoric/assert": "0.6.1-dev-a0c5f45.0+a0c5f45",
|
|
25
|
+
"@agoric/internal": "0.3.3-dev-a0c5f45.0+a0c5f45",
|
|
26
26
|
"@endo/base64": "^0.2.34",
|
|
27
27
|
"@endo/bundle-source": "^2.7.0",
|
|
28
28
|
"@endo/check-bundle": "^0.2.21",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"typeCoverage": {
|
|
52
52
|
"atLeast": 75.52
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "a0c5f45598785cdb60fb472649eecdcd13f05108"
|
|
55
55
|
}
|