XinFinOrg / XDPoSChain

Customer centric, Hybrid & Interoperable XinFin Network
https://www.xinfin.org
GNU Lesser General Public License v3.0
51 stars 63 forks source link

Improve the performance of eth_getLogs #568

Closed JukLee0ira closed 2 months ago

JukLee0ira commented 3 months ago

Proposed changes

Not all fields of a receipt are persisted to disk. Some are re-computed on read. The most expensive field to re-compute is the bloom filter which will not even be returned in eth_getLogs. Here we define a new decoding of receipts specifically for this use-case which avoids extra processing.

Test 'eth_getLogs'

Vertical comparison

Before optimization, run the command and save the result to file1.log:

curl -X POST -H "Content-Type: application/json" --data '{  "method":"eth_getLogs",  "params":[{ "fromBlock":"0x1010d", "toBlock":"0x11a400",    address":"xdc0000000000000000000000000000000000000088",    "topics":[ ]  }],  "id":1,  "jsonrpc":"2.0"}' http://127.0.0.1:8545 | jq > file1.log

After optimization, run the same command and save the result to file2.log:

curl -X POST -H "Content-Type: application/json" --data '{  "method":"eth_getLogs",  "params":[{ "fromBlock":"0x1010d", "toBlock":"0x11a400",    address":"xdc0000000000000000000000000000000000000088",    "topics":[ ]  }],  "id":2,  "jsonrpc":"2.0"}' http://127.0.0.1:8545| jq > file2.log

Here are their diff results:

3c3
<   "id": 1,
---
>   "id": 2,

Horizontal comparison

After the modification, sync the block data, run the command, and save the result to file3.log:

curl -X POST -H "Content-Type: application/json" --data '{  "method":"eth_getLogs",  "params":[{ "fromBlock":"0x1010d", "toBlock":"0x11a400",    address":"xdc0000000000000000000000000000000000000088",    "topics":[ ]  }],  "id":3,  "jsonrpc":"2.0"}' http://127.0.0.1:8545 | jq > file3.log

Run the command to read the log from the public RPC node and save the result to file4.log:

curl -X POST -H "Content-Type: application/json" --data '{  "method":"eth_getLogs",  "params":[{ "fromBlock":"0x1010d", "toBlock":"0x11a400",    address":"xdc0000000000000000000000000000000000000088",    "topics":[ ]  }],  "id":4,  "jsonrpc":"2.0"}' https://apothem.xdcrpc.com | jq > file4.log

Here are their diff results:

3c3
<   "id": 3,
---
>   "id": 4,

Types of changes

What types of changes does your code introduce to XDC network? Put an in the boxes that apply

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

gzliudan commented 3 months ago

Please rebase on the latest dev-upgrade branch.