-
Notifications
You must be signed in to change notification settings - Fork 113
bitcoind chain source: Poll tip before intialization
#706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
👋 Thanks for assigning @benthecarman as a reviewer! |
benthecarman
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
88605f3 to
c0880d9
Compare
|
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 }; |
Closes #415.
Previously, we couldn't poll the chain tip in
Builder::buildas 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.