Skip to content

Commit fc380fd

Browse files
committed
Refresh fee estimates during initialization
Startup separately awaited fee estimates and backend capability checks before initializing wallets. These checks must complete before replay can construct claim transactions using the fee estimator. Move the checks into wallet initialization while preserving their ordering. Run fee refresh and required 0FC validation concurrently, then synchronize chain state only after both succeed. Co-Authored-By: HAL 9000
1 parent f552c4b commit fc380fd

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

‎src/chain/mod.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,17 @@ impl ChainSource {
312312
pub(crate) async fn initialize_wallets(
313313
&self, stop_sync_receiver: tokio::sync::watch::Receiver<()>, onchain_wallet: Arc<Wallet>,
314314
channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>,
315-
output_sweeper: Arc<Sweeper>,
315+
output_sweeper: Arc<Sweeper>, zero_fee_commitments_support_required: bool,
316316
) -> Result<(), Error> {
317+
// Replay can broadcast claims, so refresh fees and validate the backend before syncing.
318+
// TODO: drop 0FC chain source validation when support is ubiquitous.
319+
tokio::try_join!(
320+
self.update_fee_rate_estimates(),
321+
self.validate_zero_fee_commitments_support_if_required(
322+
zero_fee_commitments_support_required
323+
)
324+
)?;
325+
317326
#[cfg(not(feature = "chain-bitcoind"))]
318327
let _ = (stop_sync_receiver, onchain_wallet);
319328
match &self.kind {

‎src/lib.rs‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,6 @@ impl Node {
354354
|| monitor_owns_any_0fc_channels
355355
|| self.config.anchor_channels_config.enable_zero_fee_commitments;
356356

357-
// Block to ensure we update our fee rate cache once on startup.
358-
// Also take this opportunity to make sure our chain source supports 0FC channels
359-
// if they are enabled.
360-
//
361-
// TODO: drop 0FC chain source validation when support is ubiquitous
362-
let chain_source = Arc::clone(&self.chain_source);
363-
self.runtime.block_on(async move {
364-
tokio::try_join!(
365-
chain_source.update_fee_rate_estimates(),
366-
chain_source.validate_zero_fee_commitments_support_if_required(
367-
zero_fee_commitments_support_required
368-
)
369-
)
370-
})?;
371-
372357
// Synchronize Lightning chain state before peers or event processing can act on stale
373358
// confirmations. Each restored ChannelMonitor may have been persisted at a different tip.
374359
self.runtime.block_on(self.chain_source.initialize_wallets(
@@ -377,6 +362,7 @@ impl Node {
377362
Arc::clone(&self.channel_manager),
378363
Arc::clone(&self.chain_monitor),
379364
Arc::clone(&self.output_sweeper),
365+
zero_fee_commitments_support_required,
380366
))?;
381367

382368
// Spawn background task continuously syncing onchain, lightning, and fee rate cache.

0 commit comments

Comments
 (0)