Skip to content

Commit

Permalink
Set max account API resource limit to 1000. (#933)
Browse files Browse the repository at this point in the history
Co-authored-by: chris erway <[email protected]>
  • Loading branch information
winder and cce authored Mar 18, 2022
1 parent 21e8a98 commit 46a1099
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
23 changes: 18 additions & 5 deletions api/handlers_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
)

var defaultOpts = ExtraOptions{
MaxAPIResourcesPerAccount: 1000,

MaxTransactionsLimit: 10000,
DefaultTransactionsLimit: 1000,

Expand Down Expand Up @@ -260,10 +262,11 @@ func TestAccountExcludeParameters(t *testing.T) {
//////////

testCases := []struct {
address basics.Address
exclude []string
check func(*testing.T, generated.AccountResponse)
errStatus int
address basics.Address
exclude []string
check func(*testing.T, generated.AccountResponse)
errStatus int
includeDeleted bool
}{{
address: test.AccountA,
exclude: []string{"all"},
Expand All @@ -281,6 +284,15 @@ func TestAccountExcludeParameters(t *testing.T) {
require.NotNil(t, r.Account.Assets)
require.NotNil(t, r.Account.AppsLocalState)
}}, {
address: test.AccountA,
exclude: []string{},
includeDeleted: true,
check: func(t *testing.T, r generated.AccountResponse) {
require.NotNil(t, r.Account.CreatedAssets)
require.NotNil(t, r.Account.CreatedApps)
require.NotNil(t, r.Account.Assets)
require.NotNil(t, r.Account.AppsLocalState)
}}, {
address: test.AccountA,
check: func(t *testing.T, r generated.AccountResponse) {
require.NotNil(t, r.Account.CreatedAssets)
Expand Down Expand Up @@ -346,7 +358,7 @@ func TestAccountExcludeParameters(t *testing.T) {
for _, tc := range testCases {
t.Run(fmt.Sprintf("exclude %v", tc.exclude), func(t *testing.T) {
c, api, rec := setupReq("/v2/accounts/:account-id", "account-id", tc.address.String())
err := api.LookupAccountByID(c, tc.address.String(), generated.LookupAccountByIDParams{Exclude: &tc.exclude})
err := api.LookupAccountByID(c, tc.address.String(), generated.LookupAccountByIDParams{IncludeAll: &tc.includeDeleted, Exclude: &tc.exclude})
require.NoError(t, err)
if tc.errStatus != 0 {
require.Equal(t, tc.errStatus, rec.Code)
Expand Down Expand Up @@ -522,6 +534,7 @@ func TestAccountMaxResultsLimit(t *testing.T) {
includeDeleted bool
errStatus int
}{
{address: test.AccountA, exclude: []string{}, errStatus: http.StatusBadRequest},
{address: test.AccountA, exclude: []string{"all"}},
{address: test.AccountA, exclude: []string{"created-assets", "created-apps", "apps-local-state", "assets"}},
{address: test.AccountA, exclude: []string{"assets", "created-apps"}},
Expand Down
2 changes: 1 addition & 1 deletion cmd/algorand-indexer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func init() {
daemonCmd.Flags().MarkHidden("enable-all-parameters")
}

daemonCmd.Flags().Uint32VarP(&maxAPIResourcesPerAccount, "max-api-resources-per-account", "", 0, "set the maximum total number of resources (created assets, created apps, asset holdings, and application local state) per account that will be allowed in REST API lookupAccountByID and searchForAccounts responses before returning a 400 Bad Request. Set zero for no limit (default: unlimited)")
daemonCmd.Flags().Uint32VarP(&maxAPIResourcesPerAccount, "max-api-resources-per-account", "", 1000, "set the maximum total number of resources (created assets, created apps, asset holdings, and application local state) per account that will be allowed in REST API lookupAccountByID and searchForAccounts responses before returning a 400 Bad Request. Set zero for no limit")

daemonCmd.Flags().Uint32VarP(&maxTransactionsLimit, "max-transactions-limit", "", 10000, "set the maximum allowed Limit parameter for querying transactions")
daemonCmd.Flags().Uint32VarP(&defaultTransactionsLimit, "default-transactions-limit", "", 1000, "set the default Limit parameter for querying transactions, if none is provided")
Expand Down
12 changes: 6 additions & 6 deletions idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ func (db *IndexerDb) checkAccountResourceLimit(ctx context.Context, tx pgx.Tx, o
var rewardsbase uint64
var keytype *string
var accountDataJSONStr []byte
var holdingCount, assetCount, appCount, lsCount uint64
var holdingCount, assetCount, appCount, lsCount sql.NullInt64
cols := []interface{}{&addr, &microalgos, &rewardstotal, &createdat, &closedat, &deleted, &rewardsbase, &keytype, &accountDataJSONStr}
if countOnly {
if o.IncludeAssetHoldings {
Expand Down Expand Up @@ -1788,10 +1788,10 @@ func (db *IndexerDb) checkAccountResourceLimit(ctx context.Context, tx pgx.Tx, o
// check limit against filters (only count what would be returned)
var resultCount, totalAssets, totalAssetParams, totalAppLocalStates, totalAppParams uint64
if countOnly {
totalAssets = holdingCount
totalAssetParams = assetCount
totalAppLocalStates = lsCount
totalAppParams = appCount
totalAssets = uint64(holdingCount.Int64)
totalAssetParams = uint64(assetCount.Int64)
totalAppLocalStates = uint64(lsCount.Int64)
totalAppParams = uint64(appCount.Int64)
} else {
totalAssets = ad.TotalAssets
totalAssetParams = ad.TotalAssetParams
Expand Down Expand Up @@ -1948,7 +1948,7 @@ func (db *IndexerDb) buildAccountQuery(opts idb.AccountQueryOptions, countOnly b
where = ` WHERE NOT la.deleted`
}
if countOnly {
selectCols = `count(*) as app_count`
selectCols = `count(*) as ls_count`
} else {
selectCols = `json_agg(la.app) as lsapps, json_agg(la.localstate) as lsls, json_agg(la.created_at) as ls_created_at, json_agg(la.closed_at) as ls_closed_at, json_agg(la.deleted) as ls_deleted`
}
Expand Down
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sql_test `<description>` `<database>` `<query>` `<substring>`

# Debugging

You'll need to break before the `algorand-indexer import` call and startup your debugger in import mode.
Add true to the end of the `algorand-indexer import` call, use the provided command to initialize indexer.

It may be useful to edit one of the entry point scripts to make sure the dataset you're interested in is loaded first.

Expand Down
4 changes: 2 additions & 2 deletions test/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,12 @@ function create_delete_tests() {
'"created-at-round": 13' \
'"deleted-at-round": 37'

rest_test "[rest - account/application] account with a deleted application" \
rest_test "[rest - account/application] account with a deleted application excluded" \
"/v2/accounts/XNMIHFHAZ2GE3XUKISNMOYKNFDOJXBJMVHRSXVVVIK3LNMT22ET2TA4N4I?pretty" \
200 \
false \
'"id": 82'
rest_test "[rest - account/application] account with a deleted application" \
rest_test "[rest - account/application] account with a deleted application included" \
"/v2/accounts/XNMIHFHAZ2GE3XUKISNMOYKNFDOJXBJMVHRSXVVVIK3LNMT22ET2TA4N4I?pretty&include-all=true" \
200 \
true \
Expand Down

0 comments on commit 46a1099

Please sign in to comment.