Skip to content

Commit a6d30c6

Browse files
authored
networking: rename BlocksByRootRequestRoots to RequestedBlockRoots (#339)
1 parent 054b2e9 commit a6d30c6

5 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/lean_spec/subspecs/networking/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
BLOCKS_BY_ROOT_PROTOCOL_V1,
1616
STATUS_PROTOCOL_V1,
1717
BlocksByRootRequest,
18-
BlocksByRootRequestRoots,
1918
CodecError,
19+
RequestedBlockRoots,
2020
ResponseCode,
2121
Status,
2222
decode_request,
@@ -52,7 +52,7 @@
5252
"STATUS_PROTOCOL_V1",
5353
# ReqResp - Message types
5454
"BlocksByRootRequest",
55-
"BlocksByRootRequestRoots",
55+
"RequestedBlockRoots",
5656
"Status",
5757
# ReqResp - Codec
5858
"CodecError",

src/lean_spec/subspecs/networking/client/reqresp_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
BLOCKS_BY_ROOT_PROTOCOL_V1,
4343
STATUS_PROTOCOL_V1,
4444
BlocksByRootRequest,
45-
BlocksByRootRequestRoots,
45+
RequestedBlockRoots,
4646
Status,
4747
)
4848
from lean_spec.subspecs.networking.transport import PeerId
@@ -162,7 +162,7 @@ async def _do_blocks_by_root_request(
162162

163163
try:
164164
# Build and send the request.
165-
request = BlocksByRootRequest(roots=BlocksByRootRequestRoots(data=roots))
165+
request = BlocksByRootRequest(roots=RequestedBlockRoots(data=roots))
166166
request_bytes = encode_request(request.encode_bytes())
167167
await stream.write(request_bytes)
168168

src/lean_spec/subspecs/networking/reqresp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
BLOCKS_BY_ROOT_PROTOCOL_V1,
2020
STATUS_PROTOCOL_V1,
2121
BlocksByRootRequest,
22-
BlocksByRootRequestRoots,
22+
RequestedBlockRoots,
2323
Status,
2424
)
2525

@@ -30,7 +30,7 @@
3030
"REQRESP_PROTOCOL_IDS",
3131
# Message types
3232
"BlocksByRootRequest",
33-
"BlocksByRootRequestRoots",
33+
"RequestedBlockRoots",
3434
"Status",
3535
# Codec
3636
"CodecError",

src/lean_spec/subspecs/networking/reqresp/message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class Status(Container):
4848
"""The protocol ID for the BlocksByRoot v1 request/response message."""
4949

5050

51-
class BlocksByRootRequestRoots(SSZList[Bytes32]):
52-
"""List of requested root hashes."""
51+
class RequestedBlockRoots(SSZList[Bytes32]):
52+
"""List of block roots requested from a peer."""
5353

5454
LIMIT: ClassVar[int] = MAX_REQUEST_BLOCKS
5555

@@ -61,5 +61,5 @@ class BlocksByRootRequest(Container):
6161
This is primarily used to recover recent or missing blocks from a peer.
6262
"""
6363

64-
roots: BlocksByRootRequestRoots
65-
"""List of requested root hashes."""
64+
roots: RequestedBlockRoots
65+
"""List of block roots requested from a peer."""

tests/lean_spec/subspecs/networking/reqresp/test_handler.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
BLOCKS_BY_ROOT_PROTOCOL_V1,
2626
STATUS_PROTOCOL_V1,
2727
BlocksByRootRequest,
28-
BlocksByRootRequestRoots,
28+
RequestedBlockRoots,
2929
Status,
3030
)
3131
from lean_spec.types import Bytes32
@@ -354,7 +354,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
354354
response = MockResponseStream()
355355

356356
request = BlocksByRootRequest(
357-
roots=BlocksByRootRequestRoots(data=[Bytes32(b"\x11" * 32), Bytes32(b"\x22" * 32)])
357+
roots=RequestedBlockRoots(data=[Bytes32(b"\x11" * 32), Bytes32(b"\x22" * 32)])
358358
)
359359

360360
await handler.handle_blocks_by_root(request, response)
@@ -390,7 +390,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
390390

391391
# Request two blocks, only one exists
392392
request = BlocksByRootRequest(
393-
roots=BlocksByRootRequestRoots(
393+
roots=RequestedBlockRoots(
394394
data=[
395395
Bytes32(b"\x11" * 32), # exists
396396
Bytes32(b"\x99" * 32), # missing
@@ -415,9 +415,7 @@ async def run_test() -> tuple[list[bytes], list[tuple[ResponseCode, str]]]:
415415
handler = DefaultRequestHandler() # No block_lookup set
416416
response = MockResponseStream()
417417

418-
request = BlocksByRootRequest(
419-
roots=BlocksByRootRequestRoots(data=[Bytes32(b"\x11" * 32)])
420-
)
418+
request = BlocksByRootRequest(roots=RequestedBlockRoots(data=[Bytes32(b"\x11" * 32)]))
421419

422420
await handler.handle_blocks_by_root(request, response)
423421

@@ -440,7 +438,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
440438
handler = DefaultRequestHandler(block_lookup=lookup)
441439
response = MockResponseStream()
442440

443-
request = BlocksByRootRequest(roots=BlocksByRootRequestRoots(data=[]))
441+
request = BlocksByRootRequest(roots=RequestedBlockRoots(data=[]))
444442

445443
await handler.handle_blocks_by_root(request, response)
446444

@@ -469,7 +467,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
469467

470468
# First block causes error, second succeeds
471469
request = BlocksByRootRequest(
472-
roots=BlocksByRootRequestRoots(data=[Bytes32(b"\x11" * 32), Bytes32(b"\x22" * 32)])
470+
roots=RequestedBlockRoots(data=[Bytes32(b"\x11" * 32), Bytes32(b"\x22" * 32)])
473471
)
474472

475473
await handler.handle_blocks_by_root(request, response)
@@ -546,7 +544,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
546544
server = ReqRespServer(handler=handler)
547545

548546
# Build wire-format request
549-
request = BlocksByRootRequest(roots=BlocksByRootRequestRoots(data=[root1]))
547+
request = BlocksByRootRequest(roots=RequestedBlockRoots(data=[root1]))
550548
request_bytes = encode_request(request.encode_bytes())
551549

552550
stream = MockStream(request_data=request_bytes)
@@ -794,7 +792,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
794792
server = ReqRespServer(handler=handler)
795793

796794
# Client side: encode request
797-
request = BlocksByRootRequest(roots=BlocksByRootRequestRoots(data=[root1, root2]))
795+
request = BlocksByRootRequest(roots=RequestedBlockRoots(data=[root1, root2]))
798796
request_wire = encode_request(request.encode_bytes())
799797

800798
# Server side: handle request
@@ -835,9 +833,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
835833
server = ReqRespServer(handler=handler)
836834

837835
# Request two blocks, only one exists
838-
request = BlocksByRootRequest(
839-
roots=BlocksByRootRequestRoots(data=[root1, root_missing])
840-
)
836+
request = BlocksByRootRequest(roots=RequestedBlockRoots(data=[root1, root_missing]))
841837
request_wire = encode_request(request.encode_bytes())
842838

843839
stream = MockStream(request_data=request_wire)
@@ -1190,7 +1186,7 @@ async def lookup(r: Bytes32) -> SignedBlockWithAttestation | None:
11901186
handler = DefaultRequestHandler(block_lookup=lookup)
11911187
response = MockResponseStream()
11921188

1193-
request = BlocksByRootRequest(roots=BlocksByRootRequestRoots(data=[root]))
1189+
request = BlocksByRootRequest(roots=RequestedBlockRoots(data=[root]))
11941190

11951191
await handler.handle_blocks_by_root(request, response)
11961192

@@ -1215,7 +1211,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
12151211
response = MockResponseStream()
12161212

12171213
request = BlocksByRootRequest(
1218-
roots=BlocksByRootRequestRoots(
1214+
roots=RequestedBlockRoots(
12191215
data=[
12201216
Bytes32(b"\x11" * 32),
12211217
Bytes32(b"\x22" * 32),
@@ -1253,7 +1249,7 @@ async def lookup(root: Bytes32) -> SignedBlockWithAttestation | None:
12531249
response = MockResponseStream()
12541250

12551251
request = BlocksByRootRequest(
1256-
roots=BlocksByRootRequestRoots(
1252+
roots=RequestedBlockRoots(
12571253
data=[
12581254
Bytes32(b"\x11" * 32),
12591255
Bytes32(b"\x22" * 32),
@@ -1374,7 +1370,7 @@ async def lookup(r: Bytes32) -> SignedBlockWithAttestation | None:
13741370

13751371
# BlocksByRoot request
13761372
blocks_request = encode_request(
1377-
BlocksByRootRequest(roots=BlocksByRootRequestRoots(data=[root])).encode_bytes()
1373+
BlocksByRootRequest(roots=RequestedBlockRoots(data=[root])).encode_bytes()
13781374
)
13791375
blocks_stream = MockStream(request_data=blocks_request)
13801376

0 commit comments

Comments
 (0)