From 8ffd9d570b4926ffc508e997774f12887e88e03b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 13 Dec 2019 00:35:53 +1030 Subject: [PATCH] channeld: cleanup: use the channel_feerate() accessor everywhere. And also move it to initial_channel, so we can use it there. This saves churn in the next patch. Signed-off-by: Rusty Russell --- channeld/channeld.c | 10 +++++----- channeld/full_channel.c | 11 +++-------- common/initial_channel.c | 7 ++++++- common/initial_channel.h | 7 +++++++ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 379c3ef93..44e30379b 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -1392,11 +1392,11 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg) /* We were supposed to check this was affordable as we go. */ if (peer->channel->funder == REMOTE) { status_debug("Feerates are %u/%u", - peer->channel->view[LOCAL].feerate_per_kw, - peer->channel->view[REMOTE].feerate_per_kw); + channel_feerate(peer->channel, LOCAL), + channel_feerate(peer->channel, REMOTE)); assert(can_funder_afford_feerate(peer->channel, - peer->channel->view[LOCAL] - .feerate_per_kw)); + channel_feerate(peer->channel, + LOCAL))); } if (!fromwire_commitment_signed(tmpctx, msg, @@ -1443,7 +1443,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg) type_to_string(msg, struct pubkey, &peer->channel->funding_pubkey [REMOTE]), - peer->channel->view[LOCAL].feerate_per_kw); + channel_feerate(peer->channel, LOCAL)); } /* BOLT #2: diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 98e9f51af..350b6e6f7 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -231,7 +231,7 @@ static void add_htlcs(struct bitcoin_tx ***txs, { size_t i; struct bitcoin_txid txid; - u32 feerate_per_kw = channel->view[side].feerate_per_kw; + u32 feerate_per_kw = channel_feerate(channel, side); /* Get txid of commitment transaction */ bitcoin_txid((*txs)[0], &txid); @@ -306,7 +306,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, ctx, &channel->funding_txid, channel->funding_txout, channel->funding, channel->funder, channel->config[!side].to_self_delay, &keyset, - channel->view[side].feerate_per_kw, + channel_feerate(channel, side), channel->config[side].dust_limit, channel->view[side].owed[side], channel->view[side].owed[!side], committed, htlcmap, commitment_number ^ channel->commitment_number_obscurer, side); @@ -370,7 +370,7 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel, const struct htlc **removing, enum side side) { - u32 feerate = view->feerate_per_kw; + u32 feerate = channel_feerate(channel, side); struct amount_sat dust_limit = channel->config[side].dust_limit; size_t untrimmed; @@ -972,11 +972,6 @@ bool channel_update_feerate(struct channel *channel, u32 feerate_per_kw) return true; } -u32 channel_feerate(const struct channel *channel, enum side side) -{ - return channel->view[side].feerate_per_kw; -} - bool channel_sending_commit(struct channel *channel, const struct htlc ***htlcs) { diff --git a/common/initial_channel.c b/common/initial_channel.c index a68ad9bcd..e542b54be 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -100,7 +100,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, /* They specify our to_self_delay and v.v. */ channel->config[!side].to_self_delay, &keyset, - channel->view[side].feerate_per_kw, + channel_feerate(channel, side), channel->config[side].dust_limit, channel->view[side].owed[side], channel->view[side].owed[!side], @@ -110,6 +110,11 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, err_reason); } +u32 channel_feerate(const struct channel *channel, enum side side) +{ + return channel->view[side].feerate_per_kw; +} + static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view) { return tal_fmt(ctx, "{ feerate_per_kw=%"PRIu32"," diff --git a/common/initial_channel.h b/common/initial_channel.h index f5486a794..b7e5dca95 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -122,4 +122,11 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, enum side side, char** err_reason); +/** + * channel_feerate: Get fee rate for this side of channel. + * @channel: The channel + * @side: the side + */ +u32 channel_feerate(const struct channel *channel, enum side side); + #endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */