Skip to content

Commit 7fbb055

Browse files
authored
Merge pull request zcash#6965 from daira/fix-getblocksubsidy-suggestions
Fix getblocksubsidy suggestions
2 parents 1e5eb36 + 4ddd340 commit 7fbb055

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

src/consensus/params.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ namespace Consensus {
194194

195195
const auto expectedRecipients = params.FundingPeriodIndex(startHeight, endHeight - 1) + 1;
196196
if (expectedRecipients > recipients.size()) {
197-
return FundingStreamError::INSUFFICIENT_ADDRESSES;
197+
return FundingStreamError::INSUFFICIENT_RECIPIENTS;
198198
}
199199

200200
// Lockbox output periods must not start before NU6
@@ -221,8 +221,8 @@ namespace Consensus {
221221
throw std::runtime_error("Canopy network upgrade not active at funding stream start height.");
222222
case FundingStreamError::ILLEGAL_RANGE:
223223
throw std::runtime_error("Illegal start/end height combination for funding stream.");
224-
case FundingStreamError::INSUFFICIENT_ADDRESSES:
225-
throw std::runtime_error("Insufficient payment addresses to fully exhaust funding stream.");
224+
case FundingStreamError::INSUFFICIENT_RECIPIENTS:
225+
throw std::runtime_error("Insufficient recipient identifiers to fully exhaust funding stream.");
226226
case FundingStreamError::NU6_NOT_ACTIVE:
227227
throw std::runtime_error("NU6 network upgrade not active at lockbox period start height.");
228228
default:
@@ -349,7 +349,11 @@ namespace Consensus {
349349
// Funding streams are disabled if Canopy is not active.
350350
if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
351351
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
352+
// The following indexed access is safe as Consensus::MAX_FUNDING_STREAMS is used
353+
// in the definition of vFundingStreams.
352354
auto fs = vFundingStreams[idx];
355+
356+
// Funding period is [startHeight, endHeight).
353357
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
354358
activeStreams.push_back(std::make_pair(FundingStreamInfo[idx], fs.value()));
355359
}
@@ -372,16 +376,10 @@ namespace Consensus {
372376

373377
// Funding streams are disabled if Canopy is not active.
374378
if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
375-
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
376-
// The following indexed access is safe as Consensus::MAX_FUNDING_STREAMS is used
377-
// in the definition of vFundingStreams.
378-
auto fs = vFundingStreams[idx];
379-
// Funding period is [startHeight, endHeight)
380-
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
381-
requiredElements.insert(std::make_pair(
382-
fs.value().Recipient(*this, nHeight),
383-
FundingStreamInfo[idx].Value(blockSubsidy)));
384-
}
379+
for (const auto& [fsinfo, fs] : GetActiveFundingStreams(nHeight)) {
380+
requiredElements.insert(std::make_pair(
381+
fs.Recipient(*this, nHeight),
382+
fsinfo.Value(blockSubsidy)));
385383
}
386384
}
387385

src/consensus/params.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extern const struct FSInfo FundingStreamInfo[];
134134
enum FundingStreamError {
135135
CANOPY_NOT_ACTIVE,
136136
ILLEGAL_RANGE,
137-
INSUFFICIENT_ADDRESSES,
137+
INSUFFICIENT_RECIPIENTS,
138138
NU6_NOT_ACTIVE,
139139
};
140140

src/miner.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -115,39 +115,38 @@ class AddOutputsToCoinbaseTxAndSign
115115
}
116116

117117
CAmount SetFoundersRewardAndGetMinerValue(sapling::Builder& saplingBuilder) const {
118-
auto block_subsidy = chainparams.GetConsensus().GetBlockSubsidy(nHeight);
118+
const auto& consensus = chainparams.GetConsensus();
119+
const auto block_subsidy = consensus.GetBlockSubsidy(nHeight);
119120
auto miner_reward = block_subsidy; // founders' reward or funding stream amounts will be subtracted below
120121

121122
if (nHeight > 0) {
122123
if (chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
123-
auto fundingStreamElements = chainparams.GetConsensus().GetActiveFundingStreamElements(
124-
nHeight,
125-
block_subsidy);
126-
127124
LogPrint("pow", "%s: Constructing funding stream outputs for height %d", __func__, nHeight);
128-
for (Consensus::FundingStreamElement fselem : fundingStreamElements) {
129-
miner_reward -= fselem.second;
130-
examine(fselem.first, match {
125+
for (const auto& [fsinfo, fs] : consensus.GetActiveFundingStreams(nHeight)) {
126+
const auto amount = fsinfo.Value(block_subsidy);
127+
miner_reward -= amount;
128+
129+
examine(fs.Recipient(consensus, nHeight), match {
131130
[&](const libzcash::SaplingPaymentAddress& pa) {
132-
LogPrint("pow", "%s: Adding Sapling funding stream output of value %d", __func__, fselem.second);
131+
LogPrint("pow", "%s: Adding Sapling funding stream output of value %d", __func__, amount);
133132
saplingBuilder.add_recipient(
134133
{},
135134
pa.GetRawBytes(),
136-
fselem.second,
135+
amount,
137136
libzcash::Memo::ToBytes(std::nullopt));
138137
},
139138
[&](const CScript& scriptPubKey) {
140-
LogPrint("pow", "%s: Adding transparent funding stream output of value %d", __func__, fselem.second);
141-
mtx.vout.emplace_back(fselem.second, scriptPubKey);
139+
LogPrint("pow", "%s: Adding transparent funding stream output of value %d", __func__, amount);
140+
mtx.vout.emplace_back(amount, scriptPubKey);
142141
},
143142
[&](const Consensus::Lockbox& lockbox) {
144-
LogPrint("pow", "%s: Noting lockbox output of value %d", __func__, fselem.second);
143+
LogPrint("pow", "%s: Noting lockbox output of value %d", __func__, amount);
145144
}
146145
});
147146
}
148147
} else if (nHeight <= chainparams.GetConsensus().GetLastFoundersRewardBlockHeight(nHeight)) {
149148
// Founders reward is 20% of the block subsidy
150-
auto vFoundersReward = miner_reward / 5;
149+
const auto vFoundersReward = miner_reward / 5;
151150
// Take some reward away from us
152151
miner_reward -= vFoundersReward;
153152
// And give it to the founders

0 commit comments

Comments
 (0)