diff --git a/Makefile b/Makefile index 901b330..56379a2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .ONESHELL: .DEFAULT_GOAL: all -py := poetry run +py := uv run source_dir := bridge_indexer unit_tests_dir := tests @@ -14,12 +14,6 @@ test: install: poetry install `if [ "${DEV}" = "0" ]; then echo "--only main"; fi` --sync -isort: - $(py) isort $(source_dir) $(unit_tests_dir) - -ssort: - $(py) ssort $(source_dir) $(unit_tests_dir) - black: $(py) black $(source_dir) $(unit_tests_dir) @@ -29,7 +23,7 @@ ruff: mypy: $(py) mypy $(source_dir) $(unit_tests_dir) -lint: isort ssort black ruff mypy +lint: black ruff mypy wipe: $(py) dipdup $(dipdup_args) schema wipe --force @@ -41,7 +35,7 @@ run: $(py) dipdup $(dipdup_args) run up: - docker-compose up --build --remove-orphans --force-recreate --abort-on-container-exit + docker compose up --build --remove-orphans --force-recreate --abort-on-container-exit down: - docker-compose down --volumes + docker compose down --volumes diff --git a/bridge_indexer/handlers/bridge_matcher.py b/bridge_indexer/handlers/bridge_matcher.py index 8b3cfc2..18ce1f9 100644 --- a/bridge_indexer/handlers/bridge_matcher.py +++ b/bridge_indexer/handlers/bridge_matcher.py @@ -24,8 +24,7 @@ class BridgeMatcher: async def check_pending_tezos_deposits(cls): if not BridgeMatcherLocks.pending_tezos_deposits: return - else: - BridgeMatcherLocks.pending_tezos_deposits = False + BridgeMatcherLocks.pending_tezos_deposits = False qs = TezosDepositOperation.filter(bridge_deposits=None) async for l1_deposit in qs: @@ -45,20 +44,29 @@ async def check_pending_tezos_deposits(cls): async def check_pending_inbox(cls): if not BridgeMatcherLocks.pending_inbox: return - else: - BridgeMatcherLocks.pending_inbox = False - - qs = BridgeDepositOperation.filter( - inbox_message=None, - ).order_by( - 'l1_transaction__level', 'l1_transaction__counter', 'l1_transaction__nonce', - ).prefetch_related('l1_transaction') + BridgeMatcherLocks.pending_inbox = False + + qs = ( + BridgeDepositOperation.filter( + inbox_message=None, + ) + .order_by( + 'l1_transaction__level', + 'l1_transaction__counter', + 'l1_transaction__nonce', + ) + .prefetch_related('l1_transaction') + ) async for bridge_deposit in qs: bridge_deposit: BridgeDepositOperation - inbox_message = await RollupInboxMessage.filter( - parameters_hash=bridge_deposit.l1_transaction.parameters_hash, - level=bridge_deposit.l1_transaction.level, - ).order_by('index').first() + inbox_message = ( + await RollupInboxMessage.filter( + parameters_hash=bridge_deposit.l1_transaction.parameters_hash, + level=bridge_deposit.l1_transaction.level, + ) + .order_by('index') + .first() + ) if inbox_message: bridge_deposit.inbox_message = inbox_message @@ -72,12 +80,15 @@ async def check_pending_inbox(cls): async def check_pending_etherlink_deposits(cls): if not BridgeMatcherLocks.pending_etherlink_deposits: return - else: - BridgeMatcherLocks.pending_etherlink_deposits = False + BridgeMatcherLocks.pending_etherlink_deposits = False - qs = EtherlinkDepositOperation.filter( - bridge_deposits=None, - ).prefetch_related('l2_token').order_by('level', 'transaction_index', 'log_index') + qs = ( + EtherlinkDepositOperation.filter( + bridge_deposits=None, + ) + .prefetch_related('l2_token') + .order_by('level', 'transaction_index', 'log_index') + ) async for l2_deposit in qs: l2_deposit: EtherlinkDepositOperation @@ -114,13 +125,16 @@ async def check_pending_etherlink_deposits(cls): async def check_pending_etherlink_xtz_deposits(cls): if not BridgeMatcherLocks.pending_etherlink_xtz_deposits: return - else: - BridgeMatcherLocks.pending_etherlink_xtz_deposits = False + BridgeMatcherLocks.pending_etherlink_xtz_deposits = False - qs = EtherlinkDepositOperation.filter( - bridge_deposits=None, - l2_token_id='xtz', - ).order_by('level', 'transaction_index').prefetch_related('l2_token', 'l2_token__ticket') + qs = ( + EtherlinkDepositOperation.filter( + bridge_deposits=None, + l2_token_id='xtz', + ) + .order_by('level', 'transaction_index') + .prefetch_related('l2_token', 'l2_token__ticket') + ) async for l2_deposit in qs: l2_deposit: EtherlinkDepositOperation bridge_deposit = ( @@ -159,8 +173,7 @@ async def check_pending_etherlink_xtz_deposits(cls): async def check_pending_etherlink_withdrawals(cls): if not BridgeMatcherLocks.pending_etherlink_withdrawals: return - else: - BridgeMatcherLocks.pending_etherlink_withdrawals = False + BridgeMatcherLocks.pending_etherlink_withdrawals = False qs = EtherlinkWithdrawOperation.filter(bridge_withdrawals=None) async for l2_withdrawal in qs: @@ -179,20 +192,29 @@ async def check_pending_etherlink_withdrawals(cls): async def check_pending_outbox(cls): if not BridgeMatcherLocks.pending_outbox: return - else: - BridgeMatcherLocks.pending_outbox = False - - qs = BridgeWithdrawOperation.filter( - outbox_message=None, - ).order_by( - 'l2_transaction__level', 'l2_transaction__transaction_index', 'l2_transaction__log_index', - ).prefetch_related('l2_transaction') + BridgeMatcherLocks.pending_outbox = False + + qs = ( + BridgeWithdrawOperation.filter( + outbox_message=None, + ) + .order_by( + 'l2_transaction__level', + 'l2_transaction__transaction_index', + 'l2_transaction__log_index', + ) + .prefetch_related('l2_transaction') + ) async for bridge_withdrawal in qs: bridge_withdrawal: BridgeWithdrawOperation - outbox_message = await RollupOutboxMessage.filter( - parameters_hash=bridge_withdrawal.l2_transaction.parameters_hash, - bridge_withdrawals=None, - ).order_by('level', 'index').first() + outbox_message = ( + await RollupOutboxMessage.filter( + parameters_hash=bridge_withdrawal.l2_transaction.parameters_hash, + bridge_withdrawals=None, + ) + .order_by('level', 'index') + .first() + ) if outbox_message: bridge_withdrawal.outbox_message = outbox_message @@ -206,8 +228,7 @@ async def check_pending_outbox(cls): async def check_pending_tezos_withdrawals(cls): if not BridgeMatcherLocks.pending_tezos_withdrawals: return - else: - BridgeMatcherLocks.pending_tezos_withdrawals = False + BridgeMatcherLocks.pending_tezos_withdrawals = False qs = TezosWithdrawOperation.filter(bridge_withdrawals=None).order_by('level') async for l1_withdrawal in qs: diff --git a/bridge_indexer/handlers/rollup_message.py b/bridge_indexer/handlers/rollup_message.py index 9b8f3c6..ff07389 100644 --- a/bridge_indexer/handlers/rollup_message.py +++ b/bridge_indexer/handlers/rollup_message.py @@ -1,9 +1,8 @@ import threading - +from collections.abc import AsyncGenerator from datetime import datetime -from typing import Any -from typing import AsyncGenerator from typing import TYPE_CHECKING +from typing import Any from uuid import NAMESPACE_OID from uuid import uuid5 @@ -32,7 +31,6 @@ from bridge_indexer.models import TezosTicket from bridge_indexer.types.kernel.evm_events.withdrawal import WithdrawalPayload as FAWithdrawalPayload from bridge_indexer.types.kernel_native.evm_events.withdrawal import WithdrawalPayload as NativeWithdrawalPayload - from bridge_indexer.types.rollup.tezos_parameters.default import DefaultParameter from bridge_indexer.types.rollup.tezos_parameters.default import TicketContent as RollupParametersTicketContent from bridge_indexer.types.rollup.tezos_storage import RollupStorage @@ -98,7 +96,10 @@ async def update_proof(self): bridge_withdraw_operation: BridgeWithdrawOperation outbox_message = bridge_withdraw_operation.outbox_message - if head_data.level > outbox_message.level + self._protocol.smart_rollup_challenge_window + self._protocol.smart_rollup_max_active_outbox_levels: + if ( + head_data.level + > outbox_message.level + self._protocol.smart_rollup_challenge_window + self._protocol.smart_rollup_max_active_outbox_levels + ): continue if await RollupCementedCommitment.filter(inbox_level__gte=outbox_message.level).count() == 0: @@ -391,10 +392,12 @@ async def from_outbox_message(self, ticket_service: TicketService) -> str: ticket = await ticket_service.fetch_ticket( parameters.ticket.ticketer, - RollupParametersTicketContent.model_validate(obj={ - 'nat': str(parameters.ticket.content.ticket_id), - 'bytes': bytes_field, - }), + RollupParametersTicketContent.model_validate( + obj={ + 'nat': str(parameters.ticket.content.ticket_id), + 'bytes': bytes_field, + } + ), ) comparable_data = ComparableDTO( diff --git a/bridge_indexer/handlers/ticket.py b/bridge_indexer/handlers/ticket.py index 5f8d835..03acfb4 100644 --- a/bridge_indexer/handlers/ticket.py +++ b/bridge_indexer/handlers/ticket.py @@ -11,6 +11,7 @@ if TYPE_CHECKING: from dipdup.datasources.tezos_tzkt import TezosTzktDatasource from dipdup.datasources.tzip_metadata import TzipMetadataDatasource + from bridge_indexer.handlers.service_container import BridgeConstantStorage from bridge_indexer.models import EtherlinkToken @@ -160,7 +161,7 @@ def get_ticket_content_bytes( ) ticket_content_hex = ''.join( - remove_0x_prefix(hex_encode_abi_type(abi_type, value)) for abi_type, value in zip(abi_types, normalized_values) + remove_0x_prefix(hex_encode_abi_type(abi_type, value)) for abi_type, value in zip(abi_types, normalized_values, strict=False) ) return bytes.fromhex(ticket_content_hex) diff --git a/bridge_indexer/types/output_proof/output_proof.py b/bridge_indexer/types/output_proof/output_proof.py index 0d68500..5087b6e 100644 --- a/bridge_indexer/types/output_proof/output_proof.py +++ b/bridge_indexer/types/output_proof/output_proof.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import from bridge_indexer.types.output_proof.tree_encoding import TreeEncoding from bridge_indexer.types.output_proof.unpacker import BaseBinarySchema diff --git a/bridge_indexer/types/output_proof/unpacker.py b/bridge_indexer/types/output_proof/unpacker.py index c5b22c1..e2bc6c7 100644 --- a/bridge_indexer/types/output_proof/unpacker.py +++ b/bridge_indexer/types/output_proof/unpacker.py @@ -1,7 +1,6 @@ import sys from collections import OrderedDict from typing import Any -from typing import Type from pydantic import BaseModel @@ -11,7 +10,7 @@ class Part(BaseModel): name: str size: int | str | None - type: Type['BaseBinarySchema'] | str + type: type['BaseBinarySchema'] | str class BaseBinarySchema: diff --git a/bridge_indexer/types/rollup_node/proof.py b/bridge_indexer/types/rollup_node/proof.py index ca1f03d..bcc1891 100644 --- a/bridge_indexer/types/rollup_node/proof.py +++ b/bridge_indexer/types/rollup_node/proof.py @@ -1,4 +1,3 @@ -import json from typing import TYPE_CHECKING from base58 import b58decode_check @@ -6,9 +5,9 @@ from pydantic import BaseModel if TYPE_CHECKING: - from typing import Generator + from collections.abc import Generator - from pydantic.typing import AnyCallable + from pydantic.deprecated.decorator import AnyCallable CallableGenerator = Generator[AnyCallable, None, None] @@ -81,10 +80,3 @@ class Proof(str): class OutputProof(BaseModel): commitment: SmartRollupCommitmentHash proof: Proof - - -data = '{"commitment":"src139Y6mMHjFv1sLG8hAx9SP4sNT8Wz52DRZSos5gZqBxJUcS8cj4","proof":"03000248499c9d41a8ad43af5c2143d08d3046c0fcda8c0ccca35a493c62d9a71b2cb448499c9d41a8ad43af5c2143d08d3046c0fcda8c0ccca35a493c62d9a71b2cb40005820764757261626c65d059a01a146cc0254fb559ac85e2bcc1e6e51ccde65f6bda09869f4e86cbf442a903746167c00800000004536f6d650003c08cd439daf609f838d2c8a43aa75ed227baaaca7f4a9312448959d2641896f5b6820576616c7565810370766d8107627566666572738205696e707574820468656164c00100066c656e677468c00100066f75747075740004820132810a6c6173745f6c6576656cc004002d42a70133810f76616c69646974795f706572696f64c00400013b0082013181086f7574626f78657301c184015f5d012fa2c09e9d0fb1f84ba48fc95ba3b90a9404cc8e31e3cb434601b0fb23d45d39fbf6a301179a010bfac0c699abb5e9b26ce388c58d1712bd11b79d7ac52d2c5d296578fc0cea8dc4685c010609c0713ac44b458e045d6ba3fd64685bfa03f512c655fafea361d8ae2909b70cd33e010302c0ef8a57be3c044cc0852c87c9c0c0a818649935c58f48e63e659766ba9a1539c601018fc0730f6f5c72cf675562c3808fbb1a8c7d6d77cc9a3457c7c7e89295b5f728ead500dcc0762d69ead8181946282f52bde668ab7789d5538a99ea660a22ccc6f2fa3516b8006f003d0024c063cff88ca82e2c6e0b5cdfea29819148427f4f86cb3a791f2e45822a880f01360018c0f6913ff706bd5195c84a8f0bce104d258e86f5292ddd86ac4835844c24c48fae000d00070003c0a301ecbe3b8643e33f5462e08aa448a77d81ab4450b819b5ba8dcbdae347304b8107323931393133360003810468656164c001008208636f6e74656e74730003820130c0e8000000e400000000df07070a0000001600008a7390072a389159c73687165cd7910e8a39160607070a000000160155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc0007070707002a05090a0000007405020000006e07040100000010636f6e74726163745f616464726573730a0000001c050a000000160158827df9def8a4d2c92152c872c553b01ff3de0b0007040100000008746f6b656e5f69640a0000000305002a0704010000000a746f6b656e5f747970650a0000000905010000000346413200050155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc000000000877697468647261770132c0e8000000e400000000df07070a0000001600008a7390072a389159c73687165cd7910e8a39160607070a000000160155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc0007070707002a05090a0000007405020000006e07040100000010636f6e74726163745f616464726573730a0000001c050a000000160158827df9def8a4d2c92152c872c553b01ff3de0b0007040100000008746f6b656e5f69640a0000000305002a0704010000000a746f6b656e5f747970650a0000000905010000000346413200050155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc00000000087769746864726177c04c4bee8b261e5aa4de96a58dcb00a8c69a0125fcaed4e8844d1501776867852e066c656e677468c00103c09b2a388621c7631a1cb7ba04a2befdff5ba9411eee89f2e97b54e36ec3081a8cc0f16c32fc0389207e2a49d6c949950399d78cebfedd65ec1a63e208f626aa3036c085f8e370f9722a724dfa244ec6322c9dd23ebd31e914d1f796faf21e650f5f80c0883eae96313f9934c2b34264155923b34bd63ca3e421d5e566c90e2149490c78c095cf380de310d3eea4bbab05ffca1e5009bd6fe38318d68c57287ae4e013fd5cc0355175ef3f98242f1ecd6f9035c95a359b7795e8bf9124db7aaa4fb090e43054c0722759fdcd2027211b4a1d994562c1dd0d108e51106e52cd516b19040eb9dede0134810d6d6573736167655f6c696d6974c002a401047761736dd0c793e2bb253ac6f51153c363fe3acb12dd711522feb80c2c1ae125b427113f4e48499c9d41a8ad43af5c2143d08d3046c0fcda8c0ccca35a493c62d9a71b2cb4002c8ae00000000000df07070a0000001600008a7390072a389159c73687165cd7910e8a39160607070a000000160155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc0007070707002a05090a0000007405020000006e07040100000010636f6e74726163745f616464726573730a0000001c050a000000160158827df9def8a4d2c92152c872c553b01ff3de0b0007040100000008746f6b656e5f69640a0000000305002a0704010000000a746f6b656e5f747970650a0000000905010000000346413200050155c34fe2c664715ec4c0a43a01f1e4141fa9b3cc00000000087769746864726177"}' - -op = OutputProof.parse_obj(json.loads(data)) -opc = op.commitment -assert opc diff --git a/bridge_indexer/types/ticketer/tezos_parameters/withdraw.py b/bridge_indexer/types/ticketer/tezos_parameters/withdraw.py index 61233d1..8e3758e 100644 --- a/bridge_indexer/types/ticketer/tezos_parameters/withdraw.py +++ b/bridge_indexer/types/ticketer/tezos_parameters/withdraw.py @@ -3,15 +3,16 @@ from __future__ import annotations +from typing import Literal + from pydantic import BaseModel -from pydantic import Extra from bridge_indexer.types.tezos.forged_tezos_account import ForgedTezosAccount class TicketContent(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal[forbid] = 'forbid' ticket_id: int metadata: bytes | None @@ -19,7 +20,7 @@ class Config: class Ticket(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal[forbid] = 'forbid' ticketer: ForgedTezosAccount content: TicketContent @@ -28,7 +29,7 @@ class Config: class WithdrawParameter(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal[forbid] = 'forbid' receiver: ForgedTezosAccount ticket: Ticket diff --git a/bridge_indexer/types/ticketer/tezos_storage.py b/bridge_indexer/types/ticketer/tezos_storage.py index 6acaf5b..c712fd8 100644 --- a/bridge_indexer/types/ticketer/tezos_storage.py +++ b/bridge_indexer/types/ticketer/tezos_storage.py @@ -3,15 +3,14 @@ from __future__ import annotations -from typing import Dict +from typing import Literal from pydantic import BaseModel -from pydantic import Extra class Content(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal['forbid'] = 'forbid' nat: str bytes: str | None @@ -19,14 +18,14 @@ class Config: class Token(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal['forbid'] = 'forbid' fa12: str class Fa2(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal['forbid'] = 'forbid' address: str nat: str @@ -34,15 +33,15 @@ class Config: class Token1(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal['forbid'] = 'forbid' fa2: Fa2 class TicketerStorage(BaseModel): class Config: - extra = Extra.forbid + forbid: Literal['forbid'] = 'forbid' content: Content - metadata: Dict[str, str] + metadata: dict[str, str] token: Token | Token1 diff --git a/pyproject.toml b/pyproject.toml index f6450e5..cac4871 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,9 @@ indent-style = "space" extend-select = ["B", "C4", "FA", "G", "I", "PTH", "Q", "RET", "RUF", "TCH", "UP"] flake8-quotes = { inline-quotes = "single", multiline-quotes = "single" } +[tool.ruff.lint.isort] +force-single-line = true + [tool.black] line-length = 140 target-version = ["py312"]