Skip to content

Commit dfd65e8

Browse files
committed
refactor(cch): extract BTC_BLOCK_TIME_MILLIS named constant
Replace the magic number `600 * 1000` with a documented named constant `BTC_BLOCK_TIME_MILLIS` (600,000 ms = 10 minutes per Bitcoin block) for improved readability and maintainability.
1 parent 2ba20c2 commit dfd65e8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

crates/fiber-lib/src/cch/actor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ use crate::time::{Duration, SystemTime, UNIX_EPOCH};
3232
pub const ACTION_RETRY_BASE_MILLIS: u64 = 1000; // 1 second initial delay
3333
pub const ACTION_RETRY_MAX_MILLIS: u64 = 600_000; // 10 minute max delay
3434

35+
/// Average time per Bitcoin block in milliseconds (10 minutes = 600 seconds = 600,000 ms).
36+
pub const BTC_BLOCK_TIME_MILLIS: u64 = 600_000;
37+
3538
fn calculate_retry_delay(retry_count: u32) -> Duration {
3639
// Exponential backoff starting from ACTION_RETRY_BASE_MILLIS, capped at ACTION_RETRY_MAX_MILLIS
3740
let max_shift = (ACTION_RETRY_MAX_MILLIS / ACTION_RETRY_BASE_MILLIS).ilog2();
@@ -515,7 +518,7 @@ impl<S: CchOrderStore> CchState<S> {
515518
let btc_final_cltv_millis = self
516519
.config
517520
.btc_final_tlc_expiry_delta_blocks
518-
.checked_mul(600 * 1000)
521+
.checked_mul(BTC_BLOCK_TIME_MILLIS)
519522
.ok_or_else(|| {
520523
CchError::ConfigError(format!(
521524
"btc_final_tlc_expiry_delta_blocks ({}) is too large and causes overflow when converting to milliseconds",

0 commit comments

Comments
 (0)