chaintopology: fix notification first time fee estimate works.

We probably want to notify everyone immediately, rather than
waiting for the first change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-03-01 14:31:09 +10:30
parent 4848c0022f
commit 959d1c9983

View File

@ -357,17 +357,6 @@ static void add_feerate_history(struct chain_topology *topo,
topo->feehistory[feerate][0] = val; topo->feehistory[feerate][0] = val;
} }
/* Did the the feerate change since we last estimated it ? */
static bool feerate_changed(struct chain_topology *topo, u32 old_feerates[])
{
for (int f = 0; f < NUM_FEERATES; f++) {
if (try_get_feerate(topo, f) != old_feerates[f])
return true;
}
return false;
}
/* We sanitize feerates if necessary to put them in descending order. */ /* We sanitize feerates if necessary to put them in descending order. */
static void update_feerates(struct bitcoind *bitcoind, static void update_feerates(struct bitcoind *bitcoind,
const u32 *satoshi_per_kw, const u32 *satoshi_per_kw,
@ -379,6 +368,7 @@ static void update_feerates(struct bitcoind *bitcoind,
* 2 minutes. The following will do that in a polling interval * 2 minutes. The following will do that in a polling interval
* independent manner. */ * independent manner. */
double alpha = 1 - pow(0.1,(double)topo->poll_seconds / 120); double alpha = 1 - pow(0.1,(double)topo->poll_seconds / 120);
bool feerate_changed = false;
for (size_t i = 0; i < NUM_FEERATES; i++) { for (size_t i = 0; i < NUM_FEERATES; i++) {
u32 feerate = satoshi_per_kw[i]; u32 feerate = satoshi_per_kw[i];
@ -392,14 +382,18 @@ static void update_feerates(struct bitcoind *bitcoind,
/* Initial smoothed feerate is the polled feerate */ /* Initial smoothed feerate is the polled feerate */
if (!old_feerates[i]) { if (!old_feerates[i]) {
feerate_changed = true;
old_feerates[i] = feerate; old_feerates[i] = feerate;
init_feerate_history(topo, i, feerate); init_feerate_history(topo, i, feerate);
log_debug(topo->log, log_debug(topo->log,
"Smoothed feerate estimate for %s initialized to polled estimate %u", "Smoothed feerate estimate for %s initialized to polled estimate %u",
feerate_name(i), feerate); feerate_name(i), feerate);
} else } else {
if (feerate != old_feerates[i])
feerate_changed = true;
add_feerate_history(topo, i, feerate); add_feerate_history(topo, i, feerate);
}
/* Smooth the feerate to avoid spikes. */ /* Smooth the feerate to avoid spikes. */
u32 feerate_smooth = feerate * alpha + old_feerates[i] * (1 - alpha); u32 feerate_smooth = feerate * alpha + old_feerates[i] * (1 - alpha);
@ -435,7 +429,7 @@ static void update_feerates(struct bitcoind *bitcoind,
maybe_completed_init(topo); maybe_completed_init(topo);
} }
if (feerate_changed(topo, old_feerates)) if (feerate_changed)
notify_feerate_change(bitcoind->ld); notify_feerate_change(bitcoind->ld);
next_updatefee_timer(topo); next_updatefee_timer(topo);