Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some Websocket issues, remove Index.head relation #144

Merged
merged 50 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a4e1731
Fix action order in callbacks, refactor datasource class
droserasprout Sep 26, 2021
3f705e8
Fix race in emitter
droserasprout Sep 26, 2021
30422f2
typo
droserasprout Sep 26, 2021
c9bf752
Another typo
droserasprout Sep 26, 2021
93b7bff
Another typo
droserasprout Sep 26, 2021
ce814ab
Another typo
droserasprout Sep 26, 2021
c3b0747
Another typo
droserasprout Sep 26, 2021
733adfc
Let callbacks handle locks by themselves
droserasprout Sep 26, 2021
b4632b1
FFFFUUU
droserasprout Sep 26, 2021
6ff14d5
Fix missing level on emit
droserasprout Sep 26, 2021
f523d10
Another stupid typo
droserasprout Sep 26, 2021
e5601bf
Emit timeout
droserasprout Sep 26, 2021
a24e5ae
Capture exceptions early
droserasprout Sep 26, 2021
57b9613
Log dead tasks
droserasprout Sep 26, 2021
5936752
Merge branch 'master' into fix/ws-message-race
droserasprout Sep 28, 2021
a088564
Merge branch 'master' into fix/ws-message-race
droserasprout Sep 28, 2021
0c7b8ba
Drop pyee ☠
droserasprout Sep 28, 2021
ba2a4a7
Rename callbacks
droserasprout Sep 28, 2021
212eb43
Unlink head
droserasprout Sep 28, 2021
20481f3
Cleanup
droserasprout Sep 28, 2021
31fd05b
Cleanup, fix ugly database logger setting
droserasprout Sep 28, 2021
615eb22
Typos
droserasprout Sep 28, 2021
2e7d499
Update changelog
droserasprout Sep 28, 2021
f0d5b38
BlockCache improvements
droserasprout Sep 28, 2021
51448a2
typo;
droserasprout Sep 28, 2021
8079152
Ignore missing head
droserasprout Sep 28, 2021
64282a3
Fix dipdup initialization order
droserasprout Sep 28, 2021
ba43f59
Changelog
droserasprout Sep 28, 2021
a33398e
Cleanup
droserasprout Sep 28, 2021
83ccb7c
Fix cleaning up old blocks
droserasprout Sep 29, 2021
659b43d
Drop Index.hash
droserasprout Sep 29, 2021
26978d3
Cleanup
droserasprout Sep 29, 2021
d15ae13
Cleanup
droserasprout Sep 29, 2021
262bcef
Drop `stateless` fields
droserasprout Sep 29, 2021
46e8acf
Drop BlockCache, simplify block hash checks
droserasprout Sep 29, 2021
9b02c68
Cleanup
droserasprout Sep 29, 2021
bb97c1d
Check operation status before converting
droserasprout Sep 29, 2021
0ba5cb5
Comment
droserasprout Sep 29, 2021
a60e8a5
Changelog
droserasprout Sep 29, 2021
a766727
Cleanup, drop useless self.level check in datasource
droserasprout Sep 29, 2021
f06c4e8
Head constraint
droserasprout Sep 29, 2021
5fe6021
Revert multiple heads, add docs
droserasprout Sep 30, 2021
f613517
Changelog
droserasprout Sep 30, 2021
ffda67b
Lint
droserasprout Sep 30, 2021
c007ba4
Kill me please
droserasprout Sep 30, 2021
933cc90
Dont do sql in ws loop
droserasprout Sep 30, 2021
65d401f
Head sub, typing
droserasprout Sep 30, 2021
7b2aff4
Codestyle, cache blocks on init, bigmap fixes
droserasprout Sep 30, 2021
5939568
Typo
droserasprout Sep 30, 2021
071e8ba
Docs
droserasprout Sep 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ replace = __version__ = '{new_version}'
[bumpversion:glob:src/*/docker/Dockerfile]
search = FROM dipdup/dipdup:{current_version}
replace = FROM dipdup/dipdup:{new_version}

[bumpversion:glob:CHANGELOG.md]
search = '## [unreleased]'
replace = '## {new_version}'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Fixed creation of missing project package on `init`.
* Fixed invalid handler callbacks generated on `init`.
* Fixed detection of existing types in the project.
* Fixed race condition caused by event emitter concurrency.

## 3.0.1 - 2021-09-24

Expand Down
14 changes: 1 addition & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ tortoise-orm = "0.17.5"
pydantic = "^1.8.1"
aiosignalrcore = "^0.9.2"
fcache = "^0.4.7"
pyee = "^8.1.0"
APScheduler = "^3.7.0"
sentry-sdk = "^1.1.0"
pyhumps = "^3.0.2"
Expand Down
65 changes: 27 additions & 38 deletions src/dipdup/datasources/datasource.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
from abc import abstractmethod
from enum import Enum
from logging import Logger
from typing import Awaitable, List, Protocol

from pyee import AsyncIOEventEmitter # type: ignore
from typing import Awaitable, List, Protocol, Set

from dipdup.config import HTTPConfig
from dipdup.http import HTTPGateway
from dipdup.models import BigMapData, HeadBlockData, OperationData


class EventType(Enum):
operations = 'operatitions'
big_maps = 'big_maps'
rollback = 'rollback'
head = 'head'


class OperationsCallback(Protocol):
def __call__(self, datasource: 'IndexDatasource', operations: List[OperationData], block: HeadBlockData) -> Awaitable[None]:
def __call__(self, datasource: 'IndexDatasource', operations: List[OperationData]) -> Awaitable[None]:
...


class BigMapsCallback(Protocol):
def __call__(self, datasource: 'IndexDatasource', big_maps: List[BigMapData], block: HeadBlockData) -> Awaitable[None]:
def __call__(self, datasource: 'IndexDatasource', big_maps: List[BigMapData]) -> Awaitable[None]:
...


Expand All @@ -33,7 +23,7 @@ def __call__(self, datasource: 'IndexDatasource', from_level: int, to_level: int


class HeadCallback(Protocol):
def __call__(self, datasource: 'IndexDatasource', block: HeadBlockData) -> Awaitable[None]:
def __call__(self, datasource: 'IndexDatasource', head: HeadBlockData) -> Awaitable[None]:
...


Expand All @@ -45,39 +35,38 @@ async def run(self) -> None:
...


class IndexDatasource(Datasource, AsyncIOEventEmitter):
class IndexDatasource(Datasource):
def __init__(self, url: str, http_config: HTTPConfig) -> None:
HTTPGateway.__init__(self, url, http_config)
AsyncIOEventEmitter.__init__(self)

def on(self, event, f=None) -> None:
raise RuntimeError('Do not use `on` directly')
super().__init__(url, http_config)
self._on_head: Set[HeadCallback] = set()
self._on_operations: Set[OperationsCallback] = set()
self._on_big_maps: Set[BigMapsCallback] = set()
self._on_rollback: Set[RollbackCallback] = set()

def emit(self, event: str, *args, **kwargs) -> None:
if event not in ('new_listener', 'error'):
raise RuntimeError('Do not use `emit` directly')
super().emit(event, *args, **kwargs)
def on_head(self, fn: HeadCallback) -> None:
self._on_head.add(fn)

def on_operations(self, fn: OperationsCallback) -> None:
super().on(EventType.operations, fn)
self._on_operations.add(fn)

def on_big_maps(self, fn: BigMapsCallback) -> None:
super().on(EventType.big_maps, fn)
self._on_big_maps.add(fn)

def on_rollback(self, fn: RollbackCallback) -> None:
super().on(EventType.rollback, fn)

def on_head(self, fn: HeadCallback) -> None:
super().on(EventType.head, fn)
self._on_rollback.add(fn)

def emit_operations(self, operations: List[OperationData], block: HeadBlockData) -> None:
super().emit(EventType.operations, datasource=self, operations=operations, block=block)
async def emit_head(self, head: HeadBlockData) -> None:
for fn in self._on_head:
await fn(self, head)

def emit_big_maps(self, big_maps: List[BigMapData], block: HeadBlockData) -> None:
super().emit(EventType.big_maps, datasource=self, big_maps=big_maps, block=block)
async def emit_operations(self, operations: List[OperationData]) -> None:
for fn in self._on_operations:
await fn(self, operations)

def emit_rollback(self, from_level: int, to_level: int) -> None:
super().emit(EventType.rollback, datasource=self, from_level=from_level, to_level=to_level)
async def emit_big_maps(self, big_maps: List[BigMapData]) -> None:
for fn in self._on_big_maps:
await fn(self, big_maps)

def emit_head(self, block: HeadBlockData) -> None:
super().emit(EventType.head, datasource=self, block=block)
async def emit_rollback(self, from_level: int, to_level: int) -> None:
for fn in self._on_rollback:
await fn(self, from_level, to_level)
Loading