From 25b3dc0038379a39229685c969777320fc35b779 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 7 Oct 2016 14:00:17 +1030 Subject: [PATCH] channel: fix max feelevel calculation. We were out by 1000, and also derived it from the previous, not current state. Reported-by: Christian Decker Signed-off-by: Rusty Russell --- daemon/channel.c | 2 +- daemon/peer.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/daemon/channel.c b/daemon/channel.c index 61fc4f6a3..2a9b31073 100644 --- a/daemon/channel.c +++ b/daemon/channel.c @@ -172,7 +172,7 @@ uint64_t approx_max_feerate(const struct channel_state *cstate, max_funds = cstate->side[side].pay_msat + cstate->side[side].fee_msat; - return max_funds * 1000 / tx_bytes(cstate->num_nondust); + return max_funds / tx_bytes(cstate->num_nondust); } bool can_afford_feerate(const struct channel_state *cstate, uint64_t fee_rate, diff --git a/daemon/peer.c b/daemon/peer.c index 7380ca768..7f0ed0054 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -2119,7 +2119,8 @@ static void maybe_propose_new_feerate(struct peer *peer) u64 rate, max_rate; rate = desired_commit_feerate(peer->dstate); - max_rate = approx_max_feerate(peer->remote.commit->cstate, LOCAL); + max_rate = approx_max_feerate(peer->remote.staging_cstate, LOCAL); + assert(can_afford_feerate(peer->remote.staging_cstate, max_rate, LOCAL)); /* BOLT #2: *