-
Notifications
You must be signed in to change notification settings - Fork 662
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
[ShardsManager] Move ShardsManager to its own actor #8329
Conversation
@@ -1253,9 +1246,11 @@ impl Client { | |||
apply_chunks_done_callback: DoneApplyChunkCallback, | |||
) { | |||
let chunk_header = partial_chunk.cloned_header(); | |||
self.chain.blocks_delay_tracker.mark_chunk_completed(&chunk_header, Clock::utc()); | |||
self.block_production_info |
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.
Note: I think this is a bug fix. It used to be called whenever we receive a PartialEncodedChunk, but that's not the same as collecting the chunk for block production purposes.
b612511
to
4b6bc1a
Compare
chain/chunks/src/adapter.rs
Outdated
); | ||
fn process_partial_encoded_chunk_request( | ||
&self, | ||
partial_encoded_chunk_request: PartialEncodedChunkRequestMsg, |
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.
Could you also add docs for the functions here since they are the interface of ShardsManager
chain/chunks/src/adapter.rs
Outdated
} | ||
} | ||
|
||
pub struct ShardsManagerAdapterAsAdapterForNetwork { |
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.
Add comments
chain/chunks/src/adapter.rs
Outdated
} | ||
} | ||
|
||
impl ShardsManagerAdapterForNetwork for ShardsManagerAdapterAsAdapterForNetwork { |
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.
Does ShardsManagerAdapterForNetwork need to be a trait? Can you just implement ShardsManagerForNetwork as a struct and avoid having both ShardsManagerAdapterForNetwork and ShardsManagerAdapterAsAdapterForNetwork? I think having too many adapters makes the code convoluted unnecessarily.
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 would advocate for just making network use ShardsManagerAdapter directly instead of create a new adapter for it. The advantage of creating a different interface for network is to restrict the proper usage of network code of ShardsManager. The disadvantage is the code gets too complicated with some many adapters. Since the APIs and how it can be used at call sites are very simple, I don't think there is much risk of network code misusing ShardsManager. I would prefer to have simpler code here.
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.
Yeaaaaa... the proliferation of adapters is seriously confusing. Well, the immediate problem with having network use ShardsManagerAdapter is that near-chunks depends on near-network, so that would create a circular dependency. It can be avoided by moving ShardsManagerAdapter (or perhaps PeerManagerAdapter) into a lower crate, but I'm not sure where that should be - doesn't feel like it should be in primitives - maybe we don't have such a crate today.
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 see. That is indeed annoying. What if we create two adapters, ShardsManagerAdapterForNetwork and ShardsManagerAdapterForClient and implement
impl<A: MsgRecipient<ShardsManagerRequest>> ShardsManagerAdapterForNetwork for A
and
impl<A: MsgRecipient<ShardsManagerRequest>> ShardsManagerAdapterForClient for 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.
So... as we discussed offline, I really like this suggestion, and I think this is the direction we want to go. But I ran into some rather subtle roadblocks when trying to make this work.
The most problematic issue is that for testing (at least the current framework), it would be convenient to have a single interface that supports both of these adapter interfaces. For that I need a third trait ShardsManagerAdapterForTest that has both of these traits as bounds, and have the A:MsgRecipient implement ShardsManagerAdapterForTest as well - all of that is fine until I need to take a Arc and convert it to an Arc - I was surprised that this is actually an experimental feature in Rust.
Hmm, I don't think this is going to be easy to solve within this PR, so let me try a couple more things, but in the meantime let's just defer this.
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.
Actually, I've pushed a revision where I found a workaround to this. Let me know what you think. It's basically what you suggested, plus the following:
- ShardsManagerAdapterForTest that I mentioned above, plus for_client and for_network to help with trait upcasting
- I also split the Request enum. This is due to a subtle technicality too, because there's no way to do
impl<A: MsgRecipient<ShardsManagerRequest>> ShardsManagerAdapterForNetwork for A
in the near-chunks crate, because none of these traits belong to near-chunks. So, I have to do that impl in the near-network crate, but then I need the ShardsManagerRequest to also be referenceable from that crate, and therefore I moved that part of the request enum to that crate. This doesn't have much of an effect - what this means is basically that ShardsManager now has handle_client_request and handle_network_request. Nothing fancy.
5b49db5
to
e80db4e
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.
Looks good! Thank you for the change.
Please also run nayduck before merging this since this is a large PR.
Nayduck has passed: https://nayduck.near.org/#/run/2840 |
This is a big refactoring, mostly due to tests.
Some things that are worth mentioning:
#7662