-
Notifications
You must be signed in to change notification settings - Fork 2k
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
server: Integrate reconnect tasks into ChiaServer
#14071
server: Integrate reconnect tasks into ChiaServer
#14071
Conversation
d3ae22e
to
92ed6c7
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
07700ea
to
fcbf301
Compare
fcbf301
to
b9843af
Compare
f38a55c
to
7ce6243
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
7ce6243
to
0d45aa2
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
0d45aa2
to
11f6f80
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
this is not an obvious improvement to me. for example, if we ever were to write unit tests for this function, having it be a free function would make that a lot simpler (we would just need to come up with a protocol to mock the There are a few other changes in here that seems like obvious improvements though (and also somewhat unrelated to moving the free function into the class). for example, moving the exception type into the error file |
Actually it seemed clear to me that it's part of Not sure why a maybe coming unit test would justify leaving this method in its own file with a public interface vs integrating it as private method into the related class? Also i don't really get how the "pass in the two members separately" would look like with this being a task which access them at runtime (not only on task creation) other than holding a reference to the passed in members in the task which seems risky/unintuitive?
There are few somewhat unrelated simplifications, right, like getting rid of the inner wrapping method and instead create the task in place or simplify the "are we still connected check". But moving the exception isn't unrelated imo. It's just, there is 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.
is start_service.py
the only user of ChiaServer
?
By moving this logic from start_service into ChiaServer you seem to suggest that is the case. If not, this is a behavior change
@@ -60,7 +60,7 @@ async def handshake_done() -> bool: | |||
# Start both services and wait a bit | |||
await farmer_service.start() | |||
await harvester_service.start() | |||
harvester_service.add_peer(PeerInfo(str(farmer_service.self_hostname), farmer_service._server.get_port())) | |||
harvester_service._server.add_peer(PeerInfo(str(farmer_service.self_hostname), farmer_service._server.get_port())) |
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.
accessing the internal member her will make it harder to change implementation details of harvester_service
, this increases technical debt. I would prefer tests use the public interface.
def add_peer(self, peer: PeerInfo) -> None: | ||
if self._reconnect_tasks.get(peer) is not None: | ||
raise ServerError(f"Peer {peer} already added") | ||
self._reconnect_tasks[peer] = asyncio.create_task(self._reconnect_task_handler(peer)) |
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.
do you know why we have a reconnect task for each peer? It seems really wasteful for every peer to iterate over all peers just to find itself. It would seem simpler an more efficient to just have one task that iterates over all peers and retries the ones that should be retried
from chia.types.peer_info import PeerInfo | ||
|
||
|
||
def start_reconnect_task(server: ChiaServer, peer_info: PeerInfo, log: Logger) -> asyncio.Task[None]: |
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.
nothing this function accesses from server
starts with an underscore. I would think all_connections
and start_client()
are meant to be public
I think the short answer is: where it makes sense to chop up logic to be unit tested.
I would say it's increasing the coupling between those two parts. Generally I think we should be moving in the direction of splitting classes into smaller pieces. That makes them much easier to unit test.
For example, the peer list could be passed in separately from the function to reconnect a peer. This way it would make a test much simpler because you wouldn't have to create something that looks like a |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Closing in favour of #14997. |
Just feels like it belongs in there rather than in its own file because we pass in an
ChiaServer
anyway and access its connections and starting the client.Based on:
localhost
->127.0.0.1
in farmer/harvester config #14165