Merge pull request #5965 from nuttycom/bug/orchard_final_root_before_nu5_active

Revert "Only return active protocol components from z_gettreestate."
This commit is contained in:
Kris Nuttycombe 2022-05-24 10:48:08 -06:00 committed by GitHub
commit cecd228fed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 34 deletions

View File

@ -1312,26 +1312,28 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
}
// sapling
{
auto sapling_activation_height = Params().GetConsensus().GetActivationHeight(Consensus::UPGRADE_SAPLING);
if (sapling_activation_height.has_value()) {
UniValue sapling_result(UniValue::VOBJ);
UniValue sapling_commitments(UniValue::VOBJ);
sapling_commitments.pushKV("finalRoot", pindex->hashFinalSaplingRoot.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());
}
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;
auto saplingActive = [&](const CBlockIndex* pindex_cur) -> bool {
return pindex_cur && pindex_cur->nHeight >= sapling_activation_height.value();
};
while (saplingActive(pindex_skip) && !pcoinsTip->GetSaplingAnchorAt(pindex_skip->hashFinalSaplingRoot, tree)) {
pindex_skip = pindex_skip->pprev;
}
if (saplingActive(pindex_skip)) {
sapling_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
}
}
sapling_result.pushKV("commitments", sapling_commitments);
@ -1339,26 +1341,28 @@ UniValue z_gettreestate(const UniValue& params, bool fHelp)
}
// orchard
{
auto nu5_activation_height = Params().GetConsensus().GetActivationHeight(Consensus::UPGRADE_NU5);
if (nu5_activation_height.has_value()) {
UniValue orchard_result(UniValue::VOBJ);
UniValue orchard_commitments(UniValue::VOBJ);
orchard_commitments.pushKV("finalRoot", pindex->hashFinalOrchardRoot.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());
}
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;
auto orchardActive = [&](const CBlockIndex* pindex_cur) -> bool {
return pindex_cur && pindex_cur->nHeight >= nu5_activation_height.value();
};
while (orchardActive(pindex_skip) && !pcoinsTip->GetOrchardAnchorAt(pindex_skip->hashFinalOrchardRoot, tree)) {
pindex_skip = pindex_skip->pprev;
}
if (orchardActive(pindex_skip)) {
orchard_result.pushKV("skipHash", pindex_skip->GetBlockHash().GetHex());
}
}
orchard_result.pushKV("commitments", orchard_commitments);