Skip to content

Commit

Permalink
Fix: no infinite loop on tx from unauthorized emitter (#480)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odesenfans authored Oct 3, 2023
1 parent e89d27f commit 0f16a54
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/aleph/chains/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0f16a54

Please sign in to comment.