Skip to content

Commit ae2ed8f

Browse files
committed
[mining] fix pools updater only running at start
1 parent db10ab9 commit ae2ed8f

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

backend/src/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface IConfig {
3232
AUTOMATIC_POOLS_UPDATE: boolean;
3333
POOLS_JSON_URL: string,
3434
POOLS_JSON_TREE_URL: string,
35+
POOLS_UPDATE_DELAY: number,
3536
AUDIT: boolean;
3637
RUST_GBT: boolean;
3738
LIMIT_GBT: boolean;
@@ -192,6 +193,7 @@ const defaults: IConfig = {
192193
'AUTOMATIC_POOLS_UPDATE': false,
193194
'POOLS_JSON_URL': 'https://raw.githubusercontent.com/mempool/mining-pools/master/pools-v2.json',
194195
'POOLS_JSON_TREE_URL': 'https://api.github.com/repos/mempool/mining-pools/git/trees/master',
196+
'POOLS_UPDATE_DELAY': 604800, // in seconds, default is one week
195197
'AUDIT': false,
196198
'RUST_GBT': false,
197199
'LIMIT_GBT': false,

backend/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class Server {
239239
if (config.FIAT_PRICE.ENABLED) {
240240
priceUpdater.$run();
241241
}
242+
await poolsUpdater.updatePoolsJson();
242243

243244
// rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS
244245
const elapsed = Date.now() - start;

backend/src/tasks/pools-updater.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ class PoolsUpdater {
2323
return;
2424
}
2525

26-
const oneWeek = 604800;
27-
const oneDay = 86400;
28-
2926
const now = new Date().getTime() / 1000;
30-
if (now - this.lastRun < oneWeek) { // Execute the PoolsUpdate only once a week, or upon restart
27+
if (now - this.lastRun < config.MEMPOOL.POOLS_UPDATE_DELAY) { // Execute the PoolsUpdate only once a week, or upon restart
3128
return;
3229
}
3330

@@ -87,8 +84,8 @@ class PoolsUpdater {
8784
logger.info(`Mining pools-v2.json (${githubSha}) import completed`);
8885

8986
} catch (e) {
90-
this.lastRun = now - (oneWeek - oneDay); // Try again in 24h instead of waiting next week
91-
logger.err(`PoolsUpdater failed. Will try again in 24h. Exception: ${JSON.stringify(e)}`, logger.tags.mining);
87+
this.lastRun = now - 600; // Try again in 10 minutes
88+
logger.err(`PoolsUpdater failed. Will try again in 10 minutes. Exception: ${JSON.stringify(e)}`, logger.tags.mining);
9289
}
9390
}
9491

0 commit comments

Comments
 (0)