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