Skip to content

Commit a2fdf9c

Browse files
benthecarmanclaude
andcommitted
Return error for invalid onchain send fee rate
Previously, an invalid fee_rate_sat_per_vb (overflows) was silently collapsed into None via .and_then(), causing the node to substitute its default fee estimation without informing the user. Now the server returns an InvalidRequestError and the CLI rejects invalid fee rates before sending the request. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f105cbc commit a2fdf9c

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

ldk-server-cli/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ async fn main() {
634634
);
635635
},
636636
Commands::OnchainSend { address, amount, send_all, fee_rate_sat_per_vb } => {
637+
if let Some(rate) = fee_rate_sat_per_vb {
638+
// Mirrors FeeRate::from_sat_per_vb: sat/vb * 1000/4 = sat/kwu
639+
if rate.checked_mul(1000 / 4).is_none() {
640+
handle_error_msg(&format!("Invalid fee rate: {} sat/vB", rate));
641+
}
642+
}
637643
let amount_sats = amount.map(|a| a.to_sat().unwrap_or_else(|e| handle_error_msg(&e)));
638644
handle_response_result::<_, OnchainSendResponse>(
639645
client

ldk-server/src/api/onchain_send.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ pub(crate) fn handle_onchain_send_request(
2929
)
3030
})?;
3131

32-
let fee_rate = request.fee_rate_sat_per_vb.and_then(FeeRate::from_sat_per_vb);
32+
let fee_rate = match request.fee_rate_sat_per_vb {
33+
Some(rate) => Some(FeeRate::from_sat_per_vb(rate).ok_or_else(|| {
34+
LdkServerError::new(InvalidRequestError, format!("Invalid fee rate: {} sat/vB", rate))
35+
})?),
36+
None => None,
37+
};
3338
let txid = match (request.amount_sats, request.send_all) {
3439
(Some(amount_sats), None) => {
3540
context.node.onchain_payment().send_to_address(&address, amount_sats, fee_rate)?

0 commit comments

Comments
 (0)