Skip to content

Commit

Permalink
Merge pull request fedimint#6037 from tvolk131/speed_up_mprocs
Browse files Browse the repository at this point in the history
fix: GatewayLdkClient::info() doesn't rely on timestamps
  • Loading branch information
tvolk131 authored Oct 22, 2024
2 parents ca1b4e4 + 1cfa530 commit d424a7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
11 changes: 8 additions & 3 deletions devimint/src/gatewayd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,14 @@ impl Gatewayd {
let federation_id = fed.calculate_federation_id();
let invite_code = fed.invite_code()?;
info!("Recovering {federation_id}...");
cmd!(self, "connect-fed", invite_code.clone(), "--recover=true")
.run()
.await?;
poll("gateway connect-fed", || async {
cmd!(self, "connect-fed", invite_code.clone(), "--recover=true")
.run()
.await
.map_err(ControlFlow::Continue)?;
Ok(())
})
.await?;
Ok(())
}

Expand Down
36 changes: 13 additions & 23 deletions gateway/ln-gateway/src/lightning/ldk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use fedimint_core::bitcoin_migration::{
use fedimint_core::runtime::spawn;
use fedimint_core::task::TaskGroup;
use fedimint_core::{Amount, BitcoinAmountOrAll};
use ldk_node::config::EsploraSyncConfig;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::lightning::ln::PaymentHash;
use ldk_node::lightning::routing::gossip::NodeAlias;
Expand Down Expand Up @@ -99,16 +98,7 @@ impl GatewayLdkClient {
});
node_builder
.set_entropy_bip39_mnemonic(mnemonic, None)
.set_chain_source_esplora(
esplora_server_url.to_string(),
Some(EsploraSyncConfig {
// TODO: Remove these and rely on the default values.
// See here for details: https://github.com/lightningdevkit/ldk-node/issues/339#issuecomment-2344230472
onchain_wallet_sync_interval_secs: 10,
lightning_wallet_sync_interval_secs: 10,
..Default::default()
}),
);
.set_chain_source_esplora(esplora_server_url.to_string(), None);
let Some(data_dir_str) = data_dir.to_str() else {
return Err(anyhow::anyhow!("Invalid data dir path"));
};
Expand Down Expand Up @@ -224,9 +214,13 @@ impl Drop for GatewayLdkClient {
#[async_trait]
impl ILnRpcClient for GatewayLdkClient {
async fn info(&self) -> Result<GetNodeInfoResponse, LightningRpcError> {
// It's important that this is called before getting esplora chain tip data
// since we assume that the node is _never_ ahead of esplora. But if we called
// this after esplora, a block could be mined and processed in between the two
// calls.
let node_status = self.node.status();

let Some(chain_tip_block_summary) = self
let Some(esplora_chain_tip_block_summary) = self
.esplora_client
.get_blocks(None)
.await
Expand All @@ -243,17 +237,13 @@ impl ILnRpcClient for GatewayLdkClient {
});
};

let esplora_chain_tip_timestamp = chain_tip_block_summary.time.timestamp;
let block_height: u32 = chain_tip_block_summary.time.height;
let esplora_chain_tip_block_height = esplora_chain_tip_block_summary.time.height;
let ldk_node_chain_tip_block_height = node_status.current_best_block.height;

let synced_to_chain = node_status
.latest_lightning_wallet_sync_timestamp
.unwrap_or_default()
> esplora_chain_tip_timestamp
&& node_status
.latest_onchain_wallet_sync_timestamp
.unwrap_or_default()
> esplora_chain_tip_timestamp;
// The LDK node should never be ahead of the Esplora chain tip block height.
assert!(esplora_chain_tip_block_height >= ldk_node_chain_tip_block_height);

let synced_to_chain = esplora_chain_tip_block_height == ldk_node_chain_tip_block_height;

Ok(GetNodeInfoResponse {
pub_key: self.node.node_id().serialize().to_vec(),
Expand All @@ -262,7 +252,7 @@ impl ILnRpcClient for GatewayLdkClient {
None => format!("LDK Fedimint Gateway Node {}", self.node.node_id()),
},
network: self.node.config().network.to_string(),
block_height,
block_height: ldk_node_chain_tip_block_height,
synced_to_chain,
})
}
Expand Down

0 comments on commit d424a7c

Please sign in to comment.