You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the conversion from a date string into a block number only work for the Antelope chain using the (deprecated) GraphQL endpoint.
It would be best to have a general way of converting a date string (or timestamp) to the appropriate block number according to the targeted blockchain.
The text was updated successfully, but these errors were encountered:
Presenting another possible solution to this problem.
Calculating block number from timestamp via estimates
The idea is to use the negative start_block_num feature of Substreams/Firehose to query the latest block available from the endpoint. By continuously timing the response for a few blocks, we can estimate the speed of the block production for that chain.
After having refined this metric enough time, we can calculate how far the targeted block is from now:
target_block = latest_block - (now - timestamp)*speed
^^^^^^^^^^^^^^^ ^^^^^
diff in seconds in block/s
We could use the timestamp contained in the block to make the estimates and compare the final target_block timestamp to the actual requested timestamp to adjust for miscalculation. This would allow for precise targeting by moving forward or backward from the block estimate, until we hit the targeted timestamp.
The main drawback to this method is that we need to assume some things about the format of the returned data, in order to extract the block number and timestamp information from it. We need to know where to locate this data inside the response and it's guaranteed to change from chain to chain as they don't all share the same .proto definition (e.g. block.number for Antelope and block.height for Arweave).
Currently, the conversion from a date string into a block number only work for the Antelope chain using the (deprecated) GraphQL endpoint.
It would be best to have a general way of converting a date string (or timestamp) to the appropriate block number according to the targeted blockchain.
The text was updated successfully, but these errors were encountered: