Skip to content

Commit

Permalink
Merge pull request #1651 from ArkEcosystem/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
faustbrian authored Dec 5, 2018
2 parents aee3d00 + 8aff430 commit 6518001
Show file tree
Hide file tree
Showing 33 changed files with 207 additions and 55 deletions.
9 changes: 5 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ jobs:
./node_modules/.bin/cross-env ARK_ENV=test ./node_modules/.bin/jest
./packages/core-vote-report/ ./packages/core-transaction-pool/
./packages/core-snapshots-cli/ ./packages/core-logger-winston/
./packages/core-http-utils/ ./packages/core-event-emitter/
./packages/core-api/ ./packages/core-event-emitter/
./packages/core-elasticsearch/ ./packages/core-database-postgres/
./packages/core-config/ ./packages/core/ --detectOpenHandles
--runInBand --forceExit --ci --coverage | tee test_output.txt
./packages/core-config/ ./packages/core-http-utils/
--detectOpenHandles --runInBand --forceExit --ci --coverage | tee
test_output.txt
- run:
name: Last 1000 lines of test output
when: on_fail
Expand Down Expand Up @@ -157,7 +158,7 @@ jobs:
./packages/core-test-utils/ ./packages/core-p2p/
./packages/core-json-rpc/ ./packages/core-forger/
./packages/core-error-tracker-bugsnag/ ./packages/core-debugger-cli/
./packages/core-container/ ./packages/core-api/ --detectOpenHandles
./packages/core-container/ ./packages/core/ --detectOpenHandles
--runInBand --forceExit --ci --coverage | tee test_output.txt
- run:
name: Last 1000 lines of test output
Expand Down
6 changes: 6 additions & 0 deletions packages/core-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

## 0.2.12 - 2018-12-05

### Changed

- Increase cache generation timeout and make it configurable

## 0.2.11 - 2018-12-05

### Fixed
Expand Down
19 changes: 17 additions & 2 deletions packages/core-api/lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ module.exports = {
enabled: false,
host: process.env.ARK_API_HOST || '0.0.0.0',
port: process.env.ARK_API_PORT || 4003,
cache: {
/**
* How many seconds the server will try to complete the request and cache the result.
*
* Defaults to 8 seconds, set it to false if you do not care about the timeout.
*
* Setting it to false can result in requests never being completed, which is usually
* caused by low-spec servers that are unable to handle the heavy load that results
* out of SQL queries on the blocks and transactions tables.
*
* If you experience issues with the cache timeout, which is indicated by a 503 status codes,
* you should consider upgrading your hardware or tweak your PostgreSQL settings.
*/
generateTimeout: process.env.ARK_API_CACHE_TIMEOUT || 8000,
},
// @see https://hapijs.com/api#-serveroptionstls
ssl: {
enabled: process.env.ARK_API_SSL,
Expand All @@ -23,9 +38,9 @@ module.exports = {
rateLimit: {
enabled: !process.env.ARK_API_RATE_LIMIT,
pathLimit: false,
userLimit: 300,
userLimit: process.env.ARK_API_RATE_LIMIT_USER_LIMIT || 300,
userCache: {
expiresIn: 60000,
expiresIn: process.env.ARK_API_RATE_LIMIT_USER_EXPIRES || 60000,
},
ipWhitelist: ['127.0.0.1', '::ffff:127.0.0.1'],
},
Expand Down
10 changes: 6 additions & 4 deletions packages/core-api/lib/versions/1/methods/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ const publicKey = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v1.accounts.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -67,7 +69,7 @@ module.exports = server => {
server.method('v1.accounts.show', show, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -77,7 +79,7 @@ module.exports = server => {
server.method('v1.accounts.balance', balance, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -87,7 +89,7 @@ module.exports = server => {
server.method('v1.accounts.publicKey', publicKey, {
cache: {
expiresIn: 600 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand Down
6 changes: 4 additions & 2 deletions packages/core-api/lib/versions/1/methods/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ const show = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v1.blocks.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -50,7 +52,7 @@ module.exports = server => {
server.method('v1.blocks.show', show, {
cache: {
expiresIn: 600 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.query.id }),
Expand Down
12 changes: 7 additions & 5 deletions packages/core-api/lib/versions/1/methods/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ const voters = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v1.delegates.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -90,7 +92,7 @@ module.exports = server => {
server.method('v1.delegates.show', show, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -102,7 +104,7 @@ module.exports = server => {
server.method('v1.delegates.count', count, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ time: +new Date() }),
Expand All @@ -111,7 +113,7 @@ module.exports = server => {
server.method('v1.delegates.search', search, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -124,7 +126,7 @@ module.exports = server => {
server.method('v1.delegates.voters', voters, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.query.publicKey }),
Expand Down
6 changes: 4 additions & 2 deletions packages/core-api/lib/versions/1/methods/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ const show = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v1.transactions.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -49,7 +51,7 @@ module.exports = server => {
server.method('v1.transactions.show', show, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.query.id }),
Expand Down
10 changes: 6 additions & 4 deletions packages/core-api/lib/versions/2/methods/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ const search = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v2.blocks.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -67,7 +69,7 @@ module.exports = server => {
server.method('v2.blocks.show', show, {
cache: {
expiresIn: 600 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.params.id }),
Expand All @@ -76,7 +78,7 @@ module.exports = server => {
server.method('v2.blocks.transactions', transactions, {
cache: {
expiresIn: 600 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -89,7 +91,7 @@ module.exports = server => {
server.method('v2.blocks.search', search, {
cache: {
expiresIn: 30 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand Down
14 changes: 8 additions & 6 deletions packages/core-api/lib/versions/2/methods/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ const voterBalances = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v2.delegates.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -102,7 +104,7 @@ module.exports = server => {
server.method('v2.delegates.show', show, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.params.id }),
Expand All @@ -111,7 +113,7 @@ module.exports = server => {
server.method('v2.delegates.search', search, {
cache: {
expiresIn: 30 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -125,7 +127,7 @@ module.exports = server => {
server.method('v2.delegates.blocks', blocks, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -138,7 +140,7 @@ module.exports = server => {
server.method('v2.delegates.voters', voters, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -151,7 +153,7 @@ module.exports = server => {
server.method('v2.delegates.voterBalances', voterBalances, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.params.id }),
Expand Down
8 changes: 5 additions & 3 deletions packages/core-api/lib/versions/2/methods/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ const search = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v2.transactions.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -51,7 +53,7 @@ module.exports = server => {
server.method('v2.transactions.show', show, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.params.id }),
Expand All @@ -60,7 +62,7 @@ module.exports = server => {
server.method('v2.transactions.search', search, {
cache: {
expiresIn: 30 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand Down
6 changes: 4 additions & 2 deletions packages/core-api/lib/versions/2/methods/votes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ const show = async request => {
}

module.exports = server => {
const generateTimeout = require('../../utils').getCacheTimeout()

server.method('v2.votes.index', index, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request =>
Expand All @@ -48,7 +50,7 @@ module.exports = server => {
server.method('v2.votes.show', show, {
cache: {
expiresIn: 8 * 1000,
generateTimeout: 3000,
generateTimeout,
getDecoratedValue: true,
},
generateKey: request => generateCacheKey({ id: request.params.id }),
Expand Down
Loading

0 comments on commit 6518001

Please sign in to comment.