@@ -27,29 +27,23 @@ pub struct TemporalSafety {
2727 /// Second timelock in the protocol, if this timelock is reached Bob miss-behaved and will lose
2828 /// money
2929 pub punish_timelock : BlockHeight ,
30- /// The minimum number of blocks that should remain unmined before the next transaction to be
31- /// considered safe
32- pub race_thr : BlockSpan ,
30+ /// Avoid broadcasting a transaction if a race can happen with the next available execution
31+ /// fork in # blocks
32+ pub safety : BlockSpan ,
3333 /// Number of confirmation required for the arbitrating blockchain to consider a tx final
34- pub btc_finality_thr : BlockSpan ,
34+ pub arb_finality : BlockSpan ,
3535 /// Number of confirmation required for the accordant blockchain to consider a tx final
36- pub xmr_finality_thr : BlockSpan ,
37- // FIXME: this should be removed, used only const instead
38- pub sweep_monero_thr : BlockSpan ,
36+ pub acc_finality : BlockSpan ,
3937}
4038
4139impl TemporalSafety {
4240 /// Validate if temporal parameters are coherent
4341 pub fn valid_params ( & self ) -> Result < ( ) , Error > {
44- let btc_finality = self . btc_finality_thr ;
42+ let finality = self . arb_finality ;
4543 let cancel = self . cancel_timelock ;
4644 let punish = self . punish_timelock ;
47- let race = self . race_thr ;
48- if btc_finality < cancel
49- && cancel < punish
50- && btc_finality < race
51- && punish > race
52- && cancel > race
45+ let race = self . safety ;
46+ if finality < cancel && cancel < punish && finality < race && punish > race && cancel > race
5347 {
5448 Ok ( ( ) )
5549 } else {
@@ -61,23 +55,23 @@ impl TemporalSafety {
6155
6256 /// Returns whether tx is final given the finality threshold set for the chain
6357 pub fn final_tx ( & self , confs : u32 , blockchain : Blockchain ) -> bool {
64- let finality_thr = match blockchain {
65- Blockchain :: Bitcoin => self . btc_finality_thr ,
66- Blockchain :: Monero => self . xmr_finality_thr ,
58+ let finality = match blockchain {
59+ Blockchain :: Bitcoin => self . arb_finality ,
60+ Blockchain :: Monero => self . acc_finality ,
6761 } ;
68- confs >= finality_thr
62+ confs >= finality
6963 }
7064
7165 /// Lock must be final, cancel cannot be raced, add + 1 to offset initial lock confirmation
7266 pub fn stop_funding_before_cancel ( & self , lock_confirmations : u32 ) -> bool {
7367 self . final_tx ( lock_confirmations, Blockchain :: Bitcoin )
74- && lock_confirmations > ( self . cancel_timelock - self . race_thr + 1 )
68+ && lock_confirmations > ( self . cancel_timelock - self . safety + 1 )
7569 }
7670
7771 // Blocks remaining until funding will be stopped for safety, because it is too close to
7872 // cancel. Adds the same +1 offset as in stop_funding_before_cancel
7973 pub fn blocks_until_stop_funding ( & self , lock_confirmations : u32 ) -> i64 {
80- self . cancel_timelock as i64 - ( self . race_thr as i64 + 1 + lock_confirmations as i64 )
74+ self . cancel_timelock as i64 - ( self . safety as i64 + 1 + lock_confirmations as i64 )
8175 }
8276
8377 /// Lock must be final, valid after lock_minedblock + cancel_timelock
@@ -94,13 +88,13 @@ impl TemporalSafety {
9488 /// Lock must be final, but buy shall not be raced with cancel
9589 pub fn safe_buy ( & self , lock_confirmations : u32 ) -> bool {
9690 self . final_tx ( lock_confirmations, Blockchain :: Bitcoin )
97- && lock_confirmations <= ( self . cancel_timelock - self . race_thr )
91+ && lock_confirmations <= ( self . cancel_timelock - self . safety )
9892 }
9993
10094 /// Cancel must be final, but refund shall not be raced with punish
10195 pub fn safe_refund ( & self , cancel_confirmations : u32 ) -> bool {
10296 self . final_tx ( cancel_confirmations, Blockchain :: Bitcoin )
103- && cancel_confirmations <= ( self . punish_timelock - self . race_thr )
97+ && cancel_confirmations <= ( self . punish_timelock - self . safety )
10498 }
10599
106100 /// Cancel must be final, valid after cancel_confirmations > punish_timelock
0 commit comments