Skip to content

Commit

Permalink
Update zero-conf fee rate check
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Jan 6, 2025
1 parent 86ac5aa commit 55f51bb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ typedef struct _Dart_Handle* Dart_Handle;
/**
* The minimum acceptable fee rate when claiming using zero-conf
*/
#define DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET 100

#define DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET 10
#define DEFAULT_ZERO_CONF_MIN_FEE_RATE 100

/**
* The maximum acceptable amount in satoshi when claiming using zero-conf
Expand Down
9 changes: 3 additions & 6 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use strum_macros::{Display, EnumString};

use crate::error::{PaymentError, SdkError, SdkResult};
use crate::prelude::DEFAULT_EXTERNAL_INPUT_PARSERS;
use crate::receive_swap::{
DEFAULT_ZERO_CONF_MAX_SAT, DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET,
DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET,
};
use crate::receive_swap::{DEFAULT_ZERO_CONF_MAX_SAT, DEFAULT_ZERO_CONF_MIN_FEE_RATE};
use crate::utils;

// Uses f64 for the maximum precision when converting between units
Expand Down Expand Up @@ -85,7 +82,7 @@ impl Config {
cache_dir: None,
network: LiquidNetwork::Mainnet,
payment_timeout_sec: 15,
zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET,
zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE,
sync_service_url: BREEZ_SYNC_SERVICE_URL.to_string(),
zero_conf_max_amount_sat: None,
breez_api_key: Some(breez_api_key),
Expand All @@ -104,7 +101,7 @@ impl Config {
cache_dir: None,
network: LiquidNetwork::Testnet,
payment_timeout_sec: 15,
zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET,
zero_conf_min_fee_rate_msat: DEFAULT_ZERO_CONF_MIN_FEE_RATE,
sync_service_url: BREEZ_SYNC_SERVICE_URL.to_string(),
zero_conf_max_amount_sat: None,
breez_api_key,
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/receive_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use crate::{
};

/// The minimum acceptable fee rate when claiming using zero-conf
pub const DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET: u32 = 100;
pub const DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET: u32 = 10;
pub const DEFAULT_ZERO_CONF_MIN_FEE_RATE: u32 = 100;
/// The maximum acceptable amount in satoshi when claiming using zero-conf
pub const DEFAULT_ZERO_CONF_MAX_SAT: u64 = 100_000;

Expand Down Expand Up @@ -158,7 +157,8 @@ impl ReceiveSwapHandler {
// If the fees are higher than our estimated value
let tx_fees: u64 = lockup_tx.all_fees().values().sum();
let min_fee_rate = self.config.zero_conf_min_fee_rate_msat as f32 / 1000.0;
let lower_bound_estimated_fees = lockup_tx.vsize() as f32 * min_fee_rate * 0.8;
let lower_bound_estimated_fees =
lockup_tx.discount_vsize() as f32 * min_fee_rate * 0.8;

if lower_bound_estimated_fees > tx_fees as f32 {
warn!("[Receive Swap {id}] Lockup tx fees are too low: Expected at least {lower_bound_estimated_fees} sat, got {tx_fees} sat. Waiting for confirmation...");
Expand Down
6 changes: 4 additions & 2 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,15 @@ impl LiquidSdk {
amount_sat: u64,
address: &str,
) -> Result<u64, PaymentError> {
Ok(self
let fee_sat = self
.onchain_wallet
.build_tx(Some(LIQUID_FEE_RATE_MSAT_PER_VBYTE), address, amount_sat)
.await?
.all_fees()
.values()
.sum())
.sum::<u64>();
info!("Estimated tx fee: {fee_sat} sat");
Ok(fee_sat)
}

fn get_temp_p2tr_addr(&self) -> &str {
Expand Down
4 changes: 1 addition & 3 deletions packages/dart/lib/src/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6928,9 +6928,7 @@ const double LIQUID_FEE_RATE_SAT_PER_VBYTE = 0.1;

const double LIQUID_FEE_RATE_MSAT_PER_VBYTE = 100.0;

const int DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET = 100;

const int DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET = 10;
const int DEFAULT_ZERO_CONF_MIN_FEE_RATE = 100;

const int DEFAULT_ZERO_CONF_MAX_SAT = 100000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5445,9 +5445,7 @@ const double LIQUID_FEE_RATE_SAT_PER_VBYTE = 0.1;

const double LIQUID_FEE_RATE_MSAT_PER_VBYTE = 100.0;

const int DEFAULT_ZERO_CONF_MIN_FEE_RATE_TESTNET = 100;

const int DEFAULT_ZERO_CONF_MIN_FEE_RATE_MAINNET = 10;
const int DEFAULT_ZERO_CONF_MIN_FEE_RATE = 100;

const int DEFAULT_ZERO_CONF_MAX_SAT = 100000;

Expand Down

0 comments on commit 55f51bb

Please sign in to comment.