Skip to content

Commit 4008286

Browse files
Fix HTTP config and TzKT fetcher methods (#577)
1 parent 7f10968 commit 4008286

File tree

47 files changed

+713
-562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+713
-562
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].
66

7+
## [Unreleased]
8+
9+
### Added
10+
11+
- context: Allow adding contracts by code hash in runtime.
12+
- config: Added `http.ratelimit_sleep` option to set fixed sleep time on 429 responses.
13+
14+
### Fixed
15+
16+
- http: Fixed merging user-defined HTTP settings and datasource defaults.
17+
- tzkt: Fixed iterating over big map keys.
18+
719
## [6.4.1] - 2022-12-22
820

921
### Fixed

docs/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ help:
2222
docs:
2323
poetry run make html
2424
# NOTE: A hack to include generated references in mdbook pages
25-
tail -n '+35' _build/html/cli-reference.html | head -n '-63' > cli-reference.md
26-
tail -n '+35' _build/html/config-reference.html | head -n '-63' > config/reference.md
27-
tail -n '+35' _build/html/context-reference.html | head -n '-63' > include/context-reference.md
25+
tail -n '+32' _build/html/cli-reference.html | head -n '-63' > cli-reference.md
26+
tail -n '+32' _build/html/config-reference.html | head -n '-63' > config/reference.md
27+
tail -n '+32' _build/html/context-reference.html | head -n '-63' > include/context-reference.md
2828
mdbook build --dest-dir=dist/docs
2929

3030
homepage:

docs/config/reference.md

Lines changed: 9 additions & 8 deletions
Large diffs are not rendered by default.

docs/include/context-reference.md

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

poetry.lock

Lines changed: 292 additions & 275 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements.dev.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ chardet==4.0.0 ; python_version >= "3.10" and python_version < "3.11"
1818
charset-normalizer==2.1.1 ; python_version >= "3.10" and python_version < "3.11"
1919
click==8.0.4 ; python_version >= "3.10" and python_version < "3.11"
2020
colorama==0.4.6 ; python_version >= "3.10" and python_version < "3.11"
21-
coverage[toml]==7.0.0 ; python_version >= "3.10" and python_version < "3.11"
21+
coverage[toml]==7.0.1 ; python_version >= "3.10" and python_version < "3.11"
2222
datamodel-code-generator==0.13.1 ; python_version >= "3.10" and python_version < "3.11"
2323
diff-cover==7.3.0 ; python_version >= "3.10" and python_version < "3.11"
2424
dnspython==2.2.1 ; python_version >= "3.10" and python_version < "3.11"
2525
docker==6.0.1 ; python_version >= "3.10" and python_version < "3.11"
2626
docutils==0.19 ; python_version >= "3.10" and python_version < "3.11"
2727
email-validator==1.3.0 ; python_version >= "3.10" and python_version < "3.11"
2828
entrypoints==0.4 ; python_version >= "3.10" and python_version < "3.11"
29-
exceptiongroup==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
29+
exceptiongroup==1.1.0 ; python_version >= "3.10" and python_version < "3.11"
3030
execnet==1.9.0 ; python_version >= "3.10" and python_version < "3.11"
3131
flake8-bugbear==22.12.6 ; python_version >= "3.10" and python_version < "3.11"
3232
flake8-comprehensions==3.10.1 ; python_version >= "3.10" and python_version < "3.11"
@@ -40,21 +40,21 @@ imagesize==1.4.1 ; python_version >= "3.10" and python_version < "3.11"
4040
inflect==5.6.2 ; python_version >= "3.10" and python_version < "3.11"
4141
iniconfig==1.1.1 ; python_version >= "3.10" and python_version < "3.11"
4242
iso8601==1.1.0 ; python_version >= "3.10" and python_version < "3.11"
43-
isort==5.11.3 ; python_version >= "3.10" and python_version < "3.11"
43+
isort==5.11.4 ; python_version >= "3.10" and python_version < "3.11"
4444
jinja2==3.1.2 ; python_version >= "3.10" and python_version < "3.11"
4545
jsonschema==4.17.3 ; python_version >= "3.10" and python_version < "3.11"
4646
markupsafe==2.1.1 ; python_version >= "3.10" and python_version < "3.11"
4747
mccabe==0.6.1 ; python_version >= "3.10" and python_version < "3.11"
4848
msgpack==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
49-
multidict==6.0.3 ; python_version >= "3.10" and python_version < "3.11"
49+
multidict==6.0.4 ; python_version >= "3.10" and python_version < "3.11"
5050
mypy-extensions==0.4.3 ; python_version >= "3.10" and python_version < "3.11"
5151
mypy==0.991 ; python_version >= "3.10" and python_version < "3.11"
5252
openapi-schema-validator==0.3.4 ; python_version >= "3.10" and python_version < "3.11"
5353
openapi-spec-validator==0.3.1 ; python_version >= "3.10" and python_version < "3.11"
5454
orjson==3.8.3 ; python_version >= "3.10" and python_version < "3.11"
5555
packaging==21.3 ; python_version >= "3.10" and python_version < "3.11"
5656
pathspec==0.10.3 ; python_version >= "3.10" and python_version < "3.11"
57-
platformdirs==2.6.0 ; python_version >= "3.10" and python_version < "3.11"
57+
platformdirs==2.6.2 ; python_version >= "3.10" and python_version < "3.11"
5858
pluggy==1.0.0 ; python_version >= "3.10" and python_version < "3.11"
5959
prance==0.22.11.4.0 ; python_version >= "3.10" and python_version < "3.11"
6060
prometheus-client==0.14.1 ; python_version >= "3.10" and python_version < "3.11"
@@ -67,7 +67,7 @@ pygments==2.13.0 ; python_version >= "3.10" and python_version < "3.11"
6767
pyhumps==3.8.0 ; python_version >= "3.10" and python_version < "3.11"
6868
pyparsing==3.0.9 ; python_version >= "3.10" and python_version < "3.11"
6969
pypika-tortoise==0.1.6 ; python_version >= "3.10" and python_version < "3.11"
70-
pyrsistent==0.19.2 ; python_version >= "3.10" and python_version < "3.11"
70+
pyrsistent==0.19.3 ; python_version >= "3.10" and python_version < "3.11"
7171
pysignalr==0.1.2 ; python_version >= "3.10" and python_version < "3.11"
7272
pysnooper==1.1.1 ; python_version >= "3.10" and python_version < "3.11"
7373
pytest-aiohttp==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
@@ -91,7 +91,7 @@ sniffio==1.3.0 ; python_version >= "3.10" and python_version < "3.11"
9191
snowballstemmer==2.2.0 ; python_version >= "3.10" and python_version < "3.11"
9292
sphinx-click==4.4.0 ; python_version >= "3.10" and python_version < "3.11"
9393
sphinx-markdown-builder==0.5.5 ; python_version >= "3.10" and python_version < "3.11"
94-
sphinx==5.3.0 ; python_version >= "3.10" and python_version < "3.11"
94+
sphinx==6.0.0 ; python_version >= "3.10" and python_version < "3.11"
9595
sphinxcontrib-applehelp==1.0.2 ; python_version >= "3.10" and python_version < "3.11"
9696
sphinxcontrib-devhelp==1.0.2 ; python_version >= "3.10" and python_version < "3.11"
9797
sphinxcontrib-htmlhelp==2.0.0 ; python_version >= "3.10" and python_version < "3.11"

requirements.pytezos.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ charset-normalizer==2.1.1 ; python_version >= "3.10" and python_version < "3.11"
2929
click==8.0.4 ; python_version >= "3.10" and python_version < "3.11"
3030
colorama==0.4.6 ; python_version >= "3.10" and python_version < "3.11" and platform_system == "Windows" or python_version >= "3.10" and python_version < "3.11" and sys_platform == "win32"
3131
comm==0.1.2 ; python_version >= "3.10" and python_version < "3.11"
32-
cytoolz==0.12.0 ; python_version >= "3.10" and python_version < "3.11" and implementation_name == "cpython"
32+
cytoolz==0.12.1 ; python_version >= "3.10" and python_version < "3.11" and implementation_name == "cpython"
3333
datamodel-code-generator==0.13.1 ; python_version >= "3.10" and python_version < "3.11"
3434
debugpy==1.6.4 ; python_version >= "3.10" and python_version < "3.11"
3535
decorator==5.1.1 ; python_version >= "3.10" and python_version < "3.11"
@@ -42,38 +42,38 @@ entrypoints==0.4 ; python_version >= "3.10" and python_version < "3.11"
4242
eth-hash==0.5.1 ; python_version >= "3.10" and python_version < "3.11"
4343
eth-typing==3.2.0 ; python_version >= "3.10" and python_version < "3.11"
4444
eth-utils==2.1.0 ; python_version >= "3.10" and python_version < "3.11"
45-
exceptiongroup==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
45+
exceptiongroup==1.1.0 ; python_version >= "3.10" and python_version < "3.11"
4646
executing==1.2.0 ; python_version >= "3.10" and python_version < "3.11"
47-
fastecdsa==2.2.3 ; python_version >= "3.10" and python_version < "3.11"
47+
fastecdsa==2.3.0 ; python_version >= "3.10" and python_version < "3.11"
4848
fastjsonschema==2.16.2 ; python_version >= "3.10" and python_version < "3.11"
4949
fqdn==1.5.1 ; python_version >= "3.10" and python_version < "3.11"
5050
frozenlist==1.3.3 ; python_version >= "3.10" and python_version < "3.11"
5151
genson==1.2.2 ; python_version >= "3.10" and python_version < "3.11"
5252
idna==3.4 ; python_version >= "3.10" and python_version < "3.11"
5353
inflect==5.6.2 ; python_version >= "3.10" and python_version < "3.11"
54-
ipykernel==6.19.3 ; python_version >= "3.10" and python_version < "3.11"
54+
ipykernel==6.19.4 ; python_version >= "3.10" and python_version < "3.11"
5555
ipython-genutils==0.2.0 ; python_version >= "3.10" and python_version < "3.11"
5656
ipython==8.7.0 ; python_version >= "3.10" and python_version < "3.11"
5757
iso8601==1.1.0 ; python_version >= "3.10" and python_version < "3.11"
5858
isoduration==20.11.0 ; python_version >= "3.10" and python_version < "3.11"
59-
isort==5.11.3 ; python_version >= "3.10" and python_version < "3.11"
59+
isort==5.11.4 ; python_version >= "3.10" and python_version < "3.11"
6060
jedi==0.18.2 ; python_version >= "3.10" and python_version < "3.11"
6161
jinja2==3.1.2 ; python_version >= "3.10" and python_version < "3.11"
6262
jsonpointer==2.3 ; python_version >= "3.10" and python_version < "3.11"
6363
jsonschema==4.17.3 ; python_version >= "3.10" and python_version < "3.11"
6464
jsonschema[format-nongpl]==4.17.3 ; python_version >= "3.10" and python_version < "3.11"
6565
jupyter-client==7.4.8 ; python_version >= "3.10" and python_version < "3.11"
66-
jupyter-core==5.1.0 ; python_version >= "3.10" and python_version < "3.11"
66+
jupyter-core==5.1.1 ; python_version >= "3.10" and python_version < "3.11"
6767
jupyter-events==0.5.0 ; python_version >= "3.10" and python_version < "3.11"
6868
jupyter-server-terminals==0.4.3 ; python_version >= "3.10" and python_version < "3.11"
69-
jupyter-server==2.0.1 ; python_version >= "3.10" and python_version < "3.11"
69+
jupyter-server==2.0.6 ; python_version >= "3.10" and python_version < "3.11"
7070
jupyterlab-pygments==0.2.2 ; python_version >= "3.10" and python_version < "3.11"
7171
markupsafe==2.1.1 ; python_version >= "3.10" and python_version < "3.11"
7272
matplotlib-inline==0.1.6 ; python_version >= "3.10" and python_version < "3.11"
7373
mistune==2.0.4 ; python_version >= "3.10" and python_version < "3.11"
7474
mnemonic==0.20 ; python_version >= "3.10" and python_version < "3.11"
7575
msgpack==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
76-
multidict==6.0.3 ; python_version >= "3.10" and python_version < "3.11"
76+
multidict==6.0.4 ; python_version >= "3.10" and python_version < "3.11"
7777
mypy-extensions==0.4.3 ; python_version >= "3.10" and python_version < "3.11"
7878
nbclassic==0.4.8 ; python_version >= "3.10" and python_version < "3.11"
7979
nbclient==0.7.2 ; python_version >= "3.10" and python_version < "3.11"
@@ -93,7 +93,7 @@ pathspec==0.10.3 ; python_version >= "3.10" and python_version < "3.11"
9393
pendulum==2.1.2 ; python_version >= "3.10" and python_version < "3.11"
9494
pexpect==4.8.0 ; python_version >= "3.10" and python_version < "3.11" and sys_platform != "win32"
9595
pickleshare==0.7.5 ; python_version >= "3.10" and python_version < "3.11"
96-
platformdirs==2.6.0 ; python_version >= "3.10" and python_version < "3.11"
96+
platformdirs==2.6.2 ; python_version >= "3.10" and python_version < "3.11"
9797
ply==3.11 ; python_version >= "3.10" and python_version < "3.11"
9898
prance==0.22.11.4.0 ; python_version >= "3.10" and python_version < "3.11"
9999
prometheus-client==0.14.1 ; python_version >= "3.10" and python_version < "3.11"
@@ -111,7 +111,7 @@ pygments==2.13.0 ; python_version >= "3.10" and python_version < "3.11"
111111
pyhumps==3.8.0 ; python_version >= "3.10" and python_version < "3.11"
112112
pyparsing==3.0.9 ; python_version >= "3.10" and python_version < "3.11"
113113
pypika-tortoise==0.1.6 ; python_version >= "3.10" and python_version < "3.11"
114-
pyrsistent==0.19.2 ; python_version >= "3.10" and python_version < "3.11"
114+
pyrsistent==0.19.3 ; python_version >= "3.10" and python_version < "3.11"
115115
pysha3==1.0.2 ; python_version >= "3.10" and python_version < "3.11"
116116
pysignalr==0.1.2 ; python_version >= "3.10" and python_version < "3.11"
117117
pysnooper==1.1.1 ; python_version >= "3.10" and python_version < "3.11"

requirements.slim.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ frozenlist==1.3.3 ; python_version >= "3.10" and python_version < "3.11"
1515
idna==3.4 ; python_version >= "3.10" and python_version < "3.11"
1616
iso8601==1.1.0 ; python_version >= "3.10" and python_version < "3.11"
1717
msgpack==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
18-
multidict==6.0.3 ; python_version >= "3.10" and python_version < "3.11"
18+
multidict==6.0.4 ; python_version >= "3.10" and python_version < "3.11"
1919
orjson==3.8.3 ; python_version >= "3.10" and python_version < "3.11"
2020
prometheus-client==0.14.1 ; python_version >= "3.10" and python_version < "3.11"
2121
pydantic==1.9.2 ; python_version >= "3.10" and python_version < "3.11"

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ genson==1.2.2 ; python_version >= "3.10" and python_version < "3.11"
2323
idna==3.4 ; python_version >= "3.10" and python_version < "3.11"
2424
inflect==5.6.2 ; python_version >= "3.10" and python_version < "3.11"
2525
iso8601==1.1.0 ; python_version >= "3.10" and python_version < "3.11"
26-
isort==5.11.3 ; python_version >= "3.10" and python_version < "3.11"
26+
isort==5.11.4 ; python_version >= "3.10" and python_version < "3.11"
2727
jinja2==3.1.2 ; python_version >= "3.10" and python_version < "3.11"
2828
jsonschema==4.17.3 ; python_version >= "3.10" and python_version < "3.11"
2929
markupsafe==2.1.1 ; python_version >= "3.10" and python_version < "3.11"
3030
msgpack==1.0.4 ; python_version >= "3.10" and python_version < "3.11"
31-
multidict==6.0.3 ; python_version >= "3.10" and python_version < "3.11"
31+
multidict==6.0.4 ; python_version >= "3.10" and python_version < "3.11"
3232
mypy-extensions==0.4.3 ; python_version >= "3.10" and python_version < "3.11"
3333
openapi-schema-validator==0.3.4 ; python_version >= "3.10" and python_version < "3.11"
3434
openapi-spec-validator==0.3.1 ; python_version >= "3.10" and python_version < "3.11"
3535
orjson==3.8.3 ; python_version >= "3.10" and python_version < "3.11"
3636
packaging==21.3 ; python_version >= "3.10" and python_version < "3.11"
3737
pathspec==0.10.3 ; python_version >= "3.10" and python_version < "3.11"
38-
platformdirs==2.6.0 ; python_version >= "3.10" and python_version < "3.11"
38+
platformdirs==2.6.2 ; python_version >= "3.10" and python_version < "3.11"
3939
prance==0.22.11.4.0 ; python_version >= "3.10" and python_version < "3.11"
4040
prometheus-client==0.14.1 ; python_version >= "3.10" and python_version < "3.11"
4141
pydantic==1.9.2 ; python_version >= "3.10" and python_version < "3.11"
4242
pydantic[email]==1.9.2 ; python_version >= "3.10" and python_version < "3.11"
4343
pyhumps==3.8.0 ; python_version >= "3.10" and python_version < "3.11"
4444
pyparsing==3.0.9 ; python_version >= "3.10" and python_version < "3.11"
4545
pypika-tortoise==0.1.6 ; python_version >= "3.10" and python_version < "3.11"
46-
pyrsistent==0.19.2 ; python_version >= "3.10" and python_version < "3.11"
46+
pyrsistent==0.19.3 ; python_version >= "3.10" and python_version < "3.11"
4747
pysignalr==0.1.2 ; python_version >= "3.10" and python_version < "3.11"
4848
pysnooper==1.1.1 ; python_version >= "3.10" and python_version < "3.11"
4949
python-dotenv==0.19.2 ; python_version >= "3.10" and python_version < "3.11"

src/dipdup/config.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
import json
2020
import logging.config
2121
import re
22+
import sys
2223
from abc import ABC
2324
from abc import abstractmethod
2425
from collections import Counter
2526
from contextlib import suppress
26-
from copy import copy
2727
from dataclasses import field
2828
from io import StringIO
2929
from os import environ as env
@@ -187,27 +187,52 @@ class HTTPConfig:
187187
:param retry_multiplier: Multiplier for sleep time between retries
188188
:param ratelimit_rate: Number of requests per period ("drops" in leaky bucket)
189189
:param ratelimit_period: Time period for rate limiting in seconds
190+
:param ratelimit_sleep: Sleep time between requests when rate limit is reached
190191
:param connection_limit: Number of simultaneous connections
191192
:param connection_timeout: Connection timeout in seconds
192193
:param batch_size: Number of items fetched in a single paginated request (for some APIs)
193-
:param replay_path: Development-only option to replay HTTP requests from a file
194+
:param replay_path: Development-only option to use cached HTTP responses instead of making real requests
194195
"""
195196

196-
retry_count: int | None = None # default: inf
197-
retry_sleep: float | None = None # default: 0
198-
retry_multiplier: float | None = None # default: 0
197+
retry_count: int | None = None
198+
retry_sleep: float | None = None
199+
retry_multiplier: float | None = None
199200
ratelimit_rate: int | None = None
200201
ratelimit_period: int | None = None
201-
connection_limit: int | None = None # default: 100
202-
connection_timeout: int | None = None # default: 60
202+
ratelimit_sleep: float | None = None
203+
connection_limit: int | None = None
204+
connection_timeout: int | None = None
203205
batch_size: int | None = None
204206
replay_path: str | None = None
205207

206-
def merge(self, other: HTTPConfig | None) -> 'HTTPConfig':
207-
"""Set missing values from other config"""
208-
config = copy(self)
209-
if other:
210-
for k, v in other.__dict__.items():
208+
209+
@dataclass
210+
class ResolvedHTTPConfig:
211+
"""HTTP client configuration with defaults"""
212+
213+
retry_count: int = sys.maxsize
214+
retry_sleep: float = 0.0
215+
retry_multiplier: float = 1.0
216+
ratelimit_rate: int = 0
217+
ratelimit_period: int = 0
218+
ratelimit_sleep: float = 5.0
219+
connection_limit: int = 100
220+
connection_timeout: int = 60
221+
batch_size: int = 1000
222+
replay_path: str | None = None
223+
224+
@classmethod
225+
def create(
226+
cls,
227+
default: HTTPConfig,
228+
user: HTTPConfig | None,
229+
) -> 'ResolvedHTTPConfig':
230+
config = cls()
231+
# NOTE: Apply datasource defaults first
232+
for merge_config in (default, user):
233+
if merge_config is None:
234+
continue
235+
for k, v in merge_config.__dict__.items():
211236
if v is not None:
212237
setattr(config, k, v)
213238
return config
@@ -1402,7 +1427,8 @@ def __post_init_post_parse__(self) -> None:
14021427

14031428
self.paths: list[Path] = []
14041429
self.environment: dict[str, str] = {}
1405-
self._contract_addresses = {contract.address for contract in self.contracts.values()}
1430+
self._contract_addresses = {v.address: k for k, v in self.contracts.items() if v.address is not None}
1431+
self._contract_code_hashes = {v.code_hash: k for k, v in self.contracts.items() if v.code_hash is not None}
14061432

14071433
@property
14081434
def schema_name(self) -> str:
@@ -1554,7 +1580,7 @@ def add_index(
15541580
last_level: int = 0,
15551581
) -> None:
15561582
if name in self.indexes:
1557-
raise IndexAlreadyExistsError(self, name)
1583+
raise IndexAlreadyExistsError(name)
15581584
template_config = IndexTemplateConfig(
15591585
template=template,
15601586
values=values,

0 commit comments

Comments
 (0)