From 0f16a543e8d590a34e181aec0439697f291cc5ad Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Tue, 3 Oct 2023 15:41:12 +0200 Subject: [PATCH] Fix: no infinite loop on tx from unauthorized emitter (#480) Problem: the Ethereum sync tx handler enters an infinite loop when the last transaction from the sync smart contract comes from an unauthorized emitter. The problem arises because the Ethereum height is not stored when this occurs. Solution: store the last height in all cases. --- src/aleph/chains/ethereum.py | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/aleph/chains/ethereum.py b/src/aleph/chains/ethereum.py index 1f9e69fc8..757233b32 100644 --- a/src/aleph/chains/ethereum.py +++ b/src/aleph/chains/ethereum.py @@ -195,36 +195,36 @@ async def _request_transactions( publisher = event_data.args.addr timestamp = event_data.args.timestamp - if publisher not in config.ethereum.authorized_emitters.value: - LOGGER.info( - "TX with unauthorized emitter %s in block %s" - % (publisher, event_data.blockNumber) - ) - continue - - last_height = event_data.blockNumber + if publisher in config.ethereum.authorized_emitters.value: + message = event_data.args.message + try: + jdata = json.loads(message) + context = TxContext( + chain=CHAIN_NAME, + hash=event_data.transactionHash.hex(), + time=timestamp, + height=event_data.blockNumber, + publisher=publisher, + ) + yield jdata, context - message = event_data.args.message - try: - jdata = json.loads(message) - context = TxContext( - chain=CHAIN_NAME, - hash=event_data.transactionHash.hex(), - time=timestamp, - height=event_data.blockNumber, - publisher=publisher, - ) - yield jdata, context + except json.JSONDecodeError: + # if it's not valid json, just ignore it... + LOGGER.info("Incoming logic data is not JSON, ignoring. %r" % message) - except json.JSONDecodeError: - # if it's not valid json, just ignore it... - LOGGER.info("Incoming logic data is not JSON, ignoring. %r" % message) + except Exception: + LOGGER.exception("Can't decode incoming logic data %r" % message) - except Exception: - LOGGER.exception("Can't decode incoming logic data %r" % message) + else: + LOGGER.info( + "TX with unauthorized emitter %s in block %s", + publisher, + event_data.blockNumber, + ) # Since we got no critical exception, save last received object # block height to do next requests from there. + last_height = event_data.blockNumber if last_height: with self.session_factory() as session: upsert_chain_sync_status(