Browse Source

bitcoind: Smooth fee changes over a number of estimates

Implements an EWMA for the fee estimation. Achieves 90% influence of the newer
fee after 5 minutes, and adjusts to the polling rate that is configured.
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
fe405f49be
  1. 11
      lightningd/chaintopology.c

11
lightningd/chaintopology.c

@ -237,6 +237,8 @@ static void update_feerates(struct bitcoind *bitcoind,
{
u32 old_feerates[NUM_FEERATES];
bool changed = false;
/* Rate of change of the fee smoothing, depending on the poll-interval */
double change_rate = (double)topo->poll_seconds / 150 * 0.9;
for (size_t i = 0; i < NUM_FEERATES; i++) {
u32 feerate = satoshi_per_kw[i];
@ -248,7 +250,14 @@ static void update_feerates(struct bitcoind *bitcoind,
if (!feerate)
continue;
if (feerate < feerate_floor())
/* Smooth the feerate to avoid spikes. The goal is to have the
* fee consist of 0.9 * feerate + 0.1 * old_feerate after 300
* seconds. The following will do that in a polling interval
* independent manner. */
feerate =
feerate * (1 - change_rate) + old_feerates[i] * change_rate;
if (feerate < feerate_floor())
feerate = feerate_floor();
if (feerate != topo->feerate[i]) {

Loading…
Cancel
Save