Skip to content

Commit 80bd4ad

Browse files
committed
3.3.4-rc7
- include config disable_rate_limit - minor package upgrades - date parser fix
1 parent 81ae93b commit 80bd4ad

File tree

6 files changed

+254
-223
lines changed

6 files changed

+254
-223
lines changed

api/plugins.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@ import fastifyRateLimit from 'fastify-rate-limit';
1313
import fastify_eosjs from "./plugins/fastify-eosjs";
1414

1515
export function registerPlugins(server: Fastify.FastifyInstance<Server, IncomingMessage, ServerResponse>, params: any) {
16-
server.register(fastifyElasticsearch, params.fastify_elasticsearch);
17-
server.register(fastifySwagger, params.fastify_swagger);
18-
server.register(fastifyCors);
19-
server.register(fastifyFormbody);
20-
server.register(fastifyRedis, params.fastify_redis);
21-
server.register(fastifyRateLimit, params.fastify_rate_limit);
22-
server.register(fastify_eosjs, params.fastify_eosjs);
16+
server.register(fastifyElasticsearch, params.fastify_elasticsearch);
17+
18+
if (params.fastify_swagger) {
19+
server.register(fastifySwagger, params.fastify_swagger);
20+
}
21+
22+
server.register(fastifyCors);
23+
24+
server.register(fastifyFormbody);
25+
26+
server.register(fastifyRedis, params.fastify_redis);
27+
28+
if (params.fastify_rate_limit) {
29+
server.register(fastifyRateLimit, params.fastify_rate_limit);
30+
}
31+
32+
server.register(fastify_eosjs, params.fastify_eosjs);
2333
}

api/server.ts

+28-24
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {createWriteStream, existsSync, mkdirSync} from "fs";
1212
import {SocketManager} from "./socketManager";
1313
import {HyperionModuleLoader} from "../modules/loader";
1414
import {extendedActions} from "./routes/v2-history/get_actions/definitions";
15-
import {Socket, io} from "socket.io-client";
15+
import {io, Socket} from "socket.io-client";
1616

1717
class HyperionApiServer {
1818

@@ -93,38 +93,42 @@ class HyperionApiServer {
9393

9494
const ioRedisClient = new IORedis(this.manager.conn.redis);
9595

96-
let rateLimiterWhitelist = ['127.0.0.1'];
97-
98-
if (this.conf.api.rate_limit_allow && this.conf.api.rate_limit_allow.length > 0) {
99-
const tempSet = new Set<string>(['127.0.0.1', ...this.conf.api.rate_limit_allow]);
100-
rateLimiterWhitelist = [...tempSet];
101-
}
96+
const pluginParams = {
97+
fastify_elasticsearch: {
98+
client: this.manager.elasticsearchClient
99+
},
100+
fastify_redis: this.manager.conn.redis,
101+
fastify_eosjs: this.manager,
102+
} as any;
102103

103-
let rateLimiterRPM = 1000;
104-
if (this.conf.api.rate_limit_rpm) {
105-
rateLimiterRPM = this.conf.api.rate_limit_rpm;
104+
if(!this.conf.api.disable_rate_limit) {
105+
let rateLimiterWhitelist = ['127.0.0.1'];
106+
if (this.conf.api.rate_limit_allow && this.conf.api.rate_limit_allow.length > 0) {
107+
const tempSet = new Set<string>(['127.0.0.1', ...this.conf.api.rate_limit_allow]);
108+
rateLimiterWhitelist = [...tempSet];
109+
}
110+
let rateLimiterRPM = 1000;
111+
if (this.conf.api.rate_limit_rpm) {
112+
rateLimiterRPM = this.conf.api.rate_limit_rpm;
113+
}
114+
pluginParams.fastify_rate_limit = {
115+
max: rateLimiterRPM,
116+
allowList: rateLimiterWhitelist,
117+
timeWindow: '1 minute',
118+
redis: ioRedisClient
119+
}
106120
}
107121

108-
const api_rate_limit = {
109-
max: rateLimiterRPM,
110-
allowList: rateLimiterWhitelist,
111-
timeWindow: '1 minute',
112-
redis: ioRedisClient
113-
};
114-
115122
if (this.conf.features.streaming.enable) {
116123
this.activateStreaming();
117124
}
118125

119126
const docsConfig = generateOpenApiConfig(this.manager.config);
127+
if(docsConfig) {
128+
pluginParams.fastify_swagger = docsConfig;
129+
}
120130

121-
registerPlugins(this.fastify, {
122-
fastify_elasticsearch: {client: this.manager.elasticsearchClient},
123-
fastify_swagger: docsConfig,
124-
fastify_rate_limit: api_rate_limit,
125-
fastify_redis: this.manager.conn.redis,
126-
fastify_eosjs: this.manager,
127-
});
131+
registerPlugins(this.fastify, pluginParams);
128132

129133
this.addGenericTypeParsing();
130134
}

chains/example.config.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"chain_api_error_log": false,
2424
"custom_core_token": "",
2525
"enable_export_action": false,
26+
"disable_rate_limit": false,
2627
"rate_limit_rpm": 1000,
2728
"rate_limit_allow": [],
2829
"disable_tx_cache": false,

interfaces/hyperionConfig.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ interface ApiLimits {
8080
}
8181

8282
interface ApiConfigs {
83+
disable_rate_limit?: boolean;
8384
disable_tx_cache?: boolean;
8485
tx_cache_expiration_sec?: number | string;
8586
rate_limit_rpm?: number;

0 commit comments

Comments
 (0)