dcp-worker 3.2.29 → 3.2.30-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/.gitlab-ci.yml CHANGED
@@ -28,4 +28,5 @@ tidelift:
28
28
  script:
29
29
  - echo "Running alignment and saving to Tidelift"
30
30
  - ./tidelift alignment save --wait
31
+ allow_failure: true
31
32
  cache: []
package/bin/dcp-worker CHANGED
@@ -120,14 +120,15 @@ function parseCliArgs()
120
120
 
121
121
  leavePublicGroup: {
122
122
  type: 'boolean',
123
- describe: 'Do not fetch slices from public compute group. Ignored if --publicGroupFallback is set',
124
- default: false,
123
+ describe: 'Do not fetch slices from public compute group.',
124
+ default: undefined,
125
125
  },
126
+
126
127
  publicGroupFallback: {
127
128
  describe: 'If set, worker will prefer private groups but fall back on the public group if no preferred work is available',
128
129
  type: 'boolean',
129
- default: 'false',
130
- defaultDescription: false,
130
+ default: 'undefined',
131
+ defaultDescription: undefined,
131
132
  },
132
133
 
133
134
  identityKey: {
@@ -242,7 +243,7 @@ async function main()
242
243
  port: cliArgs.port
243
244
  };
244
245
 
245
- verifyDefaultConfigIntegrity();
246
+ verifyDefaultConfigIntegrity(); /* Bail before TUI & as early as possible if config file is bad */
246
247
 
247
248
  process.on('SIGINT', handleSigDeath);
248
249
  process.on('SIGTERM', handleSigDeath);
@@ -260,7 +261,7 @@ async function main()
260
261
  if (cliArgs.pidFile)
261
262
  require('../lib/pidfile').write(cliArgs.pidFile);
262
263
 
263
- /* Figure out of the worker's identity and put that keystore in the wallet */
264
+ /* Figure out the worker's identity and put that keystore in the wallet */
264
265
  let identityKeystore = false;
265
266
  if (cliArgs.identityKey)
266
267
  identityKeystore = await new wallet.IdKeystore(cliArgs.identityKey, '');
@@ -278,11 +279,13 @@ async function main()
278
279
  * which were derived from dcpConfig in the first place. defaultOptions are overrideable by the usual
279
280
  * dcpConfig mechanisms, but since they are dynamic (or non-user-facing) they don't come from the
280
281
  * etc/dcp-worker-config.js file that ships with the work.
282
+ *
283
+ * It is important to never disable leavePublicGroup as a side effect of any other operation, or
284
+ * slight configuration errors could have large security impacts.
281
285
  */
282
286
  const dcpWorkerOptions = dcpConfig.worker;
283
287
  const forceOptions = {
284
288
  paymentAddress,
285
- leavePublicGroup: cliArgs.leavePublicGroup || dcpConfig.worker.leavePublicGroup || cliArgs.publicGroupFallback || false,
286
289
  };
287
290
  const defaultOptions = {
288
291
  sandboxOptions: {
@@ -290,9 +293,21 @@ async function main()
290
293
  },
291
294
  };
292
295
 
296
+ if (cliArgs.leavePublicGroup !== undefined)
297
+ forceOptions.leavePublicGroup = mkBool(cliArgs.leavePublicGroup);
298
+ if (cliArgs.publicGroupFallback !== undefined)
299
+ forceOptions.publicGroupFallback = mkBool(cliArgs.publicGroupFallback);
300
+
293
301
  addConfig(dcpWorkerOptions, defaultOptions, dcpConfig.worker, forceOptions);
294
302
  processCoresAndDensity(dcpWorkerOptions, cliArgs);
295
303
 
304
+ /* Support magic value used by Windows screensaver configuration /wg June 2023 */
305
+ if (dcpWorkerOptions.leavePublicGroup === 'fallback')
306
+ {
307
+ dcpWorkerOptions.publicGroupFallback = true;
308
+ dcpWorkerOptions.leavePublicGroup = undefined;
309
+ }
310
+
296
311
  /* cliArgs.join is the list of compute groups to join */
297
312
  if (cliArgs.join && cliArgs.join.length)
298
313
  {
@@ -345,27 +360,37 @@ async function main()
345
360
 
346
361
  require('../lib/remote-console').setMainEval(function mainEval() { return eval(arguments[0]) });
347
362
 
348
- // Activate public group fallback
349
- // If requested by CLI
350
- // OR if requested by dcpConfig and not forbidden by the cli
351
- if (cliArgs.publicGroupFallback
352
- || (dcpConfig.worker?.leavePublicGroup === 'fallback'
353
- && typeof cliArgs.publicGroupFallback !== false))
363
+ if (dcpWorkerOptions.publicGroupFallback)
354
364
  {
355
- dcpWorkerOptions.publicGroupFallback = true;
356
-
357
- // If local config blocks the public group, then complain instead of activating fallback
358
- if (dcpConfig.worker?.leavePublicGroup === true)
359
- {
360
- console.warn('* Public Group fallback has been requested, but the public group is blocked by local configuration');
361
- }
365
+ if (dcpWorkerOptions.leavePublicGroup)
366
+ console.warn(' ! Public Group fallback has been requested, but the public group is blocked by local configuration');
362
367
  else
363
368
  {
364
- worker.on('fetchend', slicesFetched => {
365
- // Iff we got work in this fetch, then leave the public group for the
366
- // next fetch
367
- dcpConfig.worker.leavePublicGroup = Boolean(slicesFetched > 0);
368
- });
369
+ /* Enable public group fallback - this currently works by enabling or disabling the public group
370
+ * on the next fetch based on whether or not the most recent fetch was an empty task or not.
371
+ */
372
+ worker.on('fetch', fetchEventHandler);
373
+
374
+ function fetchEventHandler(ev)
375
+ {
376
+ var slicesFetched;
377
+
378
+ if (ev instanceof Error)
379
+ {
380
+ console.error('Error fetching task:', ev);
381
+ return;
382
+ }
383
+
384
+ if (typeof ev === 'number') /* <= June 2023 Worker events: remove ~ Sep 2023 /wg */
385
+ slicesFetched = ev;
386
+ else
387
+ {
388
+ const task = ev;
389
+ slicesFetched = task.slices.length;
390
+ }
391
+
392
+ dcpWorkerOptions.leavePublicGroup = Boolean(slicesFetched > 0);
393
+ }
369
394
  }
370
395
  }
371
396
 
@@ -395,7 +420,7 @@ async function main()
395
420
  introBanner += ` . Joining compute ${qty(dcpWorkerOptions.computeGroups, 'group')} ` + dcpWorkerOptions.computeGroups.map(el => el.joinKey).join(', ') + '\n';
396
421
  if (dcpWorkerOptions.publicGroupFallback)
397
422
  introBanner += ' . Falling back on public group when preferred groups have no work' + '\n';
398
- else if (dcpWorkerOptions.leavePublicGroup)
423
+ if (dcpWorkerOptions.leavePublicGroup)
399
424
  introBanner += ' . Leaving the public compute group' + '\n';
400
425
  if (dcpWorkerOptions.cores)
401
426
  introBanner += ` . Target cores: ${JSON.stringify(dcpWorkerOptions.cores)}\n`;
@@ -679,7 +704,7 @@ function verifyDefaultConfigIntegrity()
679
704
  {
680
705
  const originalMd5sum = fs.readFileSync(md5sumPath, 'ascii');
681
706
  const actualMd5sum = crypto.createHash('md5')
682
- .update(fs.readFileSync(workerConfPath, 'ascii'))
707
+ .update(fs.readFileSync(workerConfPath))
683
708
  .digest('hex');
684
709
 
685
710
  if (!originalMd5sum.startsWith(actualMd5sum))
@@ -707,3 +732,12 @@ function verifyDefaultConfigIntegrity()
707
732
  process.exit(1);
708
733
  }
709
734
  }
735
+
736
+ /**
737
+ * Cast b to boolean such that 'false' becomes false, falsey things become false, and everything else
738
+ * becomes true.
739
+ */
740
+ function mkBool(b)
741
+ {
742
+ return Boolean(b) && (b !== 'false');
743
+ }
@@ -30,7 +30,10 @@ function getLogger({ outputMode='detect' }) {
30
30
  catch (error)
31
31
  {
32
32
  console.error(`032: Failed to load worker logger "${outputMode}":`, error);
33
- throw new Error(`Unknown outputMode "${outputMode}"`);
33
+
34
+ if (error.code === 'MODULE_NOT_FOUND')
35
+ throw new Error(`Unknown outputMode "${outputMode}"`);
36
+ throw error;
34
37
  }
35
38
  }
36
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcp-worker",
3
- "version": "3.2.29",
3
+ "version": "3.2.30-0",
4
4
  "description": "JavaScript portion of DCP Workers for Node.js",
5
5
  "main": "bin/dcp-worker",
6
6
  "keywords": [
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git@github.com:Distributed-Compute-Labs/dcp-worker.git"
15
+ "url": "git+ssh://git@gitlab.com/Distributed-Compute-Protocol/dcp-worker.git"
16
16
  },
17
17
  "license": "MIT",
18
18
  "author": "Kings Distributed Systems",
@@ -37,7 +37,7 @@
37
37
  "blessed": "^0.1.81",
38
38
  "blessed-contrib": "^4.11.0",
39
39
  "chalk": "^4.1.0",
40
- "dcp-client": "4.2.32",
40
+ "dcp-client": "gitlab:Distributed-Compute-Protocol/dcp-client#develop",
41
41
  "semver": "^7.3.8"
42
42
  },
43
43
  "optionalDependencies": {
@@ -49,6 +49,6 @@
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=16",
52
- "npm": ">=6"
52
+ "npm": ">=7"
53
53
  }
54
54
  }