cardano-foundation/cardano-graphql

tokenMints_aggregate->sum->quantity giving inconsistent results

KingOsman opened this issue · 1 comments

Summary

Given the query below

query assetsForPolicyId($policy_id: Hash28Hex!, $offset: Int!) {
  assets(
    where: { 
        policyId: { _eq: $policy_id }
    }
    limit: 2500
    offset: $offset
  ) {
    assetId
    tokenMints_aggregate {
      aggregate {
        count
        sum {
          quantity
        }
      }
    }
  }
}

variables:  {
"policy_id": "d9f8b0ecf8a3ab299c8413edc44bd0cfdf7aadf1648655391fcb30ed",
"offset": 0
}

the 'quantity' field keeps changing. the summation is not consistent. idea is to consider assets whose count/quantity is 1 (NFTs) to come up with a final count. unfortunately i always get different values. the policy has both mint and burn transactions so some math is involved here for sure - it's not just positive summations.

Steps to reproduce the bug

  1. send query above to graphql (loop through 2.5k at a time and set your offset to be the running length of your assets)
  2. initial vars: {
    "policy_id": "d9f8b0ecf8a3ab299c8413edc44bd0cfdf7aadf1648655391fcb30ed",
    "offset": 0
    }
  3. sum up quantity in result for each asset
  4. repeat the steps above a second, third and fourth time and compare results

some code here...

results = []
policy_id = "d9f8b0ecf8a3ab299c8413edc44bd0cfdf7aadf1648655391fcb30ed"
for i in range(1,10): #run the query a number of times
    results.append(get_policy_asset_quantities(policy_id)) 

for r in results:
    lst_tmp = [asset for asset in r if asset["tokenMints_aggregate"]["aggregate"]["sum"]["quantity"] == "1"]
    print(len(lst_tmp))

Actual Result

output of the print:
7166
7104
7182
7275
7182
7241
7143
7231
7312

Expected Result

I expect the resultant lists to be the same length - they are originating from the same query and filtered the same way. It always varies. Sometimes the quantity is 0 for the assets, sometimes not. This is unreliable data.

Environment

I see this in my local environment but also when I use the public graphql endpoint found below.
It's very easy to reproduce.

https://graphql-api.mainnet.dandelion.link/

Platform

  • Linux (Ubuntu)
  • Linux (Other)
  • macOS
  • Windows

Platform version

No response

Runtime

  • Node.js
  • Docker

Runtime version

No response

oops... the query was returning similar assets on every new page request. i fixed it by enforcing ordering. thanks and sorry for the confusion. if you add this to the GQL query it fixes it

order_by: {assetId: asc}