-
Notifications
You must be signed in to change notification settings - Fork 413
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 /files/contracts/partial/{chain}
endpoint and explicit ordering, resolve SQL NULL comparison bug
#1416
Conversation
/files/contracts/partial
endpoint and explicit ordering/files/contracts/partial
endpoint and explicit ordering, resolve SQL NULL comparison bug
/files/contracts/partial
endpoint and explicit ordering, resolve SQL NULL comparison bug/files/contracts/partial/{chain}
endpoint and explicit ordering, resolve SQL NULL comparison bug
Since creation_match could get a `null` value in the database the comparisons if it's **not** equal to `perfect` were failing because any comparison against a NULL value retuns NULL in SQL. Fix these cases by using COALSCE to set NULL values to empty string on comparison
eeec824
to
28c6827
Compare
I cannot understand why this happens. Maybe the unique constraint doesn't work with a NULL column?
Right now they are not used. If we need them for the rebuilding the database we can implement them again, you can remove them |
I didn't know about it, good catch! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a doubt on why random is used, but other than that LGTM 👍
Ok I'll spin out another issue for the deduplication issue in `compiled_contracts
Ok but I don't really understand the use of the sourcify/services/server/src/server/services/utils/database-util.ts Lines 429 to 451 in 28c6827
|
Do you remember that inside sourcify_sync we had some values with |
This PR was intended to add the
/files/contracts/partial/{chain}
endpoint that is missing to list all contracts under a certain chain.However during the process, specifically when adding proper tests, I've noticed the
partial
andany
endpoints not working as expected, and some other potential issues explained below for further investigation.TLDR;
/files/contracts/partial/{chain}
endpoint as specified in Implementing/files/contracts/partial
endpoint #1415 with an option to sortasc
anddesc
compiled_contracts
matchType
not used indatabase-utils.ts
SQL NULL comparison bug
This was due to the queries being used in
countSourcifyMatchAddresses
andgetSourcifyMatchAddressesByChainAndMatch
.Both SQL queries count the number of perfect matches with
creation_match = 'perfect' OR runtime_match = 'perfect'
and the partial matches with the logical inversecreation_match != 'perfect' AND runtime_match != 'perfect'
. However this does not work as expected in SQL because thecreation_match
field in our case can beNULL
and any comparison withNULL
resolves toNULL
, and not totrue
as expected.This can also be seen by comparing the contract numbers in
stats.json
vs the API output:/stats.json
for Mainnet:/files/contracts/full/1/
:/files/contracts/any/1/
:The difference (i.e. partial count) gives 141,264 whereas from stats.json we've got 529,877.
The bug can be resolved by adding a
COALESCE(creation_match, '')
to make theNULL
values''
for comparisons.Potential issues
Deduplication not working in
compiled_contracts
When debugging the tests I've noticed the identical test contracts are getting added to the
compiled_contracts
table multiple times. I'd have expected them to be deduplicated because the table has a unique key property in the schema definition:sourcify/services/database/migrations/20231109160022-create-alliance-schema.js
Line 204 in 653952d
However during testing the contracts get added multiple times:
Am I missing something or is there something wrong?
To reproduce
add a breakpoint at
sourcify/services/server/test/integration/repository-handlers/files.spec.ts
Line 56 in 653952d
Add an
.only
modifier to describe:sourcify/services/server/test/integration/repository-handlers/files.spec.ts
Line 43 in 653952d
run the
Mocha - Server Integration
, deploy and verify multiple contracts, and connect to the test database atlocalhost:5431
.matchType
indatabase_utils.ts
While looking at the
database_utils.ts
code I've noticed thematchType
variable is not used in functions:sourcify/services/server/src/server/services/utils/database-util.ts
Line 429 in eeec824
sourcify/services/server/src/server/services/utils/database-util.ts
Line 452 in eeec824
But it seems these functions themselves are not used at all. Can they be removed?