channeld: implement approx_max_feerate.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-11-21 15:56:59 +10:30 committed by Christian Decker
parent f45d962a14
commit 8999e2293a
2 changed files with 28 additions and 1 deletions

View File

@ -678,6 +678,33 @@ static int change_htlcs(struct channel *channel,
return cflags;
}
/* FIXME: The sender's requirements are *implied* by this, not stated! */
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if the sender cannot
* afford the new fee rate on the receiving node's current commitment
* transaction
*/
u32 approx_max_feerate(const struct channel *channel)
{
size_t num;
u64 weight;
const struct htlc **committed, **adding, **removing;
const tal_t *tmpctx = tal_tmpctx(channel);
gather_htlcs(tmpctx, channel, !channel->funder,
&committed, &removing, &adding);
/* Assume none are trimmed; this gives lower bound on feerate. */
num = tal_count(committed) + tal_count(adding) - tal_count(removing);
tal_free(tmpctx);
weight = 724 + 172 * num;
return channel->view[!channel->funder].owed_msat[channel->funder]
/ weight * 1000;
}
bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw)
{
u64 fee_msat, dust = dust_limit_satoshis(channel, !channel->funder);

View File

@ -170,7 +170,7 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
const struct preimage *preimage);
/**
* approx_max_feerate: what's the we (initiator) could raise fee rate to?
* approx_max_feerate: what's the max funder could raise fee rate to?
* @channel: The channel state
*
* This is not exact! To check if their offer is valid, try