Merge pull request #5963 from nuttycom/bug/orchard_final_root_before_nu5_active

Do not return Orchard components from z_gettreestate before NU5 activation.
This commit is contained in:
Steven 2022-05-17 07:10:07 -07:00 committed by GitHub
commit a45c2a2d4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 28 deletions

View File

@ -1316,20 +1316,22 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
UniValue sapling_result(UniValue::VOBJ); UniValue sapling_result(UniValue::VOBJ);
UniValue sapling_commitments(UniValue::VOBJ); UniValue sapling_commitments(UniValue::VOBJ);
sapling_commitments.pushKV("finalRoot", pindex->hashFinalSaplingRoot.GetHex()); sapling_commitments.pushKV("finalRoot", pindex->hashFinalSaplingRoot.GetHex());
bool need_skiphash = false; if (Params().GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_SAPLING)) {
SaplingMerkleTree tree; bool need_skiphash = false;
if (pcoinsTip->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, tree)) { SaplingMerkleTree tree;
CDataStream s(SER_NETWORK, PROTOCOL_VERSION); if (pcoinsTip->GetSaplingAnchorAt(pindex->hashFinalSaplingRoot, tree)) {
s << tree; CDataStream s(SER_NETWORK, PROTOCOL_VERSION);
sapling_commitments.pushKV("finalState", HexStr(s.begin(), s.end())); s << tree;
} else { sapling_commitments.pushKV("finalState", HexStr(s.begin(), s.end()));
// Set skipHash to the most recent block that has a finalState. } else {
const CBlockIndex* pindex_skip = pindex->pprev; // Set skipHash to the most recent block that has a finalState.
while (pindex_skip && !pcoinsTip->GetSaplingAnchorAt(pindex_skip->hashFinalSaplingRoot, tree)) { const CBlockIndex* pindex_skip = pindex->pprev;
pindex_skip = pindex_skip->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 (pindex_skip) {
sapling_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
}
} }
} }
sapling_result.pushKV("commitments", sapling_commitments); sapling_result.pushKV("commitments", sapling_commitments);
@ -1341,20 +1343,22 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
UniValue orchard_result(UniValue::VOBJ); UniValue orchard_result(UniValue::VOBJ);
UniValue orchard_commitments(UniValue::VOBJ); UniValue orchard_commitments(UniValue::VOBJ);
orchard_commitments.pushKV("finalRoot", pindex->hashFinalOrchardRoot.GetHex()); orchard_commitments.pushKV("finalRoot", pindex->hashFinalOrchardRoot.GetHex());
bool need_skiphash = false; if (Params().GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_NU5)) {
OrchardMerkleFrontier tree; bool need_skiphash = false;
if (pcoinsTip->GetOrchardAnchorAt(pindex->hashFinalOrchardRoot, tree)) { OrchardMerkleFrontier tree;
CDataStream s(SER_NETWORK, PROTOCOL_VERSION); if (pcoinsTip->GetOrchardAnchorAt(pindex->hashFinalOrchardRoot, tree)) {
s << OrchardMerkleFrontierLegacySer(tree); CDataStream s(SER_NETWORK, PROTOCOL_VERSION);
orchard_commitments.pushKV("finalState", HexStr(s.begin(), s.end())); s << OrchardMerkleFrontierLegacySer(tree);
} else { orchard_commitments.pushKV("finalState", HexStr(s.begin(), s.end()));
// Set skipHash to the most recent block that has a finalState. } else {
const CBlockIndex* pindex_skip = pindex->pprev; // Set skipHash to the most recent block that has a finalState.
while (pindex_skip && !pcoinsTip->GetOrchardAnchorAt(pindex_skip->hashFinalOrchardRoot, tree)) { const CBlockIndex* pindex_skip = pindex->pprev;
pindex_skip = pindex_skip->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 (pindex_skip) {
orchard_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
}
} }
} }
orchard_result.pushKV("commitments", orchard_commitments); orchard_result.pushKV("commitments", orchard_commitments);