Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 161
Periodically archive fully resolved channel monitors#307
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
Merged
tnull
merged 4 commits into
lightningdevkit:main
from
tnull:2024-06-archive-fully-resolved-monitorsJun 14, 2024
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
de73ddc
Periodically archive fully-resolved channel monitors
tnull a503eb5
f Rename the const to `RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL`
tnull 9dba3ac
Also update `latest_sync_` timestamps in `sync_wallets`
tnull accd3c8
Also update the fee rate cache in `sync_wallets`
tnull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -122,7 +122,8 @@ pub use builder::BuildError; | ||
| pub use builder::NodeBuilder as Builder; | ||
| use config::{ | ||
| NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, RGS_SYNC_INTERVAL, | ||
| NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, | ||
| RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL, RGS_SYNC_INTERVAL, | ||
| WALLET_SYNC_INTERVAL_MINIMUM_SECS, | ||
| }; | ||
| use connection::ConnectionManager; | ||
| @@ -198,6 +199,7 @@ pub struct Node { | ||
| latest_fee_rate_cache_update_timestamp: Arc<RwLock<Option<u64>>>, | ||
| latest_rgs_snapshot_timestamp: Arc<RwLock<Option<u64>>>, | ||
| latest_node_announcement_broadcast_timestamp: Arc<RwLock<Option<u64>>>, | ||
| latest_channel_monitor_archival_height: Arc<RwLock<Option<u32>>>, | ||
| } | ||
| impl Node { | ||
| @@ -343,10 +345,13 @@ impl Node { | ||
| let tx_sync = Arc::clone(&self.tx_sync); | ||
| let sync_cman = Arc::clone(&self.channel_manager); | ||
| let archive_cman = Arc::clone(&self.channel_manager); | ||
| let sync_cmon = Arc::clone(&self.chain_monitor); | ||
| let archive_cmon = Arc::clone(&self.chain_monitor); | ||
| let sync_sweeper = Arc::clone(&self.output_sweeper); | ||
| let sync_logger = Arc::clone(&self.logger); | ||
| let sync_wallet_timestamp = Arc::clone(&self.latest_wallet_sync_timestamp); | ||
| let sync_monitor_archival_height = Arc::clone(&self.latest_channel_monitor_archival_height); | ||
| let mut stop_sync = self.stop_sender.subscribe(); | ||
| let wallet_sync_interval_secs = | ||
| self.config.wallet_sync_interval_secs.max(WALLET_SYNC_INTERVAL_MINIMUM_SECS); | ||
| @@ -376,6 +381,12 @@ impl Node { | ||
| let unix_time_secs_opt = | ||
| SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs()); | ||
| *sync_wallet_timestamp.write().unwrap() = unix_time_secs_opt; | ||
| periodically_archive_fully_resolved_monitors( | ||
| Arc::clone(&archive_cman), | ||
| Arc::clone(&archive_cmon), | ||
| Arc::clone(&sync_monitor_archival_height) | ||
| ); | ||
| } | ||
| Err(e) => { | ||
| log_error!(sync_logger, "Background sync of Lightning wallet failed: {}", e) | ||
| @@ -1113,7 +1124,8 @@ impl Node { | ||
| } | ||
| } | ||
| /// Manually sync the LDK and BDK wallets with the current chain state. | ||
| /// Manually sync the LDK and BDK wallets with the current chain state and update the fee rate | ||
| /// cache. | ||
| /// | ||
| /// **Note:** The wallets are regularly synced in the background, which is configurable via | ||
| /// [`Config::onchain_wallet_sync_interval_secs`] and [`Config::wallet_sync_interval_secs`]. | ||
| @@ -1128,14 +1140,22 @@ impl Node { | ||
| let wallet = Arc::clone(&self.wallet); | ||
| let tx_sync = Arc::clone(&self.tx_sync); | ||
| let sync_cman = Arc::clone(&self.channel_manager); | ||
| let archive_cman = Arc::clone(&self.channel_manager); | ||
| let sync_cmon = Arc::clone(&self.chain_monitor); | ||
| let archive_cmon = Arc::clone(&self.chain_monitor); | ||
| let fee_estimator = Arc::clone(&self.fee_estimator); | ||
| let sync_sweeper = Arc::clone(&self.output_sweeper); | ||
| let sync_logger = Arc::clone(&self.logger); | ||
| let confirmables = vec![ | ||
| &*sync_cman as &(dyn Confirm + Sync + Send), | ||
| &*sync_cmon as &(dyn Confirm + Sync + Send), | ||
| &*sync_sweeper as &(dyn Confirm + Sync + Send), | ||
| ]; | ||
| let sync_wallet_timestamp = Arc::clone(&self.latest_wallet_sync_timestamp); | ||
| let sync_fee_rate_update_timestamp = | ||
| Arc::clone(&self.latest_fee_rate_cache_update_timestamp); | ||
| let sync_onchain_wallet_timestamp = Arc::clone(&self.latest_onchain_wallet_sync_timestamp); | ||
| let sync_monitor_archival_height = Arc::clone(&self.latest_channel_monitor_archival_height); | ||
| tokio::task::block_in_place(move || { | ||
| tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on( | ||
| @@ -1148,13 +1168,38 @@ impl Node { | ||
| "Sync of on-chain wallet finished in {}ms.", | ||
| now.elapsed().as_millis() | ||
| ); | ||
| let unix_time_secs_opt = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .ok() | ||
| .map(|d| d.as_secs()); | ||
| *sync_onchain_wallet_timestamp.write().unwrap() = unix_time_secs_opt; | ||
| }, | ||
| Err(e) => { | ||
| log_error!(sync_logger, "Sync of on-chain wallet failed: {}", e); | ||
| return Err(e); | ||
| }, | ||
| }; | ||
| let now = Instant::now(); | ||
| match fee_estimator.update_fee_estimates().await { | ||
| Ok(()) => { | ||
| log_info!( | ||
| sync_logger, | ||
| "Fee rate cache update finished in {}ms.", | ||
| now.elapsed().as_millis() | ||
| ); | ||
| let unix_time_secs_opt = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .ok() | ||
| .map(|d| d.as_secs()); | ||
| *sync_fee_rate_update_timestamp.write().unwrap() = unix_time_secs_opt; | ||
| }, | ||
| Err(e) => { | ||
| log_error!(sync_logger, "Fee rate cache update failed: {}", e,); | ||
| return Err(e); | ||
| }, | ||
| } | ||
| let now = Instant::now(); | ||
| match tx_sync.sync(confirmables).await { | ||
| Ok(()) => { | ||
| @@ -1163,6 +1208,18 @@ impl Node { | ||
| "Sync of Lightning wallet finished in {}ms.", | ||
| now.elapsed().as_millis() | ||
| ); | ||
| let unix_time_secs_opt = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .ok() | ||
| .map(|d| d.as_secs()); | ||
| *sync_wallet_timestamp.write().unwrap() = unix_time_secs_opt; | ||
| periodically_archive_fully_resolved_monitors( | ||
| archive_cman, | ||
| archive_cmon, | ||
| sync_monitor_archival_height, | ||
| ); | ||
| Ok(()) | ||
| }, | ||
| Err(e) => { | ||
| @@ -1486,3 +1543,19 @@ pub(crate) fn total_anchor_channels_reserve_sats( | ||
| * anchor_channels_config.per_channel_reserve_sats | ||
| }) | ||
| } | ||
| fn periodically_archive_fully_resolved_monitors( | ||
| channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>, | ||
| latest_channel_monitor_archival_height: Arc<RwLock<Option<u32>>>, | ||
| ) { | ||
| let mut latest_archival_height_lock = latest_channel_monitor_archival_height.write().unwrap(); | ||
| let cur_height = channel_manager.current_best_block().height; | ||
| let should_archive = latest_archival_height_lock | ||
| .as_ref() | ||
| .map_or(true, |h| cur_height >= h + RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL); | ||
tnull marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if should_archive { | ||
| chain_monitor.archive_fully_resolved_channel_monitors(); | ||
tnull marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| *latest_archival_height_lock = Some(cur_height); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.