openzeppelin_relayer/constants/plugins.rs
1// =============================================================================
2// Plugin Configuration Constants
3// =============================================================================
4//
5// All constants below can be overridden via environment variables.
6// See docs/plugins/index.mdx for the full configuration guide.
7//
8// Environment Variable Naming Convention:
9// PLUGIN_POOL_* → Pool server & connection pool settings
10// PLUGIN_SOCKET_* → Shared socket service settings
11// PLUGIN_TRACE_* → Trace collection settings
12//
13// =============================================================================
14
15/// Default plugin execution timeout in seconds.
16/// Override in config.json per-plugin: `"timeout": 60`
17pub const DEFAULT_PLUGIN_TIMEOUT_SECONDS: u64 = 300; // 5 minutes
18
19// =============================================================================
20// Plugin Pool Server Configuration
21// These constants are the source of truth. The TypeScript pool-server.ts and
22// worker-pool.ts files should use matching values.
23// =============================================================================
24
25/// Maximum concurrent connections from Rust to the Node.js pool server.
26/// Env: PLUGIN_POOL_MAX_CONNECTIONS
27/// Increase for high concurrency (3000+ VUs).
28pub const DEFAULT_POOL_MAX_CONNECTIONS: usize = 2048;
29
30/// Minimum worker threads in Node.js pool (floor).
31/// Internal constant, not user-configurable.
32pub const DEFAULT_POOL_MIN_THREADS: usize = 2;
33
34/// Maximum worker threads floor (minimum threads even on small machines).
35/// Internal constant, not user-configurable.
36pub const DEFAULT_POOL_MAX_THREADS_FLOOR: usize = 8;
37
38/// Concurrent tasks per worker thread in Node.js pool.
39/// Internal constant, not user-configurable.
40pub const DEFAULT_POOL_CONCURRENT_TASKS_PER_WORKER: usize = 20;
41
42/// Headroom multiplier for calculating concurrent tasks per worker.
43/// Applied to base task calculation to provide buffer for:
44/// - Queue buildup during traffic spikes
45/// - Variable plugin execution latency
46/// - Temporary load imbalances across workers
47/// Internal constant, not user-configurable.
48pub const CONCURRENT_TASKS_HEADROOM_MULTIPLIER: f64 = 1.2;
49
50/// Maximum concurrent tasks per worker thread (hard cap).
51/// This cap prevents excessive memory usage and GC pressure per worker.
52/// Validated through load testing as a stable upper bound.
53/// Internal constant, not user-configurable.
54pub const MAX_CONCURRENT_TASKS_PER_WORKER: usize = 250;
55
56/// Worker idle timeout in milliseconds.
57/// Internal constant, not user-configurable.
58pub const DEFAULT_POOL_IDLE_TIMEOUT_MS: u64 = 60000; // 60 seconds
59
60/// Socket connection backlog for the pool server.
61/// Env: PLUGIN_POOL_SOCKET_BACKLOG (internal, rarely needs tuning)
62pub const DEFAULT_POOL_SOCKET_BACKLOG: u32 = 2048;
63
64/// Plugin execution timeout within the pool (milliseconds).
65/// Internal constant - use per-plugin `timeout` in config.json instead.
66pub const DEFAULT_POOL_EXECUTION_TIMEOUT_MS: u64 = 30000; // 30 seconds
67
68/// Timeout for individual pool requests (seconds).
69/// Env: PLUGIN_POOL_REQUEST_TIMEOUT_SECS
70pub const DEFAULT_POOL_REQUEST_TIMEOUT_SECS: u64 = 30;
71
72/// Maximum queued requests before rejection.
73/// Env: PLUGIN_POOL_MAX_QUEUE_SIZE
74/// Increase for high concurrency (3000+ VUs).
75pub const DEFAULT_POOL_MAX_QUEUE_SIZE: usize = 5000;
76
77/// Wait time (ms) when queue is full before rejecting.
78/// Env: PLUGIN_POOL_QUEUE_SEND_TIMEOUT_MS
79/// Increase for bursty traffic patterns.
80pub const DEFAULT_POOL_QUEUE_SEND_TIMEOUT_MS: u64 = 500;
81
82/// Minimum seconds between health checks.
83/// Env: PLUGIN_POOL_HEALTH_CHECK_INTERVAL_SECS
84/// Prevents health check storms under high load.
85pub const DEFAULT_POOL_HEALTH_CHECK_INTERVAL_SECS: u64 = 5;
86
87/// Retry attempts when connecting to pool server.
88/// Env: PLUGIN_POOL_CONNECT_RETRIES
89/// Increase for high concurrency scenarios.
90pub const DEFAULT_POOL_CONNECT_RETRIES: usize = 15;
91
92// =============================================================================
93// Shared Socket Service Configuration
94// Controls the Unix socket for plugin ↔ relayer communication.
95// =============================================================================
96
97/// Idle timeout for plugin connections (seconds).
98/// Env: PLUGIN_SOCKET_IDLE_TIMEOUT_SECS
99/// Connections idle longer than this are closed.
100pub const DEFAULT_SOCKET_IDLE_TIMEOUT_SECS: u64 = 60;
101
102/// Read timeout per line from plugins (seconds).
103/// Env: PLUGIN_SOCKET_READ_TIMEOUT_SECS
104/// Time to wait for a complete message from a plugin.
105pub const DEFAULT_SOCKET_READ_TIMEOUT_SECS: u64 = 30;
106
107/// Maximum concurrent plugin connections to the relayer.
108/// Env: PLUGIN_SOCKET_MAX_CONCURRENT_CONNECTIONS
109/// Should be >= PLUGIN_POOL_MAX_CONNECTIONS.
110pub const DEFAULT_SOCKET_MAX_CONCURRENT_CONNECTIONS: usize = 4096;
111
112/// Trace collection timeout (milliseconds).
113/// Env: PLUGIN_TRACE_TIMEOUT_MS
114/// Short timeout since traces arrive immediately after plugin execution.
115pub const DEFAULT_TRACE_TIMEOUT_MS: u64 = 100;