Skip to content

Commit

Permalink
max fee introduction (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkanoider authored May 9, 2023
1 parent 04c4ee7 commit cd3e455
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ MIN_PAYMENT_AMT=100
EXP_HOURS = 24
# Expiration of pending orders
EXP_SECONDS = 900
# Max routing fee that we want to pay to the network, 0.001 = 0.1%
MAX_ROUTING_FEE=0.001
16 changes: 16 additions & 0 deletions src/lightning/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod invoice;
use std::cmp::Ordering;

use crate::lightning::invoice::decode_invoice;

use anyhow::Result;
Expand Down Expand Up @@ -161,6 +163,19 @@ impl LndConnector {
let payment_hash = payment_hash.to_vec();
let hash = payment_hash.to_hex();

// We need to set a max fee amount
// If the amount is small we use a different max routing fee
let max_fee = match amount.cmp(&100) {
Ordering::Less | Ordering::Equal => amount as f64 * 0.1,
Ordering::Greater => {
amount as f64
* var("MAX_ROUTING_FEE")
.unwrap()
.parse::<f64>()
.unwrap_or(0.001)
}
};

let track_payment_req = TrackPaymentRequest {
payment_hash,
no_inflight_updates: true,
Expand All @@ -182,6 +197,7 @@ impl LndConnector {
let mut request = SendPaymentRequest {
payment_request: payment_request.to_string(),
timeout_seconds: 60,
fee_limit_sat: max_fee as i64,
..Default::default()
};

Expand Down

0 comments on commit cd3e455

Please sign in to comment.