Skip to content

Commit 043a029

Browse files
operation_unfiltered index release (#514)
1 parent 7c4e7a7 commit 043a029

File tree

9 files changed

+52
-31
lines changed

9 files changed

+52
-31
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- index: New index kind `operation_unfiltered`.
12+
913
### Fixed
1014

1115
- cli: Configure package logger in addition to `dipdup` one.
1216
- database: Fixed crash when using F expressions inside versioned transactions.
17+
- project: Fixed options in DipDup version question.
1318
- tzkt: Fixed deserializing `EventData` model.
1419

1520
## [6.2.0] - 2022-10-12

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S
4949

5050
- Crash reporting MUST be opt-in (disabled by default) both in config and project templates.
5151
- Sentry events and crash reports MUST NOT contain any sensitive information (IP addresses, hostnames, etc.)
52-
- DipDup SHOULD NOT perform network requests to APIs not defined in config as datasources.
52+
- DipDup SHOULD NOT perform network requests to APIs not defined in config as datasources. Current exceptions: GitHub.
5353

5454
## Docker images
5555

docs/config/reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ http: HTTP client configuration</p>
470470

471471
<dl class="py class">
472472
<dt class="sig sig-object py" id="dipdup.config.OperationUnfilteredIndexConfig">
473-
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">dipdup.config.</span></span><span class="sig-name descname"><span class="pre">OperationUnfilteredIndexConfig</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">kind:</span> <span class="pre">~typing.Literal['operation_unfiltered'],</span> <span class="pre">datasource:</span> <span class="pre">~typing.Union[str,</span> <span class="pre">~dipdup.config.TzktDatasourceConfig],</span> <span class="pre">handlers:</span> <span class="pre">~typing.Tuple[~dipdup.config.OperationUnfilteredHandlerConfig,</span> <span class="pre">...],</span> <span class="pre">types:</span> <span class="pre">~typing.Tuple[~dipdup.enums.OperationType,</span> <span class="pre">...]</span> <span class="pre">=</span> <span class="pre">(&lt;OperationType.transaction:</span> <span class="pre">'transaction'&gt;,),</span> <span class="pre">first_level:</span> <span class="pre">int</span> <span class="pre">=</span> <span class="pre">0,</span> <span class="pre">last_level:</span> <span class="pre">int</span> <span class="pre">=</span> <span class="pre">0</span></em><span class="sig-paren">)</span><a class="headerlink" href="#dipdup.config.OperationUnfilteredIndexConfig" title="Permalink to this definition">¶</a></dt>
473+
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">dipdup.config.</span></span><span class="sig-name descname"><span class="pre">OperationUnfilteredIndexConfig</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">kind:</span> <span class="pre">~typing.Literal['operation_unfiltered'],</span> <span class="pre">datasource:</span> <span class="pre">~typing.Union[str,</span> <span class="pre">~dipdup.config.TzktDatasourceConfig],</span> <span class="pre">handlers:</span> <span class="pre">~typing.Tuple[~dipdup.config.OperationUnfilteredHandlerConfig,</span> <span class="pre">...],</span> <span class="pre">types:</span> <span class="pre">~typing.Tuple[~dipdup.enums.OperationType,</span> <span class="pre">...]</span> <span class="pre">=</span> <span class="pre">(&lt;OperationType.origination:</span> <span class="pre">'origination'&gt;,),</span> <span class="pre">first_level:</span> <span class="pre">int</span> <span class="pre">=</span> <span class="pre">0,</span> <span class="pre">last_level:</span> <span class="pre">int</span> <span class="pre">=</span> <span class="pre">0</span></em><span class="sig-paren">)</span><a class="headerlink" href="#dipdup.config.OperationUnfilteredIndexConfig" title="Permalink to this definition">¶</a></dt>
474474
<dd><p>Operation index config</p>
475475
<dl class="field-list simple">
476476
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
477477
<dd class="field-odd"><ul class="simple">
478-
<li><p><strong>kind</strong> – always <cite>operation</cite></p></li>
478+
<li><p><strong>kind</strong> – always <cite>operation_unfiltered</cite></p></li>
479479
<li><p><strong>handlers</strong> – List of indexer handlers</p></li>
480480
<li><p><strong>first_level</strong> – Level to start indexing from</p></li>
481481
<li><p><strong>last_level</strong> – Level to stop indexing at (DipDup will terminate at this level)</p></li>

docs/indexes/big_map.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `big_map` index
22

3+
Big maps are lazy structures allowing to access and update only exact keys. Gas costs for these operations doesn't depend on the size of a big map, but you can't iterate over it's keys onchain.
4+
35
`big_map` index allows querying only updates of specific big maps. In some cases, it can drastically reduce the amount of data transferred and thus indexing speed compared to fetching all operations.
46

57
```yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# `operation_unfiltered` index

src/dipdup/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""Root DipDup package.
2+
3+
Contains software versions and other metadata. Also applies some CLI environment hacks on import.
4+
"""
15
import logging
26
import sys
37
import warnings
@@ -7,6 +11,10 @@
711
__version__ = '6.2.0'
812
__spec_version__ = '1.2'
913

14+
version = tuple(int(x) for x in __version__.split('.'))
15+
major_version = version[0]
16+
minor_version = f'{version[0]}.{version[1]}'
17+
1018
spec_version_mapping = {
1119
'0.1': '<=0.4.3',
1220
'1.0': '>=1.0.0, <=1.1.2',

src/dipdup/config.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,15 +949,15 @@ def address_filter(self) -> Set[str]:
949949
class OperationUnfilteredIndexConfig(IndexConfig):
950950
"""Operation index config
951951
952-
:param kind: always `operation`
952+
:param kind: always `operation_unfiltered`
953953
:param handlers: List of indexer handlers
954954
:param first_level: Level to start indexing from
955955
:param last_level: Level to stop indexing at (DipDup will terminate at this level)
956956
"""
957957

958958
kind: Literal['operation_unfiltered']
959959
handlers: Tuple[OperationUnfilteredHandlerConfig, ...]
960-
types: Tuple[OperationType, ...] = (OperationType.transaction,)
960+
types: Tuple[OperationType, ...] = (OperationType.origination,)
961961

962962
first_level: int = 0
963963
last_level: int = 0
@@ -1094,6 +1094,14 @@ class HeadIndexConfig(IndexConfig):
10941094
datasource: Union[str, TzktDatasourceConfig]
10951095
handlers: Tuple[HeadHandlerConfig, ...]
10961096

1097+
@property
1098+
def first_level(self) -> int:
1099+
return 0
1100+
1101+
@property
1102+
def last_level(self) -> int:
1103+
return 0
1104+
10971105

10981106
@dataclass
10991107
class TokenTransferHandlerConfig(HandlerConfig, kind='handler'):

src/dipdup/index.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
from typing import DefaultDict
1010
from typing import Deque
1111
from typing import Dict
12+
from typing import Generic
1213
from typing import Iterable
1314
from typing import Iterator
1415
from typing import List
1516
from typing import Optional
1617
from typing import Sequence
1718
from typing import Set
1819
from typing import Tuple
20+
from typing import TypeVar
1921
from typing import Union
2022
from typing import cast
2123

@@ -36,6 +38,7 @@
3638
from dipdup.config import OperationHandlerTransactionPatternConfig
3739
from dipdup.config import OperationIndexConfig
3840
from dipdup.config import OperationType
41+
from dipdup.config import OperationUnfilteredIndexConfig
3942
from dipdup.config import ResolvedIndexConfigT
4043
from dipdup.config import SkipHistory
4144
from dipdup.config import TokenTransferHandlerConfig
@@ -71,6 +74,8 @@
7174

7275
_logger = logging.getLogger(__name__)
7376

77+
ConfigT = TypeVar('ConfigT', bound=ResolvedIndexConfigT)
78+
7479

7580
@dataclass(frozen=True)
7681
class OperationSubgroup:
@@ -108,14 +113,10 @@ def extract_operation_subgroups(
108113
for _operation_index, operation in enumerate(operations):
109114
# NOTE: Filtering out operations that are not part of any index
110115
if operation.type == 'transaction':
111-
if operation.entrypoint not in entrypoints and len(entrypoints) != 0:
116+
if entrypoints and operation.entrypoint not in entrypoints:
112117
filtered += 1
113118
continue
114-
if (
115-
operation.sender_address not in addresses
116-
and operation.target_address not in addresses
117-
and len(addresses) != 0
118-
):
119+
if addresses and operation.sender_address not in addresses and operation.target_address not in addresses:
119120
filtered += 1
120121
continue
121122

@@ -146,7 +147,7 @@ def extract_operation_subgroups(
146147
)
147148

148149

149-
class Index:
150+
class Index(Generic[ConfigT]):
150151
"""Base class for index implementations
151152
152153
Provides common interface for managing index state and switching between sync and realtime modes.
@@ -155,7 +156,7 @@ class Index:
155156
message_type: MessageType
156157
_queue: Deque
157158

158-
def __init__(self, ctx: DipDupContext, config: ResolvedIndexConfigT, datasource: TzktDatasource) -> None:
159+
def __init__(self, ctx: DipDupContext, config: ConfigT, datasource: TzktDatasource) -> None:
159160
self._ctx = ctx
160161
self._config = config
161162
self._datasource = datasource
@@ -298,9 +299,8 @@ def _extract_level(
298299
return batch_levels.pop()
299300

300301

301-
class OperationIndex(Index):
302+
class OperationIndex(Index[OperationIndexConfig]):
302303
message_type = MessageType.operation
303-
_config: OperationIndexConfig
304304

305305
def __init__(self, ctx: DipDupContext, config: OperationIndexConfig, datasource: TzktDatasource) -> None:
306306
super().__init__(ctx, config, datasource)
@@ -611,7 +611,6 @@ async def _get_contract_hashes(self, address: str) -> Tuple[int, int]:
611611

612612
class BigMapIndex(Index):
613613
message_type = MessageType.big_map
614-
_config: BigMapIndexConfig
615614

616615
def __init__(self, ctx: DipDupContext, config: BigMapIndexConfig, datasource: TzktDatasource) -> None:
617616
super().__init__(ctx, config, datasource)
@@ -838,7 +837,6 @@ def _get_big_map_pairs(self) -> Set[Tuple[str, str]]:
838837

839838
class HeadIndex(Index):
840839
message_type: MessageType = MessageType.head
841-
_config: HeadIndexConfig
842840

843841
def __init__(self, ctx: DipDupContext, config: HeadIndexConfig, datasource: TzktDatasource) -> None:
844842
super().__init__(ctx, config, datasource)
@@ -887,7 +885,6 @@ def push_head(self, head: HeadBlockData) -> None:
887885

888886
class TokenTransferIndex(Index):
889887
message_type = MessageType.token_transfer
890-
_config: TokenTransferIndexConfig
891888

892889
def __init__(self, ctx: DipDupContext, config: TokenTransferIndexConfig, datasource: TzktDatasource) -> None:
893890
super().__init__(ctx, config, datasource)
@@ -1026,10 +1023,10 @@ def _get_token_ids(self) -> Set[int]:
10261023

10271024
class OperationUnfilteredIndex(OperationIndex):
10281025
message_type = MessageType.operation
1029-
_config: OperationIndexConfig
10301026

1031-
def __init__(self, ctx: DipDupContext, config: OperationIndexConfig, datasource: TzktDatasource) -> None:
1032-
super().__init__(ctx, config, datasource)
1027+
def __init__(self, ctx: DipDupContext, config: OperationUnfilteredIndexConfig, datasource: TzktDatasource) -> None:
1028+
# FIXME: Ugly inheritance hack
1029+
Index.__init__(self, ctx, config, datasource) # type: ignore
10331030
self._queue: Deque[Tuple[OperationSubgroup, ...]] = deque()
10341031
self._contract_hashes: Dict[str, Tuple[int, int]] = {}
10351032

@@ -1071,7 +1068,6 @@ async def _match_operation_subgroup(self, operation_subgroup: OperationSubgroup)
10711068

10721069
class EventIndex(Index):
10731070
message_type = MessageType.event
1074-
_config: EventIndexConfig
10751071

10761072
def __init__(self, ctx: DipDupContext, config: EventIndexConfig, datasource: TzktDatasource) -> None:
10771073
super().__init__(ctx, config, datasource)

src/dipdup/project.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from pydantic import Field
1010
from tabulate import tabulate
1111

12-
from dipdup import __version__
12+
from dipdup import major_version
13+
from dipdup import minor_version
1314
from dipdup.exceptions import ConfigurationError
1415
from dipdup.utils.codegen import load_template
1516
from dipdup.utils.codegen import write
@@ -271,12 +272,12 @@ class BaseProject(Project):
271272
description='Choose DipDup version',
272273
default=0,
273274
choices=(
274-
'6',
275-
'6.1',
275+
major_version,
276+
minor_version,
276277
),
277278
comments=(
278-
'Latest stable release',
279-
'Latest release of 6.1 branch',
279+
'latest stable',
280+
'current stable',
280281
),
281282
),
282283
ChoiceQuestion(
@@ -304,12 +305,12 @@ class BaseProject(Project):
304305
choices=(
305306
'hasura/graphql-engine:v2.14.0',
306307
'hasura/graphql-engine:v2.14.0',
307-
# 'hasura/graphql-engine:v2.15.0-beta.1',
308+
'hasura/graphql-engine:v2.15.0-beta.1',
308309
),
309310
comments=(
310-
f'tested with DipDup {__version__}',
311-
'latest',
312-
# 'beta',
311+
f'tested with DipDup {minor_version}',
312+
'latest stable',
313+
'latest beta',
313314
),
314315
),
315316
NotifyQuestion(

0 commit comments

Comments
 (0)