-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Asyncify filters #2744
Conversation
8c454d6
to
eead3d6
Compare
There was a problem hiding this 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(): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"an instated contract with an address" | |
"an instantiated contract with an address" |
Unrelated to these changes but I think this is a typo?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
web3/middleware/filter.py
Outdated
) -> AsyncIterable[Tuple[Optional[BlockNumber], Optional[BlockNumber]]]: | ||
"""Returns an iterator unloading ranges of available blocks | ||
|
||
starting from `fromBlock` to the latest mined block, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
starting from `fromBlock` to the latest mined block, | |
starting from `from_block` to the latest mined block, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
web3/middleware/filter.py
Outdated
"""Returns an iterator unloading ranges of available blocks | ||
|
||
starting from `fromBlock` to the latest mined block, | ||
until reaching toBlock. e.g.: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
until reaching toBlock. e.g.: | |
until reaching to_block. e.g.: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
web3/middleware/filter.py
Outdated
|
||
async def async_get_logs_multipart( | ||
w3: "Web3", | ||
startBlock: BlockNumber, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
There was a problem hiding this 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.
@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 |
Sweet! Test failure should be fixed in #2751 |
fd5cfa5
to
ab52bd3
Compare
* 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
ab52bd3
to
a9fac74
Compare
d9bfdb7
to
949a125
Compare
What was wrong?
Filters needed asyncing
Related to Issue #1413
Closes #2573
How was it fixed?
Asynced filters
Todo:
Cute Animal Picture