Skip to content

Commit

Permalink
Merge pull request zcash#6965 from daira/fix-getblocksubsidy-suggestions
Browse files Browse the repository at this point in the history
Fix getblocksubsidy suggestions
  • Loading branch information
str4d authored Oct 24, 2024
2 parents 1e5eb36 + 4ddd340 commit 7fbb055
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
24 changes: 11 additions & 13 deletions src/consensus/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace Consensus {

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

// Lockbox output periods must not start before NU6
Expand All @@ -221,8 +221,8 @@ namespace Consensus {
throw std::runtime_error("Canopy network upgrade not active at funding stream start height.");
case FundingStreamError::ILLEGAL_RANGE:
throw std::runtime_error("Illegal start/end height combination for funding stream.");
case FundingStreamError::INSUFFICIENT_ADDRESSES:
throw std::runtime_error("Insufficient payment addresses to fully exhaust funding stream.");
case FundingStreamError::INSUFFICIENT_RECIPIENTS:
throw std::runtime_error("Insufficient recipient identifiers to fully exhaust funding stream.");
case FundingStreamError::NU6_NOT_ACTIVE:
throw std::runtime_error("NU6 network upgrade not active at lockbox period start height.");
default:
Expand Down Expand Up @@ -349,7 +349,11 @@ namespace Consensus {
// Funding streams are disabled if Canopy is not active.
if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
// The following indexed access is safe as Consensus::MAX_FUNDING_STREAMS is used
// in the definition of vFundingStreams.
auto fs = vFundingStreams[idx];

// Funding period is [startHeight, endHeight).
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
activeStreams.push_back(std::make_pair(FundingStreamInfo[idx], fs.value()));
}
Expand All @@ -372,16 +376,10 @@ namespace Consensus {

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

Expand Down
2 changes: 1 addition & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extern const struct FSInfo FundingStreamInfo[];
enum FundingStreamError {
CANOPY_NOT_ACTIVE,
ILLEGAL_RANGE,
INSUFFICIENT_ADDRESSES,
INSUFFICIENT_RECIPIENTS,
NU6_NOT_ACTIVE,
};

Expand Down
27 changes: 13 additions & 14 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,39 +115,38 @@ class AddOutputsToCoinbaseTxAndSign
}

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

if (nHeight > 0) {
if (chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
auto fundingStreamElements = chainparams.GetConsensus().GetActiveFundingStreamElements(
nHeight,
block_subsidy);

LogPrint("pow", "%s: Constructing funding stream outputs for height %d", __func__, nHeight);
for (Consensus::FundingStreamElement fselem : fundingStreamElements) {
miner_reward -= fselem.second;
examine(fselem.first, match {
for (const auto& [fsinfo, fs] : consensus.GetActiveFundingStreams(nHeight)) {
const auto amount = fsinfo.Value(block_subsidy);
miner_reward -= amount;

examine(fs.Recipient(consensus, nHeight), match {
[&](const libzcash::SaplingPaymentAddress& pa) {
LogPrint("pow", "%s: Adding Sapling funding stream output of value %d", __func__, fselem.second);
LogPrint("pow", "%s: Adding Sapling funding stream output of value %d", __func__, amount);
saplingBuilder.add_recipient(
{},
pa.GetRawBytes(),
fselem.second,
amount,
libzcash::Memo::ToBytes(std::nullopt));
},
[&](const CScript& scriptPubKey) {
LogPrint("pow", "%s: Adding transparent funding stream output of value %d", __func__, fselem.second);
mtx.vout.emplace_back(fselem.second, scriptPubKey);
LogPrint("pow", "%s: Adding transparent funding stream output of value %d", __func__, amount);
mtx.vout.emplace_back(amount, scriptPubKey);
},
[&](const Consensus::Lockbox& lockbox) {
LogPrint("pow", "%s: Noting lockbox output of value %d", __func__, fselem.second);
LogPrint("pow", "%s: Noting lockbox output of value %d", __func__, amount);
}
});
}
} else if (nHeight <= chainparams.GetConsensus().GetLastFoundersRewardBlockHeight(nHeight)) {
// Founders reward is 20% of the block subsidy
auto vFoundersReward = miner_reward / 5;
const auto vFoundersReward = miner_reward / 5;
// Take some reward away from us
miner_reward -= vFoundersReward;
// And give it to the founders
Expand Down

0 comments on commit 7fbb055

Please sign in to comment.