ApeWorX / ApeWorX/web3.py

Proposal: global polling latency

Open
#1,940 1 comment 0 reactions 0 assignees View on GitHub
priority: p2 normal
Dominant language
Python
Stars
5.5k
Forks
1.7k
Avg merge
3d 10h
Merged PRs (30d)
2

Description

Hi There,

The polling latency parameter was exposed for `getTransactionReceipt`: https://github.com/ethereum/web3.py/issues/1130, but other parameters like request timeout parameters are already used more widely than just receipts.

**High-level proposal**

My proposal would be to introduce a global polling latency parameter that can remember the timestamp of the last request to to the provider and `sleep` for the appropriate time to ensure node use falls within rate limits.

**Why**

This enables several use cases:

- ergonomics improvements => `getTransactionReceipt` now has the parameter but this is somewhat arbitrary because it's the only function that builds in repetitive retries. It also has to be specified on every use. If other functions are used in a loop by users, this would trigger the need for a global poll latency parameter and maximize throughput from rate limited nodes (like Infura)
- important stepping stone towards building an eventual forking capability for `web3.py` / `eth-tester`. While building a fork capability, I'm running into issues with rate limiting already
- support "sharing" local nodes between teams. Right now, teams can use `ngrok` to expose local nodes over the wire and share quick access to a local node instance (as a private testnet of sorts). However, `ngrok` is rate limited on the free plan and other uses outside of `getTransactionReceipt` trigger rate limits

**Detailed proposal**

I think `polling_latency` could be a direct argument to `HTTPProvider`. Alternatively, if it's possible to do this as an argument to `requests.Session`, this could be documented directly just like `timeout` is currently documented (but I'm not sure if this is possible due to the need to have persistent state across requests?).

Documentation for `timeout`: https://web3py.readthedocs.io/en/stable/providers.html#httpprovider.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.