Skip to content

Commit 722e3c2

Browse files
Fixed missing operations when handler pattern contains item without entrypoint (#976)
1 parent 29db572 commit 722e3c2

File tree

9 files changed

+25
-17
lines changed

9 files changed

+25
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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+
### Fixed
10+
11+
- tezos.tzkt.operations: Fixed missing operations when handler pattern contains item without entrypoint.
12+
713
## [7.5.2] - 2024-03-20
814

915
### Fixed

docs/15.thanks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ We are grateful to all the people who helped us with the project.
3333
- [Igor Sereda](https://github.com/igorsereda)
3434
- [Javier Graciá Carpio](https://github.com/jagracar)
3535
- [Karan Dua](https://github.com/Karantezsure)
36+
- [Kornii](https://github.com/lourenc)
3637
- [Nick Kalomoiris](https://github.com/nikos-kalomoiris)
3738
- [magicCity](https://github.com/tezosmiami)
3839
- [pravind](https://github.com/pravind)

src/dipdup/codegen/tezos_tzkt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from dipdup.datasources.tezos_tzkt import late_tzkt_initialization
3939
from dipdup.exceptions import ConfigurationError
4040
from dipdup.exceptions import FrameworkException
41+
from dipdup.models.tezos_tzkt import DEFAULT_ENTRYPOINT
4142
from dipdup.package import DipDupPackage
4243
from dipdup.utils import json_dumps
4344
from dipdup.utils import pascal_to_snake
@@ -46,9 +47,8 @@
4647

4748

4849
def match_entrypoint_schema(entrypoint_name: str, entrypoint_schemas: list[dict[str, Any]]) -> dict[str, Any]:
49-
if entrypoint_name == 'default' and len(entrypoint_schemas) == 1:
50+
if entrypoint_name == DEFAULT_ENTRYPOINT and len(entrypoint_schemas) == 1:
5051
return entrypoint_schemas[0]['parameterSchema'] # type: ignore[no-any-return]
51-
5252
return next(ep['parameterSchema'] for ep in entrypoint_schemas if ep['name'] == entrypoint_name)
5353

5454

src/dipdup/dipdup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(self, ctx: DipDupContext) -> None:
9696
self._ctx = ctx
9797
self._indexes: dict[str, Index[Any, Any, Any]] = {}
9898
# FIXME: Tezos-specific
99-
self._entrypoint_filter: set[str | None] = set()
99+
self._entrypoint_filter: set[str] = set()
100100
self._address_filter: set[str] = set()
101101
self._code_hash_filter: set[int] = set()
102102
# NOTE: Monitoring purposes

src/dipdup/indexes/tezos_tzkt_operations/index.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from dipdup.indexes.tezos_tzkt_operations.matcher import match_operation_subgroup
3030
from dipdup.indexes.tezos_tzkt_operations.matcher import match_operation_unfiltered_subgroup
3131
from dipdup.models import RollbackMessage
32+
from dipdup.models.tezos_tzkt import DEFAULT_ENTRYPOINT
3233
from dipdup.models.tezos_tzkt import TzktMessageType
3334
from dipdup.models.tezos_tzkt import TzktOperationData
3435
from dipdup.prometheus import Metrics
@@ -38,14 +39,14 @@
3839
QueueItem = tuple[OperationSubgroup, ...] | RollbackMessage
3940

4041

41-
def entrypoint_filter(handlers: tuple[TzktOperationsHandlerConfig, ...]) -> set[str | None]:
42+
def entrypoint_filter(handlers: tuple[TzktOperationsHandlerConfig, ...]) -> set[str]:
4243
"""Set of entrypoints to filter operations with before an actual matching"""
4344
entrypoints = set()
4445
for handler_config in handlers:
4546
for pattern_config in handler_config.pattern:
4647
if not isinstance(pattern_config, TransactionPatternConfig):
4748
continue
48-
entrypoints.add(pattern_config.entrypoint)
49+
entrypoints.add(pattern_config.entrypoint or DEFAULT_ENTRYPOINT)
4950

5051
return entrypoints
5152

@@ -101,7 +102,7 @@ def code_hash_filter(handlers: tuple[TzktOperationsHandlerConfig, ...]) -> set[i
101102
def extract_operation_subgroups(
102103
operations: Iterable[TzktOperationData],
103104
addresses: set[str],
104-
entrypoints: set[str | None],
105+
entrypoints: set[str],
105106
code_hashes: set[int],
106107
) -> Iterator[OperationSubgroup]:
107108
filtered: int = 0
@@ -112,7 +113,8 @@ def extract_operation_subgroups(
112113
for _operation_index, op in enumerate(operations):
113114
# NOTE: Filtering out operations that are not part of any index
114115
if op.type == 'transaction':
115-
if entrypoints and op.entrypoint not in entrypoints:
116+
entrypoint = op.entrypoint or DEFAULT_ENTRYPOINT
117+
if entrypoints and entrypoint not in entrypoints:
116118
filtered += 1
117119
continue
118120

@@ -140,12 +142,10 @@ def extract_operation_subgroups(
140142

141143
for key, operations in operation_subgroups.items():
142144
hash_, counter = key
143-
entrypoints = {op.entrypoint for op in operations}
144145
yield OperationSubgroup(
145146
hash=hash_,
146147
counter=counter,
147148
operations=tuple(operations),
148-
entrypoints=entrypoints,
149149
)
150150

151151

@@ -160,11 +160,11 @@ def __init__(
160160
datasource: TzktDatasource,
161161
) -> None:
162162
super().__init__(ctx, config, datasource)
163-
self._entrypoint_filter: set[str | None] = set()
163+
self._entrypoint_filter: set[str] = set()
164164
self._address_filter: set[str] = set()
165165
self._code_hash_filter: set[int] = set()
166166

167-
async def get_filters(self) -> tuple[set[str | None], set[str], set[int]]:
167+
async def get_filters(self) -> tuple[set[str], set[str], set[int]]:
168168
if isinstance(self._config, TzktOperationsUnfilteredIndexConfig):
169169
return set(), set(), set()
170170

src/dipdup/indexes/tezos_tzkt_operations/matcher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class OperationSubgroup:
3535
hash: str
3636
counter: int
3737
operations: tuple[TzktOperationData, ...]
38-
entrypoints: set[str | None]
3938

4039

4140
OperationsHandlerArgumentU = (

src/dipdup/models/tezos_tzkt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from dipdup.models import MessageType
1818
from dipdup.subscriptions import Subscription
1919

20+
DEFAULT_ENTRYPOINT = 'default'
21+
2022
ParameterType = TypeVar('ParameterType', bound=BaseModel)
2123
StorageType = TypeVar('StorageType', bound=BaseModel)
2224
KeyType = TypeVar('KeyType', bound=BaseModel)
@@ -241,7 +243,7 @@ def from_json(
241243
if target_json.get('address', '').startswith('KT1'):
242244
# NOTE: TzKT returns None for `default` entrypoint
243245
if entrypoint is None:
244-
entrypoint = 'default'
246+
entrypoint = DEFAULT_ENTRYPOINT
245247

246248
# NOTE: Empty parameter in this case means `{"prim": "Unit"}`
247249
if parameter is None:

tests/configs/demo_dex.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ indexes:
161161
token_contract: kusd_token_mainnet
162162
symbol: kUSD
163163
decimals: 18
164-
first_level: 1434927
165-
last_level: 1435026
164+
first_level: 3032136
165+
last_level: 3032136
166166

167167
hdao_mainnet:
168168
template: quipuswap_fa2

tests/test_demos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ async def assert_run_dex() -> None:
100100
async with in_transaction() as conn:
101101
symbols = (await conn.execute_query('select count(distinct(symbol)) from trade group by symbol;'))[0]
102102
assert symbols == 2
103-
assert trades == 56
104-
assert positions == 133
103+
assert trades == 55
104+
assert positions == 125
105105

106106

107107
async def assert_run_domains() -> None:

0 commit comments

Comments
 (0)