Related with #46, but with a different approach. We can probably use both, or one of them.
Currently, the verifiedQueryClient.GetStoreData() always execute a ABCI query based on the latest block, and wait for the next block (= latest + 1
) for the light block verification. That logic is correct basically, but I think we don't always need to make a query based on the latest block. If there is some cases where it's okay to make a query based on a previous block, we might be able to skip waiting for a new block sometimes. This strategy will speed up the verifiedQueryClient.
Case 1: When handling events subscribed
We can get a block height of that event as below. Then, we can make a ABCI query based on that height in order to get chain states related with that event. Then, we can call GetStoreData()
with that height (if we make it accept a height).
func (e RegisterOracleEvent) EventHandler(event ctypes.ResultEvent) error {
eventDataTx := event.Data.(types.EventDataTx)
queryHeight := eventDataTx.Height
...
... := queryClient.GetStoreData(..., queryHeight)
...
}
If the event handler was triggered right after the event was emitted, the GetStoreData()
will wait for a next block (= queryHeight + 1
). But, the event subscriber was delayed for some reason, the GetStoreData()
will skip waiting. But the possibility of this case is low. The subscriber won't be delayed in most cases.
Case 2: When handling end-user requests
Currently, it seems that all end-user requests should be handled based on the latest block. Here could be also a temporal delay between the time when the end-user decides to send a request and the time when the verifiedQueryClient starts its logic. However, in general, end-users send requests without checking if certain states are finalized in the chain. In other words, end-users don't usually have any desired block height when they send requests to oracles. So, I think this approach is not that helpful for this case.
Discussion
So, it seems that the approach #46 is more useful in most cases. But still, this approach is more lightweight. We need to keep thinking if this approach is needed.