-
Notifications
You must be signed in to change notification settings - Fork 385
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
Require chain::Listen
impls in block sync be Send + Sync
#1349
Require chain::Listen
impls in block sync be Send + Sync
#1349
Conversation
Tagging 106 as it addresses a user issue. |
94650bd
to
6cc0cd7
Compare
Note that it seems to be possible to allow both // this blanket impl is backwards-incompatible but shouldn't be a huge issue for implementors
// it'll probably remove their code if it causes failure and DynamicWrapper shouldn't be needed any longer
impl<T: Listen + ?Sized> Listen for &T {
fn block_connected(&self, block: &Block, height: u32) {
(*self).block_connected(block, height)
}
fn block_disconnected(&self, header: &BlockHeader, height: u32) {
(*self).block_disconnected(header, height)
}
}
struct ChainListenerSet<T: Listen>(Vec<(u32, T)>); The users can then pick whatever is the most suitable for them. |
Yea, removing the dyn would fix it, but sadly this API is intended to be used with at least two different types of Listen in the same Vec, hence the dyn :/ |
@TheBlueMatt you can still pass in *Not strictly required, you could also write |
Users who want to use lightning-block-sync's init module would be reasonable in wanting to use it in a multithreaded environment, however because it takes a list of listeners as dyn chain::Listen without any Send or Sync bound they fail in doing so. Here we make the type bounds on `chain::Listen` generic across `chain::Listen + ?Sized`, which the existing bound of `&dyn chain::Listen` satisfies. Thus, this is strictly less restrictive and allows for the use of `&dyn chain::Listen + Send + Sync`.
Oh! I see your point - |
6cc0cd7
to
84a08db
Compare
|
Codecov Report
@@ Coverage Diff @@
## main #1349 +/- ##
==========================================
+ Coverage 90.60% 90.80% +0.19%
==========================================
Files 72 72
Lines 40075 42338 +2263
==========================================
+ Hits 36310 38443 +2133
- Misses 3765 3895 +130
Continue to review full report at Codecov.
|
Users who want to use
lightning-block-sync
'sinit
module wouldbe reasonable in wanting to use it in a multithreaded environment,
however because it takes a list of listeners as
dyn chain::Listen
without any
Send
orSync
bound they fail in doing so.Here we add a
Send + Sync
bound, requiring any listeners be both.This could be less generic for users with their own
chain::Listen
listener that is not
Send
orSync
, but given multi-threadingsupport is important and the LDK-included
chain::Listen
implementations are
Send + Sync
, this seems like an acceptabletradeoff.
CC @johncantrell97