Repository navigation
fix: db error in ListTransactions - #1081
Merged
Merged
Conversation
dzolt-4chain
previously approved these changes
Oct 28, 2026
kuba-4chain
previously approved these changes
Oct 28, 2026
pawellewandowski98
dismissed stale reviews from kuba-4chain and dzolt-4chain
via
October 28, 2026 13:02
c71e157
|
pawellewandowski98
enabled auto-merge (squash)
October 28, 2026 13:27
kuba-4chain
approved these changes
Oct 28, 2026
dzolt-4chain
approved these changes
Oct 28, 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.



Load labels and tags by row id to fix "stack depth limit exceeded" on Postgres
What Changed
loadLabels(pkg/internal/storage/repo/transactions.go).FindTransactionsuses it instead of GORM'sPreloadof the many2manyLabels.loadTags(pkg/internal/storage/repo/outputs.go).ListAndCountOutputs(whenIncludeTagsis set) andFindInputsAndOutputsWithBasketsuse it instead ofPreload("Tags").bsv_labels/bsv_tagsand filter on the single id column:transaction_id IN (...)oroutput_id IN (...).relationBatchSize(5,000), well under the bind-parameter limits of SQLite (32,766) and Postgres (65,535).ListAndCountOutputs, tags are loaded after the paged query, only for the rows on that page.Why It Was Necessary
ListTransactionsfailed withERROR: stack depth limit exceededonce a user had a few thousand transactions.LabelandTagare keyed by(name, user_id), soPreloadloads them with a row-value list,WHERE (name, user_id) IN ((..),(..),...), one tuple per distinct label or tag. Postgres fails to evaluate that list somewhere between 5,000 and 8,000 tuples.FindTransactions, used byListTransactions, abort and abort-abandoned;ListAndCountOutputs, used byListOutputswith tags and by balance;FindInputsAndOutputsWithBaskets, used byListActions.Testing Performed
TestFindTransactions_ManyDistinctLabels(repo/transactions_find_labels_test.go):TestOutputs_ManyDistinctTags(repo/outputs_tags_test.go):ListAndCountOutputswith tags andFindInputsAndOutputsWithBaskets.go test ./pkg/internal/storage/repo/ -run ManyDistinctTEST_DB_MODE=postgres go test ./pkg/internal/storage/repo/ -run ManyDistinctImpact / Risk
Preload("Labels")calls load a single transaction, so they never build a large list.(tx_id, vout) IN (...)list for no-send change outpoints stays small in practice.