Skip to content

Commit

Permalink
Fix (ZkSync-lite): Notify decoding progress
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <ojuswimail@gmail.com>
  • Loading branch information
OjusWiZard committed May 21, 2024
1 parent 370aa2f commit dcd4009
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Changelog
=========

* :bug:`7905` rotki will now properly show the decoding progress of zksync-lite transactions.
* :feature:`7358` Added support for detection of staked GRT tokens on Arbitrum.
* :bug:`-` Fix the issue where the MATIC amount always shows as zero in the Polygon balance table.
* :bug:`7915` Show OKX balances locked in active trades.
Expand Down
4 changes: 2 additions & 2 deletions docs/websockets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ When the endpoint to start the task for decoding undecoded transactions is queri

{
"type": "evm_undecoded_transactions",
"data": {evm_chain":"ethereum", "total":2, "processed":0}
"data": {chain":"ethereum", "total":2, "processed":0}
}


- ``evm_chain``: Evm chain where the task is decoding transactions.
- ``chain``: Chain where the task is decoding transactions.
- ``total``: Total number of transactions that will be decoded.
- ``processed``: The total number of transactions that have already been decoded.

Expand Down
5 changes: 4 additions & 1 deletion rotkehlchen/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,10 @@ def decode_pending_evmlike_transactions(
"""
decoded_num = 0
# For now it's only zksync lite
decoded_num = self.rotkehlchen.chains_aggregator.zksync_lite.decode_undecoded_transactions(force_redecode=ignore_cache) # noqa: E501
decoded_num = self.rotkehlchen.chains_aggregator.zksync_lite.decode_undecoded_transactions(
force_redecode=ignore_cache,
send_ws_notifications=True,
)
return {
'result': {'decoded_tx_number': decoded_num},
'message': '',
Expand Down
4 changes: 2 additions & 2 deletions rotkehlchen/chain/evm/decoding/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def decode_transaction_hashes(
self.msg_aggregator.add_message(
message_type=WSMessageType.EVM_UNDECODED_TRANSACTIONS,
data={
'evm_chain': self.evm_inquirer.chain_name,
'chain': self.evm_inquirer.chain_name,
'total': total_transactions,
'processed': tx_index,
},
Expand Down Expand Up @@ -602,7 +602,7 @@ def decode_transaction_hashes(
self.msg_aggregator.add_message(
message_type=WSMessageType.EVM_UNDECODED_TRANSACTIONS,
data={
'evm_chain': self.evm_inquirer.chain_name,
'chain': self.evm_inquirer.chain_name,
'total': total_transactions,
'processed': total_transactions,
},
Expand Down
33 changes: 30 additions & 3 deletions rotkehlchen/chain/zksync_lite/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pysqlcipher3.dbapi2 import IntegrityError

from rotkehlchen.accounting.structures.balance import Balance
from rotkehlchen.api.websockets.typedefs import WSMessageType
from rotkehlchen.assets.asset import Asset, CryptoAsset
from rotkehlchen.assets.utils import TokenEncounterInfo, get_or_create_evm_token
from rotkehlchen.chain.ethereum.utils import asset_normalized_value
Expand Down Expand Up @@ -838,9 +839,14 @@ def decode_transaction(
(1, transaction.tx_hash),
)

def decode_undecoded_transactions(self, force_redecode: bool) -> int:
def decode_undecoded_transactions(
self,
force_redecode: bool,
send_ws_notifications: bool = False,
) -> int:
"""Decodes undecoded zksync lite transactions. If force redecode is True
then all transactions are redecoded.
then all transactions are redecoded. If send_ws_notifications is True then the decoding
progress is broadcasted via websocket messages.
Returns the number of decoded transactions (not events in transactions)
"""
queryfilter, bindings = '', ()
Expand All @@ -851,7 +857,8 @@ def decode_undecoded_transactions(self, force_redecode: bool) -> int:
with self.database.conn.read_ctx() as cursor:
tracked_addresses = self.database.get_blockchain_accounts(cursor).zksync_lite

for transaction in transactions:
total_transactions = len(transactions)
for tx_index, transaction in enumerate(transactions):
with self.database.user_write() as write_cursor: # delete old tx events
write_cursor.execute(
'DELETE FROM history_events WHERE event_identifier=?',
Expand All @@ -860,4 +867,24 @@ def decode_undecoded_transactions(self, force_redecode: bool) -> int:

self.decode_transaction(transaction, tracked_addresses)

if send_ws_notifications and tx_index % 10 == 0:
self.database.msg_aggregator.add_message(
message_type=WSMessageType.EVM_UNDECODED_TRANSACTIONS,
data={
'chain': 'zksync lite',
'total': total_transactions,
'processed': tx_index,
},
)

if send_ws_notifications:
self.database.msg_aggregator.add_message(
message_type=WSMessageType.EVM_UNDECODED_TRANSACTIONS,
data={
'chain': 'zksync lite',
'total': total_transactions,
'processed': total_transactions,
},
)

return len(transactions)
4 changes: 2 additions & 2 deletions rotkehlchen/tests/api/test_ethereum_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,10 +1354,10 @@ def test_decoding_missing_transactions(
assert result['decoded_tx_number']['ethereum'] == len(transactions)

websocket_connection.wait_until_messages_num(num=4, timeout=4)
assert websocket_connection.pop_message() == {'type': 'evm_undecoded_transactions', 'data': {'evm_chain': 'ethereum', 'total': 2, 'processed': 0}} # noqa: E501
assert websocket_connection.pop_message() == {'type': 'evm_undecoded_transactions', 'data': {'chain': 'ethereum', 'total': 2, 'processed': 0}} # noqa: E501
assert websocket_connection.pop_message()
assert websocket_connection.pop_message()
assert websocket_connection.pop_message() == {'type': 'evm_undecoded_transactions', 'data': {'evm_chain': 'ethereum', 'total': 2, 'processed': 2}} # noqa: E501
assert websocket_connection.pop_message() == {'type': 'evm_undecoded_transactions', 'data': {'chain': 'ethereum', 'total': 2, 'processed': 2}} # noqa: E501

dbevents = DBHistoryEvents(rotki.data.db)
with rotki.data.db.conn.read_ctx() as cursor:
Expand Down

0 comments on commit dcd4009

Please sign in to comment.