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

REST API: Add Header-Only parameter to blocks endpoint, return error if there are too many transactions. #1241

Merged
merged 6 commits into from
Sep 28, 2022

Conversation

shiqizng
Copy link
Contributor

@shiqizng shiqizng commented Sep 23, 2022

Summary

#332 Adding header-only parameter to GET /v2/blocks/{round-number} which would return a block excluding the transactions. If the number of the transactions in a request block exceeds MaxTransactionsLimit, the endpoint return err code 400 when header-only parameter isn't set.

Test Plan

new unit tests and integration tests.

@shiqizng shiqizng added Enhancement New feature or request Team Lamprey labels Sep 23, 2022
@shiqizng shiqizng self-assigned this Sep 23, 2022
@codecov
Copy link

codecov bot commented Sep 23, 2022

Codecov Report

Merging #1241 (ba9165e) into develop (ef29f58) will increase coverage by 0.19%.
The diff coverage is 83.87%.

@@             Coverage Diff             @@
##           develop    #1241      +/-   ##
===========================================
+ Coverage    60.92%   61.11%   +0.19%     
===========================================
  Files           52       52              
  Lines         8488     8512      +24     
===========================================
+ Hits          5171     5202      +31     
+ Misses        2859     2848      -11     
- Partials       458      462       +4     
Impacted Files Coverage Δ
api/error_messages.go 100.00% <ø> (ø)
api/generated/common/routes.go 46.51% <ø> (ø)
idb/idb.go 69.35% <0.00%> (-2.32%) ⬇️
api/generated/v2/routes.go 19.36% <75.00%> (+1.60%) ⬆️
api/handlers.go 75.70% <100.00%> (+0.22%) ⬆️
idb/postgres/postgres.go 64.45% <100.00%> (+0.05%) ⬆️
fetcher/fetcher.go 50.87% <0.00%> (-1.32%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

idb/idb.go Outdated Show resolved Hide resolved
@@ -480,6 +481,9 @@ func (db *IndexerDb) GetBlock(ctx context.Context, round uint64, options idb.Get
results := make([]idb.TxnRow, 0)
for txrow := range out {
results = append(results, txrow)
if uint64(len(results)) > options.MaxTransactionsLimit {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a limit to the idb.TransactionFilter parameters above to avoid fetching all transactions.

Be careful about off-by-one problems, I think the limit would need to be options.MaxTransactionsLimit + 1 in order for this check to be detected.

I'm not 100% certain, but I think there is also a potential deadlock related to the out channel. db.yieldTxnsThreadSimple would be stuck filling the out channel if we return early, so you need to make sure the range function exits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think with the limit filter added, we're ok with out channel. When line 484 is true, out would be empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right, but the return inside the range seems dangerous. Here's an example of clearing out the channel (I thought there were others but this is the only one I could find): https://github.com/algorand/indexer/blob/develop/api/handlers.go#L1216

Could you move the if statement to the outside of the range statement? It should still be efficient, thanks to the limit, but would also ensure that the channel is closed.

Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

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

Looks good, just had some comments about the loop that builds the block result.

@shiqizng shiqizng requested a review from winder September 28, 2022 13:45
@winder winder changed the title enhancement: blocks with many transactions REST API: Add Header-Only parameter to blocks endpoint, return error if there are too many transactions. Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Team Lamprey
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants