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

Asyncify filters #2744

Merged
merged 11 commits into from
Dec 23, 2022
Merged

Asyncify filters #2744

merged 11 commits into from
Dec 23, 2022

Conversation

pacrob
Copy link
Contributor

@pacrob pacrob commented Dec 2, 2022

What was wrong?

Filters needed asyncing

Related to Issue #1413
Closes #2573

How was it fixed?

Asynced filters

Todo:

Cute Animal Picture

image

@pacrob pacrob force-pushed the asyncify-filters branch 3 times, most recently from 8c454d6 to eead3d6 Compare December 2, 2022 22:01
@pacrob pacrob requested review from kclowes and fselmo December 2, 2022 22:13
Copy link
Collaborator

@fselmo fselmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass comments... This looks great. Thanks for all that work! We should definitely do another pass at it after rebasing with the snake casing PR, as we discussed.



@pytest.fixture(scope="module")
def event_loop():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is used in a few files in this PR. Can we abstract this out to the tests/utils file as _event_loop_fixture_logic as you did with some of the other fixtures in these PRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had not tried because it's a shorter fixture. I tried to extract the logic and couldn't get it to work. But I found a single-line solution elsewhere in the codebase and plugged than in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single-line solution seems to leave event loops unclosed, so I put the original solution back. I got it down to 3 lines though.



@pytest.fixture(scope="module")
def event_loop():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fixture logic here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single line solution found instead of extracting

web3/contract.py Outdated
if not self.address:
raise TypeError(
"This method can be only called on "
"an instated contract with an address"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"an instated contract with an address"
"an instantiated contract with an address"

Unrelated to these changes but I think this is a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yepper!

web3/contract.py Outdated
) -> AsyncLogFilter:
"""
Create filter object that tracks logs emitted by this contract event.
# optional --- update the params descriptions here or remove this line
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more copy / paste blip

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

web3/contract.py Outdated
) -> LogFilter:
"""
Create filter object that tracks logs emitted by this contract event.
# optional --- update the params descriptions here or remove this line
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was copy / pasted from my comment in the PR that was merged in here 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

web3/eth.py Show resolved Hide resolved
) -> AsyncIterable[Tuple[Optional[BlockNumber], Optional[BlockNumber]]]:
"""Returns an iterator unloading ranges of available blocks

starting from `fromBlock` to the latest mined block,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
starting from `fromBlock` to the latest mined block,
starting from `from_block` to the latest mined block,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

"""Returns an iterator unloading ranges of available blocks

starting from `fromBlock` to the latest mined block,
until reaching toBlock. e.g.:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
until reaching toBlock. e.g.:
until reaching to_block. e.g.:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️


async def async_get_logs_multipart(
w3: "Web3",
startBlock: BlockNumber,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use start_block and stop_block here, as well as change these in the synchronous get_logs_multipart. This can be in a separate PR if preferred but I think it's a pretty small change that would be simple enough to review if it gets its own commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on! It's looking good to me! I had a few small comments, and had similar thoughts around camelCase/snake_case-ing as @fselmo said. And I assume you've checked this a few times already, but it's definitely worth a manual check here to double check filter and async filters work before merging.

conftest.py Show resolved Hide resolved
web3/middleware/filter.py Show resolved Hide resolved
web3/eth.py Outdated Show resolved Hide resolved
conftest.py Show resolved Hide resolved
@pacrob pacrob mentioned this pull request Dec 6, 2022
@kclowes
Copy link
Collaborator

kclowes commented Dec 7, 2022

@pacrob I just noticed that we have a bunch more warnings in our tests now as well. Looks like they're related to unclosed event loops in the core tests.

@pacrob
Copy link
Contributor Author

pacrob commented Dec 7, 2022

@pacrob I just noticed that we have a bunch more warnings in our tests now as well. Looks like they're related to unclosed event loops in the core tests.

I had updated the locations where event_loop needed a different scope to what I thought was a more concise bit of code. But apparently it also didn't close the loop. Reverted, and associated warning are gone.

@kclowes
Copy link
Collaborator

kclowes commented Dec 7, 2022

Sweet! Test failure should be fixed in #2751

@pacrob pacrob force-pushed the asyncify-filters branch 2 times, most recently from fd5cfa5 to ab52bd3 Compare December 8, 2022 20:37
Paul Robinson and others added 10 commits December 20, 2022 10:42
* async filters eth module
* update method_formatters.py to select the appropriate sync/async filter type
* asyncify filter middleware and tests
# async contract filter methods
* set up async filter testing fixtures 
* async a few filter tests
* async existing filter test

* async test_filter_against_transaction_logs

* async test_filter_against_pending_transactions

* async test_contract_get_logs

* async test_contract_topic_filters

* async test_contract_past_event_filtering

* async test_contract_on_event_filtering

* async test_contract_data_filters
* clean up event_loop fixtures, types, and some snekcasing
@pacrob pacrob merged commit 9f08272 into master Dec 23, 2022
@pacrob pacrob deleted the asyncify-filters branch December 23, 2022 18:25
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.

'AsyncEth' object has no attribute 'filter'
3 participants