|
5 | 5 | domain. All messages are SSZ-encoded and then compressed with Snappy frames. |
6 | 6 | """ |
7 | 7 |
|
8 | | -from pydantic import Field |
9 | | -from typing_extensions import Annotated |
| 8 | +from typing import ClassVar, Type |
10 | 9 |
|
11 | 10 | from lean_spec.subspecs.containers import Checkpoint, SignedBlockWithAttestation |
12 | | -from lean_spec.types import Bytes32, StrictBaseModel |
| 11 | +from lean_spec.types import Bytes32, SSZList, SSZType, StrictBaseModel |
13 | 12 |
|
14 | 13 | from ..config import MAX_REQUEST_BLOCKS |
15 | 14 | from ..types import ProtocolId |
@@ -67,24 +66,26 @@ class Status(StrictBaseModel): |
67 | 66 | BLOCKS_BY_ROOT_PROTOCOL_V1: ProtocolId = "/leanconsensus/req/blocks_by_root/1/" |
68 | 67 | """The protocol ID for the BlocksByRoot v1 request/response message.""" |
69 | 68 |
|
70 | | -BlocksByRootRequest = Annotated[ |
71 | | - list[Bytes32], |
72 | | - Field(max_length=MAX_REQUEST_BLOCKS), |
73 | | -] |
74 | | -""" |
75 | | -A request for one or more blocks by their root hashes. |
76 | 69 |
|
77 | | -This is primarily used to recover recent or missing blocks from a peer. |
78 | | -""" |
| 70 | +class BlocksByRootRequest(SSZList[Bytes32]): |
| 71 | + """ |
| 72 | + A request for one or more blocks by their root hashes. |
79 | 73 |
|
80 | | -BlocksByRootResponse = Annotated[ |
81 | | - list[SignedBlockWithAttestation], |
82 | | - Field(max_length=MAX_REQUEST_BLOCKS), |
83 | | -] |
84 | | -""" |
85 | | -A response containing the requested `SignedBlockWithAttestation` objects. |
| 74 | + This is primarily used to recover recent or missing blocks from a peer. |
| 75 | + """ |
86 | 76 |
|
87 | | -The length of the list may be less than the number of requested blocks if |
88 | | -the responding peer does not have all of them. Each block is sent in a |
89 | | -separate `response_chunk`. |
90 | | -""" |
| 77 | + ELEMENT_TYPE: ClassVar[Type[SSZType]] = Bytes32 |
| 78 | + LIMIT: ClassVar[int] = MAX_REQUEST_BLOCKS |
| 79 | + |
| 80 | + |
| 81 | +class BlocksByRootResponse(SSZList[SignedBlockWithAttestation]): |
| 82 | + """ |
| 83 | + A response containing the requested `SignedBlockWithAttestation` objects. |
| 84 | +
|
| 85 | + The length of the list may be less than the number of requested blocks if |
| 86 | + the responding peer does not have all of them. Each block is sent in a |
| 87 | + separate `response_chunk`. |
| 88 | + """ |
| 89 | + |
| 90 | + ELEMENT_TYPE: ClassVar[Type[SSZType]] = SignedBlockWithAttestation |
| 91 | + LIMIT: ClassVar[int] = MAX_REQUEST_BLOCKS |
0 commit comments