diff --git a/lightningd/chaintopology.h b/lightningd/chaintopology.h index b14445890..268d65857 100644 --- a/lightningd/chaintopology.h +++ b/lightningd/chaintopology.h @@ -155,6 +155,7 @@ void begin_topology(struct chain_topology *topo); struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo, const struct bitcoin_txid *txid); +/* In channel_control.c */ void notify_feerate_change(struct lightningd *ld); #if DEVELOPER diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 14a853d94..c3302dd0f 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -18,6 +18,47 @@ #include #include +static void update_feerates(struct lightningd *ld, struct channel *channel) +{ + u8 *msg = towire_channel_feerates(NULL, + get_feerate(ld->topology, + FEERATE_IMMEDIATE), + feerate_min(ld), + feerate_max(ld)); + subd_send_msg(channel->owner, take(msg)); +} + +static void try_update_feerates(struct lightningd *ld, struct channel *channel) +{ + /* No point until funding locked in */ + if (!channel_fees_can_change(channel)) + return; + + /* Can't if no daemon listening. */ + if (!channel->owner) + return; + + update_feerates(ld, channel); +} + +void notify_feerate_change(struct lightningd *ld) +{ + struct peer *peer; + + /* FIXME: We should notify onchaind about NORMAL fee change in case + * it's going to generate more txs. */ + list_for_each(&ld->peers, peer, list) { + struct channel *channel = peer_active_channel(peer); + + if (!channel) + continue; + + /* FIXME: We choose not to drop to chain if we can't contact + * peer. We *could* do so, however. */ + try_update_feerates(ld, channel); + } +} + static void lockin_complete(struct channel *channel) { /* We set this once we're locked in. */ diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index c9d733ea1..8f3e43a28 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1671,47 +1671,6 @@ void htlcs_notify_new_block(struct lightningd *ld, u32 height) } while (removed); } -static void update_feerates(struct lightningd *ld, struct channel *channel) -{ - u8 *msg = towire_channel_feerates(NULL, - get_feerate(ld->topology, - FEERATE_IMMEDIATE), - feerate_min(ld), - feerate_max(ld)); - subd_send_msg(channel->owner, take(msg)); -} - -void try_update_feerates(struct lightningd *ld, struct channel *channel) -{ - /* No point until funding locked in */ - if (!channel_fees_can_change(channel)) - return; - - /* Can't if no daemon listening. */ - if (!channel->owner) - return; - - update_feerates(ld, channel); -} - -void notify_feerate_change(struct lightningd *ld) -{ - struct peer *peer; - - /* FIXME: We should notify onchaind about NORMAL fee change in case - * it's going to generate more txs. */ - list_for_each(&ld->peers, peer, list) { - struct channel *channel = peer_active_channel(peer); - - if (!channel) - continue; - - /* FIXME: We choose not to drop to chain if we can't contact - * peer. We *could* do so, however. */ - try_update_feerates(ld, channel); - } -} - #if DEVELOPER static void json_dev_ignore_htlcs(struct command *cmd, const char *buffer, const jsmntok_t *params) diff --git a/lightningd/peer_htlcs.h b/lightningd/peer_htlcs.h index 6386ffa67..f1083315e 100644 --- a/lightningd/peer_htlcs.h +++ b/lightningd/peer_htlcs.h @@ -60,5 +60,4 @@ void onchain_fulfilled_htlc(struct channel *channel, void htlcs_notify_new_block(struct lightningd *ld, u32 height); -void try_update_feerates(struct lightningd *ld, struct channel *channel); #endif /* LIGHTNING_LIGHTNINGD_PEER_HTLCS_H */