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

Function compute_channel_apys

plugins/bkpr/channelsapy.c:161–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161struct channel_apy **compute_channel_apys(const tal_t *ctx, struct db *db,
162 u64 start_time,
163 u64 end_time,
164 u32 current_blockheight)
165{
166 struct channel_event **evs;
167 struct channel_apy *apy, **apys;
168 struct account *acct, **accts;
169
170 evs = list_channel_events_timebox(ctx, db, start_time, end_time);
171 accts = list_accounts(ctx, db);
172
173 apys = tal_arr(ctx, struct channel_apy *, 0);
174
175 /* Sort events by acct_name */
176 asort(evs, tal_count(evs), cmp_channel_event_acct, NULL);
177 /* Sort accounts by name also */
178 asort(accts, tal_count(accts), cmp_acct, NULL);
179
180 acct = NULL;
181 apy = new_channel_apy(apys);
182 for (size_t i = 0; i < tal_count(evs); i++) {
183 struct channel_event *ev = evs[i];
184 bool ok;
185
186 if (!acct || acct->db_id != ev->acct_db_id) {
187 if (acct && is_channel_account(acct)) {
188 fillin_apy_acct_details(db, acct,
189 current_blockheight,
190 apy);
191 /* Save current apy, make new */
192 tal_arr_expand(&apys, apy);
193 apy = new_channel_apy(apys);
194 }
195 acct = search_account(accts, ev->acct_db_id);
196 assert(acct);
197 }
198
199 /* No entry for external or wallet accts */
200 if (!is_channel_account(acct))
201 continue;
202
203 /* Accumulate routing stats */
204 if (streq("routed", ev->tag)
205 || streq("invoice", ev->tag)) {
206 ok = amount_msat_add(&apy->routed_in,
207 apy->routed_in,
208 ev->credit);
209 assert(ok);
210 ok = amount_msat_add(&apy->routed_out,
211 apy->routed_out,
212 ev->debit);
213 assert(ok);
214
215 /* No fees for invoices */
216 if (streq("invoice", ev->tag))
217 continue;
218

Callers 1

getblockheight_doneFunction · 0.85

Calls 8

list_accountsFunction · 0.85
new_channel_apyFunction · 0.85
is_channel_accountFunction · 0.85
fillin_apy_acct_detailsFunction · 0.85
search_accountFunction · 0.85
amount_msat_addFunction · 0.85
amount_msat_zeroFunction · 0.85

Tested by

no test coverage detected