Skip to content

Commit

Permalink
Make out of order check optional
Browse files Browse the repository at this point in the history
- For some network, out of order check of transactions is really slow
- Taking as an example the last week, we only observed one out of order issue in the logs
- With this PR we can configure it via environment variables to speed up transaction processing
  • Loading branch information
Uxio0 committed Nov 7, 2024
1 parent 6bbe647 commit ce60b4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,12 @@
"ETH_REORG_BLOCKS", default=200 if ETH_L2_NETWORK else 10
) # Number of blocks from the current block number needed to consider a block valid/stable

# Events processing
# ------------------------------------------------------------------------------
PROCESSING_ENABLE_OUT_OF_ORDER_CHECK = env.bool(
"PROCESSING_ENABLE_OUT_OF_ORDER_CHECK", default=True
) # Enable out of order check, in case some transactions appear after a reindex so Safes don't get corrupt. Disabling it can speed up processing

# Tokens
# ------------------------------------------------------------------------------
TOKENS_LOGO_BASE_URI = env.str(
Expand Down
18 changes: 12 additions & 6 deletions safe_transaction_service/history/services/index_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __new__(cls):
settings.ETH_REORG_BLOCKS,
settings.ETH_L2_NETWORK,
settings.ETH_INTERNAL_TX_DECODED_PROCESS_BATCH,
settings.PROCESSING_ENABLE_OUT_OF_ORDER_CHECK,
)
return cls.instance

Expand All @@ -87,13 +88,15 @@ def __init__(
eth_reorg_blocks: int,
eth_l2_network: bool,
eth_internal_tx_decoded_process_batch: int,
processing_enable_out_of_order_check: bool,
):
self.ethereum_client = ethereum_client
self.eth_reorg_blocks = eth_reorg_blocks
self.eth_l2_network = eth_l2_network
self.eth_internal_tx_decoded_process_batch = (
eth_internal_tx_decoded_process_batch
)
self.processing_enable_out_of_order_check = processing_enable_out_of_order_check

# Prevent circular import
from ..indexers.tx_processor import SafeTxProcessor, SafeTxProcessorProvider
Expand Down Expand Up @@ -431,12 +434,15 @@ def process_decoded_txs(self, safe_address: ChecksumAddress) -> int:
"""

# Check if a new decoded tx appeared before other already processed (due to a reindex)
if InternalTxDecoded.objects.out_of_order_for_safe(safe_address):
logger.error("[%s] Found out of order transactions", safe_address)
self.fix_out_of_order(
safe_address,
InternalTxDecoded.objects.pending_for_safe(safe_address)[0].internal_tx,
)
if self.processing_enable_out_of_order_check:
if InternalTxDecoded.objects.out_of_order_for_safe(safe_address):
logger.error("[%s] Found out of order transactions", safe_address)
self.fix_out_of_order(
safe_address,
InternalTxDecoded.objects.pending_for_safe(safe_address)[
0
].internal_tx,
)

# Use chunks for memory issues
total_processed_txs = 0
Expand Down

0 comments on commit ce60b4f

Please sign in to comment.