Skip to content

Commit 8a54e9d

Browse files
authored
feat: stacks core event and rpc proxy body limits configurable via env (#2278)
1 parent 42357ee commit 8a54e9d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ PG_APPLICATION_NAME=stacks-blockchain-api
7272
STACKS_CORE_EVENT_PORT=3700
7373
STACKS_CORE_EVENT_HOST=127.0.0.1
7474

75+
# Stacks core event payload body size limit. Defaults to 500MB.
76+
# STACKS_CORE_EVENT_BODY_LIMIT=500000000
77+
7578
STACKS_BLOCKCHAIN_API_PORT=3999
7679
STACKS_BLOCKCHAIN_API_HOST=127.0.0.1
7780

@@ -81,6 +84,9 @@ STACKS_CORE_RPC_PORT=20443
8184
# STACKS_CORE_PROXY_HOST=127.0.0.1
8285
# STACKS_CORE_PROXY_PORT=20443
8386

87+
# Stacks core RPC proxy body size limit. Defaults to 10MB.
88+
# STACKS_CORE_PROXY_BODY_LIMIT=10000000
89+
8490
# Configure a path to a file containing additional stacks-node `POST /v2/tranascation` URLs for the /v2 proxy to mutlicast.
8591
# The file should be a newline-delimited list of URLs.
8692
# STACKS_API_EXTRA_TX_ENDPOINTS_FILE=./config/extra-tx-post-endpoints.txt

src/api/routes/core-node-rpc-proxy.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,12 @@ export const CoreNodeRpcProxyRouter: FastifyPluginAsync<
254254
});
255255
}
256256

257-
const maxBodySize = 10_000_000; // 10 MB max POST body size
258257
fastify.addContentTypeParser(
259258
'application/octet-stream',
260-
{ parseAs: 'buffer', bodyLimit: maxBodySize },
259+
{
260+
parseAs: 'buffer',
261+
bodyLimit: parseInt(process.env['STACKS_CORE_PROXY_BODY_LIMIT'] ?? '10000000'),
262+
},
261263
(_req, body, done) => {
262264
done(null, body);
263265
}

src/event-stream/event-server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,6 @@ export async function startEventServer(opts: {
784784
eventHost = hostname;
785785
}
786786

787-
const bodyLimit = 1_000_000 * 500; // 500MB body limit
788-
789787
const reqLogSerializer = (req: FastifyRequest) => ({
790788
method: req.method,
791789
url: req.url,
@@ -812,7 +810,7 @@ export async function startEventServer(opts: {
812810
};
813811

814812
const app = Fastify({
815-
bodyLimit,
813+
bodyLimit: parseInt(process.env['STACKS_CORE_EVENT_BODY_LIMIT'] ?? '500000000'),
816814
trustProxy: true,
817815
logger: loggerOpts,
818816
ignoreTrailingSlash: true,

0 commit comments

Comments
 (0)