Magickbase / godwoken_explorer

Godwoken Explorer
https://v1.gwscan.com
18 stars 9 forks source link

[v1.1] Multiple token with same id but different balances are returned #542

Closed Keith-CY closed 2 years ago

Keith-CY commented 2 years ago

image address: 0x23333496565720d945784a35aa655471493c0641

There're several udts of id: 1 are returned, with different balances`

Naupio commented 2 years ago

link #555

Keith-CY commented 2 years ago

link #555

Better to add reason and solution in the commit message so others who don't know about elixir can understand this commit, it's also a good habit to work on open source projects

Keith-CY commented 2 years ago

Issue of repeated udts is fixed by this commit, but it cannot explain why there're multiple different balances.

Keith-CY commented 2 years ago

image image

CKB balances of 0x23333496565720d945784a35aa655471493c0641 from graphql and rpc are not the same

Naupio commented 2 years ago

account udt table has multiple row with same udt id, the result must filter the stale row and use latest updated_at row to show

Naupio commented 2 years ago

account ckb should query with account_ckbs api, not show in account udts api link #565

Keith-CY commented 2 years ago

account ckb should query with account_ckbs api, not show in account udts api link #565

It's better to include ckb in udt list because it is at the same position as other bridge udts on layer2, except it's native token on layer1.

Besides, the value is still incorrect returned by account_ckbs image

Keith-CY commented 2 years ago

account udt table has multiple row with same udt id, the result must filter the stale row and use latest updated_at row to show

It is not reasonable to have multiple records of the same id

Naupio commented 2 years ago

on v1.1 staging env: multiple token which udt=1 was invalid data that generated by previous version with some bug, we will clear the invalid data in the v1.1 staging database

Naupio commented 2 years ago

According to me and Miles discussion, we will use account_udt table data to show the ckb(also a layer2 udt) balance with normal query. we will do not use rpc to fetch godwoken node ckb api to show the data.

Naupio commented 2 years ago

this issue need fix stale data on v1.1 staging database. cc @zmcNotafraid

Naupio commented 2 years ago

address with: 0x23333496565720d945784a35aa655471493c0641

restfull rpc fetch ckb data: https://api.v1-betanet.gwscan.com/api/accounts/0x23333496565720d945784a35aa655471493c0641

result:

{"ckb":"3909.999999999996251051","eth_addr":"0x23333496565720d945784a35aa655471493c0641","id":79,"transfer_count":38,"tx_count":93,"type":"eth_user","user":{"nonce":"93","udt_list":[{"balance":"499990000000000000000000000","icon":null,"id":889,"name":null,"symbol":null,"type":"bridge","udt_decimal":null,"updated_at":"2022-05-12T17:08:34"},{"balance":"499989900000000000000000000","icon":null,"id":888,"name":null,"symbol":null,"type":"bridge","udt_decimal":null,"updated_at":"2022-05-12T17:08:30"},{"balance":"499999999999999980000000000","icon":null,"id":887,"name":null,"symbol":null,"type":"bridge","udt_decimal":null,"updated_at":"2022-05-12T17:08:28"},{"balance":"499999999999999979911554801","icon":null,"id":886,"name":null,"symbol":null,"type":"bridge","udt_decimal":null,"updated_at":"2022-05-12T17:08:23"},{"balance":"761007953602454563398","icon":null,"id":374,"name":null,"symbol":null,"type":"bridge","udt_decimal":null,"updated_at":"2022-05-17T04:52:45"},{"balance":"10000","icon":"https://cryptologos.cc/logos/usd-coin-usdc-logo.svg?v=002","id":80,"name":"USD Coin","symbol":"USDC","type":"bridge","udt_decimal":18,"updated_at":"2022-05-12T07:09:19"}]}}
Naupio commented 2 years ago

address with: 0x23333496565720d945784a35aa655471493c0641

graphql fetch ckb data on account_udts table:

query {
  account_ckbs(
    input: { address_hashes: ["0x23333496565720d945784a35aa655471493c0641"] }
  ) {
    address_hash
    balance
  }

  account_udts(
    input: { address_hashes: ["0x23333496565720d945784a35aa655471493c0641"] }
  ) {
    address_hash
    balance
    udt {
      decimal
      id
      type
      name
      bridge_account_id
    }
  }
}

result

{
  "data": {
    "account_ckbs": [
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "3259999999999996251051"
      }
    ],
    "account_udts": [
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "3259999999999996251051",
        "udt": {
          "bridge_account_id": null,
          "decimal": null,
          "id": "1",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "10000000000000000000000",
        "udt": {
          "bridge_account_id": 238,
          "decimal": 18,
          "id": "80",
          "name": "USD Coin",
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "761007953602454563398",
        "udt": {
          "bridge_account_id": null,
          "decimal": null,
          "id": "374",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499999999999999979911554801",
        "udt": {
          "bridge_account_id": null,
          "decimal": null,
          "id": "886",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499999999999999980000000000",
        "udt": {
          "bridge_account_id": null,
          "decimal": null,
          "id": "887",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499989900000000000000000000",
        "udt": {
          "bridge_account_id": null,
          "decimal": null,
          "id": "888",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499990000000000000000000000",
        "udt": {
          "bridge_account_id": null,
          "decimal": null,
          "id": "889",
          "name": null,
          "type": "BRIDGE"
        }
      }
    ]
  }
}
Naupio commented 2 years ago

it seems the fetcher is not in the correct way to running, we need to fix it on the account_udt table

cc @zmcNotafraid

Naupio commented 2 years ago

multitoken was fixed by clear stale data on the account_udt table

example:

    query {
      account_udts(input: {address_hashes: ["0x23333496565720d945784a35aa655471493c0641"]}) {
        address_hash
        balance
        udt{
          id
          type
          name
          bridge_account_id
        }
      }
    }

return:

{
  "data": {
    "account_udts": [
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "3259999999999996251051",
        "udt": {
          "bridge_account_id": null,
          "id": "1",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "10000000000000000000000",
        "udt": {
          "bridge_account_id": 238,
          "id": "80",
          "name": "USD Coin",
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "761007953602454563398",
        "udt": {
          "bridge_account_id": null,
          "id": "374",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499999999999999979911554801",
        "udt": {
          "bridge_account_id": null,
          "id": "886",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499999999999999980000000000",
        "udt": {
          "bridge_account_id": null,
          "id": "887",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499989900000000000000000000",
        "udt": {
          "bridge_account_id": null,
          "id": "888",
          "name": null,
          "type": "BRIDGE"
        }
      },
      {
        "address_hash": "0x23333496565720d945784a35aa655471493c0641",
        "balance": "499990000000000000000000000",
        "udt": {
          "bridge_account_id": null,
          "id": "889",
          "name": null,
          "type": "BRIDGE"
        }
      }
    ]
  }
}
Keith-CY commented 2 years ago

udt of id 1, namely ckb is still returned, with an incorrect balance