diff --git a/zip-0207.html b/zip-0207.html
index 077dd7a20..84d08007c 100644
--- a/zip-0207.html
+++ b/zip-0207.html
@@ -222,6 +222,8 @@
MAX_FUNDING_STREAMS,
};
+const auto FIRST_FUNDING_STREAM = FS_ECC;
+
struct Params {
...
int nFundingPeriodLength;
@@ -234,16 +236,17 @@
Consensus::FundingStream idx,
std::vector<std::string> addresses,
uint64_t valueNumerator,
- uint64_t valueDenominator)
+ uint64_t valueDenominator,
+ int startHeight,
+ int endHeight)
{
assert(valueNumerator < valueDenominator);
assert(valueNumerator < INT64_MAX / MAX_MONEY);
params.vFundingPeriods[idx].addresses = addresses;
params.vFundingPeriods[idx].valueNumerator = valueNumerator;
params.vFundingPeriods[idx].valueDenominator = valueDenominator;
- params.vFundingPeriods[idx].startHeight =
- params.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight;
- params.vFundingPeriods[idx].endHeight = HeightForHalving(params, 1);
+ params.vFundingPeriods[idx].startHeight = startHeight;
+ params.vFundingPeriods[idx].endHeight = endHeight;
assert(params.vFundingPeriods[idx].startHeight < params.vFundingPeriods[idx].endHeight);
};
@@ -252,9 +255,11 @@
consensus.nFundingPeriodLength = consensus.nSubsidyPostBlossomHalvingInterval / 48;
- AddZIP207FundingStream(consensus, Consensus::FS_ECC, FS_ECC_ADDRESSES, 7, 100);
- AddZIP207FundingStream(consensus, Consensus::FS_ZF, FS_ZF_ADDRESSES, 5, 100);
- AddZIP207FundingStream(consensus, Consensus::FS_MG, FS_MG_ADDRESSES, 8, 100);
+ int devFundStartHeight = HeightForHalving(params, 1);
+ int devFundEndHeight = HeightForHalving(params, 2);
+ AddZIP207FundingStream(consensus, Consensus::FS_ECC, FS_ECC_ADDRESSES, 7, 100, devFundStartHeight, devFundEndHeight);
+ AddZIP207FundingStream(consensus, Consensus::FS_ZF, FS_ZF_ADDRESSES, 5, 100, devFundStartHeight, devFundEndHeight);
+ AddZIP207FundingStream(consensus, Consensus::FS_MG, FS_MG_ADDRESSES, 8, 100, devFundStartHeight, devFundEndHeight);
...
}
@@ -264,17 +269,23 @@
const Consensus::Params& params,
Consensus::FundingStream idx)
{
- // Integer division is floor division in C++
- auto curPeriod = (
- nHeight + params.nSubsidyPostBlossomHalvingInterval - HeightForHalving(params, 1)
- ) / params.nFundingPeriodLength;
- auto startPeriod = (
- params.vFundingPeriods[idx].startHeight
- + params.nSubsidyPostBlossomHalvingInterval
- - HeightForHalving(params, 1)
- ) / params.nFundingPeriodLength;
+ assert(nHeight <= INT_MAX - params.nSubsidyPostBlossomHalvingInterval);
+ assert(params.vFundingPeriods[idx].startHeight <= INT_MAX - params.nSubsidyPostBlossomHalvingInterval);
+
+ int curPeriodNumerator = nHeight + params.nSubsidyPostBlossomHalvingInterval - HeightForHalving(params, 1);
+ int startPeriodNumerator = params.vFundingPeriods[idx].startHeight + params.nSubsidyPostBlossomHalvingInterval
+ - HeightForHalving(params, 1);
+
+ // Integer division is floor division for nonnegative integers in C++
+ assert(curPeriodNumerator >= 0);
+ assert(startPeriodNumerator >= 0);
+ auto curPeriod = curPeriodNumerator / params.nFundingPeriodLength;
+ auto startPeriod = startPeriodNumerator / params.nFundingPeriodLength;
auto addressIndex = curPeriod - startPeriod;
- return params.vFundingPeriods[idx].addresses[addressIndex];
+
+ auto addresses = params.vFundingPeriods[idx].addresses;
+ assert(addressIndex >= 0 && addressIndex < addresses.size());
+ return addresses[addressIndex];
};
CAmount FundingStreamValue(
@@ -282,7 +293,7 @@
const Consensus::Params& params,
Consensus::FundingStream idx)
{
- // Integer division is floor division in C++
+ // Integer division is floor division for nonnegative integers in C++
return CAmount((
GetBlockSubsidy(nHeight, params) * params.vFundingPeriods[idx].valueNumerator
) / params.vFundingPeriods[idx].valueDenominator);
@@ -293,7 +304,7 @@
const Consensus::Params& params)
{
std::set<std::pair<CScript, CAmount>> requiredStreams;
- for (int idx = Consensus::FS_ZECC_EF; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
+ for (int idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
// Funding period is [startHeight, endHeight)
if (nHeight >= params.vFundingPeriods[idx].startHeight &&
nHeight < params.vFundingPeriods[idx].endHeight)
diff --git a/zip-0207.rst b/zip-0207.rst
index 36603514e..fa2bed198 100644
--- a/zip-0207.rst
+++ b/zip-0207.rst
@@ -224,6 +224,8 @@ Example implementation
MAX_FUNDING_STREAMS,
};
+ const auto FIRST_FUNDING_STREAM = FS_ECC;
+
struct Params {
...
int nFundingPeriodLength;
@@ -236,16 +238,17 @@ Example implementation
Consensus::FundingStream idx,
std::vector addresses,
uint64_t valueNumerator,
- uint64_t valueDenominator)
+ uint64_t valueDenominator,
+ int startHeight,
+ int endHeight)
{
assert(valueNumerator < valueDenominator);
assert(valueNumerator < INT64_MAX / MAX_MONEY);
params.vFundingPeriods[idx].addresses = addresses;
params.vFundingPeriods[idx].valueNumerator = valueNumerator;
params.vFundingPeriods[idx].valueDenominator = valueDenominator;
- params.vFundingPeriods[idx].startHeight =
- params.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight;
- params.vFundingPeriods[idx].endHeight = HeightForHalving(params, 1);
+ params.vFundingPeriods[idx].startHeight = startHeight;
+ params.vFundingPeriods[idx].endHeight = endHeight;
assert(params.vFundingPeriods[idx].startHeight < params.vFundingPeriods[idx].endHeight);
};
@@ -254,9 +257,11 @@ Example implementation
consensus.nFundingPeriodLength = consensus.nSubsidyPostBlossomHalvingInterval / 48;
- AddZIP207FundingStream(consensus, Consensus::FS_ECC, FS_ECC_ADDRESSES, 7, 100);
- AddZIP207FundingStream(consensus, Consensus::FS_ZF, FS_ZF_ADDRESSES, 5, 100);
- AddZIP207FundingStream(consensus, Consensus::FS_MG, FS_MG_ADDRESSES, 8, 100);
+ int devFundStartHeight = HeightForHalving(params, 1);
+ int devFundEndHeight = HeightForHalving(params, 2);
+ AddZIP207FundingStream(consensus, Consensus::FS_ECC, FS_ECC_ADDRESSES, 7, 100, devFundStartHeight, devFundEndHeight);
+ AddZIP207FundingStream(consensus, Consensus::FS_ZF, FS_ZF_ADDRESSES, 5, 100, devFundStartHeight, devFundEndHeight);
+ AddZIP207FundingStream(consensus, Consensus::FS_MG, FS_MG_ADDRESSES, 8, 100, devFundStartHeight, devFundEndHeight);
...
}
@@ -266,17 +271,23 @@ Example implementation
const Consensus::Params& params,
Consensus::FundingStream idx)
{
- // Integer division is floor division in C++
- auto curPeriod = (
- nHeight + params.nSubsidyPostBlossomHalvingInterval - HeightForHalving(params, 1)
- ) / params.nFundingPeriodLength;
- auto startPeriod = (
- params.vFundingPeriods[idx].startHeight
- + params.nSubsidyPostBlossomHalvingInterval
- - HeightForHalving(params, 1)
- ) / params.nFundingPeriodLength;
+ assert(nHeight <= INT_MAX - params.nSubsidyPostBlossomHalvingInterval);
+ assert(params.vFundingPeriods[idx].startHeight <= INT_MAX - params.nSubsidyPostBlossomHalvingInterval);
+
+ int curPeriodNumerator = nHeight + params.nSubsidyPostBlossomHalvingInterval - HeightForHalving(params, 1);
+ int startPeriodNumerator = params.vFundingPeriods[idx].startHeight + params.nSubsidyPostBlossomHalvingInterval
+ - HeightForHalving(params, 1);
+
+ // Integer division is floor division for nonnegative integers in C++
+ assert(curPeriodNumerator >= 0);
+ assert(startPeriodNumerator >= 0);
+ auto curPeriod = curPeriodNumerator / params.nFundingPeriodLength;
+ auto startPeriod = startPeriodNumerator / params.nFundingPeriodLength;
auto addressIndex = curPeriod - startPeriod;
- return params.vFundingPeriods[idx].addresses[addressIndex];
+
+ auto addresses = params.vFundingPeriods[idx].addresses;
+ assert(addressIndex >= 0 && addressIndex < addresses.size());
+ return addresses[addressIndex];
};
CAmount FundingStreamValue(
@@ -284,7 +295,7 @@ Example implementation
const Consensus::Params& params,
Consensus::FundingStream idx)
{
- // Integer division is floor division in C++
+ // Integer division is floor division for nonnegative integers in C++
return CAmount((
GetBlockSubsidy(nHeight, params) * params.vFundingPeriods[idx].valueNumerator
) / params.vFundingPeriods[idx].valueDenominator);
@@ -295,7 +306,7 @@ Example implementation
const Consensus::Params& params)
{
std::set> requiredStreams;
- for (int idx = Consensus::FS_ZECC_EF; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
+ for (int idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
// Funding period is [startHeight, endHeight)
if (nHeight >= params.vFundingPeriods[idx].startHeight &&
nHeight < params.vFundingPeriods[idx].endHeight)