-
Notifications
You must be signed in to change notification settings - Fork 114
Refactor chain sourcing logic to make result propagation more robust #599
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
Changes from all commits
fb34a27
c1157a3
c765545
128fdfd
9444bc4
a6349a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| // http://opensource.org/licenses/MIT>, at your option. You may not use this file except in | ||
| // accordance with one or both of these licenses. | ||
|
|
||
| use super::WalletSyncStatus; | ||
| use super::{periodically_archive_fully_resolved_monitors, WalletSyncStatus}; | ||
|
|
||
| use crate::config::{ | ||
| BitcoindRestClientConfig, Config, FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS, TX_BROADCAST_TIMEOUT_SECS, | ||
|
|
@@ -306,6 +306,19 @@ impl BitcoindChainSource { | |
| })?; | ||
| } | ||
|
|
||
| let res = self | ||
| .poll_and_update_listeners_inner(channel_manager, chain_monitor, output_sweeper) | ||
| .await; | ||
|
|
||
| self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res); | ||
|
|
||
| res | ||
| } | ||
|
|
||
| async fn poll_and_update_listeners_inner( | ||
| &self, channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>, | ||
| output_sweeper: Arc<Sweeper>, | ||
| ) -> Result<(), Error> { | ||
| let latest_chain_tip_opt = self.latest_chain_tip.read().unwrap().clone(); | ||
| let chain_tip = if let Some(tip) = latest_chain_tip_opt { | ||
| tip | ||
|
|
@@ -317,9 +330,7 @@ impl BitcoindChainSource { | |
| }, | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to poll for chain data: {:?}", e); | ||
| let res = Err(Error::TxSyncFailed); | ||
| self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cleanup here, does that mean that the previous commit would send redundant updates?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite sure what you mean? We previously propagated manually whenever erroring out. But now we can just bubble up the error as we'll propagate to subscribers in the wrapping method.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but before the change in this commit (this specific commit), was the propagate method being called twice? I am wondering if all commits in the stack are leaving the code in a correct state.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, that might be true. Happy to squash the cleanup if you prefer.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now went ahead and did so |
||
| return res; | ||
| return Err(Error::TxSyncFailed); | ||
| }, | ||
| } | ||
| }; | ||
|
|
@@ -329,7 +340,7 @@ impl BitcoindChainSource { | |
| let chain_listener = ChainListener { | ||
| onchain_wallet: Arc::clone(&self.onchain_wallet), | ||
| channel_manager: Arc::clone(&channel_manager), | ||
| chain_monitor, | ||
| chain_monitor: Arc::clone(&chain_monitor), | ||
| output_sweeper, | ||
| }; | ||
| let mut spv_client = | ||
|
|
@@ -344,13 +355,19 @@ impl BitcoindChainSource { | |
| now.elapsed().unwrap().as_millis() | ||
| ); | ||
| *self.latest_chain_tip.write().unwrap() = Some(tip); | ||
|
|
||
| periodically_archive_fully_resolved_monitors( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Context question: channel manager already knows the best block and I assume it is updated somehow, but still we need an external trigger here to archive? It seems responsibility is now with two units instead of one.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far we left when/how to archive to the users in LDK. I guess we could consider making it part of the background processor eventually, but I don't think
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I was confused a bit about the two sources of block information being used (here the connection event, and then the height in cm). But if this is how it is done for now, it's ok. |
||
| Arc::clone(&channel_manager), | ||
| chain_monitor, | ||
| Arc::clone(&self.kv_store), | ||
| Arc::clone(&self.logger), | ||
| Arc::clone(&self.node_metrics), | ||
| )?; | ||
| }, | ||
| Ok(_) => {}, | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to poll for chain data: {:?}", e); | ||
| let res = Err(Error::TxSyncFailed); | ||
| self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res); | ||
| return res; | ||
| return Err(Error::TxSyncFailed); | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -376,9 +393,7 @@ impl BitcoindChainSource { | |
| }, | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to poll for mempool transactions: {:?}", e); | ||
| let res = Err(Error::TxSyncFailed); | ||
| self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res); | ||
| return res; | ||
| return Err(Error::TxSyncFailed); | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -388,24 +403,13 @@ impl BitcoindChainSource { | |
| locked_node_metrics.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt; | ||
| locked_node_metrics.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt; | ||
|
|
||
| let write_res = write_node_metrics( | ||
| write_node_metrics( | ||
| &*locked_node_metrics, | ||
| Arc::clone(&self.kv_store), | ||
| Arc::clone(&self.logger), | ||
| ); | ||
| match write_res { | ||
| Ok(()) => (), | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to persist node metrics: {}", e); | ||
| let res = Err(Error::PersistenceFailed); | ||
| self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res); | ||
| return res; | ||
| }, | ||
| } | ||
| )?; | ||
joostjager marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let res = Ok(()); | ||
| self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res); | ||
| res | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(super) async fn update_fee_rate_estimates(&self) -> Result<(), Error> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.