Skip to content

Commit 1916d8e

Browse files
committed
move polling interval to config variable
1 parent 3b25caf commit 1916d8e

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

config-files/config-batcher-docker.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ batcher:
3737
# When replacing the message, how much higher should the max fee in comparison to the original one
3838
# The calculation is replacement_max_fee >= original_max_fee + original_max_fee * min_bump_percentage / 100
3939
min_bump_percentage: 10
40+
# How often to poll for BalanceUnlocked events in seconds (default: 600 seconds = 10 minutes)
41+
balance_unlock_polling_interval_seconds: 600
4042

config-files/config-batcher-ethereum-package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ batcher:
3535
# When replacing the message, how much higher should the max fee in comparison to the original one
3636
# The calculation is replacement_max_fee >= original_max_fee + original_max_fee * min_bump_percentage / 100
3737
min_bump_percentage: 10
38+
# How often to poll for BalanceUnlocked events in seconds (default: 600 seconds = 10 minutes)
39+
balance_unlock_polling_interval_seconds: 600
3840

config-files/config-batcher.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ batcher:
3737
# When replacing the message, how much higher should the max fee in comparison to the original one
3838
# The calculation is replacement_max_fee >= original_max_fee + original_max_fee * min_bump_percentage / 100
3939
min_bump_percentage: 10
40+
# How often to poll for BalanceUnlocked events in seconds (default: 600 seconds = 10 minutes)
41+
balance_unlock_polling_interval_seconds: 600

crates/batcher/src/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct BatcherConfigFromYaml {
5353
pub non_paying: Option<NonPayingConfigFromYaml>,
5454
pub amount_of_proofs_for_min_max_fee: usize,
5555
pub min_bump_percentage: u64,
56+
pub balance_unlock_polling_interval_seconds: u64,
5657
}
5758

5859
#[derive(Debug, Deserialize)]

crates/batcher/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub struct Batcher {
105105
current_min_max_fee: RwLock<U256>,
106106
amount_of_proofs_for_min_max_fee: usize,
107107
min_bump_percentage: U256,
108+
balance_unlock_polling_interval_seconds: u64,
108109

109110
// Shared state access:
110111
// Two kinds of threads interact with the shared state:
@@ -331,6 +332,7 @@ impl Batcher {
331332
max_batch_proof_qty: config.batcher.max_batch_proof_qty,
332333
amount_of_proofs_for_min_max_fee: config.batcher.amount_of_proofs_for_min_max_fee,
333334
min_bump_percentage: U256::from(config.batcher.min_bump_percentage),
335+
balance_unlock_polling_interval_seconds: config.batcher.balance_unlock_polling_interval_seconds,
334336
last_uploaded_batch_block: Mutex::new(last_uploaded_batch_block),
335337
pre_verification_is_enabled: config.batcher.pre_verification_is_enabled,
336338
non_paying_config,
@@ -496,10 +498,10 @@ impl Batcher {
496498
}
497499

498500
/// Poll for BalanceUnlocked events from BatcherPaymentService contract.
499-
/// Runs every 10 minutes and checks the last 100 blocks for events.
501+
/// Runs at configurable intervals and checks recent blocks for events (2x the polling interval).
500502
/// When an event is detected, removes user's proofs from queue and resets UserState.
501503
pub async fn poll_balance_unlocked_events(self: Arc<Self>) -> Result<(), BatcherError> {
502-
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(20)); // 10 minutes
504+
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(self.balance_unlock_polling_interval_seconds));
503505

504506
loop {
505507
interval.tick().await;
@@ -521,8 +523,10 @@ impl Batcher {
521523
}
522524
};
523525

524-
// Calculate the block range (last 100 blocks)
525-
let from_block = current_block.saturating_sub(U64::from(100));
526+
// Calculate the block range based on polling interval
527+
// Formula: interval / 12 * 2 (assuming 12-second block times, look back 2x the interval)
528+
let block_range = (self.balance_unlock_polling_interval_seconds / 12) * 2;
529+
let from_block = current_block.saturating_sub(U64::from(block_range));
526530

527531
// Create filter for BalanceUnlocked events
528532
let filter = self.payment_service

infra/ansible/playbooks/templates/config-files/config-batcher.yaml.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ batcher:
3232
non_paying:
3333
address: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 # Anvil address 9
3434
replacement_private_key: {{ batcher_replacement_private_key }}
35+
# When validating if the msg covers the minimum max fee
36+
# A batch of how many proofs should it cover
37+
amount_of_proofs_for_min_max_fee: 128
38+
# When replacing the message, how much higher should the max fee in comparison to the original one
39+
# The calculation is replacement_max_fee >= original_max_fee + original_max_fee * min_bump_percentage / 100
40+
min_bump_percentage: 10
41+
# How often to poll for BalanceUnlocked events in seconds (default: 600 seconds = 10 minutes)
42+
balance_unlock_polling_interval_seconds: 600

0 commit comments

Comments
 (0)