Hello friends!
I’m working on this simple “Zcash Halving Countdown”, but I’m not sure how to get the next halving block height.
Reading the Zcash Protocol Specification page 134, I got the following formula:
But this formula returns the halving number, e.g. 0, 1, 2, and so on…
I can bruteforce every block height incremently, until halving == 2
, but I don’t like this solution.
I would like to know if there’s a formula to get the next halving height, or the remaining blocks until next halving?
edit
Running a bruteforce for few iterations:
Next halving: 2726400
Next halving: 4406400
Next halving: 6086400
Looks like halvings occurs every 1680000 blocks, is that correct?
2 Likes
hanh
March 2, 2023, 1:08am
2
If you look at the equation, N changes every PostBlossomHalvingInterval
.
PS: It is a staircase function.
2 Likes
Hello @hanh
Could you share more details here please ?
Hello @hanh
Please do it fast so we could work on it .
postBlossomHalvingInterval
is defined by:
const postBlossomHalvingInterval = Math.floor(preBlossomHalvingInterval * blossomPoWTargetSpacingRatio)
Where:
preBlossomHalvingInterval
is a constant with the value 840000
blossomPoWTargetSpacingRatio
is the ratio between:
preBlossomPoWTargetSpacing
= 150
postBlossomPoWTargetSpacing
= 75
Meaning postBlossomHalvingInterval
equals 840000 * 2 = 1680000
.
So N
changes every 1680000
blocks counting from the first halving, e.g.:
Halving N
Height
1
1046400
2
2726400
3
4406400
Not 100% sure, but I think this is correct.
1 Like
Full javascript code for height > SlowStartShift
AND isBlossomActivated(height)
function calculateHalvingNumber(height) {
const blossomActivationHeight = 653600;
const preBlossomHalvingInterval = 840000;
const preBlossomPoWTargetSpacing = 150;
const postBlossomPoWTargetSpacing = 75;
const blossomPoWTargetSpacingRatio = preBlossomPoWTargetSpacing / postBlossomPoWTargetSpacing;
const postBlossomHalvingInterval = Math.floor(preBlossomHalvingInterval * blossomPoWTargetSpacingRatio)
const slowStartInterval = 20000;
const slowStartShift = slowStartInterval / 2;
const halving = Math.floor(( (blossomActivationHeight - slowStartShift) / preBlossomHalvingInterval ) + ( (height - blossomActivationHeight) / postBlossomHalvingInterval ));
return halving;
}
2 Likes