diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 62f3efa88..89b3d767f 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -527,13 +527,12 @@ class Blocks { } } - let block = await bitcoinClient.getBlock(hash); - // Not Bitcoin network, return the block as it if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false) { - return block; + return await bitcoinApi.$getBlock(hash); } + let block = await bitcoinClient.getBlock(hash); block = prepareBlock(block); // Bitcoin network, add our custom data on top @@ -547,8 +546,8 @@ class Blocks { return blockExtended; } - public async $getStrippedBlockTransactions(hash: string, skipMemoryCache: boolean = false, - skipDBLookup: boolean = false): Promise + public async $getStrippedBlockTransactions(hash: string, skipMemoryCache = false, + skipDBLookup = false): Promise { if (skipMemoryCache === false) { // Check the memory cache diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 1dc9f66ea..fe6b858e0 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -172,7 +172,7 @@ export class Common { static indexingEnabled(): boolean { return ( - ['mainnet', 'testnet', 'signet', 'regtest'].includes(config.MEMPOOL.NETWORK) && + ['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) && config.DATABASE.ENABLED === true && config.MEMPOOL.INDEXING_BLOCKS_AMOUNT !== 0 ); diff --git a/backend/src/routes.ts b/backend/src/routes.ts index aeda734e1..0bd3aa7cf 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -761,7 +761,19 @@ class Routes { public async getBlock(req: Request, res: Response) { try { const block = await blocks.$getBlock(req.params.hash); - res.setHeader('Expires', new Date(Date.now() + 1000 * 600).toUTCString()); + + const blockAge = new Date().getTime() / 1000 - block.timestamp; + const day = 24 * 3600; + let cacheDuration; + if (blockAge > 365 * day) { + cacheDuration = 30 * day; + } else if (blockAge > 30 * day) { + cacheDuration = 10 * day; + } else { + cacheDuration = 600 + } + + res.setHeader('Expires', new Date(Date.now() + 1000 * cacheDuration).toUTCString()); res.json(block); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 7138c5748..c72038f38 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -6588,11 +6588,11 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "node_modules/common-shakeify": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/common-shakeify/-/common-shakeify-0.6.2.tgz", - "integrity": "sha512-vxlXr26fqxm8ZJ0jh8MlvpeN6IbyUKqsVmgb4rAjDM/0f4nKebiHaAXpF/Mm86W9ENR5iSI7UOnUTylpVyplUA==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/common-shakeify/-/common-shakeify-1.1.1.tgz", + "integrity": "sha512-M9hTU14RkpKvNggSU4zJIzgm89inwjnhipxvKxCNms/gM77R7keRqOqGYIM/Jr4BBhtbZB8ZF//raYqAbHk/DA==", "dependencies": { - "@goto-bus-stop/common-shake": "^2.2.0", + "@goto-bus-stop/common-shake": "^2.3.0", "convert-source-map": "^1.5.1", "through2": "^2.0.3", "transform-ast": "^2.4.3", @@ -8603,7 +8603,7 @@ "node_modules/escope": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/escope/-/escope-3.6.0.tgz", - "integrity": "sha1-4Bl16BJ4GhY6ba392AOY3GTIicM=", + "integrity": "sha512-75IUQsusDdalQEW/G/2esa87J7raqdJF+Ca0/Xm5C3Q58Nr4yVYjZGp/P1+2xiEVgXRrA39dpRb8LcshajbqDQ==", "dependencies": { "es6-map": "^0.1.3", "es6-weak-map": "^2.0.1", @@ -16304,15 +16304,15 @@ "integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==" }, "node_modules/tinyify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/tinyify/-/tinyify-3.0.0.tgz", - "integrity": "sha512-RtjVjC1xwwxt8AMVfxEmo+FzRJB6p5sAOtFaJj8vMrkWShtArsM4dLVRWhx2Vc07Me3NWgmP7pi9UPm/a2XNNA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/tinyify/-/tinyify-3.1.0.tgz", + "integrity": "sha512-r4tHoDkWhhoItWbxJ3KCHXask3hJN7gCUkR5PLfnQzQagTA6oDkzhCbiEDHkMqo7Ck7vVSA1pTP1gDc9p1AC1w==", "dependencies": { "@goto-bus-stop/envify": "^5.0.0", "acorn-node": "^1.8.2", "browser-pack-flat": "^3.0.9", "bundle-collapser": "^1.3.0", - "common-shakeify": "^0.6.0", + "common-shakeify": "^1.1.1", "dash-ast": "^1.0.0", "minify-stream": "^2.0.1", "multisplice": "^1.0.0", @@ -22670,11 +22670,11 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "common-shakeify": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/common-shakeify/-/common-shakeify-0.6.2.tgz", - "integrity": "sha512-vxlXr26fqxm8ZJ0jh8MlvpeN6IbyUKqsVmgb4rAjDM/0f4nKebiHaAXpF/Mm86W9ENR5iSI7UOnUTylpVyplUA==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/common-shakeify/-/common-shakeify-1.1.1.tgz", + "integrity": "sha512-M9hTU14RkpKvNggSU4zJIzgm89inwjnhipxvKxCNms/gM77R7keRqOqGYIM/Jr4BBhtbZB8ZF//raYqAbHk/DA==", "requires": { - "@goto-bus-stop/common-shake": "^2.2.0", + "@goto-bus-stop/common-shake": "^2.3.0", "convert-source-map": "^1.5.1", "through2": "^2.0.3", "transform-ast": "^2.4.3", @@ -24256,7 +24256,7 @@ "escope": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/escope/-/escope-3.6.0.tgz", - "integrity": "sha1-4Bl16BJ4GhY6ba392AOY3GTIicM=", + "integrity": "sha512-75IUQsusDdalQEW/G/2esa87J7raqdJF+Ca0/Xm5C3Q58Nr4yVYjZGp/P1+2xiEVgXRrA39dpRb8LcshajbqDQ==", "requires": { "es6-map": "^0.1.3", "es6-weak-map": "^2.0.1", @@ -30040,15 +30040,15 @@ "integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==" }, "tinyify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/tinyify/-/tinyify-3.0.0.tgz", - "integrity": "sha512-RtjVjC1xwwxt8AMVfxEmo+FzRJB6p5sAOtFaJj8vMrkWShtArsM4dLVRWhx2Vc07Me3NWgmP7pi9UPm/a2XNNA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/tinyify/-/tinyify-3.1.0.tgz", + "integrity": "sha512-r4tHoDkWhhoItWbxJ3KCHXask3hJN7gCUkR5PLfnQzQagTA6oDkzhCbiEDHkMqo7Ck7vVSA1pTP1gDc9p1AC1w==", "requires": { "@goto-bus-stop/envify": "^5.0.0", "acorn-node": "^1.8.2", "browser-pack-flat": "^3.0.9", "bundle-collapser": "^1.3.0", - "common-shakeify": "^0.6.0", + "common-shakeify": "^1.1.1", "dash-ast": "^1.0.0", "minify-stream": "^2.0.1", "multisplice": "^1.0.0", diff --git a/frontend/src/app/components/graphs/graphs.component.html b/frontend/src/app/components/graphs/graphs.component.html index 8914adf0a..6f93676f6 100644 --- a/frontend/src/app/components/graphs/graphs.component.html +++ b/frontend/src/app/components/graphs/graphs.component.html @@ -1,10 +1,10 @@