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 outbox message hash #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion bridge_indexer/handlers/etherlink/on_withdraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ async def on_withdraw(
) -> None:
ctx.logger.info(f'Etherlink FA Withdraw Event found: {event.data.transaction_hash}')
token_contract = event.payload.ticket_owner.removeprefix('0x')
etherlink_token = await EtherlinkToken.get_or_none(id=token_contract)
etherlink_token = await EtherlinkToken.get_or_none(id=token_contract).prefetch_related('ticket')
if not etherlink_token:
if event.payload.sender == event.payload.ticket_owner:
ctx.logger.warning('Uncommon Withdraw Routing Info: `ticket_owner == sender`. Mark Operation as `Deposit Revert`.')
else:
ctx.logger.warning(f'Incorrect Withdraw Routing Info: Specified `proxy` contract address not whitelisted: {token_contract}.')
if etherlink_token and event.payload.proxy != etherlink_token.ticket.ticketer_address:
ctx.logger.warning('Uncommon Withdraw Routing Info: `proxy != ticketer_address`.')

withdrawal = await EtherlinkWithdrawOperation.create(
timestamp=datetime.fromtimestamp(event.data.timestamp, tz=UTC),
Expand Down
13 changes: 8 additions & 5 deletions bridge_indexer/handlers/rollup_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from tortoise.exceptions import DoesNotExist

from bridge_indexer.handlers.bridge_matcher_locks import BridgeMatcherLocks
from bridge_indexer.handlers.ticket import MICHELSON_OUTBOX_INTERFACE
from bridge_indexer.models import BridgeOperation
from bridge_indexer.models import BridgeOperationStatus
from bridge_indexer.models import BridgeWithdrawOperation
Expand Down Expand Up @@ -291,7 +292,8 @@ async def _handle_outbox_level(self, outbox_level):
for outbox_message in outbox:
try:
parameters_hash = await OutboxParametersHash(outbox_message).from_outbox_message()
except ValueError:
except ValueError as e:
self._logger.warning(f'Skip hashing outbox message. {str(e)}')
continue

self._create_outbox_batch.append(
Expand Down Expand Up @@ -370,14 +372,15 @@ async def from_outbox_message(self) -> str:
try:
transaction = outbox_message['message']['transactions'][0]
parameters_micheline = transaction['parameters']
ticket = await TezosTicket.get(ticketer_address=transaction['destination'])
michelson_outbox_interface = ticket.outbox_interface
micheline_expression = michelson_to_micheline(michelson_outbox_interface)

micheline_expression = michelson_to_micheline(MICHELSON_OUTBOX_INTERFACE)
michelson_type = MichelsonType.match(micheline_expression)

parameters_data = michelson_type.from_micheline_value(parameters_micheline).to_python_object()
parameters: WithdrawParameter = WithdrawParameter.model_validate(parameters_data)

ticket = await TezosTicket.get(ticketer_address=parameters.ticket.ticketer)

comparable_data = ComparableDTO(
receiver=str(parameters.receiver),
ticket_hash=ticket.hash,
Expand All @@ -386,7 +389,7 @@ async def from_outbox_message(self) -> str:
proxy=transaction['destination'],
)
except (AttributeError, KeyError, DoesNotExist):
raise ValueError
raise ValueError(f'Can\'t get OutboxParametersHash from message: {outbox_message}')

return self._hash_from_dto(comparable_data)

Expand Down
2 changes: 1 addition & 1 deletion bridge_indexer/handlers/service_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def register(self):
tzkt: TezosTzktDatasource = ctx.get_tezos_tzkt_datasource('tzkt')
tezos_node: HttpDatasource = ctx.get_http_datasource('tezos_node')
rollup_node: HttpDatasource = ctx.get_http_datasource('rollup_node')
metadata: TzipMetadataDatasource = ctx.get_metadata_datasource('metadata')
metadata: TzipMetadataDatasource = ctx.get_tzip_metadata_datasource('metadata')

bridge = BridgeConstantStorage()

Expand Down
6 changes: 4 additions & 2 deletions bridge_indexer/handlers/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from bridge_indexer.types.rollup.tezos_parameters.default import TicketContent as TicketContent


MICHELSON_OUTBOX_INTERFACE = 'pair (address %receiver) (pair %ticket (address %ticketer) (pair (pair %content (nat %ticket_id) (option %metadata bytes)) (nat %amount)))'

class TicketService:
def __init__(self, tzkt: 'TezosTzktDatasource', metadata: 'TzipMetadataDatasource', bridge: 'BridgeConstantStorage'):
self._tzkt: TezosTzktDatasource = tzkt
Expand Down Expand Up @@ -75,7 +77,7 @@ async def fetch_ticket(self, ticketer_address, ticket_content: TicketContent):
ticket_id=ticket_content.ticket_id,
token=token,
metadata=ticket_content.metadata_hex,
outbox_interface='pair (address %receiver) (pair %ticket (address %ticketer) (pair (pair %content (nat %ticket_id) (option %metadata bytes)) (nat %amount)))',
outbox_interface=MICHELSON_OUTBOX_INTERFACE,
whitelisted=True,
)

Expand All @@ -92,7 +94,7 @@ async def register_native_ticket(self):
ticket_id=ticket_content.ticket_id,
token=xtz,
metadata=ticket_content.metadata_hex,
outbox_interface='pair (address %receiver) (pair %ticket (address %ticketer) (pair (pair %content (nat %ticket_id) (option %metadata bytes)) (nat %amount)))',
outbox_interface=MICHELSON_OUTBOX_INTERFACE,
whitelisted=True,
)
await EtherlinkToken.create(
Expand Down
2 changes: 2 additions & 0 deletions bridge_indexer/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class Meta:
cemented_at = fields.DatetimeField(index=True, null=False)
cemented_level = fields.IntField(null=False)

failure_count = fields.IntField(null=True, default=None)

bridge_withdrawals: fields.ReverseRelation['BridgeWithdrawOperation']


Expand Down
Loading
Loading