reth icon indicating copy to clipboard operation
reth copied to clipboard

feature request: python bindings for ExEx

Open bout3fiddy opened this issue 1 year ago • 2 comments

Description

Following the announcement of ExEx, I can imagine this would be very useful for indexers, real-time analytics teams etc. with a background in python.

I can imagine searchers could find benefit in this, especially for rollups. For Ethereum mainnet, this may not be as useful since they typically want to know if a tx in the mempool (or bundle?) gets included.

We probably need a Notification class, and I'm thinking it could be something that simply tracks state changes in a contract:

class ExExNotifications:

    def __init__(self, contract_address: str):
        self.address = contract_address

    def state_write(self) -> bool:
        # logic here checks state of the previous contract and returns True if state was changed

    def state_read(self) -> bool:
        # logic here returns True if contract's state was read by any other contract in the block

    async def listen(self):
        # async method to listen to state changes

    # rest of the logic invoking exex to fetch old and new states

Which could then be used as follows:

from pyreth import exex

trigger = exex.Notifications(some_contract_address):

with trigger.sync():
    if trigger.state_read():
        # check, for example, if peripheral contracts have their states changed
        # example an AMM's exponential moving average price oracle was read. check if lending market
        # dependent on the oracle has it's state changed.

     if trigger.state_write():
        # do something if, say, state price of the AMM changed

Additional context

No response

bout3fiddy avatar May 04 '24 07:05 bout3fiddy

for this we'd need a bunch of wrapper types with pyo3 that define the py <-> rust interface and then a way to call this from rust

https://pyo3.rs/v0.21.2/python-from-rust

mattsse avatar May 04 '24 12:05 mattsse

@bout3fiddy you can have a wrapper around rust with pyo3, or simpler, just write a simple network code with ExEx in rust, and send notification to another python service.

ghost avatar May 07 '24 11:05 ghost

This issue is stale because it has been open for 21 days with no activity.

github-actions[bot] avatar May 29 '24 01:05 github-actions[bot]

@bout3fiddy you can have a wrapper around rust with pyo3, or simpler, just write a simple network code with ExEx in rust, and send notification to another python service.

this is correct, see https://reth.rs/developers/exex/remote.html for an example of such a service.

I will close this issue as not planned, let me know if you have something else in mind that's not covered by a Remote ExEx!

shekhirin avatar Jul 15 '24 10:07 shekhirin