dcp-worker 3.2.29 → 3.2.30-1

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,14 @@ 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
131
  },
132
132
 
133
133
  identityKey: {
@@ -242,7 +242,7 @@ async function main()
242
242
  port: cliArgs.port
243
243
  };
244
244
 
245
- verifyDefaultConfigIntegrity();
245
+ verifyDefaultConfigIntegrity(); /* Bail before TUI & as early as possible if config file is bad */
246
246
 
247
247
  process.on('SIGINT', handleSigDeath);
248
248
  process.on('SIGTERM', handleSigDeath);
@@ -260,7 +260,7 @@ async function main()
260
260
  if (cliArgs.pidFile)
261
261
  require('../lib/pidfile').write(cliArgs.pidFile);
262
262
 
263
- /* Figure out of the worker's identity and put that keystore in the wallet */
263
+ /* Figure out the worker's identity and put that keystore in the wallet */
264
264
  let identityKeystore = false;
265
265
  if (cliArgs.identityKey)
266
266
  identityKeystore = await new wallet.IdKeystore(cliArgs.identityKey, '');
@@ -278,11 +278,13 @@ async function main()
278
278
  * which were derived from dcpConfig in the first place. defaultOptions are overrideable by the usual
279
279
  * dcpConfig mechanisms, but since they are dynamic (or non-user-facing) they don't come from the
280
280
  * etc/dcp-worker-config.js file that ships with the work.
281
+ *
282
+ * It is important to never disable leavePublicGroup as a side effect of any other operation, or
283
+ * slight configuration errors could have large security impacts.
281
284
  */
282
285
  const dcpWorkerOptions = dcpConfig.worker;
283
286
  const forceOptions = {
284
287
  paymentAddress,
285
- leavePublicGroup: cliArgs.leavePublicGroup || dcpConfig.worker.leavePublicGroup || cliArgs.publicGroupFallback || false,
286
288
  };
287
289
  const defaultOptions = {
288
290
  sandboxOptions: {
@@ -290,9 +292,21 @@ async function main()
290
292
  },
291
293
  };
292
294
 
295
+ if (cliArgs.leavePublicGroup !== undefined)
296
+ forceOptions.leavePublicGroup = mkBool(cliArgs.leavePublicGroup);
297
+ if (cliArgs.publicGroupFallback !== undefined)
298
+ forceOptions.publicGroupFallback = mkBool(cliArgs.publicGroupFallback);
299
+
293
300
  addConfig(dcpWorkerOptions, defaultOptions, dcpConfig.worker, forceOptions);
294
301
  processCoresAndDensity(dcpWorkerOptions, cliArgs);
295
302
 
303
+ /* Support magic value used by Windows screensaver configuration /wg June 2023 */
304
+ if (dcpWorkerOptions.leavePublicGroup === 'fallback')
305
+ {
306
+ dcpWorkerOptions.publicGroupFallback = true;
307
+ dcpWorkerOptions.leavePublicGroup = undefined;
308
+ }
309
+
296
310
  /* cliArgs.join is the list of compute groups to join */
297
311
  if (cliArgs.join && cliArgs.join.length)
298
312
  {
@@ -345,27 +359,37 @@ async function main()
345
359
 
346
360
  require('../lib/remote-console').setMainEval(function mainEval() { return eval(arguments[0]) });
347
361
 
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))
362
+ if (dcpWorkerOptions.publicGroupFallback)
354
363
  {
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
- }
364
+ if (dcpWorkerOptions.leavePublicGroup)
365
+ console.warn(' ! Public Group fallback has been requested, but the public group is blocked by local configuration');
362
366
  else
363
367
  {
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
- });
368
+ /* Enable public group fallback - this currently works by enabling or disabling the public group
369
+ * on the next fetch based on whether or not the most recent fetch was an empty task or not.
370
+ */
371
+ worker.on('fetch', fetchEventHandler);
372
+
373
+ function fetchEventHandler(ev)
374
+ {
375
+ var slicesFetched;
376
+
377
+ if (ev instanceof Error)
378
+ {
379
+ console.error('Error fetching task:', ev);
380
+ return;
381
+ }
382
+
383
+ if (typeof ev === 'string') /* <= June 2023 Worker events: remove ~ Sep 2023 /wg */
384
+ slicesFetched = ev;
385
+ else
386
+ {
387
+ const task = ev;
388
+ slicesFetched = task.slices?.length;
389
+ }
390
+
391
+ dcpWorkerOptions.leavePublicGroup = Boolean(slicesFetched > 0);
392
+ }
369
393
  }
370
394
  }
371
395
 
@@ -395,7 +419,7 @@ async function main()
395
419
  introBanner += ` . Joining compute ${qty(dcpWorkerOptions.computeGroups, 'group')} ` + dcpWorkerOptions.computeGroups.map(el => el.joinKey).join(', ') + '\n';
396
420
  if (dcpWorkerOptions.publicGroupFallback)
397
421
  introBanner += ' . Falling back on public group when preferred groups have no work' + '\n';
398
- else if (dcpWorkerOptions.leavePublicGroup)
422
+ if (dcpWorkerOptions.leavePublicGroup)
399
423
  introBanner += ' . Leaving the public compute group' + '\n';
400
424
  if (dcpWorkerOptions.cores)
401
425
  introBanner += ` . Target cores: ${JSON.stringify(dcpWorkerOptions.cores)}\n`;
@@ -679,7 +703,7 @@ function verifyDefaultConfigIntegrity()
679
703
  {
680
704
  const originalMd5sum = fs.readFileSync(md5sumPath, 'ascii');
681
705
  const actualMd5sum = crypto.createHash('md5')
682
- .update(fs.readFileSync(workerConfPath, 'ascii'))
706
+ .update(fs.readFileSync(workerConfPath))
683
707
  .digest('hex');
684
708
 
685
709
  if (!originalMd5sum.startsWith(actualMd5sum))
@@ -707,3 +731,12 @@ function verifyDefaultConfigIntegrity()
707
731
  process.exit(1);
708
732
  }
709
733
  }
734
+
735
+ /**
736
+ * Cast b to boolean such that 'false' becomes false, falsey things become false, and everything else
737
+ * becomes true.
738
+ */
739
+ function mkBool(b)
740
+ {
741
+ return Boolean(b) && (b !== 'false');
742
+ }
@@ -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-1",
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",
@@ -49,6 +49,6 @@
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=16",
52
- "npm": ">=6"
52
+ "npm": ">=7"
53
53
  }
54
54
  }