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

Fix file contract element bug #28

Merged
merged 3 commits into from
May 15, 2024
Merged

Fix file contract element bug #28

merged 3 commits into from
May 15, 2024

Conversation

chris124567
Copy link
Member

Account for multiple revisions of the same contract in the same block. If we only look at the data from ForEachFileContractElement we will only get the latest revision which will result in missing data in fcDBIDs (the map that connects file contract IDs and their revision numbers to the file_contract_elements id in the database), which will cause addFileContracts or addFileContractRevisions to fail with "missing dbID". For example in block 22051: https://siascan.com/tx/293ba9948c6bf4ac4b639a6326421be234b73279934a9a0a4feda7012ca80722 and https://siascan.com/tx/60d7b56390e373c67066cb440f1821f46b2dd245e134556eaf4fac472a58d6e9

@chris124567 chris124567 requested a review from ChrisSchinnerl May 9, 2024 18:46
Copy link
Member

@ChrisSchinnerl ChrisSchinnerl left a comment

Choose a reason for hiding this comment

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

Since this PR specifically targets a bug to fix I'd include a regression test to both verify the issue existed and to make sure it is fixed now.

@ChrisSchinnerl ChrisSchinnerl requested a review from n8maninger May 14, 2024 10:22
@chris124567
Copy link
Member Author

chris124567 commented May 14, 2024

Since this PR specifically targets a bug to fix I'd include a regression test to both verify the issue existed and to make sure it is fixed now.

When I comment out either or both of the following loops in addFileContractElements which were introduced in this PR the newly added test fails with the same error mentioned in the PR description.

        for j, fc := range txn.FileContracts {
            fcID := txn.FileContractID(j)
            dbFC := explorer.DBFileContract{ID: txn.FileContractID(j), RevisionNumber: fc.RevisionNumber}
            if _, exists := fcDBIds[dbFC]; exists {
                continue
            }

            if err := addFC(fcID, 0, fc, false, true, false); err != nil {
                return nil, fmt.Errorf("addFileContractElements: %w", err)
            }
        }
        for _, fcr := range txn.FileContractRevisions {
            fc := fcr.FileContract
            dbFC := explorer.DBFileContract{ID: fcr.ParentID, RevisionNumber: fc.RevisionNumber}
            if _, exists := fcDBIds[dbFC]; exists {
                continue
            }

            if err := addFC(fcr.ParentID, 0, fc, false, true, false); err != nil {
                return nil, fmt.Errorf("addFileContractElements: %w", err)
            }
        }

And the test passes so I think this is good. I had to debug this odd issue with the Payout field in revisions which took longer than it should have 😄

@n8maninger n8maninger merged commit 56c7558 into master May 15, 2024
6 checks passed
@n8maninger n8maninger deleted the fix-file-contract-bug branch May 15, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants