Skip to content

Commit 81d161b

Browse files
committed
fmt
1 parent 9691bdc commit 81d161b

File tree

8 files changed

+108
-158
lines changed

8 files changed

+108
-158
lines changed

src/builder.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ impl NodeBuilder {
523523

524524
let liquidity_source_config =
525525
self.liquidity_source_config.get_or_insert(LiquiditySourceConfig::default());
526-
liquidity_source_config.sip_client =
527-
Some(SIPClientConfig { node_id, address, csv_delay });
526+
liquidity_source_config.sip_client = Some(SIPClientConfig { node_id, address, csv_delay });
528527
self
529528
}
530529

@@ -1872,7 +1871,11 @@ fn build_with_store_internal(
18721871
});
18731872

18741873
lsc.sip_client.as_ref().map(|config| {
1875-
liquidity_source_builder.sip_client(config.node_id, config.address.clone(), config.csv_delay)
1874+
liquidity_source_builder.sip_client(
1875+
config.node_id,
1876+
config.address.clone(),
1877+
config.csv_delay,
1878+
)
18761879
});
18771880

18781881
lsc.sip_service.as_ref().map(|config| {
@@ -2020,18 +2023,17 @@ fn build_with_store_internal(
20202023
_leak_checker.0.push(Arc::downgrade(&wallet) as Weak<dyn Any + Send + Sync>);
20212024
}
20222025

2023-
let sip_manager = liquidity_source_config
2024-
.as_ref()
2025-
.and_then(|lsc| lsc.sip_client.as_ref())
2026-
.map(|sip_config| {
2026+
let sip_manager = liquidity_source_config.as_ref().and_then(|lsc| lsc.sip_client.as_ref()).map(
2027+
|sip_config| {
20272028
Arc::new(crate::sip::SipManager::new(
20282029
xprv,
20292030
sip_config.node_id,
20302031
sip_config.csv_delay,
20312032
config.network,
20322033
Arc::clone(&logger),
20332034
))
2034-
});
2035+
},
2036+
);
20352037

20362038
Ok(Node {
20372039
runtime,

src/event.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ where
528528
channel_manager: Arc<ChannelManager>, connection_manager: Arc<ConnectionManager<L>>,
529529
output_sweeper: Arc<Sweeper>, network_graph: Arc<Graph>,
530530
liquidity_source: Option<Arc<LiquiditySource<Arc<Logger>>>>,
531-
sip_manager: Option<Arc<crate::sip::SipManager>>,
532-
payment_store: Arc<PaymentStore>, peer_store: Arc<PeerStore<L>>,
533-
keys_manager: Arc<KeysManager>, static_invoice_store: Option<StaticInvoiceStore>,
534-
onion_messenger: Arc<OnionMessenger>, om_mailbox: Option<Arc<OnionMessageMailbox>>,
535-
runtime: Arc<Runtime>, logger: L, config: Arc<Config>,
531+
sip_manager: Option<Arc<crate::sip::SipManager>>, payment_store: Arc<PaymentStore>,
532+
peer_store: Arc<PeerStore<L>>, keys_manager: Arc<KeysManager>,
533+
static_invoice_store: Option<StaticInvoiceStore>, onion_messenger: Arc<OnionMessenger>,
534+
om_mailbox: Option<Arc<OnionMessageMailbox>>, runtime: Arc<Runtime>, logger: L,
535+
config: Arc<Config>,
536536
) -> Self {
537537
Self {
538538
event_queue,
@@ -597,8 +597,7 @@ where
597597
}
598598

599599
let cur_height = self.channel_manager.current_best_block().height;
600-
let locktime =
601-
LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO);
600+
let locktime = LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO);
602601

603602
let mut outputs = vec![bitcoin::TxOut {
604603
value: channel_amount,
@@ -1854,37 +1853,39 @@ where
18541853
..
18551854
} => {
18561855
// Check if any inputs belong to SIP UTXOs that need the server's signature.
1857-
let sip_inputs = self.sip_manager.as_ref().map(|sip_manager| {
1858-
let sip_wallet = sip_manager.wallet();
1859-
let utxos = sip_wallet.swappable_utxos();
1860-
unsigned_transaction
1861-
.input
1862-
.iter()
1863-
.enumerate()
1864-
.filter_map(|(i, input)| {
1865-
utxos
1866-
.iter()
1867-
.find(|u| u.outpoint == input.previous_output)
1868-
.map(|_| (i, input.previous_output))
1869-
})
1870-
.collect::<Vec<_>>()
1871-
}).unwrap_or_default();
1856+
let sip_inputs = self
1857+
.sip_manager
1858+
.as_ref()
1859+
.map(|sip_manager| {
1860+
let sip_wallet = sip_manager.wallet();
1861+
let utxos = sip_wallet.swappable_utxos();
1862+
unsigned_transaction
1863+
.input
1864+
.iter()
1865+
.enumerate()
1866+
.filter_map(|(i, input)| {
1867+
utxos
1868+
.iter()
1869+
.find(|u| u.outpoint == input.previous_output)
1870+
.map(|_| (i, input.previous_output))
1871+
})
1872+
.collect::<Vec<_>>()
1873+
})
1874+
.unwrap_or_default();
18721875

18731876
if !sip_inputs.is_empty() {
18741877
// This funding tx contains SIP inputs. Sign the wallet-owned inputs,
18751878
// then stash the partially-signed tx until the server's signatures arrive.
18761879
match self.wallet.sign_owned_inputs(unsigned_transaction) {
18771880
Ok(partially_signed_tx) => {
18781881
if let Some(sip_manager) = self.sip_manager.as_ref() {
1879-
sip_manager.stash_pending_funding(
1880-
crate::sip::PendingSipFunding {
1881-
channel_id,
1882-
counterparty_node_id,
1883-
tx: partially_signed_tx,
1884-
sip_inputs,
1885-
is_v1_open: false,
1886-
},
1887-
);
1882+
sip_manager.stash_pending_funding(crate::sip::PendingSipFunding {
1883+
channel_id,
1884+
counterparty_node_id,
1885+
tx: partially_signed_tx,
1886+
sip_inputs,
1887+
is_v1_open: false,
1888+
});
18881889
}
18891890
},
18901891
Err(()) => {

src/lib.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,8 +1965,7 @@ impl Node {
19651965
/// Call this when a deposit to a SIP address is detected on-chain. In production this
19661966
/// would be driven by chain sync; for testing it can be called manually.
19671967
pub fn register_sip_utxo(
1968-
&self, outpoint: OutPoint, value: Amount, address_index: u32,
1969-
prevtx: Transaction,
1968+
&self, outpoint: OutPoint, value: Amount, address_index: u32, prevtx: Transaction,
19701969
) -> Result<(), Error> {
19711970
let sip = self.sip_manager.as_ref().ok_or(Error::LiquiditySourceUnavailable)?;
19721971
sip.wallet().register_utxo(outpoint, value, address_index, prevtx);
@@ -2058,16 +2057,13 @@ impl Node {
20582057
// Create channel directly, bypassing check_sufficient_funds_for_channel
20592058
// since the funds come from SIP UTXOs, not the regular BDK wallet.
20602059
let user_channel_id: u128 = u128::from_ne_bytes(
2061-
self.keys_manager.get_secure_random_bytes()[..16]
2062-
.try_into()
2063-
.expect("16-byte slice"),
2060+
self.keys_manager.get_secure_random_bytes()[..16].try_into().expect("16-byte slice"),
20642061
);
20652062

20662063
let mut user_config = default_user_config(&self.config);
20672064
user_config.channel_handshake_config.announce_for_forwarding = false;
2068-
user_config
2069-
.channel_handshake_config
2070-
.max_inbound_htlc_value_in_flight_percent_of_channel = 100;
2065+
user_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel =
2066+
100;
20712067

20722068
self.channel_manager
20732069
.create_channel(
@@ -2120,8 +2116,9 @@ impl Node {
21202116
Error::ChannelSplicingFailed
21212117
})?;
21222118

2123-
let min_feerate =
2124-
self.fee_estimator.estimate_fee_rate(crate::fee_estimator::ConfirmationTarget::ChannelFunding);
2119+
let min_feerate = self
2120+
.fee_estimator
2121+
.estimate_fee_rate(crate::fee_estimator::ConfirmationTarget::ChannelFunding);
21252122
let max_feerate = FeeRate::from_sat_per_kwu(min_feerate.to_sat_per_kwu() * 3 / 2);
21262123

21272124
let funding_template = self
@@ -2132,7 +2129,8 @@ impl Node {
21322129
Error::ChannelSplicingFailed
21332130
})?;
21342131

2135-
let sip_coin_source = crate::sip::coin_selection::SipCoinSelectionSource::new(sip.wallet_arc());
2132+
let sip_coin_source =
2133+
crate::sip::coin_selection::SipCoinSelectionSource::new(sip.wallet_arc());
21362134
let contribution = self
21372135
.runtime
21382136
.block_on(funding_template.splice_in(
@@ -2216,11 +2214,7 @@ impl Node {
22162214

22172215
for (input_idx, outpoint) in &pending.sip_inputs {
22182216
let server_sig = sip_signatures.get(outpoint).ok_or_else(|| {
2219-
log_error!(
2220-
self.logger,
2221-
"Missing server signature for SIP input {}",
2222-
outpoint
2223-
);
2217+
log_error!(self.logger, "Missing server signature for SIP input {}", outpoint);
22242218
Error::ChannelSplicingFailed
22252219
})?;
22262220

@@ -2267,22 +2261,14 @@ impl Node {
22672261

22682262
if pending.is_v1_open {
22692263
self.channel_manager
2270-
.funding_transaction_generated(
2271-
*channel_id,
2272-
pending.counterparty_node_id,
2273-
tx,
2274-
)
2264+
.funding_transaction_generated(*channel_id, pending.counterparty_node_id, tx)
22752265
.map_err(|e| {
22762266
log_error!(self.logger, "Failed to complete SIP channel open: {:?}", e);
22772267
Error::ChannelCreationFailed
22782268
})
22792269
} else {
22802270
self.channel_manager
2281-
.funding_transaction_signed(
2282-
channel_id,
2283-
&pending.counterparty_node_id,
2284-
tx,
2285-
)
2271+
.funding_transaction_signed(channel_id, &pending.counterparty_node_id, tx)
22862272
.map_err(|e| {
22872273
log_error!(self.logger, "Failed to complete SIP splice funding: {:?}", e);
22882274
Error::ChannelSplicingFailed
@@ -2291,9 +2277,7 @@ impl Node {
22912277
}
22922278

22932279
/// Marks a SIP UTXO as refunded after the refund transaction has been broadcast.
2294-
pub fn mark_sip_refunded(
2295-
&self, outpoint: &OutPoint, spending_txid: Txid,
2296-
) -> Result<(), Error> {
2280+
pub fn mark_sip_refunded(&self, outpoint: &OutPoint, spending_txid: Txid) -> Result<(), Error> {
22972281
let sip = self.sip_manager.as_ref().ok_or(Error::LiquiditySourceUnavailable)?;
22982282
sip.wallet().mark_refunded(outpoint, spending_txid);
22992283
Ok(())

src/liquidity.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ where
293293
let lsps1_client_config = self.lsps1_client.as_ref().map(|s| s.ldk_client_config.clone());
294294
let lsps2_client_config = self.lsps2_client.as_ref().map(|s| s.ldk_client_config.clone());
295295
let lsps5_client_config = None;
296-
let sip_client_config =
297-
self.sip_client.as_ref().map(|_| LdkSIPClientConfig {});
296+
let sip_client_config = self.sip_client.as_ref().map(|_| LdkSIPClientConfig {});
298297
let liquidity_client_config = Some(LiquidityClientConfig {
299298
lsps1_client_config,
300299
lsps2_client_config,
@@ -1011,16 +1010,8 @@ where
10111010
csv_delay,
10121011
);
10131012
},
1014-
LiquidityEvent::SIPClient(SIPClientEvent::UtxoRegistered {
1015-
lsp_node_id,
1016-
outpoint,
1017-
}) => {
1018-
log_info!(
1019-
self.logger,
1020-
"SIP UTXO {} registered with LSP {}",
1021-
outpoint,
1022-
lsp_node_id,
1023-
);
1013+
LiquidityEvent::SIPClient(SIPClientEvent::UtxoRegistered { lsp_node_id, outpoint }) => {
1014+
log_info!(self.logger, "SIP UTXO {} registered with LSP {}", outpoint, lsp_node_id,);
10241015
},
10251016
LiquidityEvent::SIPClient(SIPClientEvent::SwapAccepted {
10261017
lsp_node_id,

src/sip/coin_selection.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ mod tests {
110110
async fn test_empty_wallet_returns_err() {
111111
let wallet = make_wallet();
112112
let source = SipCoinSelectionSource::new(wallet);
113-
let result =
114-
source.select_confirmed_utxos(None, vec![], &[], 1000, u64::MAX).await;
113+
let result = source.select_confirmed_utxos(None, vec![], &[], 1000, u64::MAX).await;
115114
assert!(result.is_err());
116115
}
117116

@@ -137,19 +136,15 @@ mod tests {
137136
sequence: Sequence::MAX,
138137
witness: Witness::new(),
139138
}],
140-
output: vec![bitcoin::TxOut {
141-
value: Amount::from_sat(100_000),
142-
script_pubkey,
143-
}],
139+
output: vec![bitcoin::TxOut { value: Amount::from_sat(100_000), script_pubkey }],
144140
};
145141
let outpoint = OutPoint::new(prevtx.compute_txid(), 0);
146142

147143
wallet.register_utxo(outpoint, Amount::from_sat(100_000), addr.index, prevtx);
148144
wallet.confirm_utxo(&outpoint, 800_000);
149145

150146
let source = SipCoinSelectionSource::new(Arc::clone(&wallet));
151-
let result =
152-
source.select_confirmed_utxos(None, vec![], &[], 1000, u64::MAX).await;
147+
let result = source.select_confirmed_utxos(None, vec![], &[], 1000, u64::MAX).await;
153148

154149
assert!(result.is_ok());
155150
let selection = result.unwrap();

src/sip/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ impl SipManager {
7272
master_xpriv: Xpriv, server_pubkey: PublicKey, csv_delay: u16, network: Network,
7373
logger: Arc<Logger>,
7474
) -> Self {
75-
let wallet =
76-
Arc::new(SipWallet::new(master_xpriv, server_pubkey, csv_delay, network, logger.clone()));
75+
let wallet = Arc::new(SipWallet::new(
76+
master_xpriv,
77+
server_pubkey,
78+
csv_delay,
79+
network,
80+
logger.clone(),
81+
));
7782
Self {
7883
wallet,
7984
pending_fundings: Mutex::new(HashMap::new()),
@@ -95,9 +100,7 @@ impl SipManager {
95100
}
96101

97102
/// Takes the pending funding for the given channel, if any.
98-
pub(crate) fn take_pending_funding(
99-
&self, channel_id: &ChannelId,
100-
) -> Option<PendingSipFunding> {
103+
pub(crate) fn take_pending_funding(&self, channel_id: &ChannelId) -> Option<PendingSipFunding> {
101104
self.pending_fundings.lock().unwrap().remove(channel_id)
102105
}
103106

@@ -123,9 +126,7 @@ impl SipManager {
123126
}
124127

125128
/// Returns a clone of the pending funding for the given channel, without removing it.
126-
pub(crate) fn peek_pending_funding(
127-
&self, channel_id: &ChannelId,
128-
) -> Option<PendingSipFunding> {
129+
pub(crate) fn peek_pending_funding(&self, channel_id: &ChannelId) -> Option<PendingSipFunding> {
129130
self.pending_fundings.lock().unwrap().get(channel_id).cloned()
130131
}
131132

0 commit comments

Comments
 (0)