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

RPC API update #3836

Closed
JackyWYX opened this issue Aug 3, 2021 · 1 comment
Closed

RPC API update #3836

JackyWYX opened this issue Aug 3, 2021 · 1 comment
Labels
design Design and architectural plans/issues

Comments

@JackyWYX
Copy link
Contributor

JackyWYX commented Aug 3, 2021

Problem

From our recent investigation to the RPC service degradation, we found the issue is mostly caused by the following two RPCs:

  • getBlocks
  • getLogs

The two RPCs will query block information with the given range. The range is unlimited, which means if a user call these RPC methods from genesis to latest, the server will loop through 10 million blocks to give the result, which will take a large portion of server endpoints.

Solution

We are planning an upcoming release which contains the fix #3830 to be deployed to RPC server. This fix will add a limitation to the two RPC methods, which is currently set as 1024 blocks for each request. If a user request a batch larger than 1024, the RPC will return an error:

> curl -s --request POST 'http://localhost:9500/' --header 'Content-Type: application/json' --data-raw '{
    "jsonrpc": "2.0",
    "method": "hmyv2_getBlocks", 
    "params": [
        1, 
        1026, 
        {
            "withSigners": false, 
            "fullTx": false,
            "inclStaking": false
        }
    ], 
    "id": 1
}'
{
    "jsonrpc":"2.0",
    "id":1,
    "error":{
        "code":-32000,
        "message":"GetBlocks query must be smaller than size 1024"
    }
} 

Impact and execution

The two RPCs are not backward-compatible, thus will potentially incur service interruption in DAPPs. We encourage all DAPP developers to check the usage of this RPC method, and update the code to avoid any service interruption.

We are planning to release this version to our RPC server at Aug 9th, 2021.

Please leave a comment below if you have any concerns or questions regarding the change.

@JackyWYX JackyWYX added the design Design and architectural plans/issues label Aug 3, 2021
@gupadhyaya
Copy link
Contributor

gupadhyaya commented Aug 3, 2021

In terms of the impact on sdks:

  • harmony-js sdk has two apis that call getLog rpc hmy_test_ws.blockchain.logs(options) and hmy_test_ws.messenger.send as shown below:
const { Harmony } = require("@harmony-js/core");
const { ChainID, ChainType } = require("@harmony-js/utils");
const hmy_test_ws = new Harmony("wss://ws.s0.b.hmny.io", {
    chainType: ChainType.Harmony,
    chainId: ChainID.HmyTestnet,
  });
  let options = {
    fromBlock: "0xC849ED",
    toBlock: "0xC85D75",
    address: "0x87e91c87196de58f6dc413d81c699da8ef39e4b9",
  };

  const logs = await hmy_test_ws.messenger.send(
    "hmy_getLogs",
    [options],
    hmy_ws.chainType,
    hmy_ws.chainId
  );
  console.log(logs.error);

and

let options = {
  fromBlock: '0xC849ED',
  toBlock: '0xC85D75',
  address: "0x87e91c87196de58f6dc413d81c699da8ef39e4b9",
};
let logs = hmy_test_ws.blockchain.logs(options);
logs.on("data", function (res, err) {
  if (err) {
    console.log(err);
  }
  console.log(res);
}).on("error", (err) => {
  console.log(err);
});
  • web3js filter api and getPastEvents contract api are also effected
const filter = web3.eth.filter({
  fromBlock: 0,
  toBlock: 'latest',
  address: contractAddress,
  topics: [web3.sha3('newtest(string,uint256,string,string,uint256)')]
})

filter.watch((error, result) => {
   //
})

and

await contract.getPastEvents('MyEvent', {
      filter: {},
      fromBlock: fromBlockNum,
      toBlock: toBlockNum,
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design and architectural plans/issues
Projects
None yet
Development

No branches or pull requests

3 participants