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

Having issues with Cloudflare endpoints #949

Closed
bogdan opened this issue Jul 13, 2020 · 12 comments
Closed

Having issues with Cloudflare endpoints #949

bogdan opened this issue Jul 13, 2020 · 12 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@bogdan
Copy link

bogdan commented Jul 13, 2020

Given an example:

import {ethers, providers } from 'ethers';

const provider = new providers.JsonRpcProvider("https://cloudflare-eth.com")

var privateKey = '0x00000000000000000000000000000000000000000000000000000000000000d0';
var wallet = new ethers.Wallet(privateKey,provider);

const contract = new ethers.Contract(
  '0xD1E5b0FF1287aA9f9A268759062E4Ab08b9Dacbe',
  [
    {
      constant: true,
      inputs: [
        {
          name: 'tokenId',
          type: 'uint256',
        },
      ],
      name: 'ownerOf',
      outputs: [
        {
          name: '',
          type: 'address',
        },
      ],
      payable: false,
      stateMutability: 'view',
      type: 'function',
    },
  ],
  wallet,
)

contract.functions.ownerOf(
  '0x6d8b296e38dfd295f2f4feb9ef2721c48210b7d77c0a08867123d9bd5150cf47'
).then(console.log, console.log)

Produces:

Error: processing response error (body={"jsonrpc":"2.0","id":46,"error":{"code":3,"message":"execution reverted: ERC721: owner query for nonexistent token","data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000"}}, error={"code":3,"data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000"}, requestBody="{\"method\":\"eth_call\",\"params\":[{\"from\":\"0x379ff6375f4a44f458683629ef05141d73fae55a\",\"to\":\"0xd1e5b0ff1287aa9f9a268759062e4ab08b9dacbe\",\"data\":\"0x6352211e6d8b296e38dfd295f2f4feb9ef2721c48210b7d77c0a08867123d9bd5150cf47\"},\"latest\"],\"id\":46,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="https://cloudflare-eth.com", code=SERVER_ERROR, version=web/5.0.1)
    at Logger.makeError (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/logger/lib/index.js:179:21)
    at Logger.throwError (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/logger/lib/index.js:188:20)
    at /Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:192:32
    at step (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:33:23)
    at Object.next (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:14:53)
    at fulfilled (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  reason: 'processing response error',
  code: 'SERVER_ERROR',
  body: {
    jsonrpc: '2.0',
    id: 46,
    error: {
      code: 3,
      message: 'execution reverted: ERC721: owner query for nonexistent token',
      data: '0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000'
    }
  },
  error: Error: execution reverted: ERC721: owner query for nonexistent token
      at getResult (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:70:21)
      at /Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:186:46
      at step (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:33:23)
      at Object.next (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:14:53)
      at fulfilled (/Users/bogdan/makabu/unstoppable/resolution/node_modules/@ethersproject/web/lib/index.js:5:58)
      at processTicksAndRejections (internal/process/task_queues.js:93:5) {
    code: 3,
    data: '0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000'
  },
  requestBody: '{"method":"eth_call","params":[{"from":"0x379ff6375f4a44f458683629ef05141d73fae55a","to":"0xd1e5b0ff1287aa9f9a268759062e4ab08b9dacbe","data":"0x6352211e6d8b296e38dfd295f2f4feb9ef2721c48210b7d77c0a08867123d9bd5150cf47"},"latest"],"id":46,"jsonrpc":"2.0"}',
  requestMethod: 'POST',
  url: 'https://cloudflare-eth.com'
}

It is interesting that the same call to mainnet.infura.io doesn't produce such error.

@ricmoo
Copy link
Member

ricmoo commented Jul 13, 2020

This is likely an issue with Cloudflare. I've removed it from getDefaultProvider because it does not seem maintained at all and is regularly (and incredibly) out of sync.

You can try comparing the result of provider.getBlockNumber to see how far out of date a node is.

Let me know. :)

@ricmoo ricmoo added the discussion Questions, feedback and general information. label Jul 13, 2020
@bogdan
Copy link
Author

bogdan commented Jul 13, 2020

I checked the console an cloudflare return a different response for the same RPC request compared to infura.

# Request

{"method":"eth_call","params":[{"from":"0x379ff6375f4a44f458683629ef05141d73fae55a","to":"0xd1e5b0ff1287aa9f9a268759062e4ab08b9dacbe","data":"0x6352211e6d8b296e38dfd295f2f4feb9ef2721c48210b7d77c0a08867123d9bd5150cf48"},"latest"],"id":46,"jsonrpc":"2.0"}

# Cloudflare Response

{"jsonrpc":"2.0","id":46,"error":{"code":3,"message":"execution reverted: ERC721: owner query for nonexistent token","data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000"}}

# Infura Response

{"jsonrpc":"2.0","id":46,"result":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000"}%

Obviously, cloudflare response format is not supported by ethers and this is probably unrelated to being out of date or something else.

Do you that cloudflare response should be supported by ethers or it is out of standard and cloudflare broke the spec with it?

@zemse
Copy link
Collaborator

zemse commented Jul 13, 2020

@bogdan Can you try with this request: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83} or provider.getBlockNumber() and check if you are getting latest block numbers on cloudfare like infura as @ricmoo has suggested?

@ricmoo
Copy link
Member

ricmoo commented Jul 13, 2020

The Cloudflare backends do not expose eth_blockNumber (indeed crazy), so ethers has custom logic In the CloudflareProvider to get the latest block and take the number from it. Can you try using the CloudflareProvider to get the block number.

Absurd, I agree. :)

@ricmoo ricmoo changed the title [BUG] Error making RPC calls to cloudflare eth node Having issues with Cloudflare endpoints Jul 13, 2020
@bogdan
Copy link
Author

bogdan commented Jul 14, 2020

The Cloudflare backends do not expose eth_blockNumber

Really?

Isn't it just this:

$ curl https://cloudflare-eth.com -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

{"jsonrpc":"2.0","id":1,"result":"0x9f9039"}%

@ricmoo
Copy link
Member

ricmoo commented Jul 15, 2020

Oh you are right! They seem to have fixed that! :)

I can probably remove that extra logic from the CloudflareProvider now. :)

@ricmoo
Copy link
Member

ricmoo commented Jul 22, 2020

So, circling back to this. Were you able to confirm you got a different error on Cloudflare vs others while the block numbers were similar?

@bogdan
Copy link
Author

bogdan commented Jul 23, 2020

@ricmoo yes, I confirm.

Please check for yourself:

PROJECTID="<infura-project-id>"

for URI in https://main-rpc.linkpool.io https://mainnet.infura.io/v3/$PROJECTID https://cloudflare-eth.com ; do
  echo $URI
  RES=`curl -s $URI -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'`
  echo $RES
  RES=`curl -s $URI -H "Content-Type: application/json" --data "{\"method\":\"eth_call\",\"params\":[{\"from\":\"0x379ff6375f4a44f458683629ef05141d73fae55a\",\"to\":\"0xd1e5b0ff1287aa9f9a268759062e4ab08b9dacbe\",\"data\":\"0x6352211e6d8b296e38dfd295f2f4feb9ef2721c48210b7d77c0a08867123d9bd5150cf48\"},\"latest\"],\"id\":46,\"jsonrpc\":\"2.0\"}"`
  echo $RES
  echo
done

My output:

https://main-rpc.linkpool.io
{"jsonrpc":"2.0","result":"0xa0732e","id":1}
{"jsonrpc":"2.0","result":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000","id":46}

https://mainnet.infura.io/v3/<ID>
{"jsonrpc":"2.0","id":1,"result":"0xa0732e"}
{"jsonrpc":"2.0","id":46,"result":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000"}

https://cloudflare-eth.com
{"jsonrpc":"2.0","id":1,"result":"0xa0732c"}
{"jsonrpc":"2.0","id":46,"error":{"code":3,"message":"execution reverted: ERC721: owner query for nonexistent token","data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000"}}

@ricmoo
Copy link
Member

ricmoo commented Oct 8, 2020

Oh, I see the issue now! When there is a revert, which most nodes treat like a normal result (which it is; revert is just a fancy return), Cloudflare is decoupling it for you. I can fix this in the CloudflareProvider.

@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. and removed discussion Questions, feedback and general information. labels Oct 8, 2020
@ricmoo
Copy link
Member

ricmoo commented Nov 22, 2020

It looks like modern nodes are all doing something similar, so I've put logic in to undo this "convenience". In v6 I may re-address how provider call forwards a revert vs. a return, but for now keeping the existing functionality is more important.

ricmoo added a commit that referenced this issue Nov 23, 2020
@bogdan
Copy link
Author

bogdan commented Nov 23, 2020

I've rerun the script today after that major node upgrade and now infura and cloudflare are in sync. Linkpool is different though:

https://main-rpc.linkpool.io
{"jsonrpc":"2.0","result":"0xabf458","id":1}
{"jsonrpc":"2.0","error":{"code":-32042,"message":"Bad response on request: [ Account ]. Error cause was EmptyResponse, (majority count: 97 / total: 97)"},"id":46}

https://mainnet.infura.io/v3/781c1e5cae32417b93eac26042950d25
{"jsonrpc":"2.0","id":1,"result":"0xaca4b6"}
{"jsonrpc":"2.0","id":46,"error":{"code":3,"data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000","message":"execution reverted: ERC721: owner query for nonexistent token"}}

https://cloudflare-eth.com
{"jsonrpc":"2.0","id":1,"result":"0xaca4b5"}
{"jsonrpc":"2.0","id":46,"error":{"code":3,"message":"execution reverted: ERC721: owner query for nonexistent token","data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000294552433732313a206f776e657220717565727920666f72206e6f6e6578697374656e7420746f6b656e0000000000000000000000000000000000000000000000"}}

So practically we can close this issue and open a new one for linkpool, but I am not sure about all the details, maybe linkpool will just need to update its geth node version.

The good news is that geth node itself seems to be moving the right direction.

@ricmoo
Copy link
Member

ricmoo commented Nov 24, 2020

It looks like LinkPool (I've not heard of that one before) doesn't return any of the needed data to recreate the actual correct revert data returned, so I don't think there is anything that can be done for that... :s

Glad it works for Geth though. I'll close this issue.

Thanks! :)

@ricmoo ricmoo closed this as completed Nov 24, 2020
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

3 participants