Skip to content

Commit

Permalink
Merge pull request zcash#5963 from nuttycom/bug/orchard_final_root_be…
Browse files Browse the repository at this point in the history
…fore_nu5_active

Do not return Orchard components from z_gettreestate before NU5 activation.
  • Loading branch information
r3ld3v authored May 17, 2022
2 parents 46c41f5 + c44e58e commit a45c2a2
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,20 +1316,22 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
UniValue sapling_result(UniValue::VOBJ);
UniValue sapling_commitments(UniValue::VOBJ);
sapling_commitments.pushKV("finalRoot", pindex->hashFinalSaplingRoot.GetHex());
bool need_skiphash = false;
SaplingMerkleTree tree;
if (pcoinsTip->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, tree)) {
CDataStream s(SER_NETWORK, PROTOCOL_VERSION);
s << tree;
sapling_commitments.pushKV("finalState", HexStr(s.begin(), s.end()));
} else {
// Set skipHash to the most recent block that has a finalState.
const CBlockIndex* pindex_skip = pindex->pprev;
while (pindex_skip && !pcoinsTip->GetSaplingAnchorAt(pindex_skip->hashFinalSaplingRoot, tree)) {
pindex_skip = pindex_skip->pprev;
}
if (pindex_skip) {
sapling_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
if (Params().GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_SAPLING)) {
bool need_skiphash = false;
SaplingMerkleTree tree;
if (pcoinsTip->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, tree)) {
CDataStream s(SER_NETWORK, PROTOCOL_VERSION);
s << tree;
sapling_commitments.pushKV("finalState", HexStr(s.begin(), s.end()));
} else {
// Set skipHash to the most recent block that has a finalState.
const CBlockIndex* pindex_skip = pindex->pprev;
while (pindex_skip && !pcoinsTip->GetSaplingAnchorAt(pindex_skip->hashFinalSaplingRoot, tree)) {
pindex_skip = pindex_skip->pprev;
}
if (pindex_skip) {
sapling_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
}
}
}
sapling_result.pushKV("commitments", sapling_commitments);
Expand All @@ -1341,20 +1343,22 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
UniValue orchard_result(UniValue::VOBJ);
UniValue orchard_commitments(UniValue::VOBJ);
orchard_commitments.pushKV("finalRoot", pindex->hashFinalOrchardRoot.GetHex());
bool need_skiphash = false;
OrchardMerkleFrontier tree;
if (pcoinsTip->GetOrchardAnchorAt(pindex->hashFinalOrchardRoot, tree)) {
CDataStream s(SER_NETWORK, PROTOCOL_VERSION);
s << OrchardMerkleFrontierLegacySer(tree);
orchard_commitments.pushKV("finalState", HexStr(s.begin(), s.end()));
} else {
// Set skipHash to the most recent block that has a finalState.
const CBlockIndex* pindex_skip = pindex->pprev;
while (pindex_skip && !pcoinsTip->GetOrchardAnchorAt(pindex_skip->hashFinalOrchardRoot, tree)) {
pindex_skip = pindex_skip->pprev;
}
if (pindex_skip) {
orchard_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
if (Params().GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_NU5)) {
bool need_skiphash = false;
OrchardMerkleFrontier tree;
if (pcoinsTip->GetOrchardAnchorAt(pindex->hashFinalOrchardRoot, tree)) {
CDataStream s(SER_NETWORK, PROTOCOL_VERSION);
s << OrchardMerkleFrontierLegacySer(tree);
orchard_commitments.pushKV("finalState", HexStr(s.begin(), s.end()));
} else {
// Set skipHash to the most recent block that has a finalState.
const CBlockIndex* pindex_skip = pindex->pprev;
while (pindex_skip && !pcoinsTip->GetOrchardAnchorAt(pindex_skip->hashFinalOrchardRoot, tree)) {
pindex_skip = pindex_skip->pprev;
}
if (pindex_skip) {
orchard_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
}
}
}
orchard_result.pushKV("commitments", orchard_commitments);
Expand Down

0 comments on commit a45c2a2

Please sign in to comment.