oasislabs/oasis-gateway

Polling sometimes gives output of `0x`

Closed this issue · 13 comments

Steps to reproduce:

  1. Deploy contract, e.g.,
v0/api/service/deploy 
{"data":"0x00736973000100167b22636f6e666964656e7469616c223a66616c73657d608060405234801561001057600080fd5b506102f9806100206000396000f3fe60806040526004361061006d576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635b34b966146100725780635caf51da146100895780637531dafc146100c45780638ada066e146100ff578063c847beca1461012a575b600080fd5b34801561007e57600080fd5b50610087610155565b005b34801561009557600080fd5b506100c2600480360360208110156100ac57600080fd5b81019080803590602001909291905050506101a0565b005b3480156100d057600080fd5b506100fd600480360360208110156100e757600080fd5b8101908080359060200190929190505050610242565b005b34801561010b57600080fd5b506101146102aa565b6040518082815260200191505060405180910390f35b34801561013657600080fd5b5061013f6102b3565b6040518082815260200191505060405180910390f35b600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a1565b6000548114151561023f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001807f636f756e74657220646f6573206e6f7420657175616c20746f2065787065637481526020017f65642076616c756500000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b50565b60008090505b818110156102a657600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a18080600101915050610248565b5050565b60008054905090565b60006001600080828254019250508190555060005490509056fea165627a7a72305820a27620d56b323564bd95d25c7b9ce214b1735bf84277dcc163f541970a4357030029"} 
  1. Receive response id response = {"id":0}
  2. Poll for response address with id {"offset":0,"events":[{"id":0,"address":"0x71c741D293ba0e7466C96468ff3C2113db39771c"}]}
  3. Execute service
v0/api/service/execute {"data":"0x8ada066e","address":"0x71c741d293ba0e7466c96468ff3c2113db39771c"}
  1. Receive response id response = {"id":1}
  2. Poll for service execution output with id
{"offset":1,"events":
[{"id":1,"address":"0x71c741d293ba0e7466c96468ff3c2113db39771c","output":"0x"}]}

Notice how the output is 0x.

Note this happens inconsistently.

eauge commented

@armaniferrante thanks for raising the issue.

does this transaction execute a method that returns an output?
when you mention that it happens inconsistently, do you mean that you may get "output":"0x" or "output":"" with the same transaction?

I mean that sometimes I get the proper output and sometimes I get the undesired "output":"0x" (for different service executions).

I.e., run the above steps over and over and the output will change depending on the run.

All requests for failure:

    REQUEST: uri = http://localhost:1234/v0/api/service/deploy body = {"data":"0x00736973000100167b22636f6e666964656e7469616c223a66616c73657d608060405234801561001057600080fd5b506102f9806100206000396000f3fe60806040526004361061006d576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635b34b966146100725780635caf51da146100895780637531dafc146100c45780638ada066e146100ff578063c847beca1461012a575b600080fd5b34801561007e57600080fd5b50610087610155565b005b34801561009557600080fd5b506100c2600480360360208110156100ac57600080fd5b81019080803590602001909291905050506101a0565b005b3480156100d057600080fd5b506100fd600480360360208110156100e757600080fd5b8101908080359060200190929190505050610242565b005b34801561010b57600080fd5b506101146102aa565b6040518082815260200191505060405180910390f35b34801561013657600080fd5b5061013f6102b3565b6040518082815260200191505060405180910390f35b600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a1565b6000548114151561023f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001807f636f756e74657220646f6573206e6f7420657175616c20746f2065787065637481526020017f65642076616c756500000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b50565b60008090505b818110156102a657600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a18080600101915050610248565b5050565b60008054905090565b60006001600080828254019250508190555060005490509056fea165627a7a72305820a27620d56b323564bd95d25c7b9ce214b1735bf84277dcc163f541970a4357030029"}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"id":0}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":0,"discardPrevious":true}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"offset":0,"events":[]}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":0,"discardPrevious":true}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"offset":0,"events":[{"id":0,"address":"0x53A88947E76C90915e603664D92459fEFE173a6C"}]}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/execute body = {"data":"0x8ada066e","address":"0x53a88947e76c90915e603664d92459fefe173a6c"}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"id":1}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":1,"discardPrevious":true}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"offset":0,"events":[]}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":1,"discardPrevious":true}

RESPONSE: {"offset":1,"events":[{"id":1,"address":"0x53a88947e76c90915e603664d92459fefe173a6c","output":"0x"}]}

All requests for success:

    REQUEST: uri = http://localhost:1234/v0/api/service/deploy body = {"data":"0x00736973000100167b22636f6e666964656e7469616c223a66616c73657d608060405234801561001057600080fd5b506102f9806100206000396000f3fe60806040526004361061006d576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635b34b966146100725780635caf51da146100895780637531dafc146100c45780638ada066e146100ff578063c847beca1461012a575b600080fd5b34801561007e57600080fd5b50610087610155565b005b34801561009557600080fd5b506100c2600480360360208110156100ac57600080fd5b81019080803590602001909291905050506101a0565b005b3480156100d057600080fd5b506100fd600480360360208110156100e757600080fd5b8101908080359060200190929190505050610242565b005b34801561010b57600080fd5b506101146102aa565b6040518082815260200191505060405180910390f35b34801561013657600080fd5b5061013f6102b3565b6040518082815260200191505060405180910390f35b600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a1565b6000548114151561023f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260288152602001807f636f756e74657220646f6573206e6f7420657175616c20746f2065787065637481526020017f65642076616c756500000000000000000000000000000000000000000000000081525060400191505060405180910390fd5b50565b60008090505b818110156102a657600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a18080600101915050610248565b5050565b60008054905090565b60006001600080828254019250508190555060005490509056fea165627a7a72305820a27620d56b323564bd95d25c7b9ce214b1735bf84277dcc163f541970a4357030029"}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"id":0}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":0,"discardPrevious":true}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"offset":0,"events":[]}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":0,"discardPrevious":true}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"offset":0,"events":[{"id":0,"address":"0x74230621B866238c0928a6fA6CCdebD220Ed2a1c"}]}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/execute body = {"data":"0x8ada066e","address":"0x74230621b866238c0928a6fa6ccdebd220ed2a1c"}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"id":1}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":1,"discardPrevious":true}

  console.log ../developer-gateway/dist/index.umd.js:8926
    RESPONSE: {"offset":0,"events":[]}

  console.log ../developer-gateway/dist/index.umd.js:8916
    REQUEST: uri = http://localhost:1234/v0/api/service/poll body = {"offset":1,"discardPrevious":true}

RESPONSE: {"offset":1,"events":[{"id":1,"address":"0x74230621b866238c0928a6fa6ccdebd220ed2a1c","output":"0x0000000000000000000000000000000000000000000000000000000000000000"}]}

Note that the header being used in the above is { version: 1, body: { confidential: false } }.

We can probably close this in favor of oasisprotocol/oasis-core#1832.

eauge commented
eauge commented

I think we should file this in the runtime. I deployed the same contract 4 times in staging, and as you can see here, with address 0x658686bd67A91cA84E24a190cF9796d16718D126 I get the correct output but with address 0x4b7567Db4029526C7Ba65F6B7b2C9b7147501021 I get 0x, even though it's the same deployed contract.

{
  "offset": 0,
  "events": [
    {
      "id": 0,
      "address": "0x658686bd67A91cA84E24a190cF9796d16718D126"
    },
    {
      "id": 1,
      "address": "0x6FA5e0773f911a471308be7d9C33C40DB7c0a0A4"
    },
    {
      "id": 2,
      "address": "0x691d7878a130934048866C80d5f82C5013ae2A8D"
    },
    {
      "id": 3,
      "address": "0x4b7567Db4029526C7Ba65F6B7b2C9b7147501021"
    },
    {
      "id": 4,
      "address": "0x658686bd67A91cA84E24a190cF9796d16718D126",
      "output": "0x0000000000000000000000000000000000000000000000000000000000000000"
    },
    {
      "id": 5,
      "address": "0x6FA5e0773f911a471308be7d9C33C40DB7c0a0A4",
      "output": "0x"
    },
    {
      "id": 6,
      "address": "0x691d7878a130934048866C80d5f82C5013ae2A8D",
      "output": "0x0000000000000000000000000000000000000000000000000000000000000000"
    },
    {
      "id": 7,
      "address": "0x4b7567Db4029526C7Ba65F6B7b2C9b7147501021",
      "output": "0x"
    }
  ]
}

I cannot reproduce this when using the web3 gateway directly, which makes me hesitant to think its a runtime issue (note that I'm also using oasis_invoke).

@eauge with the example above, are you using a dev-gateway or web3 directly (it looks like the dev-gateway)?

eauge commented

Okay so I think that this was a problem of nonces. We were not initializing the nonce with the developer gateway, expecting that if a transaction was sent with an invalid nonce, the web3 gateway would return an error. However, it does not send an error for invalid nonce, but the transaction went through with a status code of success in the receipt.

What I found to be the reliable way to test for success on a contract deployment is to fetch the code of the contract.

So this should fix the bug #125 and also should make sure that when a contract is deployed, the code can be fetched. So, if this happens again, at least we will know that the contract was not deployed successfully, which was the most confusing part.

eauge commented

@armaniferrante please verify that after #125 this bug doesn't happen and we can close the issue :)

eauge commented

Or actually since it closed automatically because I closed #125, we can reopen if this issue is not fixed

RPCs seem to work after #125! Subscriptions are buggy but I think it's a client issue.