@@ -69,40 +69,38 @@ impl TimelockInfo {
69
69
Self :: combine_threshold ( 1 , once ( a) . chain ( once ( b) ) )
70
70
}
71
71
72
- /// Combines `TimelockInfo` structs, if threshold `k` is greater than one we check for
73
- /// any unspendable path.
74
- pub ( crate ) fn combine_threshold < I > ( k : usize , sub_timelocks : I ) -> TimelockInfo
72
+ /// Combines timelocks, if threshold `k` is greater than one we check for any unspendable paths.
73
+ pub ( crate ) fn combine_threshold < I > ( k : usize , timelocks : I ) -> TimelockInfo
75
74
where
76
75
I : IntoIterator < Item = TimelockInfo > ,
77
76
{
78
- // timelocks calculation
79
77
// Propagate all fields of `TimelockInfo` from each of the node's children to the node
80
78
// itself (by taking the logical-or of all of them). In case `k == 1` (this is a disjunction)
81
79
// this is all we need to do: the node may behave like any of its children, for purposes
82
80
// of timelock accounting.
83
81
//
84
82
// If `k > 1` we have the additional consideration that if any two children have conflicting
85
83
// timelock requirements, this represents an inaccessible spending branch.
86
- sub_timelocks . into_iter ( ) . fold (
87
- TimelockInfo :: default ( ) ,
88
- |mut timelock_info , sub_timelock | {
84
+ timelocks
85
+ . into_iter ( )
86
+ . fold ( TimelockInfo :: default ( ) , |mut acc , t | {
89
87
// If more than one branch may be taken, and some other branch has a requirement
90
- // that conflicts with this one, set `contains_combination`
88
+ // that conflicts with this one, set `contains_combination`.
91
89
if k > 1 {
92
- timelock_info. contains_combination |= ( timelock_info. csv_with_height
93
- && sub_timelock. csv_with_time )
94
- || ( timelock_info. csv_with_time && sub_timelock. csv_with_height )
95
- || ( timelock_info. cltv_with_time && sub_timelock. cltv_with_height )
96
- || ( timelock_info. cltv_with_height && sub_timelock. cltv_with_time ) ;
90
+ let height_and_time = ( acc. csv_with_height && t. csv_with_time )
91
+ || ( acc. csv_with_time && t. csv_with_height )
92
+ || ( acc. cltv_with_time && t. cltv_with_height )
93
+ || ( acc. cltv_with_height && t. cltv_with_time ) ;
94
+
95
+ acc. contains_combination |= height_and_time;
97
96
}
98
- timelock_info. csv_with_height |= sub_timelock. csv_with_height ;
99
- timelock_info. csv_with_time |= sub_timelock. csv_with_time ;
100
- timelock_info. cltv_with_height |= sub_timelock. cltv_with_height ;
101
- timelock_info. cltv_with_time |= sub_timelock. cltv_with_time ;
102
- timelock_info. contains_combination |= sub_timelock. contains_combination ;
103
- timelock_info
104
- } ,
105
- )
97
+ acc. csv_with_height |= t. csv_with_height ;
98
+ acc. csv_with_time |= t. csv_with_time ;
99
+ acc. cltv_with_height |= t. cltv_with_height ;
100
+ acc. cltv_with_time |= t. cltv_with_time ;
101
+ acc. contains_combination |= t. contains_combination ;
102
+ acc
103
+ } )
106
104
}
107
105
}
108
106
0 commit comments