Fix AddressPeriod(height) to align with halving heights

This commit is contained in:
Jack Grigg 2019-02-01 11:11:54 +00:00
parent 2f0817d567
commit 3322acf19e
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
1 changed files with 6 additions and 4 deletions

View File

@ -86,14 +86,14 @@ block height is defined as follows::
AddressChangeInterval = PostBlossomHalvingInterval / 48
AddressPeriod(height) =
floor((
height + AddressChangeInterval - SlowStartShift
height + PostBlossomHalvingInterval - HeightForHalving(1)
) / AddressChangeInterval)
FundingStream[FUND].AddressIndex(height) =
AddressPeriod(height) - AddressPeriod(FundingStream[FUND].StartHeight)
Address(height) = FundingStream[FUND].Addresses[FundingStream[FUND].AddressIndex(height)]
This has the property that all active funding streams change the address they are using on the same block
height schedule, aligned to the end of the mining slow start so that 48 funding periods fit cleanly within a
height schedule, aligned to the height of the first halving so that 48 funding periods fit cleanly within a
halving interval. This can be leveraged to simplify implementations, by batching the necessary outputs for
each funding period.
@ -241,10 +241,12 @@ Example implementation
{
// Integer division is floor division in C++
auto curPeriod = (
nHeight + params.nFundingPeriodLength - params.SubsidySlowStartShift()
nHeight + params.nSubsidyPostBlossomHalvingInterval - HeightForHalving(params, 1)
) / params.nFundingPeriodLength;
auto startPeriod = (
params.vFundingPeriods[idx].startHeight + params.nFundingPeriodLength - params.SubsidySlowStartShift()
params.vFundingPeriods[idx].startHeight
+ params.nSubsidyPostBlossomHalvingInterval
- HeightForHalving(params, 1)
) / params.nFundingPeriodLength;
auto addressIndex = curPeriod - startPeriod;
return params.vFundingPeriods[idx].addresses[addressIndex];