Skip to content

Commit 055836b

Browse files
committed
refactor: remove magic numbers from indexer_service
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 32c6e58 commit 055836b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

crates/service/src/service/indexer_service.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,22 @@ pub struct IndexerServiceState {
159159
pub domain_separator: Eip712Domain,
160160
}
161161

162+
const HTTP_CLIENT_TIMEOUT: Duration = Duration::from_secs(30);
163+
const DATABASE_TIMEOUT: Duration = Duration::from_secs(30);
164+
const DATABASE_MAX_CONNECTIONS: u32 = 50;
165+
166+
const MISC_BURST_SIZE: u32 = 10;
167+
const MISC_BURST_PER_MILLISECOND: u64 = 100;
168+
169+
const STATIC_BURST_SIZE: u32 = 50;
170+
const STATIC_BURST_PER_MILLISECOND: u64 = 20;
171+
172+
const DISPUTE_MANAGER_INTERVAL: Duration = Duration::from_secs(3600);
173+
162174
pub async fn run(options: IndexerServiceOptions) -> Result<(), anyhow::Error> {
163175
let http_client = reqwest::Client::builder()
164176
.tcp_nodelay(true)
165-
.timeout(Duration::from_secs(30))
177+
.timeout(HTTP_CLIENT_TIMEOUT)
166178
.build()
167179
.expect("Failed to init HTTP client");
168180

@@ -201,7 +213,7 @@ pub async fn run(options: IndexerServiceOptions) -> Result<(), anyhow::Error> {
201213
));
202214

203215
// Identify the dispute manager for the configured network
204-
let dispute_manager = dispute_manager(network_subgraph, Duration::from_secs(3600))
216+
let dispute_manager = dispute_manager(network_subgraph, DISPUTE_MANAGER_INTERVAL)
205217
.await
206218
.expect("Failed to initialize dispute manager");
207219

@@ -282,8 +294,8 @@ pub async fn run(options: IndexerServiceOptions) -> Result<(), anyhow::Error> {
282294
// agent. Hence we leave syncing and migrating entirely to the agent and
283295
// assume the models are up to date in the service.
284296
let database = PgPoolOptions::new()
285-
.max_connections(50)
286-
.acquire_timeout(Duration::from_secs(30))
297+
.max_connections(DATABASE_MAX_CONNECTIONS)
298+
.acquire_timeout(DATABASE_TIMEOUT)
287299
.connect(
288300
options
289301
.config
@@ -334,8 +346,8 @@ pub async fn run(options: IndexerServiceOptions) -> Result<(), anyhow::Error> {
334346
let misc_rate_limiter = GovernorLayer {
335347
config: Arc::new(
336348
GovernorConfigBuilder::default()
337-
.per_millisecond(100)
338-
.burst_size(10)
349+
.per_millisecond(MISC_BURST_PER_MILLISECOND)
350+
.burst_size(MISC_BURST_SIZE)
339351
.finish()
340352
.expect("Failed to set up rate limiting"),
341353
),
@@ -357,8 +369,8 @@ pub async fn run(options: IndexerServiceOptions) -> Result<(), anyhow::Error> {
357369
let static_subgraph_rate_limiter = GovernorLayer {
358370
config: Arc::new(
359371
GovernorConfigBuilder::default()
360-
.per_millisecond(20)
361-
.burst_size(50)
372+
.per_millisecond(STATIC_BURST_PER_MILLISECOND)
373+
.burst_size(STATIC_BURST_SIZE)
362374
.finish()
363375
.expect("Failed to set up rate limiting"),
364376
),

0 commit comments

Comments
 (0)