casper-node
casper-node copied to clipboard
Get the last block height of an era
Reporter: community
Currently I am searching "era_end" field from casper-client get-block. But this command has to be issued several times to find the exact block height.
Trying to figure out how to find all last blocks for all eras in one month with the least number of calls to api. The user also asked if we can get auction(state_get_auction_info) info and era info (chain_get_era_info_by_switch_block)by eraid instead of block heigh/hash
Unfortunately we don't have a better way right now other than pretty much what the user is already doing. They need to just get each block for the month and those will of course include the switch blocks. We'll be looking into providing a more ergonomic API as soon as we can (e.g. by having some of the functions accept era IDs rather than or as well as block IDs), but it's not imminent right now, and we've not decided on the 2.0 specs - so no promises. In the meantime, they could try doing optimistic searches for the switch blocks based on a heuristic of the normal number of blocks in an era, but long term, users shouldn't need to go to those lengths.
bash pseudo-code getting the information
for i in {1..{{current_block_height.stdout}}}; do
if [[ $(casper-client get-era-info-by-switch-block -b ${i} | jq -r '.result | select(.era_summary != null)') ]]; then
block=$i
Sidecar related. Check with Jakub. - Action @devendran-m Ed says (on the triage call on 27th Sep '24);
It is totally possible to add a index to the sidecar that tracks block height for switch blocks and cross indexes by block time so that a endpoint could be added to request all switch blocks within a time caller to request switch blocks by time window. Obviously some constraint on how large of a time window would be supported per request but other than that it's doable.