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

Function estimatefees_callback

lightningd/bitcoind.c:251–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249}
250
251static void estimatefees_callback(const char *buf, const jsmntok_t *toks,
252 const jsmntok_t *idtok,
253 struct estimatefee_call *call)
254{
255 const jsmntok_t *resulttok, *floortok;
256 struct feerate_est *feerates;
257 u32 floor;
258
259 resulttok = get_bitcoin_result(call->bitcoind, buf, toks, "estimatefees");
260
261 /* Modern style has floor. */
262 floortok = json_get_member(buf, resulttok, "feerate_floor");
263 if (floortok) {
264 feerates = parse_feerate_ranges(call, call->bitcoind,
265 buf, floortok,
266 json_get_member(buf, resulttok,
267 "feerates"),
268 &floor);
269 } else {
270 bitcoin_plugin_error(call->bitcoind, buf, resulttok,
271 "estimatefees",
272 "missing feerate_floor field");
273 }
274
275 /* Convert to perkw */
276 floor = feerate_from_style(floor, FEERATE_PER_KBYTE);
277 if (floor < FEERATE_FLOOR)
278 floor = FEERATE_FLOOR;
279
280 /* Anything this high is a broken fee source, not a busy mempool:
281 * clamp it rather than let it loose on the rest of lightningd. */
282 if (floor > FEERATE_CEILING) {
283 log_unusual(call->bitcoind->log,
284 "Feerate floor (%u) is above sanity ceiling (%u):"
285 " clamping!",
286 floor, (u32)FEERATE_CEILING);
287 floor = FEERATE_CEILING;
288 }
289
290 /* FIXME: We could let this go below the dynamic floor, but we'd
291 * need to know if the floor is because of their node's policy
292 * (minrelaytxfee) or mempool conditions (mempoolminfee). */
293 for (size_t i = 0; i < tal_count(feerates); i++) {
294 feerates[i].rate = feerate_from_style(feerates[i].rate,
295 FEERATE_PER_KBYTE);
296 if (feerates[i].rate > FEERATE_CEILING) {
297 log_unusual(call->bitcoind->log,
298 "Feerate for %u blocks (%u) is above sanity"
299 " ceiling (%u): clamping!",
300 feerates[i].blockcount, feerates[i].rate,
301 (u32)FEERATE_CEILING);
302 feerates[i].rate = FEERATE_CEILING;
303 }
304 if (feerates[i].rate < floor)
305 feerates[i].rate = floor;
306 }
307
308 call->cb(call->bitcoind->ld, floor, feerates, call->cb_arg);

Callers

nothing calls this directly

Calls 6

get_bitcoin_resultFunction · 0.85
json_get_memberFunction · 0.85
parse_feerate_rangesFunction · 0.85
bitcoin_plugin_errorFunction · 0.85
feerate_from_styleFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected