Skip to content

Commit ec54ea0

Browse files
authored
Merge pull request lightningdevkit#4033 from benthecarman/randomize-sweeper
Randomize order of inputs from `OutputSweeper`
2 parents 9ddd25b + 8a84ed0 commit ec54ea0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lightning/src/util/sweep.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,19 @@ where
574574
let cur_height = sweeper_state.best_block.height;
575575
let cur_hash = sweeper_state.best_block.block_hash;
576576

577-
let respend_descriptors: Vec<&SpendableOutputDescriptor> = sweeper_state
577+
let respend_descriptors_set: HashSet<&SpendableOutputDescriptor> = sweeper_state
578578
.outputs
579579
.iter()
580580
.filter(|o| filter_fn(*o, cur_height))
581581
.map(|o| &o.descriptor)
582582
.collect();
583583

584+
// we first collect into a set to avoid duplicates and to "randomize" the order
585+
// in which outputs are spent. Then we collect into a vec as that is what
586+
// `spend_outputs` requires.
587+
let respend_descriptors: Vec<&SpendableOutputDescriptor> =
588+
respend_descriptors_set.into_iter().collect();
589+
584590
// Generate the spending transaction and broadcast it.
585591
if !respend_descriptors.is_empty() {
586592
let spending_tx = self

0 commit comments

Comments
 (0)