Skip to content

Commit

Permalink
Bring back MAX_GAS_PRICE but with high default
Browse files Browse the repository at this point in the history
  • Loading branch information
thodges-gh committed Mar 13, 2020
1 parent 03a4ba6 commit bf7019e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * * * *'
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 23 additions & 2 deletions test/requests_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('createRequests', () => {
wei: '1000000000,1000000000,1000000000',
fallbackGasPrice: 25000000000,
addedGasPrice: 1000000000,

maxGasPrice: 50000000000
}

const expected = 21000000000
Expand All @@ -67,6 +67,7 @@ describe('createRequests', () => {
wei: '1000000000,1000000000',
fallbackGasPrice: 25000000000,
addedGasPrice: 1000000000,
maxGasPrice: 50000000000
}

const expected = 16000000000
Expand All @@ -85,6 +86,7 @@ describe('createRequests', () => {
wei: '1000000000,1000000000,1000000000',
fallbackGasPrice: 25000000000,
addedGasPrice: 1000000000,
maxGasPrice: 50000000000
}

const expected = 16000000000
Expand All @@ -103,6 +105,7 @@ describe('createRequests', () => {
wei: '1000000000,1000000000,1000000000',
fallbackGasPrice: 25000000000,
addedGasPrice: 1000000000,
maxGasPrice: 50000000000
}
const expected = 26000000000

Expand All @@ -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', () => {
Expand All @@ -121,7 +142,7 @@ describe('createRequests', () => {
wei: '1000000000,1000000000,1000000000',
fallbackGasPrice: 25000000000,
addedGasPrice: 1000000000,

maxGasPrice: 50000000000
}

const expected = 21000000000
Expand Down

0 comments on commit bf7019e

Please sign in to comment.