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

feat: truncate children in tx detail API to return at most 100 elements #350

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

pedroferreira1
Copy link
Member

Motivation

There are networks with low quantity of transactions that remain for a long time without transactions. Because of that, the latest tx keeps being used by blocks as parent, so it list of children increases a lot. The explorer service lambda returns 502 for any response bigger than 6mb, so some transactions (https://explorer.testnet.hathor.network/transaction/00e161a6b0bee1781ea9300680913fb76fd0fac4acab527cd9626cc1514abdc9, for example) were not being loaded.

There's no reason for the UI to receive a list of 193k elements. We should paginate it, if we decide that it's important to show all of them. For now, we are truncating it and returning the latest 100 elements.

Acceptance Criteria

  • Truncate children list in the tx detail API to return at most 100 elements.

Security Checklist

  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@pedroferreira1 pedroferreira1 self-assigned this Oct 23, 2024
# service we will truncate it and return only the latest 100 to show in the UI
# (it might even be more than we should, maybe we should paginate in the future)
if 'meta' in response and 'children' in response['meta']:
response['meta']['children'] = response['meta']['children'][-100:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Move 100 to the config.

Suggested change
response['meta']['children'] = response['meta']['children'][-100:]
response['meta']['children'] = response['meta']['children'][-TX_DAG_CHILDREN_CUTOFF:]

Or MAX_TX_CHILDREN.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7dd79d0 done

# service we will truncate it and return only the latest 100 to show in the UI
# (it might even be more than we should, maybe we should paginate in the future)
if 'meta' in response and 'children' in response['meta']:
response['meta']['children'] = response['meta']['children'][-100:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think we can be stricter with this.
We can just cap at 20 instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, 20 should be more than enough. But we are currently showing everything, so I prefer keeping it as a "big" number for now, and we can reduce it in the future if we prefer.

@pedroferreira1 pedroferreira1 requested a review from r4mmer October 23, 2024 21:06
@pedroferreira1 pedroferreira1 merged commit 19ed286 into dev Oct 23, 2024
4 checks passed
@pedroferreira1 pedroferreira1 deleted the feat/truncate-children-tx-detail branch October 23, 2024 21:15
@pedroferreira1 pedroferreira1 mentioned this pull request Oct 23, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants