Skip to content

Commit 9e21be0

Browse files
royscfselmo
andcommitted
Support blob_sidecars beacon endpoint
Co-authored-by: Felipe Selmo <[email protected]>
1 parent d1c0f29 commit 9e21be0

File tree

7 files changed

+110
-4
lines changed

7 files changed

+110
-4
lines changed

docs/web3.beacon.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,51 @@ Methods
432432
]
433433
}
434434
435+
.. py:method:: Beacon.get_blob_sidecars(block_id, indices=[])
436+
437+
.. code-block:: python
438+
439+
>>> beacon.get_blob_sidecars(1, indices=[1])
440+
{
441+
"data": [
442+
{
443+
"index": "1",
444+
"blob": ..., # ommitted
445+
"kzg_commitment": "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a",
446+
"kzg_proof": "0x7FB0A12D11Ffe8A48c2fF80dCA17adbCC1da5F6aADaAEF2b338717dcDEECf6DaB9FD7C4e4265CfBc097cD31dCB19E836",
447+
"signed_block_header": {
448+
"message": {
449+
"slot": "1",
450+
"proposer_index": "1",
451+
"parent_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
452+
"state_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
453+
"body_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
454+
},
455+
"signature": "0x1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505cc411d61252fb6cb3fa0017b679f8bb2305b26a285fa2737f175668d0dff91cc1b66ac1fb663c9bc59509846d6ec05345bd908eda73e670af888da41af171505"
456+
},
457+
"kzg_commitment_inclusion_proof": [
458+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
459+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
460+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
461+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
462+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
463+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
464+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
465+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
466+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
467+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
468+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
469+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
470+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
471+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
472+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
473+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
474+
"0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"
475+
]
476+
}
477+
]
478+
}
479+
435480
.. py:method:: Beacon.get_node_identity()
436481
437482
.. code-block:: python

newsfragments/3407.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add sync and async support for beacon ``/eth/v1/beacon/blob_sidecars`` endpoint.

tests/beacon/test_async_beacon.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,16 @@ async def test_async_cl_node_get_version(async_beacon):
267267
async def test_async_cl_node_get_syncing(async_beacon):
268268
response = await async_beacon.get_syncing()
269269
_assert_valid_response(response)
270+
271+
272+
# Blob endpoint tests
273+
274+
275+
@pytest.mark.asyncio
276+
async def test_async_cl_node_get_blob_sidecars(async_beacon):
277+
response = await async_beacon.get_blob_sidecars("head")
278+
_assert_valid_response(response)
279+
280+
# test with indices
281+
with_indices = await async_beacon.get_blob_sidecars("head", [0, 1])
282+
_assert_valid_response(with_indices)

tests/beacon/test_beacon.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,15 @@ def test_cl_node_get_version(beacon):
223223
def test_cl_node_get_syncing(beacon):
224224
response = beacon.get_syncing()
225225
_assert_valid_response(response)
226+
227+
228+
# Blob endpoint tests
229+
230+
231+
def test_cl_node_get_blob_sidecars(beacon):
232+
response = beacon.get_blob_sidecars("head")
233+
_assert_valid_response(response)
234+
235+
# test with indices
236+
with_indices = beacon.get_blob_sidecars("head", [0, 1])
237+
_assert_valid_response(with_indices)

web3/beacon/api_endpoints.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
# rewards
2727
GET_REWARDS = "/eth/v1/beacon/rewards/blocks/{0}"
2828

29+
# blobs
30+
GET_BLOB_SIDECARS = "/eth/v1/beacon/blob_sidecars/{0}"
31+
2932
# light client
3033
GET_LIGHT_CLIENT_BOOTSTRAP_STRUCTURE = "/eth/v1/beacon/light_client/bootstrap/{0}"
3134
GET_LIGHT_CLIENT_UPDATES = "/eth/v1/beacon/light_client/updates"

web3/beacon/async_beacon.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import (
22
Any,
33
Dict,
4+
List,
5+
Optional,
46
)
57

68
from eth_typing import (
@@ -17,6 +19,7 @@
1719
GET_BEACON_HEADS,
1820
GET_BEACON_STATE,
1921
GET_BLINDED_BLOCKS,
22+
GET_BLOB_SIDECARS,
2023
GET_BLOCK,
2124
GET_BLOCK_ATTESTATIONS,
2225
GET_BLOCK_HEADER,
@@ -64,10 +67,12 @@ def __init__(
6467
self.request_timeout = request_timeout
6568
self._request_session_manager = HTTPSessionManager()
6669

67-
async def _async_make_get_request(self, endpoint_uri: str) -> Dict[str, Any]:
70+
async def _async_make_get_request(
71+
self, endpoint_uri: str, params: Optional[Dict[str, str]] = None
72+
) -> Dict[str, Any]:
6873
uri = URI(self.base_url + endpoint_uri)
6974
return await self._request_session_manager.async_json_make_get_request(
70-
uri, timeout=self.request_timeout
75+
uri, params=params, timeout=self.request_timeout
7176
)
7277

7378
# [ BEACON endpoints ]
@@ -220,3 +225,14 @@ async def get_version(self) -> Dict[str, Any]:
220225

221226
async def get_syncing(self) -> Dict[str, Any]:
222227
return await self._async_make_get_request(GET_SYNCING)
228+
229+
# [ BLOB endpoints ]
230+
231+
async def get_blob_sidecars(
232+
self, block_id: str, indices: Optional[List[int]] = None
233+
) -> Dict[str, Any]:
234+
indices_param = {"indices": ",".join(map(str, indices))} if indices else None
235+
return await self._async_make_get_request(
236+
GET_BLOB_SIDECARS.format(block_id),
237+
params=indices_param,
238+
)

web3/beacon/beacon.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import (
22
Any,
33
Dict,
4+
List,
5+
Optional,
46
)
57

68
from eth_typing import (
@@ -17,6 +19,7 @@
1719
GET_BEACON_HEADS,
1820
GET_BEACON_STATE,
1921
GET_BLINDED_BLOCKS,
22+
GET_BLOB_SIDECARS,
2023
GET_BLOCK,
2124
GET_BLOCK_ATTESTATIONS,
2225
GET_BLOCK_HEADER,
@@ -62,10 +65,12 @@ def __init__(
6265
self.request_timeout = request_timeout
6366
self._request_session_manager = HTTPSessionManager()
6467

65-
def _make_get_request(self, endpoint_url: str) -> Dict[str, Any]:
68+
def _make_get_request(
69+
self, endpoint_url: str, params: Optional[Dict[str, str]] = None
70+
) -> Dict[str, Any]:
6671
uri = URI(self.base_url + endpoint_url)
6772
return self._request_session_manager.json_make_get_request(
68-
uri, timeout=self.request_timeout
73+
uri, params=params, timeout=self.request_timeout
6974
)
7075

7176
# [ BEACON endpoints ]
@@ -206,3 +211,14 @@ def get_version(self) -> Dict[str, Any]:
206211

207212
def get_syncing(self) -> Dict[str, Any]:
208213
return self._make_get_request(GET_SYNCING)
214+
215+
# [ BLOB endpoints ]
216+
217+
def get_blob_sidecars(
218+
self, block_id: str, indices: Optional[List[int]] = None
219+
) -> Dict[str, Any]:
220+
indices_param = {"indices": ",".join(map(str, indices))} if indices else None
221+
return self._make_get_request(
222+
GET_BLOB_SIDECARS.format(block_id),
223+
params=indices_param,
224+
)

0 commit comments

Comments
 (0)