From af2b2bf80331830c55261c0b8dc7117440f5cd56 Mon Sep 17 00:00:00 2001 From: benoit Date: Mon, 22 Jul 2024 15:19:07 -0400 Subject: [PATCH] Randomize (and limit) mining jobs --- lib/jobManager.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/jobManager.js b/lib/jobManager.js index e58e354..e4d1fa8 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -79,8 +79,13 @@ function JobManager(jobExpiryPeriod){ job.jobId = jobId; return new blockTemplate(job, now); }) - _this.validJobs.addJobs(miningJobs, now); - _this.emit('newJobs', miningJobs); + // randomize and limit miningJobs + randomizedMiningJobs = miningJobs.map(value => ({ value, sort: Math.random() })) + .sort((a, b) => a.sort - b.sort) + .map(({ value }) => value) + .slice(0,3) + _this.validJobs.addJobs(randomizedMiningJobs, now); + _this.emit('newJobs', randomizedMiningJobs); }; function validateNonce(nonceHex){