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

Guarantee the order of transactions in the block endpoint #489

Conversation

wei-wang-cb
Copy link
Contributor

@wei-wang-cb wei-wang-cb commented Jul 22, 2023

Motivation

This commit guarantees the order of transactions in the block endpoint. This can benefit clients in a certain way. For example, some Rosetta client requires transaction kept in order so that they can identify the coinbase (lower-case c) transaction in one block.

Solution

It does so by creating a map of fetched transactions and using that map to return the transactions in the original order they had in the block.

  • Added a new struct FetchedTransaction to represent fetched transactions
  • Updated fetchChannelTransactions to use the new FetchedTransaction struct
  • Updated UnsafeTransactions to use the new FetchedTransaction struct and create a map of fetched transactions
  • Modified the return statement in UnsafeTransactions to use the fetched transactions from the map

This PR also improves some security issues raised by salus check.

Open questions

This commit guarantees the order of transactions in the block endpoint. It does so by creating a map of fetched transactions and using that map to return the transactions in the original order they had in the block.

- Added a new struct `FetchedTransaction` to represent fetched transactions
- Updated `fetchChannelTransactions` to use the new `FetchedTransaction` struct
- Updated `UnsafeTransactions` to use the new `FetchedTransaction` struct and create a map of fetched transactions
- Modified the return statement in `UnsafeTransactions` to use the fetched transactions from the map
This commit adds a timeout to the mock server to prevent it from hanging indefinitely. This is mainly to make salus security scans happy.
This commit fixes a memory leak in the client. The client was not reading the response body of the http request when closing the body, which could lead to a memory leak. This commit fixes this by reading the response body and discarding it.

This commit makes salus check pass.
@GeekArthur
Copy link
Contributor

two generic comments (i will leave them in the PR as well):

  1. please run rosetta validation for Dogecoin and at least one non-Dogecoin asset to ensure there are no regressions as rosetta-sdk-go is a common library that is used by many Rosetta assets and Rosetta validation itself
  2. please track the performance difference as seems like we add additional linear layer for sorting so the time complexity can change from O(n) to O(c * n)

@wei-wang-cb
Copy link
Contributor Author

Hi @GeekArthur , I've done rosetta validation (check-data) for two asset and they all passed. Could you help me merge this PR?

@GeekArthur GeekArthur merged commit c8a1eee into coinbase:master Aug 23, 2023
16 checks passed
@wei-wang-cb wei-wang-cb deleted the wei/maintain-other-tx-order-in-block-endpoint branch August 23, 2023 16:45
@xiaying-peng
Copy link
Contributor

are the api_xyz.go changes generated by codegen.sh?
We should add minimal test coverage on these kinds of changes.
cc @GeekArthur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants