-
Notifications
You must be signed in to change notification settings - Fork 408
Drop ChannelManager's ChannelMonitor Arc for Deref #443
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
Drop ChannelManager's ChannelMonitor Arc for Deref #443
Conversation
06cbb0b
to
c08c163
Compare
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.
Cool! Wow, that was much more doable. Your TODOs look good but glad we found a good way forward here.
@@ -207,24 +209,23 @@ impl ChainWatchedUtil { | |||
|
|||
/// Utility for notifying listeners about new blocks, and handling block rescans if new watch | |||
/// data is registered. | |||
pub struct BlockNotifier { | |||
listeners: Mutex<Vec<Weak<ChainListener>>>, //TODO(vmw): try removing Weak | |||
pub struct BlockNotifier<CL: Deref<Target = ChainListener> + Sized + Clone> { |
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.
Man, Clone kinda sucks. Fine for this PR but we should try to remove it in a followup (unless you see an easy way to remove it now, I didn't play with it).
8ebf3e2
to
c61f5b8
Compare
c61f5b8
to
d9828de
Compare
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.
Wow, this turned out simpler than I'd thought, even if the diff is huge :).
775a964
to
5890c29
Compare
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.
Haven't gone through it with a super fine-toothed comb yet, but looks good.
lightning/src/ln/functional_tests.rs
Outdated
@@ -3556,15 +3642,17 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() { | |||
|
|||
let mut nodes_0_read = &nodes_0_serialized[..]; | |||
let keys_manager = Arc::new(test_utils::TestKeysInterface::new(&nodes[0].node_seed, Network::Testnet, Arc::new(test_utils::TestLogger::new()))); | |||
let (_, nodes_0_deserialized) = <(Sha256dHash, ChannelManager<EnforcingChannelKeys>)>::read(&mut nodes_0_read, ChannelManagerReadArgs { | |||
let (_, nodes_0_deserialized_tmp) = <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor>)>::read(&mut nodes_0_read, ChannelManagerReadArgs { | |||
// let (_, nodes_0_deserialized_tmp) = <(Sha256dHash, ChannelManager<EnforcingChannelKeys>)>::read(&mut nodes_0_read, ChannelManagerReadArgs { |
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.
oops'd.
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.
Still a stray commented-previous-copy of this line?
@@ -207,24 +209,25 @@ impl ChainWatchedUtil { | |||
|
|||
/// Utility for notifying listeners about new blocks, and handling block rescans if new watch | |||
/// data is registered. | |||
pub struct BlockNotifier { | |||
listeners: Mutex<Vec<Weak<ChainListener>>>, //TODO(vmw): try removing Weak | |||
pub struct BlockNotifier<'a, CL: Deref<Target = ChainListener + 'a> + 'a> { |
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.
We should add docs that describe the new parameters (here and everywhere) and discuss different ways to use them. Because its super easy to end up with massive type gook, we should probably define a type that defines types for Arc and maybe one for &'a as well if thats easy (plus point the docs to them).
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.
cool, hopefully the docs I added + their location make sense
@@ -326,11 +328,11 @@ const ERR: () = "You need at least 32 bit pointers (well, usize, but we'll assum | |||
/// spam due to quick disconnection/reconnection, updates are not sent until the channel has been | |||
/// offline for a full minute. In order to track this, you must call | |||
/// timer_chan_freshness_every_min roughly once per minute, though it doesn't have to be perfec. | |||
pub struct ChannelManager<ChanSigner: ChannelKeys> { |
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.
Same here, probably want type aliases for common usages and docs.
e4a1437
to
a63599c
Compare
Oops, I realized my comment was somewhat unclear, what I was looking at when I made it was this: TheBlueMatt/rust-lightning-bitcoinrpc@97d9e15 with wonderful tidbits like So instead of |
Ahh, I see what you're getting at. Let me know if these new changes seem improved. The |
a63599c
to
e3524d1
Compare
lightning-net-tokio/src/lib.rs
Outdated
pub struct SocketDescriptor { | ||
conn: Arc<Mutex<Connection>>, | ||
id: u64, | ||
peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor>>, | ||
peer_manager: SimpleArcPeerManager, |
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.
Hmm, doesn't this restrict us to very specific use-cases eg InMemoryChannelKeys + SimpleManyChannelMonitor? I think we may need to template + default these too :(.
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.
I reverted back to the previous version. This makes it "templated" iiuc, but not sure what
+ default
means 😅 Soz if missing the obvious here..
lightning/src/ln/channelmonitor.rs
Outdated
/// with static lifetimes). Other times you can afford a reference, which is more efficient, in | ||
/// which case SimpleRefChannelMonitor is the more appropriate type. Defining these type aliases | ||
/// prevents issues such as overly long function definitions. | ||
pub type SimpleArcChannelMonitor = Arc<SimpleManyChannelMonitor<OutPoint>>; |
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.
I'm really torn on what to do here - SimpleManyChannelMonitor is great, but its also meant as a thing you need to put a wrapper around to store to disk. That probably needs to be clarified in the docs for ManyChannelMonitor, but maybe for now replace SimpleArcChannelMonitor with a template A: ManyChannelMonitor -> Arc...I know, I contradicted myself here, sorry.
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.
Ah I'm not sure I understood this. What do you mean by
but its also meant as a thing you need to put a wrapper around to store to disk.
? Can't quite see the relevance. And, does "put a wrapper" mean put it into something that implements Serializable
, or something similar?
I replaced the SimpleArcChannelMonitor with a template within the SimpleArcChannelManager.
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.
As in users should almost certainly not be using SimpleManyChannelMonitor directly - they should be using MyCustomerManyChannelMonitor { in_memory_stuff: SimpleManyChannelMonitor } where the impl first writes the latest channel monitor to disk, then passes it to the in memory version. Thus, having a SimpleArcChannelMonitor is....not quite what we want (nor using SimpleManyChannelMonitor in any of the "suggested good default" types).
e3524d1
to
d054889
Compare
lightning/src/ln/channelmanager.rs
Outdated
/// usage of lightning-net-tokio (since tokio::spawn requires parameters with static lifetimes). | ||
/// But if this is not necessary, using a reference is more efficient. Defining these type aliases | ||
/// helps with issues such as long function definitions. | ||
pub type SimpleRefChannelManager<'a, 'b, CS, M> = &'a ChannelManager<CS, &'b M>; |
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.
Same here, dont think it needs the outside reference. Also would be nice to use it in the tests.
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.
Also would be nice to use it in the tests.
Hmm, the tests use EnforcingChannelKeys
but I switched the SimpleRefChannelManager to use InMemoryChannelKeys
per this comment: #443 (comment)
Could create another SimpleRefChannelManager
type that uses EnforcingChannelKeys instead!
d054889
to
ae47a3c
Compare
ae47a3c
to
59bef21
Compare
Additional changes: * Update fuzz crate to match ChannelManager's new API * Update lightning-net-tokio library to match ChannelManager's new ChannelMonitor Deref API * Update tests to match ChannelManager's new ChannelMonitor Deref API
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.
Alright. Looks good with 3 tiny nits left. I'll just fix them and merge to get this done in a bit.
lightning/src/ln/functional_tests.rs
Outdated
let node_cfgs = create_node_cfgs(2); | ||
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); | ||
let nodes = create_network(2, &node_cfgs, &node_chanmgrs); | ||
let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); |
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.
nit: stray indentation.
lightning/src/ln/functional_tests.rs
Outdated
@@ -3556,15 +3642,17 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() { | |||
|
|||
let mut nodes_0_read = &nodes_0_serialized[..]; | |||
let keys_manager = Arc::new(test_utils::TestKeysInterface::new(&nodes[0].node_seed, Network::Testnet, Arc::new(test_utils::TestLogger::new()))); | |||
let (_, nodes_0_deserialized) = <(Sha256dHash, ChannelManager<EnforcingChannelKeys>)>::read(&mut nodes_0_read, ChannelManagerReadArgs { | |||
let (_, nodes_0_deserialized_tmp) = <(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor>)>::read(&mut nodes_0_read, ChannelManagerReadArgs { | |||
// let (_, nodes_0_deserialized_tmp) = <(Sha256dHash, ChannelManager<EnforcingChannelKeys>)>::read(&mut nodes_0_read, ChannelManagerReadArgs { |
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.
Still a stray commented-previous-copy of this line?
lightning/src/ln/functional_tests.rs
Outdated
@@ -5695,7 +5855,9 @@ fn do_test_failure_delay_dust_htlc_local_commitment(announce_latest: bool) { | |||
// We can have at most two valid local commitment tx, so both cases must be covered, and both txs must be checked to get them all as | |||
// HTLC could have been removed from lastest local commitment tx but still valid until we get remote RAA | |||
|
|||
let nodes = create_network(2, &[None, None]); | |||
let node_cfgs = create_node_cfgs(3); |
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.
2 -> 3 here.
59bef21
to
4833d1a
Compare
Partly closes #237.
TODO:
Weak
pointersArc
--> reference changes