Skip to content
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

beacon: add a few various endpoints #3504

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

lrusak
Copy link
Contributor

@lrusak lrusak commented Oct 3, 2024

What was wrong?

Missing some endpoints I wanted to use in my application

How was it fixed?

Added the endpoints via the beacon API spec -> https://ethereum.github.io/beacon-APIs/

I needed to add a new async post method. I tried to follow the patterns as much as possible here to make it fit well into the existing codebase.

I added tests for the new endpoints also.

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

lrusak added 6 commits October 2, 2024 22:20
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
@reedsa
Copy link
Contributor

reedsa commented Oct 4, 2024

@lrusak If you have capacity to add sync methods/tests to this that would be awesome! Let us know what you are comfortable with.

Note: Beacon tests do not run in CI. Reminder to myself to double check tests are passing locally before merging.

@reedsa reedsa requested review from fselmo, kclowes and pacrob October 4, 2024 20:23
lrusak added 6 commits October 7, 2024 21:16
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
Signed-off-by: Lukas Rusak <lorusak@gmail.com>
@lrusak
Copy link
Contributor Author

lrusak commented Oct 8, 2024

@reedsa I added the Beacon class methods. Sorry I didn't respond earlier, life's been busy.

If acceptable I can squash the Async/Sync pair commits together and amend the commit messages.

@lrusak lrusak changed the title AsyncBeacon: add a few various endpoints beacon: add a few various endpoints Oct 8, 2024
@lrusak
Copy link
Contributor Author

lrusak commented Oct 8, 2024

$ pytest -rP tests/beacon/test_async_beacon.py
=================================================================================== test session starts ====================================================================================
platform linux -- Python 3.13.0rc3, pytest-8.3.3, pluggy-1.5.0 -- /home/lukas/Documents/git/web3.py/venv/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase(PosixPath('/home/lukas/Documents/git/web3.py/.hypothesis/examples'))
rootdir: /home/lukas/Documents/git/web3.py
configfile: pyproject.toml
plugins: xdist-3.6.1, anyio-4.6.0, hypothesis-6.112.2, flaky-3.8.1, mock-3.14.0, asyncio-0.21.2
asyncio: mode=Mode.STRICT
collected 41 items

tests/beacon/test_async_beacon.py::test_async_cl_beacon_raises_exception_on_invalid_url PASSED                                                                                       [  2%]
tests/beacon/test_async_beacon.py::test_async_beacon_user_request_timeout PASSED                                                                                                     [  4%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_genesis PASSED                                                                                                           [  7%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_hash_root PASSED                                                                                                         [  9%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_fork_data PASSED                                                                                                         [ 12%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_finality_checkpoint PASSED                                                                                               [ 14%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_validators PASSED                                                                                                        [ 17%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_validator PASSED                                                                                                         [ 19%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_validator_balances PASSED                                                                                                [ 21%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_epoch_committees PASSED                                                                                                  [ 24%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_epoch_sync_committees PASSED                                                                                             [ 26%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_epoch_randao PASSED                                                                                                      [ 29%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_block_headers PASSED                                                                                                     [ 31%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_block_header PASSED                                                                                                      [ 34%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_block PASSED                                                                                                             [ 36%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_block_root PASSED                                                                                                        [ 39%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_blinded_blocks PASSED                                                                                                    [ 41%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_rewards PASSED                                                                                                           [ 43%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_block_attestations PASSED                                                                                                [ 46%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_attestations PASSED                                                                                                      [ 48%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_attester_slashings PASSED                                                                                                [ 51%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_proposer_slashings PASSED                                                                                                [ 53%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_voluntary_exits PASSED                                                                                                   [ 56%]
tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_bls_to_execution_changes PASSED                                                                                          [ 58%]
tests/beacon/test_async_beacon.py::test_async_cl_config_get_fork_schedule PASSED                                                                                                     [ 60%]
tests/beacon/test_async_beacon.py::test_async_cl_config_get_spec PASSED                                                                                                              [ 63%]
tests/beacon/test_async_beacon.py::test_async_cl_config_get_deposit_contract PASSED                                                                                                  [ 65%]
tests/beacon/test_async_beacon.py::test_async_cl_debug_get_beacon_state PASSED                                                                                                       [ 68%]
tests/beacon/test_async_beacon.py::test_async_cl_debug_get_beacon_heads PASSED                                                                                                       [ 70%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_node_identity PASSED                                                                                                       [ 73%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_peers PASSED                                                                                                               [ 75%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_peer PASSED                                                                                                                [ 78%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_peer_count PASSED                                                                                                          [ 80%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_health PASSED                                                                                                              [ 82%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_version PASSED                                                                                                             [ 85%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_syncing PASSED                                                                                                             [ 87%]
tests/beacon/test_async_beacon.py::test_async_cl_node_get_blob_sidecars PASSED                                                                                                       [ 90%]
tests/beacon/test_async_beacon.py::test_async_cl_validator_get_attester_duties PASSED                                                                                                [ 92%]
tests/beacon/test_async_beacon.py::test_async_cl_validator_get_block_proposer_duties PASSED                                                                                          [ 95%]
tests/beacon/test_async_beacon.py::test_async_cl_validator_get_sync_committee_duties PASSED                                                                                          [ 97%]
tests/beacon/test_async_beacon.py::test_async_cl_validator_get_attestations_rewards PASSED                                                                                           [100%]

========================================================================================== PASSES ==========================================================================================
=================================================================================== slowest 10 durations ===================================================================================
17.46s call     tests/beacon/test_async_beacon.py::test_async_cl_validator_get_attestations_rewards
16.88s call     tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_validator
16.88s call     tests/beacon/test_async_beacon.py::test_async_cl_validator_get_attester_duties
16.80s call     tests/beacon/test_async_beacon.py::test_async_cl_validator_get_sync_committee_duties
16.75s call     tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_validators
14.96s call     tests/beacon/test_async_beacon.py::test_async_cl_debug_get_beacon_state
2.03s call     tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_validator_balances
0.45s call     tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_epoch_committees
0.17s call     tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_epoch_sync_committees
0.17s call     tests/beacon/test_async_beacon.py::test_async_cl_beacon_get_attestations
============================================================================== 41 passed in 103.08s (0:01:43) ==============================================================================

and

$ pytest -rP tests/beacon/test_beacon.py
=================================================================================== test session starts ====================================================================================
platform linux -- Python 3.13.0rc3, pytest-8.3.3, pluggy-1.5.0 -- /home/lukas/Documents/git/web3.py/venv/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase(PosixPath('/home/lukas/Documents/git/web3.py/.hypothesis/examples'))
rootdir: /home/lukas/Documents/git/web3.py
configfile: pyproject.toml
plugins: xdist-3.6.1, anyio-4.6.0, hypothesis-6.112.2, flaky-3.8.1, mock-3.14.0, asyncio-0.21.2
asyncio: mode=Mode.STRICT
collected 41 items

tests/beacon/test_beacon.py::test_cl_beacon_raises_exception_on_invalid_url PASSED                                                                                                   [  2%]
tests/beacon/test_beacon.py::test_beacon_user_defined_request_timeout PASSED                                                                                                         [  4%]
tests/beacon/test_beacon.py::test_cl_beacon_get_genesis PASSED                                                                                                                       [  7%]
tests/beacon/test_beacon.py::test_cl_beacon_get_hash_root PASSED                                                                                                                     [  9%]
tests/beacon/test_beacon.py::test_cl_beacon_get_fork_data PASSED                                                                                                                     [ 12%]
tests/beacon/test_beacon.py::test_cl_beacon_get_finality_checkpoint PASSED                                                                                                           [ 14%]
tests/beacon/test_beacon.py::test_cl_beacon_get_validators PASSED                                                                                                                    [ 17%]
tests/beacon/test_beacon.py::test_cl_beacon_get_validator PASSED                                                                                                                     [ 19%]
tests/beacon/test_beacon.py::test_cl_beacon_get_validator_balances PASSED                                                                                                            [ 21%]
tests/beacon/test_beacon.py::test_cl_beacon_get_epoch_committees PASSED                                                                                                              [ 24%]
tests/beacon/test_beacon.py::test_cl_beacon_get_epoch_sync_committees PASSED                                                                                                         [ 26%]
tests/beacon/test_beacon.py::test_cl_beacon_get_epoch_randao PASSED                                                                                                                  [ 29%]
tests/beacon/test_beacon.py::test_cl_beacon_get_block_headers PASSED                                                                                                                 [ 31%]
tests/beacon/test_beacon.py::test_cl_beacon_get_block_header PASSED                                                                                                                  [ 34%]
tests/beacon/test_beacon.py::test_cl_beacon_get_block PASSED                                                                                                                         [ 36%]
tests/beacon/test_beacon.py::test_cl_beacon_get_block_root PASSED                                                                                                                    [ 39%]
tests/beacon/test_beacon.py::test_cl_beacon_get_blinded_blocks PASSED                                                                                                                [ 41%]
tests/beacon/test_beacon.py::test_cl_beacon_get_rewards PASSED                                                                                                                       [ 43%]
tests/beacon/test_beacon.py::test_cl_beacon_get_block_attestations PASSED                                                                                                            [ 46%]
tests/beacon/test_beacon.py::test_cl_beacon_get_attestations PASSED                                                                                                                  [ 48%]
tests/beacon/test_beacon.py::test_cl_beacon_get_attester_slashings PASSED                                                                                                            [ 51%]
tests/beacon/test_beacon.py::test_cl_beacon_get_proposer_slashings PASSED                                                                                                            [ 53%]
tests/beacon/test_beacon.py::test_cl_beacon_get_voluntary_exits PASSED                                                                                                               [ 56%]
tests/beacon/test_beacon.py::test_cl_beacon_get_bls_to_execution_changes PASSED                                                                                                      [ 58%]
tests/beacon/test_beacon.py::test_cl_config_get_fork_schedule PASSED                                                                                                                 [ 60%]
tests/beacon/test_beacon.py::test_cl_config_get_spec PASSED                                                                                                                          [ 63%]
tests/beacon/test_beacon.py::test_cl_config_get_deposit_contract PASSED                                                                                                              [ 65%]
tests/beacon/test_beacon.py::test_cl_debug_get_beacon_state PASSED                                                                                                                   [ 68%]
tests/beacon/test_beacon.py::test_cl_debug_get_beacon_heads PASSED                                                                                                                   [ 70%]
tests/beacon/test_beacon.py::test_cl_node_get_node_identity PASSED                                                                                                                   [ 73%]
tests/beacon/test_beacon.py::test_cl_node_get_peers PASSED                                                                                                                           [ 75%]
tests/beacon/test_beacon.py::test_cl_node_get_peer PASSED                                                                                                                            [ 78%]
tests/beacon/test_beacon.py::test_cl_node_get_peer_count PASSED                                                                                                                      [ 80%]
tests/beacon/test_beacon.py::test_cl_node_get_health PASSED                                                                                                                          [ 82%]
tests/beacon/test_beacon.py::test_cl_node_get_version PASSED                                                                                                                         [ 85%]
tests/beacon/test_beacon.py::test_cl_node_get_syncing PASSED                                                                                                                         [ 87%]
tests/beacon/test_beacon.py::test_cl_node_get_blob_sidecars PASSED                                                                                                                   [ 90%]
tests/beacon/test_beacon.py::test_cl_validator_get_attester_duties PASSED                                                                                                            [ 92%]
tests/beacon/test_beacon.py::test_cl_validator_get_block_proposer_duties PASSED                                                                                                      [ 95%]
tests/beacon/test_beacon.py::test_cl_validator_get_sync_committee_duties PASSED                                                                                                      [ 97%]
tests/beacon/test_beacon.py::test_cl_validator_get_attestations_rewards PASSED                                                                                                       [100%]

========================================================================================== PASSES ==========================================================================================
=================================================================================== slowest 10 durations ===================================================================================
17.40s call     tests/beacon/test_beacon.py::test_cl_beacon_get_validators
16.81s call     tests/beacon/test_beacon.py::test_cl_validator_get_sync_committee_duties
16.79s call     tests/beacon/test_beacon.py::test_cl_validator_get_attester_duties
16.73s call     tests/beacon/test_beacon.py::test_cl_validator_get_attestations_rewards
16.70s call     tests/beacon/test_beacon.py::test_cl_beacon_get_validator
14.65s call     tests/beacon/test_beacon.py::test_cl_debug_get_beacon_state
2.08s call     tests/beacon/test_beacon.py::test_cl_beacon_get_validator_balances
0.45s call     tests/beacon/test_beacon.py::test_cl_beacon_get_epoch_committees
0.17s call     tests/beacon/test_beacon.py::test_cl_beacon_get_attestations
0.10s call     tests/beacon/test_beacon.py::test_cl_validator_get_block_proposer_duties
============================================================================== 41 passed in 102.30s (0:01:42) ==============================================================================

although I seem to need to apply another patch to get the test_async_beacon_user_request_timeout test to pass -> lrusak@30f271b

That could possibly just be an issue with python 3.13 though.

@pacrob pacrob requested review from pacrob and removed request for pacrob December 11, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants