From 552a9bcdfd0441796cd828dcd62ff3c1cf3dfa70 Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Thu, 12 Feb 2026 16:30:28 +0100 Subject: [PATCH] networking: rm request arg in RequestHandler handle_status --- .../subspecs/networking/reqresp/handler.py | 16 ++----------- .../networking/reqresp/test_handler.py | 23 ++++--------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/src/lean_spec/subspecs/networking/reqresp/handler.py b/src/lean_spec/subspecs/networking/reqresp/handler.py index 49da15d4..0c6641b2 100644 --- a/src/lean_spec/subspecs/networking/reqresp/handler.py +++ b/src/lean_spec/subspecs/networking/reqresp/handler.py @@ -148,14 +148,13 @@ class RequestHandler: block_lookup: BlockLookup | None = None """Callback to look up blocks by root.""" - async def handle_status(self, request: Status, response: StreamResponseAdapter) -> None: + async def handle_status(self, response: StreamResponseAdapter) -> None: """ Handle incoming Status request. Responds with our current chain status. Args: - request: Peer's status (logged but not used for response). response: Stream for sending our status. """ # Guard: Ensure we have a status configured. @@ -166,17 +165,6 @@ async def handle_status(self, request: Status, response: StreamResponseAdapter) await response.send_error(ResponseCode.SERVER_ERROR, "Status not available") return - # Respond with OUR status, not the peer's. - # - # The Status exchange is symmetric: each side sends its own chain state. - # The peer's status (in `request`) is useful for: - # - # - Logging for debugging - # - Peer scoring (handled elsewhere) - # - Fork detection (handled by sync layer) - # - # But it does NOT affect what we respond with. - # We always send our current head and finalized checkpoint. await response.send_success(self.our_status.encode_bytes()) async def handle_blocks_by_root( @@ -440,7 +428,7 @@ async def _dispatch( logger.debug("Status decode error: %s", e) await response.send_error(ResponseCode.INVALID_REQUEST, "Invalid Status message") return - await self.handler.handle_status(request, response) + await self.handler.handle_status(response) elif protocol_id == BLOCKS_BY_ROOT_PROTOCOL_V1: # BlocksByRoot request: Peer wants specific blocks by hash. diff --git a/tests/lean_spec/subspecs/networking/reqresp/test_handler.py b/tests/lean_spec/subspecs/networking/reqresp/test_handler.py index 7eefbc95..6a77717f 100644 --- a/tests/lean_spec/subspecs/networking/reqresp/test_handler.py +++ b/tests/lean_spec/subspecs/networking/reqresp/test_handler.py @@ -199,12 +199,7 @@ async def test_handle_status_returns_our_status(self) -> None: handler = RequestHandler(our_status=our_status) response = MockResponseStream() - peer_status = Status( - finalized=Checkpoint(root=Bytes32(b"\xaa" * 32), slot=Slot(50)), - head=Checkpoint(root=Bytes32(b"\xbb" * 32), slot=Slot(150)), - ) - - await handler.handle_status(peer_status, response) # type: ignore[arg-type] + await handler.handle_status(response) # type: ignore[arg-type] assert len(response.errors) == 0 assert len(response.successes) == 1 @@ -219,8 +214,7 @@ async def test_handle_status_no_status_returns_error(self) -> None: handler = RequestHandler() # No our_status set response = MockResponseStream() - peer_status = make_test_status() - await handler.handle_status(peer_status, response) # type: ignore[arg-type] + await handler.handle_status(response) # type: ignore[arg-type] assert len(response.successes) == 0 assert len(response.errors) == 1 @@ -233,15 +227,8 @@ async def test_handle_status_ignores_peer_status(self) -> None: handler = RequestHandler(our_status=our_status) response = MockResponseStream() - # Peer claims different chain state - peer_status = Status( - finalized=Checkpoint(root=Bytes32(b"\xff" * 32), slot=Slot(9999)), - head=Checkpoint(root=Bytes32(b"\xee" * 32), slot=Slot(10000)), - ) - - await handler.handle_status(peer_status, response) # type: ignore[arg-type] + await handler.handle_status(response) # type: ignore[arg-type] - # Our response is independent of peer's status returned_status = Status.decode_bytes(response.successes[0]) assert returned_status.head.slot == Slot(200) assert returned_status.finalized.slot == Slot(100) @@ -953,13 +940,13 @@ async def test_status_update_after_initialization(self) -> None: response1 = MockResponseStream() # First request with no status - await handler.handle_status(make_test_status(), response1) # type: ignore[arg-type] + await handler.handle_status(response1) # type: ignore[arg-type] # Update status handler.our_status = make_test_status() response2 = MockResponseStream() - await handler.handle_status(make_test_status(), response2) # type: ignore[arg-type] + await handler.handle_status(response2) # type: ignore[arg-type] # First request should fail assert len(response1.successes) == 0