Skip to content

Commit d60c51e

Browse files
committed
sapling::Builder: add funding stream outputs in a more predictable order.
Previously it was deterministic, but depended on details of the `operator<` implementations of `FundingStreamRecipient`, `SaplingPaymentAddress`, and `CScript`. Now it is just the same order as in `vFundingStreams`. Signed-off-by: Daira-Emma Hopwood <[email protected]>
1 parent e44be4f commit d60c51e

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/miner.cpp

Lines changed: 13 additions & 14 deletions
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)