mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
channeld: trivial refactor of fee_for_htlcs().
Extract out num_untrimmed_htlcs() from inside fee_for_htlcs(), and remove unused view arg. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
6efde31ade
commit
02565bcbea
@@ -363,8 +363,19 @@ static bool get_room_above_reserve(const struct channel *channel,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t num_untrimmed_htlcs(enum side side,
|
||||||
|
struct amount_sat dust_limit,
|
||||||
|
u32 feerate,
|
||||||
|
const struct htlc **committed,
|
||||||
|
const struct htlc **adding,
|
||||||
|
const struct htlc **removing)
|
||||||
|
{
|
||||||
|
return commit_tx_num_untrimmed(committed, feerate, dust_limit, side)
|
||||||
|
+ commit_tx_num_untrimmed(adding, feerate, dust_limit, side)
|
||||||
|
- commit_tx_num_untrimmed(removing, feerate, dust_limit, side);
|
||||||
|
}
|
||||||
|
|
||||||
static struct amount_sat fee_for_htlcs(const struct channel *channel,
|
static struct amount_sat fee_for_htlcs(const struct channel *channel,
|
||||||
const struct channel_view *view,
|
|
||||||
const struct htlc **committed,
|
const struct htlc **committed,
|
||||||
const struct htlc **adding,
|
const struct htlc **adding,
|
||||||
const struct htlc **removing,
|
const struct htlc **removing,
|
||||||
@@ -374,12 +385,8 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
|
|||||||
struct amount_sat dust_limit = channel->config[side].dust_limit;
|
struct amount_sat dust_limit = channel->config[side].dust_limit;
|
||||||
size_t untrimmed;
|
size_t untrimmed;
|
||||||
|
|
||||||
untrimmed = commit_tx_num_untrimmed(committed, feerate, dust_limit,
|
untrimmed = num_untrimmed_htlcs(side, dust_limit, feerate,
|
||||||
side)
|
committed, adding, removing);
|
||||||
+ commit_tx_num_untrimmed(adding, feerate, dust_limit,
|
|
||||||
side)
|
|
||||||
- commit_tx_num_untrimmed(removing, feerate, dust_limit,
|
|
||||||
side);
|
|
||||||
|
|
||||||
return commit_tx_base_fee(feerate, untrimmed);
|
return commit_tx_base_fee(feerate, untrimmed);
|
||||||
}
|
}
|
||||||
@@ -536,7 +543,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
*/
|
*/
|
||||||
if (enforce_aggregate_limits) {
|
if (enforce_aggregate_limits) {
|
||||||
struct amount_msat remainder;
|
struct amount_msat remainder;
|
||||||
struct amount_sat fee = fee_for_htlcs(channel, view,
|
struct amount_sat fee = fee_for_htlcs(channel,
|
||||||
committed,
|
committed,
|
||||||
adding,
|
adding,
|
||||||
removing,
|
removing,
|
||||||
@@ -578,7 +585,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
/* Should be able to afford both their own commit tx
|
/* Should be able to afford both their own commit tx
|
||||||
* fee, and other's commit tx fee, which are subtly
|
* fee, and other's commit tx fee, which are subtly
|
||||||
* different! */
|
* different! */
|
||||||
fee = fee_for_htlcs(channel, view,
|
fee = fee_for_htlcs(channel,
|
||||||
committed,
|
committed,
|
||||||
adding,
|
adding,
|
||||||
removing,
|
removing,
|
||||||
@@ -596,7 +603,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
|
|||||||
&remainder));
|
&remainder));
|
||||||
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;
|
||||||
}
|
}
|
||||||
fee = fee_for_htlcs(channel, view,
|
fee = fee_for_htlcs(channel,
|
||||||
committed,
|
committed,
|
||||||
adding,
|
adding,
|
||||||
removing,
|
removing,
|
||||||
|
|||||||
Reference in New Issue
Block a user