mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
lightningd: refactor forward feecheck.
Make it do the feerate calc internally. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
09e0794b06
commit
8fe0ac8d37
@@ -334,10 +334,19 @@ static void fail_out_htlc(struct htlc_out *hout,
|
|||||||
static bool check_fwd_amount(struct htlc_in *hin,
|
static bool check_fwd_amount(struct htlc_in *hin,
|
||||||
struct amount_msat amt_to_forward,
|
struct amount_msat amt_to_forward,
|
||||||
struct amount_msat amt_in_htlc,
|
struct amount_msat amt_in_htlc,
|
||||||
struct amount_msat fee)
|
u32 feerate_base, u32 feerate_ppm)
|
||||||
{
|
{
|
||||||
|
struct amount_msat fee;
|
||||||
struct amount_msat fwd;
|
struct amount_msat fwd;
|
||||||
|
|
||||||
|
if (!amount_msat_fee(&fee, amt_to_forward,
|
||||||
|
feerate_base, feerate_ppm)) {
|
||||||
|
log_broken(hin->key.channel->log, "Fee overflow forwarding %s!",
|
||||||
|
type_to_string(tmpctx, struct amount_msat,
|
||||||
|
&amt_to_forward));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (amount_msat_sub(&fwd, amt_in_htlc, fee)
|
if (amount_msat_sub(&fwd, amt_in_htlc, fee)
|
||||||
&& amount_msat_greater_eq(fwd, amt_to_forward))
|
&& amount_msat_greater_eq(fwd, amt_to_forward))
|
||||||
return true;
|
return true;
|
||||||
@@ -673,7 +682,6 @@ static void forward_htlc(struct htlc_in *hin,
|
|||||||
const struct pubkey *next_blinding)
|
const struct pubkey *next_blinding)
|
||||||
{
|
{
|
||||||
const u8 *failmsg;
|
const u8 *failmsg;
|
||||||
struct amount_msat fee;
|
|
||||||
struct lightningd *ld = hin->key.channel->peer->ld;
|
struct lightningd *ld = hin->key.channel->peer->ld;
|
||||||
struct channel *next = active_channel_by_scid(ld, scid);
|
struct channel *next = active_channel_by_scid(ld, scid);
|
||||||
struct htlc_out *hout = NULL;
|
struct htlc_out *hout = NULL;
|
||||||
@@ -695,17 +703,9 @@ static void forward_htlc(struct htlc_in *hin,
|
|||||||
* - SHOULD accept HTLCs that pay a fee equal to or greater than:
|
* - SHOULD accept HTLCs that pay a fee equal to or greater than:
|
||||||
* - fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 )
|
* - fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 )
|
||||||
*/
|
*/
|
||||||
if (!amount_msat_fee(&fee, amt_to_forward,
|
if (!check_fwd_amount(hin, amt_to_forward, hin->msat,
|
||||||
next->feerate_base,
|
next->feerate_base,
|
||||||
next->feerate_ppm)) {
|
next->feerate_ppm)) {
|
||||||
log_broken(ld->log, "Fee overflow forwarding %s!",
|
|
||||||
type_to_string(tmpctx, struct amount_msat,
|
|
||||||
&amt_to_forward));
|
|
||||||
needs_update_appended = true;
|
|
||||||
failmsg = towire_fee_insufficient(tmpctx, hin->msat, NULL);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
if (!check_fwd_amount(hin, amt_to_forward, hin->msat, fee)) {
|
|
||||||
needs_update_appended = true;
|
needs_update_appended = true;
|
||||||
failmsg = towire_fee_insufficient(tmpctx, hin->msat, NULL);
|
failmsg = towire_fee_insufficient(tmpctx, hin->msat, NULL);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|||||||
Reference in New Issue
Block a user