Skip to content

Commit 26939a9

Browse files
authored
Merge pull request zcash#6963 from str4d/fix-getblocksubsidy
Fix `getblocksubsidy`
2 parents a0602eb + 97bba69 commit 26939a9

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

src/consensus/params.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace Consensus {
4343
},
4444
{
4545
.recipient = "Lockbox NU6",
46-
.specification = "https://zips.z.cash/draft-nuttycom-funding-allocation",
46+
.specification = "https://zips.z.cash/zip-0214",
4747
.valueNumerator = 12,
4848
.valueDenominator = 100,
4949
}
@@ -342,16 +342,16 @@ namespace Consensus {
342342
}
343343
}
344344

345-
std::vector<FSInfo> Params::GetActiveFundingStreams(int nHeight) const
345+
std::vector<std::pair<FSInfo, FundingStream>> Params::GetActiveFundingStreams(int nHeight) const
346346
{
347-
std::vector<FSInfo> activeStreams;
347+
std::vector<std::pair<FSInfo, FundingStream>> activeStreams;
348348

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++) {
352352
auto fs = vFundingStreams[idx];
353353
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
354-
activeStreams.push_back(FundingStreamInfo[idx]);
354+
activeStreams.push_back(std::make_pair(FundingStreamInfo[idx], fs.value()));
355355
}
356356
}
357357
}

src/consensus/params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ struct Params {
347347
/**
348348
* Returns the vector of active funding streams as of the given height.
349349
*/
350-
std::vector<FSInfo> GetActiveFundingStreams(int nHeight) const;
350+
std::vector<std::pair<FSInfo, FundingStream>> GetActiveFundingStreams(int nHeight) const;
351351

352352
/**
353353
* Returns the vector of active funding stream elements as of the given height.

src/rpc/mining.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)
968968
UniValue lockboxstreams(UniValue::VARR);
969969
auto fsinfos = consensus.GetActiveFundingStreams(nHeight);
970970
for (int idx = 0; idx < fsinfos.size(); idx++) {
971-
const auto& fsinfo = fsinfos[idx];
971+
const auto& fsinfo = fsinfos[idx].first;
972972
CAmount nStreamAmount = fsinfo.Value(nBlockSubsidy);
973973

974974
UniValue fsobj(UniValue::VOBJ);
@@ -977,8 +977,8 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp)
977977
fsobj.pushKV("value", ValueFromAmount(nStreamAmount));
978978
fsobj.pushKV("valueZat", nStreamAmount);
979979

980-
auto fs = consensus.vFundingStreams[idx];
981-
auto recipient = fs.value().Recipient(consensus, nHeight);
980+
auto fs = fsinfos[idx].second;
981+
auto recipient = fs.Recipient(consensus, nHeight);
982982

983983
examine(recipient, match {
984984
[&](const CScript& scriptPubKey) {

src/wallet/test/rpc_wallet_tests.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,25 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
315315
}
316316
};
317317

318+
auto check_lockbox_streams = [](UniValue obj, std::vector<std::string> recipients, std::vector<double> amounts) {
319+
size_t n = recipients.size();
320+
BOOST_REQUIRE_EQUAL(amounts.size(), n);
321+
UniValue lockboxstreams = find_value(obj, "lockboxstreams");
322+
BOOST_CHECK_EQUAL(lockboxstreams.size(), n);
323+
if (lockboxstreams.size() != n) return;
324+
325+
for (int i = 0; i < n; i++) {
326+
UniValue fsobj = lockboxstreams[i];
327+
BOOST_CHECK_EQUAL(find_value(fsobj, "recipient").get_str(), recipients[i]);
328+
BOOST_CHECK_EQUAL(find_value(fsobj, "specification").get_str(), "https://zips.z.cash/zip-0214");
329+
BOOST_CHECK_EQUAL(find_value(fsobj, "value").get_real(), amounts[i]);
330+
}
331+
};
332+
318333
bool canopyEnabled =
319334
Params().GetConsensus().vUpgrades[Consensus::UPGRADE_CANOPY].nActivationHeight != Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
335+
bool nu6Enabled =
336+
Params().GetConsensus().vUpgrades[Consensus::UPGRADE_NU6].nActivationHeight != Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
320337

321338
// slow start + blossom activation + (pre blossom halving - blossom activation) * 2
322339
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 1046400"));
@@ -332,6 +349,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
332349
"t3XyYW8yBFRuMnfvm5KLGFbEVz25kckZXym"
333350
});
334351
}
352+
BOOST_CHECK(find_value(obj, "lockboxstreams").empty());
335353

336354
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 2726399"));
337355
obj = retValue.get_obj();
@@ -346,9 +364,27 @@ BOOST_AUTO_TEST_CASE(rpc_wallet)
346364
"t3XyYW8yBFRuMnfvm5KLGFbEVz25kckZXym"
347365
});
348366
}
367+
BOOST_CHECK(find_value(obj, "lockboxstreams").empty());
349368

350369
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 2726400"));
351370
obj = retValue.get_obj();
371+
BOOST_CHECK_EQUAL(find_value(obj, "miner").get_real(), nu6Enabled ? 1.25 : 1.5625);
372+
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 0.0);
373+
if (nu6Enabled) {
374+
check_funding_streams(obj, { "Zcash Community Grants NU6" },
375+
{ 0.125, },
376+
{
377+
"t3cFfPt1Bcvgez9ZbMBFWeZsskxTkPzGCow"
378+
});
379+
check_lockbox_streams(obj, { "Lockbox NU6" },
380+
{ 0.1875, });
381+
} else {
382+
BOOST_CHECK(find_value(obj, "fundingstreams").empty());
383+
BOOST_CHECK(find_value(obj, "lockboxstreams").empty());
384+
}
385+
386+
BOOST_CHECK_NO_THROW(retValue = CallRPC("getblocksubsidy 3146400"));
387+
obj = retValue.get_obj();
352388
BOOST_CHECK_EQUAL(find_value(obj, "miner").get_real(), 1.5625);
353389
BOOST_CHECK_EQUAL(find_value(obj, "founders").get_real(), 0.0);
354390
BOOST_CHECK(find_value(obj, "fundingstreams").empty());

0 commit comments

Comments
 (0)