go-vite
go-vite copied to clipboard
RPC for getting latest vmlog entries
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
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.
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 blocktoHeight: 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?
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.
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.
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.
Update: https://github.com/vitelabs/go-vite/pull/583#issuecomment-1106644160