From bf7019edd163bb5827102a1274763ce2214bf125 Mon Sep 17 00:00:00 2001 From: Thomas Hodges Date: Fri, 13 Mar 2020 11:06:13 -0500 Subject: [PATCH] Bring back MAX_GAS_PRICE but with high default --- README.md | 2 ++ config.js | 1 + package.json | 2 +- requests.js | 3 ++- test/requests_test.js | 25 +++++++++++++++++++++++-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 393219a..e5ca851 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ The `URLS`, `FIELDS`, and `WEI` environment variables need to use the same index - Default value: `25000000000` - `ADD_GAS_PRICE`: The amount of gas (in wei) to add to the max of the gas price results. - Default value: `1000000000` +- `MAX_GAS_PRICE`: The maximum gas price to send to the node if the data feeds respond with a higher value. + - Default value: `1000000000000` - `LOG_LEVEL`: The log level for the output. - Default value: `'info'` - `CRON_SCHEDULE`: The Cron schedule to use for updating gas prices (6 places) diff --git a/config.js b/config.js index ee7c29a..0026752 100644 --- a/config.js +++ b/config.js @@ -11,6 +11,7 @@ const config = { wei: process.env.WEI || '100000000,1000000000,1000000000,1000000000', fallbackGasPrice: process.env.FALLBACK_GAS_PRICE || 25000000000, addedGasPrice: process.env.ADD_GAS_PRICE || 1000000000, + maxGasPrice: process.env.MAX_GAS_PRICE || 1000000000000 }, schedule: process.env.CRON_SCHEDULE || '0 * * * * *' } diff --git a/package.json b/package.json index 38593fa..9d0ff7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cl-gas-updater", - "version": "0.1.2", + "version": "0.1.3", "description": "A service which updates the gas price for Chainlink responses", "keywords": [ "chainlink", diff --git a/requests.js b/requests.js index ba2a964..8daf303 100644 --- a/requests.js +++ b/requests.js @@ -25,7 +25,8 @@ const createRequests = async (details) => { prices.push(parseInt(details.fallbackGasPrice)) } logger.debug(prices) - return Math.max(...prices) + parseInt(details.addedGasPrice) + const gasPrice = Math.max(...prices) + parseInt(details.addedGasPrice) + return Math.min(gasPrice, details.maxGasPrice) } exports.createRequests = createRequests diff --git a/test/requests_test.js b/test/requests_test.js index dd354d9..31132d0 100644 --- a/test/requests_test.js +++ b/test/requests_test.js @@ -47,7 +47,7 @@ describe('createRequests', () => { wei: '1000000000,1000000000,1000000000', fallbackGasPrice: 25000000000, addedGasPrice: 1000000000, - + maxGasPrice: 50000000000 } const expected = 21000000000 @@ -67,6 +67,7 @@ describe('createRequests', () => { wei: '1000000000,1000000000', fallbackGasPrice: 25000000000, addedGasPrice: 1000000000, + maxGasPrice: 50000000000 } const expected = 16000000000 @@ -85,6 +86,7 @@ describe('createRequests', () => { wei: '1000000000,1000000000,1000000000', fallbackGasPrice: 25000000000, addedGasPrice: 1000000000, + maxGasPrice: 50000000000 } const expected = 16000000000 @@ -103,6 +105,7 @@ describe('createRequests', () => { wei: '1000000000,1000000000,1000000000', fallbackGasPrice: 25000000000, addedGasPrice: 1000000000, + maxGasPrice: 50000000000 } const expected = 26000000000 @@ -112,6 +115,24 @@ describe('createRequests', () => { assert.equal(gasPrice, expected) }) }) + + context('gas price too high', () => { + const details = { + urls: 'http://localhost:8080/test,http://localhost:8080/test,http://localhost:8080/test', + fields: 'tooHigh,tooHigh,tooHigh', + wei: '1000000000,1000000000,1000000000', + fallbackGasPrice: 25000000000, + addedGasPrice: 1000000000, + maxGasPrice: 50000000000 + } + const expected = 50000000000 + + it('returns the expected result', async () => { + const gasPrice = await createRequests(details) + assert.isNumber(gasPrice) + assert.equal(gasPrice, expected) + }) + }) }) context('when an endpoint returns an error', () => { @@ -121,7 +142,7 @@ describe('createRequests', () => { wei: '1000000000,1000000000,1000000000', fallbackGasPrice: 25000000000, addedGasPrice: 1000000000, - + maxGasPrice: 50000000000 } const expected = 21000000000