Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserializing of events from flow_proto fails with transactions with many events #66

Closed
franklywatson opened this issue Oct 24, 2024 · 1 comment
Assignees

Comments

@franklywatson
Copy link

A partner reported they are having an issue with this code example:

@app.route('/v2/getInfoByTransactionsId')
async def getInfoByTransactionsIdNew():
    try:
        txId = request.args.get('txId')
        app.logger.info("getInfoByTransactionsIdNew args:txId={}".format(txId))
        transaction = await get_session_client().get_transaction(id=bytes.fromhex(txId))
        transaction_result_response = await get_session_client().get_transaction_result(id=bytes.fromhex(txId))
        result_json = {"id": txId, "authorizers": "[" + "".join([i.hex() for i in transaction.authorizers]) + "]",
                       "events": [json.loads(event.payload.decode("utf-8")) for event in
                                  transaction_result_response.events], "payer": transaction.payer.hex(),
                       "payload": transaction.script.hex(),
                       "status": transaction_status_mapping[transaction_result_response.status]}
        return json.dumps(result_json)
    except Exception:
        traceback.print_exc()
        app.logger.error(traceback.format_exc())
        return traceback.format_exc()

They shared that:

Error occurred in transaction_result_response = await get_session_client().get_transaction_result(id=bytes.fromhex(txId))
I debug flow sdk. There seem to be some issues here. line 515 in clinet.py entities.TransactionResultResponse.from_proto(response, id=id) There are probably too many events in tx ef6e6dcba87c5f853e0ec940dd382d609ffe11109c28ed239843d71618fa1d71 to from_proto failed.

photo_6107171108542332275_y
photo_6107171108542332274_y

@lealobanov
Copy link
Collaborator

Managed to reproduce the call and 3 of the events are failing to deserialize, please see attached JSON file with a copy of their payloads:
failed_events.json

We have implemented a fix in this PR which adds decoding to nested structures within a payload (seems like the issue was coming from nested fields inside the Event payload such as Entitlements authorizationsthat were failing to decode). We also tested introducing restrictions on the event payload size or max. number of events per transaction, but those did not appear to cause any issues once the decoding issue was resolved.

PR with fix: #67

@lealobanov lealobanov self-assigned this Oct 28, 2024
janezpodhostnik added a commit that referenced this issue Nov 4, 2024
#66/ Deserializing of events from flow_proto fails with transactions with many events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants