ledger: fix lookupAssetResources/lookupApplicationResources delta-merge bugs#6577
Merged
algorandskiy merged 2 commits intoalgorand:masterfrom Mar 6, 2026
Merged
ledger: fix lookupAssetResources/lookupApplicationResources delta-merge bugs#6577algorandskiy merged 2 commits intoalgorand:masterfrom
algorandskiy merged 2 commits intoalgorand:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #6577 +/- ##
===========================================
- Coverage 63.02% 47.90% -15.12%
===========================================
Files 486 646 +160
Lines 68126 88226 +20100
===========================================
- Hits 42935 42268 -667
- Misses 21404 43182 +21778
+ Partials 3787 2776 -1011
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
gmalouf
reviewed
Mar 6, 2026
gmalouf
approved these changes
Mar 6, 2026
algorandskiy
approved these changes
Mar 6, 2026
This was referenced Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three bugs in
lookupAssetResourcesandlookupApplicationResourcesintroduced by #6559, with tests.Phantom zero-value holding/local-state from DB rows
The DB merge fallback (
acctupdates.go:1300,1446) calledGetAssetHolding()/GetAppLocalState()without checkingpd.Data.IsHolding()first. The DB knows whether a row has a holding viaResourceFlags, but the code ignored the flags and unconditionally materialized a zero-value struct. This kept rows alive through the(AssetHolding != nil || AssetParams != nil)filter when they should have been excluded. The correct pattern is already used inAccountResource()attrackerdb/data.go:272.Fixed by guarding both with
pd.Data.IsHolding().numDeltaDeletedunder-countThe over-request counter only checked
Holding.Deleted(assets) orState.Deleted(apps). A delta that deletes only params on a row with no holding/local-state (e.g., an app creator who never opted in) was not counted, so the DB page was too small and the result page came up short.Fixed by counting either deletion:
Holding.Deleted || Params.Deleted(and same for apps).Empty-page
StaleDatabaseRoundErrorThe SQL query for limited resources uses INNER JOINs, so when the address has no matching resources, zero rows are returned and the round stays at its zero value. The code then fell through to
resourceDbRound < currentDBRoundand returned aStaleDatabaseRoundError.Fixed by accepting the zero-row case:
resourceDbRound == currentDBRound || (len(persistedResources) == 0 && resourceDbRound == 0).Test Plan
Three new tests cover the bugs:
TestLookupAppResourcesParamsOnlyDeletion: params-only DB row + delta deletionTestLookupAssetResourcesEmptyPageDoesNotError: empty asset lookupTestLookupApplicationResourcesEmptyPageDoesNotError: empty app lookup