Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ impl RollupBlueprint for BitcoinRollup {
);
let monitoring_service = Arc::new(monitoring_service);

let fee_service =
FeeService::new(client.clone(), network, da_config.mempool_space_url.clone());
let fee_service = FeeService::new(
client.clone(),
network,
da_config.mempool_space_url.clone(),
da_config.max_fee_rate_sat_vb,
);

let service = Arc::new(
BitcoinService::from_config(
Expand Down
8 changes: 7 additions & 1 deletion bin/citrea/tests/bitcoin/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub async fn spawn_bitcoin_da_service(
utxo_selection_mode,
rpc_timeout_secs: None,
rpc_connect_timeout_secs: None,
max_fee_rate_sat_vb: None,
};

let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
Expand Down Expand Up @@ -225,7 +226,12 @@ pub async fn spawn_bitcoin_da_service(
);
let monitoring_service = Arc::new(monitoring_service);

let fee_service = FeeService::new(client.clone(), network, da_config.mempool_space_url.clone());
let fee_service = FeeService::new(
client.clone(),
network,
da_config.mempool_space_url.clone(),
da_config.max_fee_rate_sat_vb,
);

let service = Arc::new(
BitcoinService::from_config(
Expand Down
15 changes: 13 additions & 2 deletions crates/bitcoin-da/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const BASE_FEE_RATE_MULTIPLIER: f64 = 1.0;
const FEE_RATE_MULTIPLIER_FACTOR: f64 = 1.1;
const MAX_FEE_RATE_MULTIPLIER: f64 = 2.0;

const DEFAULT_MAX_FEE_RATE_SAT_VB: u64 = 15;

/// Type alias for a Partially Signed Bitcoin Transaction (PSBT).
pub type Psbt = String;

Expand All @@ -46,6 +48,7 @@ pub struct FeeService {
client: Arc<Client>,
network: Network,
mempool_space_url: String,
max_fee_rate_sat_vb: u64,
}

impl FeeService {
Expand All @@ -54,13 +57,17 @@ impl FeeService {
client: Arc<Client>,
network: bitcoin::Network,
mempool_space_url: Option<String>,
max_fee_rate_sat_vb: Option<u64>,
) -> Self {
let mempool_space_url =
mempool_space_url.unwrap_or_else(|| DEFAULT_MEMPOOL_SPACE_URL.to_string());

let max_fee_rate_sat_vb = max_fee_rate_sat_vb.unwrap_or(DEFAULT_MAX_FEE_RATE_SAT_VB);
Self {
client,
network,
mempool_space_url,
max_fee_rate_sat_vb,
}
}

Expand Down Expand Up @@ -97,10 +104,14 @@ impl FeeService {
.fee_rate
}
};

let sat_vkb = smart_fee.map_or(1000, |rate| rate.to_sat());
let sat_vb = sat_vkb / 1000;
let capped_fee_rate = sat_vb.min(self.max_fee_rate_sat_vb);

tracing::debug!("Fee rate: {capped_fee_rate} sat/vb");

tracing::debug!("Fee rate: {} sat/vb", sat_vkb / 1000);
Ok(sat_vkb / 1000)
Ok(capped_fee_rate)
}

/// Bump TX fee via cpfp.
Expand Down
6 changes: 6 additions & 0 deletions crates/bitcoin-da/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ pub struct BitcoinServiceConfig {

/// Connection timeout for RPC in seconds
pub rpc_connect_timeout_secs: Option<u64>,

/// Max fee rate in sat/vb
pub max_fee_rate_sat_vb: Option<u64>,
}

impl citrea_common::FromEnv for BitcoinServiceConfig {
Expand All @@ -149,6 +152,9 @@ impl citrea_common::FromEnv for BitcoinServiceConfig {
rpc_connect_timeout_secs: read_env("BITCOIN_RPC_CONNECT_TIMEOUT_SECS")
.ok()
.and_then(|v| v.parse::<u64>().ok()),
max_fee_rate_sat_vb: read_env("BITCOIN_MAX_FEE_RATE_SAT_VB")
.ok()
.and_then(|v| v.parse::<u64>().ok()),
})
}
}
Expand Down
Loading