-
Notifications
You must be signed in to change notification settings - Fork 128
Enable deferred writing #782
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
Draft
joostjager
wants to merge
3
commits into
lightningdevkit:main
Choose a base branch
from
joostjager:chain-mon-deferred-writes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
|---|---|---|
|
|
@@ -23,9 +23,7 @@ use lightning::routing::gossip; | |
| use lightning::routing::router::DefaultRouter; | ||
| use lightning::routing::scoring::{CombinedScorer, ProbabilisticScoringFeeParameters}; | ||
| use lightning::sign::InMemorySigner; | ||
| use lightning::util::persist::{ | ||
| KVStore, KVStoreSync, MonitorUpdatingPersister, MonitorUpdatingPersisterAsync, | ||
| }; | ||
| use lightning::util::persist::{KVStore, KVStoreSync, MonitorUpdatingPersisterAsync}; | ||
| use lightning::util::ser::{Readable, Writeable, Writer}; | ||
| use lightning::util::sweep::OutputSweeper; | ||
| use lightning_block_sync::gossip::GossipVerifier; | ||
|
|
@@ -135,6 +133,39 @@ impl<'a> KVStoreSync for dyn DynStoreTrait + 'a { | |
|
|
||
| pub(crate) type DynStore = dyn DynStoreTrait; | ||
|
|
||
| // Newtype wrapper that implements `KVStore` for `Arc<DynStore>`. This is needed because `KVStore` | ||
| // methods return `impl Future`, which is not object-safe. `DynStoreTrait` works around this by | ||
| // returning `Pin<Box<dyn Future>>` instead, and this wrapper bridges the two by delegating | ||
| // `KVStore` methods to the corresponding `DynStoreTrait::*_async` methods. | ||
| #[derive(Clone)] | ||
| pub(crate) struct DynStoreRef(pub(crate) Arc<DynStore>); | ||
|
Collaborator
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. |
||
|
|
||
| impl KVStore for DynStoreRef { | ||
| fn read( | ||
| &self, primary_namespace: &str, secondary_namespace: &str, key: &str, | ||
| ) -> impl Future<Output = Result<Vec<u8>, bitcoin::io::Error>> + Send + 'static { | ||
| DynStoreTrait::read_async(&*self.0, primary_namespace, secondary_namespace, key) | ||
| } | ||
|
|
||
| fn write( | ||
| &self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>, | ||
| ) -> impl Future<Output = Result<(), bitcoin::io::Error>> + Send + 'static { | ||
| DynStoreTrait::write_async(&*self.0, primary_namespace, secondary_namespace, key, buf) | ||
| } | ||
|
|
||
| fn remove( | ||
| &self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool, | ||
| ) -> impl Future<Output = Result<(), bitcoin::io::Error>> + Send + 'static { | ||
| DynStoreTrait::remove_async(&*self.0, primary_namespace, secondary_namespace, key, lazy) | ||
| } | ||
|
|
||
| fn list( | ||
| &self, primary_namespace: &str, secondary_namespace: &str, | ||
| ) -> impl Future<Output = Result<Vec<String>, bitcoin::io::Error>> + Send + 'static { | ||
| DynStoreTrait::list_async(&*self.0, primary_namespace, secondary_namespace) | ||
| } | ||
| } | ||
|
|
||
| pub(crate) struct DynStoreWrapper<T: SyncAndAsyncKVStore + Send + Sync>(pub(crate) T); | ||
|
|
||
| impl<T: SyncAndAsyncKVStore + Send + Sync> DynStoreTrait for DynStoreWrapper<T> { | ||
|
|
@@ -188,7 +219,7 @@ impl<T: SyncAndAsyncKVStore + Send + Sync> DynStoreTrait for DynStoreWrapper<T> | |
| } | ||
|
|
||
| pub(crate) type AsyncPersister = MonitorUpdatingPersisterAsync< | ||
| Arc<DynStore>, | ||
| DynStoreRef, | ||
| RuntimeSpawner, | ||
| Arc<Logger>, | ||
| Arc<KeysManager>, | ||
|
|
@@ -197,22 +228,21 @@ pub(crate) type AsyncPersister = MonitorUpdatingPersisterAsync< | |
| Arc<OnchainFeeEstimator>, | ||
| >; | ||
|
|
||
| pub type Persister = MonitorUpdatingPersister< | ||
| Arc<DynStore>, | ||
| Arc<Logger>, | ||
| Arc<KeysManager>, | ||
| Arc<KeysManager>, | ||
| Arc<Broadcaster>, | ||
| Arc<OnchainFeeEstimator>, | ||
| >; | ||
|
|
||
| pub(crate) type ChainMonitor = chainmonitor::ChainMonitor< | ||
| InMemorySigner, | ||
| Arc<ChainSource>, | ||
| Arc<Broadcaster>, | ||
| Arc<OnchainFeeEstimator>, | ||
| Arc<Logger>, | ||
| Arc<Persister>, | ||
| chainmonitor::AsyncPersister< | ||
| DynStoreRef, | ||
| RuntimeSpawner, | ||
| Arc<Logger>, | ||
| Arc<KeysManager>, | ||
| Arc<KeysManager>, | ||
| Arc<Broadcaster>, | ||
| Arc<OnchainFeeEstimator>, | ||
| >, | ||
| Arc<KeysManager>, | ||
| >; | ||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -1211,8 +1211,10 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>( | |
| ); | ||
|
|
||
| println!("\nB close_channel (force: {})", force_close); | ||
| // Allow the background processor to flush deferred monitor writes so that | ||
|
Collaborator
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. Hmm, do we think we could get a way to poll for this rather than introducing this potentially flaky guess? |
||
| // the channel state no longer has monitor_update_in_progress set. | ||
| tokio::time::sleep(Duration::from_secs(1)).await; | ||
| if force_close { | ||
| tokio::time::sleep(Duration::from_secs(1)).await; | ||
| node_a.force_close_channel(&user_channel_id_a, node_b.node_id(), None).unwrap(); | ||
| } else { | ||
| node_a.close_channel(&user_channel_id_a, node_b.node_id()).unwrap(); | ||
|
|
||
Oops, something went wrong.
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.
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.
This might or might not conflict with #811, we'll also need to think through this depending on the order these land.