From 666a2d0848b75337273f0d92d1e7e4bb95b54924 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Mon, 14 Oct 2024 15:10:14 +0300 Subject: [PATCH] remove unnecessary get_info calls --- libs/sdk-core/src/breez_services.rs | 13 +------------ libs/sdk-core/src/greenlight/node_api.rs | 11 ++--------- libs/sdk-core/src/node_api.rs | 2 +- libs/sdk-core/src/test_utils.rs | 2 +- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/libs/sdk-core/src/breez_services.rs b/libs/sdk-core/src/breez_services.rs index 6f452b61e..88f74067d 100644 --- a/libs/sdk-core/src/breez_services.rs +++ b/libs/sdk-core/src/breez_services.rs @@ -264,7 +264,6 @@ impl BreezServices { &self, req: SendPaymentRequest, ) -> Result { - self.start_node().await?; let parsed_invoice = parse_invoice(req.bolt11.as_str())?; let invoice_expiration = parsed_invoice.timestamp + parsed_invoice.expiry; let current_time = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(); @@ -400,7 +399,6 @@ impl BreezServices { &self, req: SendSpontaneousPaymentRequest, ) -> Result { - self.start_node().await?; let payment_res = self .node_api .send_spontaneous_payment( @@ -712,7 +710,6 @@ impl BreezServices { &self, req: RedeemOnchainFundsRequest, ) -> RedeemOnchainResult { - self.start_node().await?; let txid = self .node_api .redeem_onchain_funds(req.to_address, req.sat_per_vbyte) @@ -725,7 +722,6 @@ impl BreezServices { &self, req: PrepareRedeemOnchainFundsRequest, ) -> RedeemOnchainResult { - self.start_node().await?; let response = self.node_api.prepare_redeem_onchain_funds(req).await?; Ok(response) } @@ -809,7 +805,6 @@ impl BreezServices { /// /// Should be called when the user wants to close all the channels. pub async fn close_lsp_channels(&self) -> SdkResult> { - self.start_node().await?; let lsp = self.lsp_info().await?; let tx_ids = self.node_api.close_peer_channels(lsp.pubkey).await?; self.sync().await?; @@ -1195,7 +1190,7 @@ impl BreezServices { async fn do_sync(&self, match_local_balance: bool) -> Result<()> { let start = Instant::now(); - let node_pubkey = self.node_api.start().await?; + let node_pubkey = self.node_api.node_id().await?; self.connect_lsp_peer(node_pubkey).await?; // First query the changes since last sync state. @@ -1410,11 +1405,6 @@ impl BreezServices { get_lsp(self.persister.clone(), self.lsp_api.clone()).await } - pub(crate) async fn start_node(&self) -> Result<()> { - self.node_api.start().await?; - Ok(()) - } - /// Get the recommended fees for onchain transactions pub async fn recommended_fees(&self) -> SdkResult { self.chain_service.recommended_fees().await @@ -2545,7 +2535,6 @@ impl Receiver for PaymentReceiver { &self, req: ReceivePaymentRequest, ) -> Result { - self.node_api.start().await?; let lsp_info = get_lsp(self.persister.clone(), self.lsp.clone()).await?; let node_state = self .persister diff --git a/libs/sdk-core/src/greenlight/node_api.rs b/libs/sdk-core/src/greenlight/node_api.rs index f1c0c6f52..5900b84c6 100644 --- a/libs/sdk-core/src/greenlight/node_api.rs +++ b/libs/sdk-core/src/greenlight/node_api.rs @@ -1438,15 +1438,8 @@ impl NodeAPI for Greenlight { payment.try_into() } - async fn start(&self) -> NodeResult { - let node_info = self - .get_node_client() - .await? - .getinfo(cln::GetinfoRequest {}) - .await - .map_err(|e| NodeError::ServiceConnectivity(e.to_string()))? - .into_inner(); - Ok(hex::encode(node_info.id)) + async fn node_id(&self) -> NodeResult { + Ok(hex::encode(self.signer.node_id())) } async fn redeem_onchain_funds( diff --git a/libs/sdk-core/src/node_api.rs b/libs/sdk-core/src/node_api.rs index e1950716f..f005ed630 100644 --- a/libs/sdk-core/src/node_api.rs +++ b/libs/sdk-core/src/node_api.rs @@ -145,7 +145,7 @@ pub trait NodeAPI: Send + Sync { label: Option, trampoline_node_id: Vec, ) -> NodeResult; - async fn start(&self) -> NodeResult; + async fn node_id(&self) -> NodeResult; /// Attempts to find a payment path "manually" and send the htlcs in a way that will drain /// Large channels first. diff --git a/libs/sdk-core/src/test_utils.rs b/libs/sdk-core/src/test_utils.rs index 713030910..6cfc19b54 100644 --- a/libs/sdk-core/src/test_utils.rs +++ b/libs/sdk-core/src/test_utils.rs @@ -404,7 +404,7 @@ impl NodeAPI for MockNodeAPI { Ok(payment) } - async fn start(&self) -> NodeResult { + async fn node_id(&self) -> NodeResult { Ok("".to_string()) }