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 bfed2b7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 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
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
34 changes: 31 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 @@ -61,6 +62,7 @@ def __init__(
database: 'DBHandler',
) -> None:
self.database = database
self.msg_aggregator = database.msg_aggregator
self.session = requests.session()
set_user_agent(self.session)
self.id_to_token: dict[int, CryptoAsset] = {}
Expand Down Expand Up @@ -838,9 +840,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 +858,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 +868,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.msg_aggregator.add_message(
message_type=WSMessageType.EVM_UNDECODED_TRANSACTIONS,
data={
'evm_chain': self.ethereum_inquirer.chain_name,
'total': total_transactions,
'processed': tx_index,
},
)

if send_ws_notifications:
self.msg_aggregator.add_message(
message_type=WSMessageType.EVM_UNDECODED_TRANSACTIONS,
data={
'evm_chain': self.ethereum_inquirer.chain_name,
'total': total_transactions,
'processed': total_transactions,
},
)

return len(transactions)

0 comments on commit bfed2b7

Please sign in to comment.