go-vite icon indicating copy to clipboard operation
go-vite copied to clipboard

RPC for getting latest vmlog entries

Open weserickson opened this issue 2 years ago • 6 comments

The current RPC for getting event logs has some limitations (for instance it is not easy to request the latest n entries). https://docs.vite.org/vite-docs/api/rpc/ledger_v2.html#ledger-getvmlogsbyfilter

Possibly look at ethereum RPC for inspiration for improvements. https://eth.wiki/json-rpc/API#eth_getlogs

weserickson avatar Mar 19 '22 00:03 weserickson

This sounds interesting. Do you have an example how to get the latest n entries with eth_getLogs? I was not aware this would be possible. Apart from that what are you particulary missing with the current implementation? Comparing with https://eth.wiki/json-rpc/API#eth_getlogs only address and blockhash are additional filter options.

niklr avatar Mar 20 '22 08:03 niklr

Actually, looks like I'm wrong about eth_getLogs being able to access latest n logs, but it can at least access logs in only the latest block by setting "fromBlock": "latest" and "toBlock": "latest".

In comparisonledger_getVmLogsByFilter with "fromHeight": "0" and "toHeight": "0" seems to return ALL logs rather than only logs from the latest block. This behavior at least does not seem to match what is suggested by the docs docs

fromHeight: uint64 Start height. 0 means starting from the latest block toHeight: uint64 End height. 0 means no specific ending block

Maybe not essential change the RPC, but we will at least want to correct this documentation.

As for other features, I agree they may not be needed (address is unneeded and blockhash is already covered by ledger_getVmLogs). @charles-liu , did you have other features in mind?

weserickson avatar Mar 25 '22 20:03 weserickson

Let's fix this unexpected behavior, let fromHeight of 0 mean the latest block instead of the genesis block and avoid returning all events without pagination.

charles-liu avatar Mar 29 '22 12:03 charles-liu

In addition, we could add two pagination parameters pageIndex and pageSize to limit the maximum size of events returned in a single RPC call like ledger-getaccountblocksbyaddress.

charles-liu avatar Mar 29 '22 12:03 charles-liu

This fix changes the implementation of this interface, will it affect the current user? I think we should add quantity limits and update the documentation.

viteshan avatar Apr 06 '22 08:04 viteshan

Update: https://github.com/vitelabs/go-vite/pull/583#issuecomment-1106644160

niklr avatar Apr 22 '22 15:04 niklr