@@ -12,6 +12,11 @@ use crate::utill::{get_maker_dir, parse_field};
1212
1313use super :: api:: MIN_SWAP_AMOUNT ;
1414
15+ // Fidelity Bond relative timelock in number of blocks ( 1 block ~= 10mins)
16+ // Must be between 12,960 (≈3 months) and 25,920 (≈6 months)
17+ const MIN_FIDELITY_TIMELOCK : u32 = 12_960 ; // No. of blocks produce in 3 months(144*90)
18+ const MAX_FIDELITY_TIMELOCK : u32 = 25_920 ; // No. of blocks produce in 6 months(144*180)
19+
1520/// Maker Configuration
1621///
1722/// This struct defines all configurable parameters for the Maker module, including:
@@ -47,7 +52,7 @@ impl Default for MakerConfig {
4752 fn default ( ) -> Self {
4853 let ( fidelity_amount, fidelity_timelock, base_fee, amount_relative_fee_pct) =
4954 if cfg ! ( feature = "integration-test" ) {
50- ( 5_000_000 , 26_000 , 1000 , 2.50 ) // Test values
55+ ( 5_000_000 , MAX_FIDELITY_TIMELOCK , 1000 , 2.50 ) // Test values
5156 } else {
5257 ( 50_000 , 13104 , 100 , 0.1 ) // Production values
5358 } ;
@@ -66,6 +71,26 @@ impl Default for MakerConfig {
6671 }
6772 }
6873}
74+ /// Ensure fidelity timelock lies in the allowed range (3months-6months)
75+ fn validate_fidelity_timelock ( timelock : u32 ) -> u32 {
76+ if timelock < MIN_FIDELITY_TIMELOCK {
77+ log:: warn!(
78+ "fidelity_timelock too low ({} blocks). Clamping to minimum allowed: {} blocks" ,
79+ timelock,
80+ MIN_FIDELITY_TIMELOCK
81+ ) ;
82+ MIN_FIDELITY_TIMELOCK
83+ } else if timelock > MAX_FIDELITY_TIMELOCK {
84+ log:: warn!(
85+ "fidelity_timelock too high ({} blocks). Clamping to maximum allowed: {} blocks" ,
86+ timelock,
87+ MAX_FIDELITY_TIMELOCK
88+ ) ;
89+ MAX_FIDELITY_TIMELOCK
90+ } else {
91+ timelock
92+ }
93+ }
6994
7095impl MakerConfig {
7196 /// Constructs a [`MakerConfig`] from a specified data directory. Or creates default configs and load them.
@@ -118,10 +143,10 @@ impl MakerConfig {
118143 config_map. get ( "fidelity_amount" ) ,
119144 default_config. fidelity_amount ,
120145 ) ,
121- fidelity_timelock : parse_field (
146+ fidelity_timelock : validate_fidelity_timelock ( parse_field (
122147 config_map. get ( "fidelity_timelock" ) ,
123148 default_config. fidelity_timelock ,
124- ) ,
149+ ) ) ,
125150 base_fee : parse_field ( config_map. get ( "base_fee" ) , default_config. base_fee ) ,
126151 amount_relative_fee_pct : parse_field (
127152 config_map. get ( "amount_relative_fee_pct" ) ,
@@ -150,6 +175,7 @@ min_swap_amount = {}
150175# Fidelity Bond amount in satoshis
151176fidelity_amount = {}
152177# Fidelity Bond relative timelock in number of blocks
178+ # Must be between {} (~3 months) and {} (~6 months)
153179fidelity_timelock = {}
154180# A fixed base fee charged by the Maker for providing its services (in satoshis)
155181base_fee = {}
@@ -163,6 +189,8 @@ amount_relative_fee_pct = {}
163189 self . tor_auth_password,
164190 self . min_swap_amount,
165191 self . fidelity_amount,
192+ MIN_FIDELITY_TIMELOCK ,
193+ MAX_FIDELITY_TIMELOCK ,
166194 self . fidelity_timelock,
167195 self . base_fee,
168196 self . amount_relative_fee_pct,
@@ -252,4 +280,22 @@ mod tests {
252280 remove_temp_config ( & config_path) ;
253281 assert_eq ! ( config, MakerConfig :: default ( ) ) ;
254282 }
283+
284+ #[ test]
285+ fn fidelity_timelock_clamped_low ( ) {
286+ let contents = r#"fidelity_timelock = 1000"# ;
287+ let path = create_temp_config ( contents, "low.toml" ) ;
288+ let cfg = MakerConfig :: new ( Some ( & path) ) . unwrap ( ) ;
289+ remove_temp_config ( & path) ;
290+ assert_eq ! ( cfg. fidelity_timelock, MIN_FIDELITY_TIMELOCK ) ;
291+ }
292+
293+ #[ test]
294+ fn fidelity_timelock_clamped_high ( ) {
295+ let contents = r#"fidelity_timelock = 50000"# ;
296+ let path = create_temp_config ( contents, "high.toml" ) ;
297+ let cfg = MakerConfig :: new ( Some ( & path) ) . unwrap ( ) ;
298+ remove_temp_config ( & path) ;
299+ assert_eq ! ( cfg. fidelity_timelock, MAX_FIDELITY_TIMELOCK ) ;
300+ }
255301}
0 commit comments