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

Add v2 file contract revisions #133

Merged
merged 7 commits into from
Nov 5, 2024
Merged

Conversation

chris124567
Copy link
Member

No description provided.

persist/sqlite/v2consensus.go Show resolved Hide resolved
persist/sqlite/v2transactions.go Show resolved Hide resolved
persist/sqlite/v2transactions.go Show resolved Hide resolved
persist/sqlite/v2transactions.go Outdated Show resolved Hide resolved
Copy link
Member

@peterjan peterjan left a comment

Choose a reason for hiding this comment

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

LGTM, left some nits and suggestions on fillV2TransactionFileContractRevisions

}

if len(parents) != len(revisions) {
panic("should have a parent for every v2 revision contract")
Copy link
Member

Choose a reason for hiding this comment

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

Is this panic absolutely necessary? I can see how we want to, in some cases, panic when we have db corruption but seems quite harsh.

Copy link
Member

Choose a reason for hiding this comment

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

I think the statements can be combined using UNION ALL, you add something like "SELECT "parent", ... UNION ALL SELECT "revision" to differentiate the two and then collectFileContracts returns two slices.

var kind string
if err := rows.Scan(&kind); err != nil {
    return nil, fmt.Errorf("failed to scan contract type: %w", err)
}

fce, err := scanV2FileContract(rows)
if err != nil {
    return nil, fmt.Errorf("failed to scan file contract: %w", err)
}

if kind == "parent" {
    parents = append(contracts, fce)
} else {
    revisions = append(contracts, fce)
}

Copy link
Member

Choose a reason for hiding this comment

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

Not sure how well this would perform but something this would get rid of the duplicate select expression and clearly show what's happening.

WITH 
    base_data AS (SELECT field1, field2, field3 FROM t1 INNER JOIN t2),
    revision_data AS (SELECT *, "revision" as kind FROM base_data),
    parent_data AS (SELECT *, "parent" as kind FROM base_data)
SELECT * FROM revision_data ORDER BY x
UNION ALL
SELECT * FROM parent_data ORDER BY x

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried doing something along these lines but I don't think this is worth it unless we find we're having performance issues with the current queries. It makes the query more complicated and it seems that calling Scan twice on the same Rows doesn't work so we'd need to change the FCE scan helper too because we can't get the kind separately from the rest of the data.

@chris124567 chris124567 merged commit f3fe466 into v2 Nov 5, 2024
8 checks passed
@chris124567 chris124567 deleted the add-v2-file-contract-revisions branch November 5, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants