How to calculate slot within an epoch from total slot number?

the new “query leadership-schedule” gives the leading slot as a cumulative total slot number, which is usually a large number. How do I convert it to a relative in-epoch slot number, specifically for preview/preprod networks?

for the maninet, I somehow figure out from purely solving math equation.

SHELLEY_EPOCH_START=208
SLOTS_IN_EPOCH=432000
BYRON_SLOTS_IN_EPOCH=21600
SHELLEY_SLOT_START=$(( BYRON_SLOTS_IN_EPOCH * SHELLEY_EPOCH_START ))
slotInEpoch=$(($slot - $SHELLEY_SLOT_START - ($epoch_no - $SHELLEY_EPOCH_START)*$SLOTS_IN_EPOCH))

It works for mainnet and seems working for preview network. However, I can seem to solve/apply this formula to preprod network. And I don’t really have much faith in this formula to start with.

It would be nice if I can figure out a formula from all the genesis file so that I don’t have to tweak it by hand for a new network or when a network respins.

Thanks!

1 Like