Skip to content

Conversation

@tnull
Copy link
Collaborator

@tnull tnull commented Nov 18, 2025

Closes #415.

Previously, we couldn't poll the chain tip in Builder::build as we wouldn't have a runtime available. Since we now do, we can at least attempt to poll for the chain tip before initializing objects, avoiding that fresh nodes need to re-validate everything from genesis.

In the following commits we will use the chain source to poll a best tip
before intializing the listener objects. As a prefactor, we here move
the creation of our onchain wallet after creation of the chain source,
which in turn means we'll need to use the same pattern as for the other
listeners, i.e., not giving the wallet reference to `ChainSource` on
creation but rather handing it in when it's being used at runtime.
@tnull tnull added this to the 0.7 milestone Nov 18, 2025
@tnull tnull requested a review from tankyleo November 18, 2025 10:42
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Nov 18, 2025

👋 Thanks for assigning @benthecarman as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull tnull requested review from benthecarman and removed request for tankyleo November 18, 2025 11:43
benthecarman
benthecarman previously approved these changes Nov 18, 2025
Copy link
Contributor

@benthecarman benthecarman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit otherwise lgtm.

modified the bitcoind tests to first mine 5k blocks and checked the logs, looked like we aren't syncing every block anymore, Finished synchronizing listeners in 6958ms went to 3ms

src/builder.rs Outdated
let best_block = chain_tip_opt.unwrap_or_else(|| {
let genesis_block_hash =
bitcoin::blockdata::constants::genesis_block(config.network).block_hash();
BestBlock::new(genesis_block_hash, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just do BestBlock::from_network instead of grabbing the genesis block yourself

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Previously, we couldn't poll the chain tip in `Builder::build` as we
wouldn't have a runtime available. Since we now do, we can at least
attempt to poll for the chain tip before initializing objects, avoiding
that fresh nodes need to re-validate everything from genesis.
@tnull
Copy link
Collaborator Author

tnull commented Nov 18, 2025

Force-pushed with the following changes:

 git diff-tree -U2 88605f34 c0880d9d
diff --git a/src/builder.rs b/src/builder.rs
index 3880e573..183c7513 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -1525,9 +1525,6 @@ fn build_with_store_internal(
                } else {
                        // We're starting a fresh node.
-                       let best_block = chain_tip_opt.unwrap_or_else(|| {
-                               let genesis_block_hash =
-                                       bitcoin::blockdata::constants::genesis_block(config.network).block_hash();
-                               BestBlock::new(genesis_block_hash, 0)
-                       });
+                       let best_block =
+                               chain_tip_opt.unwrap_or_else(|| BestBlock::from_network(config.network));

                        let chain_params = ChainParameters { network: config.network.into(), best_block };

@tnull tnull requested a review from benthecarman November 18, 2025 14:39
@tnull tnull merged commit f641845 into lightningdevkit:main Nov 18, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider introducing checkpoints to shorten initial header validation

3 participants