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

Enhancement: add max int64 checks #1166

Merged
merged 4 commits into from
Aug 9, 2022
Merged

Enhancement: add max int64 checks #1166

merged 4 commits into from
Aug 9, 2022

Conversation

shiqizng
Copy link
Contributor

@shiqizng shiqizng commented Aug 5, 2022

Summary

This PR adds max int64 checks to round, application ID and asset ID in API requests.

Test Plan

Add unit tests for the handler and filter methods.

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

codecov bot commented Aug 5, 2022

Codecov Report

Merging #1166 (5a7f582) into develop (6b61b08) will increase coverage by 0.42%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1166      +/-   ##
===========================================
+ Coverage    59.85%   60.28%   +0.42%     
===========================================
  Files           51       51              
  Lines         8288     8359      +71     
===========================================
+ Hits          4961     5039      +78     
+ Misses        2868     2862       -6     
+ Partials       459      458       -1     
Impacted Files Coverage Δ
api/error_messages.go 100.00% <ø> (ø)
api/handlers.go 74.73% <100.00%> (+2.05%) ⬆️
idb/postgres/postgres.go 64.40% <100.00%> (+0.48%) ⬆️
fetcher/fetcher.go 50.87% <0.00%> (-1.32%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

api/handlers.go Outdated Show resolved Hide resolved
@@ -588,6 +589,10 @@ func (si *ServerImplementation) transactionParamsToTransactionFilter(params gene
filter.ApplicationID = uintOrDefault(params.ApplicationId)
filter.Limit = min(uintOrDefaultValue(params.Limit, si.opts.DefaultTransactionsLimit), si.opts.MaxTransactionsLimit)
filter.Round = params.Round
// Integer > math.Int64
if filter.AssetID > math.MaxInt64 || filter.ApplicationID > math.MaxInt64 || (filter.Round != nil && uint64(*filter.Round) > math.MaxInt64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that there are a lot more fields in a filter which are uint64 https://github.com/algorand/indexer/blob/develop/idb/idb.go#L196

Why are these the only ones we need to do checks for as opposed to checking all of the supplied filters?

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 moved these checks to validateTransactionFilter and added checks for all uint64 fields except for AssetAmount which is type numeric(20) in the DB table.

@@ -582,12 +582,12 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs []
partNumber++
}
if tf.AssetAmountGT != nil {
whereParts = append(whereParts, fmt.Sprintf("(t.txn -> 'txn' -> 'aamt')::bigint > $%d", partNumber))
whereParts = append(whereParts, fmt.Sprintf("(t.txn -> 'txn' -> 'aamt')::numeric(20) > $%d", partNumber))
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch, did this cause a failure before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was causing a failure for a test case I just added that has a txn with asset amount maxUint64.

@winder winder merged commit 8c49d86 into develop Aug 9, 2022
@winder winder deleted the shiqi/maxintChecks branch August 9, 2022 16:49
Eric-Warehime added a commit that referenced this pull request Sep 14, 2022
* Bump version to 2.13.0-rc1

* Bump version to 2.13.0

* Documentation for data directory. (#1125)

Co-authored-by: algobarb <[email protected]>

* Don't lookup big foreign assets. (#1141)

* Revert "Bump version to 2.13.0"

This reverts commit 0a8af61.

* Bump version to 2.13.0

* Fix import performance test runner. (#1133)

* Start on round 1 since round 0 is now computed from the genesis file.
* Wait for indexer processor to exit.
* Better logging for metric collection errors.
* Proper support for data directory.
* New test script for future release automation.

* Revert "Bump version to 2.13.0"

This reverts commit 7915890.

* Bump version to 2.13.0

* test fixes: Submodule updates (#1144)

* Update go-algorand submodule
* Fix test failure due to duplicate txns
* Add new ledger interface method

* Enhancement: remove import validator utility and obsolete ledger for evaluator (#1146)

removing a bunch of code and make the random test pass with the new ledger for evaluator

* Docs: Readme update (#1149)

* Update README header

* Testing: Use tempdir instead of /tmp for e2elive test (#1152)

* Format misc/*.py with `black` (#1153)

* apply black to e2elive.py as well (#1154)

* Enhancement: More information about S3 keys searched for and Dockerfile that uses submodule instead of channel (#1151)

* Eric's Dockerfile improvements
* Update misc/e2elive.py

* Bug-Fix: Implement BlockHdrCached + miscellany (#1162)

* Enhancement: add max int64 checks (#1166)

* state proofs: Indexer Support for State Proofs (#1002)

Adds API support to the Indexer for State Proof Transactions and header fields.

Co-authored-by: Will Winder <[email protected]>

Co-authored-by: Will Winder <[email protected]>

* Bump version to 2.14.0-rc1

* Stop Panics if no config is supplied (#1180)

Give a default config if not supplied to stop panics.

* Fix spec name collisions. (#1182)

* Update go-algorand submodule to v3.9.1-beta (#1185)

* Bump version to 2.14.0-rc2

* Disable deadlock detection (#1186)

* Add support for new block header: TxnRoot SHA256 (#989)

* Accept yaml and yml configuration files. (#1181)

* Fix bug in reveals lookup (#1198)

* Fix bug in reveals lookup (#1198)

* Bump version to 2.14.0-rc3

* add state proof example with high reveal index - from betanet (#1199)

* Devops: Bump go-algorand submodule to v3.9.2-beta (#1203)

* Bump version to 2.14.0-rc4

* enhancement: Clarify REST query parameters for accounts search (#1201)

* update description for /v2/accounts

* cicd: add darwin arm64 support to release script (#1169)

* Bump version to 2.14.0

* Downgrade mockery to prevent incorrect deprecation warning. (#1211)

* Enhancement: update e2e test policy (#1197)

*update e2e test policy

* Fix release 2.14.0 (#1214)

* Accept yaml and yml configuration files. (#1181)

* Fix bug in reveals lookup (#1198)

* add state proof example with high reveal index - from betanet (#1199)

* enhancement: Clarify REST query parameters for accounts search (#1201)

* update description for /v2/accounts

* cicd: add darwin arm64 support to release script (#1169)

* Downgrade mockery to prevent incorrect deprecation warning. (#1211)

* Enhancement: update e2e test policy (#1197)

*update e2e test policy

* Update test expected value: transaction root sha256

Co-authored-by: AlgoStephenAkiki <[email protected]>
Co-authored-by: Michael Diamant <[email protected]>
Co-authored-by: algoidan <[email protected]>
Co-authored-by: shiqizng <[email protected]>
Co-authored-by: algolucky <[email protected]>
Co-authored-by: Will Winder <[email protected]>

Co-authored-by: DevOps Service <[email protected]>
Co-authored-by: Will Winder <[email protected]>
Co-authored-by: algobarb <[email protected]>
Co-authored-by: Barbara Poon <[email protected]>
Co-authored-by: Zeph Grunschlag <[email protected]>
Co-authored-by: shiqizng <[email protected]>
Co-authored-by: AlgoStephenAkiki <[email protected]>
Co-authored-by: John Lee <[email protected]>
Co-authored-by: Or Aharonee <[email protected]>
Co-authored-by: Michael Diamant <[email protected]>
Co-authored-by: algoidan <[email protected]>
Co-authored-by: algolucky <[email protected]>
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