fastnear / fast-near

Fastest RPC for @near based on Redis/LMDB
45 stars 12 forks source link

Endpoint `/account/:accountId/data/:keyPattern` returns inconsistent data and `iterator` doesn't work #13

Open arrusev opened 1 year ago

arrusev commented 1 year ago

I'm trying to fetch the most recent state of priceoracle.testnet contract but the response differs from the one that RPC request returns.

How to reproduce:

  1. Make RPC call

    • Request:
      curl --location --request POST 'https://rpc.testnet.near.org' \
      --header 'Content-Type: application/json' \
      --data-raw '{
      "jsonrpc": "2.0",
      "id": "dontcare",
      "method": "query",
      "params": {
      "request_type": "view_state",
      "finality": "final",
      "account_id": "priceoracle.testnet",
      "prefix_base64": "U1RBVEU=" -> "STATE" in base64
      }
      }'
    • Response:
      [
      {
      "key": "U1RBVEU=",
      "value": "AgAAAABpBAAAAAAAAAACAAAAAGsEAAAAAAAAAAIAAAAAdgIAAAABaQoAAAAAAAAAAgAAAAFrCgAAAAAAAAACAAAAAXZaAAAAEwAAAHByaWNlb3JhY2xlLnRlc3RuZXQAAAAlpAAKi8oiBAAAAAAA"
      }
      ]
  2. Make Fast-Near HTTP call:

    • Request:
      curl --location --request GET 'https://rpc.web4.testnet.page/account/priceoracle.testnet/data/STATE?encoding=base64'
    • Response:
      {
      "data":
      [
      ..996 elements
      ],
      "iterator": "02643a70726963656f7261636c652e746573746e65743a535441544507e78d04"
      }
  3. Compare the results: The value AgAAAABpBAAAAAAAAAACAAAAAGsEAAAAAAAAAAIAAAAAdgIAAAABaQoAAAAAAAAAAgAAAAFrCgAAAAAAAAACAAAAAXZaAAAAEwAAAHByaWNlb3JhY2xlLnRlc3RuZXQAAAAlpAAKi8oiBAAAAAAA returned from the RPC call is missing within Fast-Near's response.

Also i've tried to supply the iterator param in order to fetch the next page but the response is 1:1 the same as without iterator(it seems like the response is cached but not refetched).

https://rpc.web4.testnet.page/account/priceoracle.testnet/data/STATE?encoding=base64&iterator=02643a70726963656f7261636c652e746573746e65743a535441544507e78d04

vgrichina commented 1 year ago

/data endpoint still needs some work to work as expected

e.g. this change has been deployed only recently https://github.com/vgrichina/fast-near/commit/50f9fce1aff3121a34d60d37f71a13b61044bea1 and I don't think testnet RPC is up to date with it

there might need to be some caching changes as well

I think only contract calls / account views have been tested extensively so far

@arrusev may you give more details on what's your use case for fetching state vs calling contract?

vgrichina commented 1 year ago

I think even with https://github.com/vgrichina/fast-near/commit/50f9fce1aff3121a34d60d37f71a13b61044bea1 there are more issues with contracts which have a lot of state changes for single key – I'm gonna prepare few more improvements to get it work

but basically main reason that /data is not in readme is because it's not quire ready as is

arrusev commented 1 year ago

we want to extend the near-api-js library to be able to execute contract functions locally, instead of calling RPC provider.

We face some issues with states bigger than 50kb and in that case, we want to use fast-near API to retrieve the whole contract state

vgrichina commented 7 months ago

@arrusev are you still working on this?

arrusev commented 7 months ago

@arrusev are you still working on this?

I am personally not involved in this anymore but other people are working on stuff related to near-api-js. @vikinatora , @gtsonevv