Skip to content

Commit e368a29

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 31fe3ce commit e368a29

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/miner.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,39 +115,40 @@ 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);
124+
const auto fundingStreams = consensus.GetActiveFundingStreams(nHeight);
126125

127126
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 {
127+
for (const auto& [fsinfo, fs] : fundingStreams) {
128+
const auto amount = fsinfo.Value(block_subsidy);
129+
miner_reward -= amount;
130+
131+
examine(fs.Recipient(consensus, nHeight), match {
131132
[&](const libzcash::SaplingPaymentAddress& pa) {
132-
LogPrint("pow", "%s: Adding Sapling funding stream output of value %d", __func__, fselem.second);
133+
LogPrint("pow", "%s: Adding Sapling funding stream output of value %d", __func__, amount);
133134
saplingBuilder.add_recipient(
134135
{},
135136
pa.GetRawBytes(),
136-
fselem.second,
137+
amount,
137138
libzcash::Memo::ToBytes(std::nullopt));
138139
},
139140
[&](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);
141+
LogPrint("pow", "%s: Adding transparent funding stream output of value %d", __func__, amount);
142+
mtx.vout.emplace_back(amount, scriptPubKey);
142143
},
143144
[&](const Consensus::Lockbox& lockbox) {
144-
LogPrint("pow", "%s: Noting lockbox output of value %d", __func__, fselem.second);
145+
LogPrint("pow", "%s: Noting lockbox output of value %d", __func__, amount);
145146
}
146147
});
147148
}
148149
} else if (nHeight <= chainparams.GetConsensus().GetLastFoundersRewardBlockHeight(nHeight)) {
149150
// Founders reward is 20% of the block subsidy
150-
auto vFoundersReward = miner_reward / 5;
151+
const auto vFoundersReward = miner_reward / 5;
151152
// Take some reward away from us
152153
miner_reward -= vFoundersReward;
153154
// And give it to the founders

0 commit comments

Comments
 (0)