hyper-multisig-cli 1.6.1 → 1.7.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/bin.js +55 -10
- package/package.json +2 -2
package/bin.js
CHANGED
|
@@ -14,6 +14,7 @@ const z32 = require('z32')
|
|
|
14
14
|
const DEFAULT_CONFIG_PATH = './multisig.json'
|
|
15
15
|
const DEFAULT_STORAGE_PATH = './storage'
|
|
16
16
|
const DEFAULT_SEED_LOG_INTERVAL = 15000
|
|
17
|
+
const DEFAULT_PROGRESS_LOG_INTERVAL = 2000
|
|
17
18
|
|
|
18
19
|
const cmdLink = command('link', description('Create multisig key'), wrapErrHandler(link))
|
|
19
20
|
|
|
@@ -38,6 +39,9 @@ const cmdVerify = command(
|
|
|
38
39
|
flag('--skip-target-well-seeded', 'Skip checking multisig target is well seeded'),
|
|
39
40
|
|
|
40
41
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
42
|
+
flag('--progress-log-interval <ms>', 'Minimum interval in ms between progress logs').default(
|
|
43
|
+
DEFAULT_PROGRESS_LOG_INTERVAL
|
|
44
|
+
),
|
|
41
45
|
arg('request', 'Signing request'),
|
|
42
46
|
rest('[...responses]', 'Signing responses'),
|
|
43
47
|
wrapErrHandler(verify)
|
|
@@ -54,6 +58,9 @@ const cmdCommit = command(
|
|
|
54
58
|
flag('--skip-target-well-seeded', 'Skip checking multisig target is well seeded'),
|
|
55
59
|
flag('--force-dangerous', 'Advanced option, it might break the core on misuse'),
|
|
56
60
|
flag('--peer-update-timeout <ms>', 'Peer update timeout in ms'),
|
|
61
|
+
flag('--progress-log-interval <ms>', 'Minimum interval in ms between progress logs').default(
|
|
62
|
+
DEFAULT_PROGRESS_LOG_INTERVAL
|
|
63
|
+
),
|
|
57
64
|
arg('request', 'Signing request'),
|
|
58
65
|
rest('[...responses]', 'Signing responses'),
|
|
59
66
|
wrapErrHandler(commit)
|
|
@@ -94,7 +101,7 @@ async function request() {
|
|
|
94
101
|
const { force, peerUpdateTimeout } = cmdRequest.flags
|
|
95
102
|
if (!length) throw new Error('Invalid command')
|
|
96
103
|
|
|
97
|
-
const { type, publicKeys, namespace, srcKey, quorum, store, swarm } = await setup()
|
|
104
|
+
const { type, publicKeys, namespace, srcKey, quorum, legacy, store, swarm } = await setup()
|
|
98
105
|
const multisig = new Multisig(store, swarm)
|
|
99
106
|
|
|
100
107
|
let request
|
|
@@ -105,7 +112,7 @@ async function request() {
|
|
|
105
112
|
force,
|
|
106
113
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
107
114
|
quorum,
|
|
108
|
-
legacy
|
|
115
|
+
legacy // legacy requests compat with hypercore-sign v3
|
|
109
116
|
})
|
|
110
117
|
.done()
|
|
111
118
|
request = res.request
|
|
@@ -115,7 +122,7 @@ async function request() {
|
|
|
115
122
|
force,
|
|
116
123
|
peerUpdateTimeout: peerUpdateTimeout,
|
|
117
124
|
quorum,
|
|
118
|
-
legacy
|
|
125
|
+
legacy // legacy requests compat with hypercore-sign v3
|
|
119
126
|
})
|
|
120
127
|
|
|
121
128
|
req.on('getting-src-blobs', () => {
|
|
@@ -145,6 +152,7 @@ async function request() {
|
|
|
145
152
|
async function verify() {
|
|
146
153
|
const { start, blobsStart, firstCommit, peerUpdateTimeout, skipTargetWellSeeded } =
|
|
147
154
|
cmdVerify.flags
|
|
155
|
+
const progressLogInterval = +cmdVerify.flags.progressLogInterval
|
|
148
156
|
const request = cmdVerify.args.request
|
|
149
157
|
const responses = cmdVerify.rest || []
|
|
150
158
|
if (!request) throw new Error('Invalid command')
|
|
@@ -157,6 +165,7 @@ async function verify() {
|
|
|
157
165
|
let runner
|
|
158
166
|
if (type === 'core') {
|
|
159
167
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
168
|
+
logDownloadProgress(srcCore, progressLogInterval)
|
|
160
169
|
runner = multisig.verifyCore(publicKeys, namespace, srcCore, request, responses, {
|
|
161
170
|
start,
|
|
162
171
|
skipTargetChecks: firstCommit,
|
|
@@ -167,6 +176,8 @@ async function verify() {
|
|
|
167
176
|
})
|
|
168
177
|
} else {
|
|
169
178
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
179
|
+
logDownloadProgress(srcDrive.core, progressLogInterval)
|
|
180
|
+
srcDrive.once('blobs', (blobs) => logDownloadProgress(blobs.core, progressLogInterval))
|
|
170
181
|
runner = multisig.verifyDrive(publicKeys, namespace, srcDrive, request, responses, {
|
|
171
182
|
start,
|
|
172
183
|
blobsStart,
|
|
@@ -177,7 +188,7 @@ async function verify() {
|
|
|
177
188
|
quorum
|
|
178
189
|
})
|
|
179
190
|
}
|
|
180
|
-
setupProgressLogs(runner, type, firstCommit, true)
|
|
191
|
+
setupProgressLogs(runner, type, firstCommit, true, progressLogInterval)
|
|
181
192
|
|
|
182
193
|
const res = await runner.done()
|
|
183
194
|
|
|
@@ -192,6 +203,7 @@ async function commit() {
|
|
|
192
203
|
const responses = cmdCommit.rest || []
|
|
193
204
|
const { swarmClientOnly, firstCommit, skipTargetWellSeeded, forceDangerous, peerUpdateTimeout } =
|
|
194
205
|
cmdCommit.flags
|
|
206
|
+
const progressLogInterval = +cmdCommit.flags.progressLogInterval
|
|
195
207
|
|
|
196
208
|
if (!request || !responses?.length) throw new Error('Invalid command')
|
|
197
209
|
|
|
@@ -204,6 +216,7 @@ async function commit() {
|
|
|
204
216
|
let runner
|
|
205
217
|
if (type === 'core') {
|
|
206
218
|
const srcCore = store.get({ key: idEnc.decode(srcKey) })
|
|
219
|
+
logDownloadProgress(srcCore, progressLogInterval)
|
|
207
220
|
runner = multisig.commitCore(publicKeys, namespace, srcCore, request, responses, {
|
|
208
221
|
swarmAsServer: !swarmClientOnly,
|
|
209
222
|
skipTargetChecks: firstCommit,
|
|
@@ -214,6 +227,8 @@ async function commit() {
|
|
|
214
227
|
})
|
|
215
228
|
} else {
|
|
216
229
|
const srcDrive = new Hyperdrive(store, idEnc.decode(srcKey))
|
|
230
|
+
logDownloadProgress(srcDrive.core, progressLogInterval)
|
|
231
|
+
srcDrive.once('blobs', (blobs) => logDownloadProgress(blobs.core, progressLogInterval))
|
|
217
232
|
runner = multisig.commitDrive(publicKeys, namespace, srcDrive, request, responses, {
|
|
218
233
|
swarmAsServer: !swarmClientOnly,
|
|
219
234
|
skipTargetChecks: firstCommit,
|
|
@@ -223,7 +238,7 @@ async function commit() {
|
|
|
223
238
|
quorum
|
|
224
239
|
})
|
|
225
240
|
}
|
|
226
|
-
setupProgressLogs(runner, type, firstCommit, false)
|
|
241
|
+
setupProgressLogs(runner, type, firstCommit, false, progressLogInterval)
|
|
227
242
|
|
|
228
243
|
const res = await runner.done()
|
|
229
244
|
|
|
@@ -319,7 +334,7 @@ async function seed() {
|
|
|
319
334
|
goodbye(() => clearInterval(interval))
|
|
320
335
|
}
|
|
321
336
|
|
|
322
|
-
function setupProgressLogs(req, name, firstCommit, dryRun) {
|
|
337
|
+
function setupProgressLogs(req, name, firstCommit, dryRun, progressLogInterval) {
|
|
323
338
|
req.on('verify-committable-start', (srcKey, tgtKey) => {
|
|
324
339
|
console.log(
|
|
325
340
|
`Verifying the ${name} is safe to commit: source ${idEnc.normalize(srcKey)} (hex: ${srcKey.toString('hex')}) to multisig target ${idEnc.normalize(tgtKey)} (hex: ${tgtKey.toString('hex')})`
|
|
@@ -328,6 +343,11 @@ function setupProgressLogs(req, name, firstCommit, dryRun) {
|
|
|
328
343
|
req.on('commit-start', () => {
|
|
329
344
|
console.log(dryRun ? `Dry running the ${name} commit` : `Committing the ${name}...`)
|
|
330
345
|
})
|
|
346
|
+
req.on('commit-blobs-progress', logBatchProgress('blobs batch', progressLogInterval))
|
|
347
|
+
req.on(
|
|
348
|
+
'commit-progress',
|
|
349
|
+
logBatchProgress(name === 'drive' ? 'db batch' : 'batch', progressLogInterval)
|
|
350
|
+
)
|
|
331
351
|
req.on('verify-committed-start', (key) => {
|
|
332
352
|
console.log(`Committed the ${name}, key ${idEnc.normalize(key)} (hex: ${key.toString('hex')})`)
|
|
333
353
|
console.log('Waiting for remote seeders to pick up the changes...')
|
|
@@ -339,6 +359,30 @@ function setupProgressLogs(req, name, firstCommit, dryRun) {
|
|
|
339
359
|
})
|
|
340
360
|
}
|
|
341
361
|
|
|
362
|
+
function logBatchProgress(label, interval) {
|
|
363
|
+
let lastLog = 0
|
|
364
|
+
return ({ processed, total }) => {
|
|
365
|
+
const now = Date.now()
|
|
366
|
+
if (processed < total && now - lastLog < interval) return
|
|
367
|
+
lastLog = now
|
|
368
|
+
console.log(`Preparing ${label}: ${processed} / ${total} blocks`)
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function logDownloadProgress(core, interval) {
|
|
373
|
+
let downloaded = 0
|
|
374
|
+
let lastLog = 0
|
|
375
|
+
core.on('download', () => {
|
|
376
|
+
downloaded++
|
|
377
|
+
const now = Date.now()
|
|
378
|
+
if (now - lastLog < interval) return
|
|
379
|
+
lastLog = now
|
|
380
|
+
console.log(
|
|
381
|
+
`Downloading source core ${idEnc.normalize(core.key)}: ${downloaded} blocks downloaded`
|
|
382
|
+
)
|
|
383
|
+
})
|
|
384
|
+
}
|
|
385
|
+
|
|
342
386
|
function printRequest(request) {
|
|
343
387
|
const runner = SignRequest.decode(request)
|
|
344
388
|
const reqStr = z32.encode(request)
|
|
@@ -369,7 +413,7 @@ async function setup(opts = {}) {
|
|
|
369
413
|
|
|
370
414
|
const { withReplication = true } = opts
|
|
371
415
|
|
|
372
|
-
const { type, publicKeys, namespace, srcKey, bootstrap, quorum } = await loadConfig(
|
|
416
|
+
const { type, publicKeys, namespace, srcKey, bootstrap, quorum, legacy } = await loadConfig(
|
|
373
417
|
configPath,
|
|
374
418
|
opts
|
|
375
419
|
)
|
|
@@ -381,7 +425,7 @@ async function setup(opts = {}) {
|
|
|
381
425
|
swarm = res.swarm
|
|
382
426
|
}
|
|
383
427
|
|
|
384
|
-
return { type, publicKeys, namespace, srcKey, quorum, store, swarm }
|
|
428
|
+
return { type, publicKeys, namespace, srcKey, quorum, legacy, store, swarm }
|
|
385
429
|
}
|
|
386
430
|
|
|
387
431
|
/**
|
|
@@ -395,7 +439,8 @@ async function loadConfig(configPath, opts = {}) {
|
|
|
395
439
|
srcKey,
|
|
396
440
|
bootstrap,
|
|
397
441
|
quorum = null,
|
|
398
|
-
multisigKey = null
|
|
442
|
+
multisigKey = null,
|
|
443
|
+
legacy = true
|
|
399
444
|
} = JSON.parse(await fs.readFile(configPath, 'utf-8'))
|
|
400
445
|
|
|
401
446
|
const { srcKeyRequired = true } = opts
|
|
@@ -425,7 +470,7 @@ async function loadConfig(configPath, opts = {}) {
|
|
|
425
470
|
}
|
|
426
471
|
}
|
|
427
472
|
|
|
428
|
-
return { type, publicKeys, namespace, srcKey, bootstrap, quorum }
|
|
473
|
+
return { type, publicKeys, namespace, srcKey, bootstrap, quorum, legacy }
|
|
429
474
|
}
|
|
430
475
|
|
|
431
476
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyper-multisig-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "CLI of hyper-multisig",
|
|
5
5
|
"main": "bin.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"bare-fs": "^4.5.4",
|
|
22
22
|
"corestore": "^7.8.0",
|
|
23
23
|
"graceful-goodbye": "^1.3.3",
|
|
24
|
-
"hyper-multisig": "^2.
|
|
24
|
+
"hyper-multisig": "^2.5.0",
|
|
25
25
|
"hypercore-id-encoding": "^1.3.0",
|
|
26
26
|
"hypercore-signing-request": "^5.0.1",
|
|
27
27
|
"hyperdrive": "^13.2.1",
|