MCPcopy Create free account
hub / github.com/ElementsProject/lightning / merge_deadlines

Function merge_deadlines

lightningd/anchorspend.c:77–105  ·  view source on GitHub ↗

Sorts deadlines into increasing block order, merges dups */

Source from the content-addressed store, hash-verified

75
76/* Sorts deadlines into increasing block order, merges dups */
77static void merge_deadlines(struct channel *channel, struct anchor_details *adet)
78{
79 size_t dst;
80
81 /* Below requires len >= 1 */
82 if (tal_count(adet->vals) == 0)
83 return;
84
85 /* Sort into block-ascending order */
86 asort(adet->vals, tal_count(adet->vals), cmp_deadline_value, NULL);
87
88 /* Merge deadlines. */
89 dst = 0;
90 for (size_t i = 1; i < tal_count(adet->vals); i++) {
91 assert(adet->vals[i].important);
92 if (adet->vals[i].block != adet->vals[dst].block) {
93 dst = i;
94 continue;
95 }
96 if (!amount_msat_accumulate(&adet->vals[dst].msat,
97 adet->vals[i].msat)) {
98 log_broken(channel->log,
99 "Cannot add deadlines %s + %s!",
100 fmt_amount_msat(tmpctx, adet->vals[dst].msat),
101 fmt_amount_msat(tmpctx, adet->vals[i].msat));
102 }
103 }
104 tal_resize(&adet->vals, dst+1);
105}
106
107static void add_one_anchor(struct anchor_details *adet,
108 const struct local_anchor_info *info,

Callers 1

create_anchor_detailsFunction · 0.85

Calls 2

amount_msat_accumulateFunction · 0.85
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected