Merge pull request #5956 from nuttycom/fix/sendmany_orchard_minconf

Ensure anchor depth is > 0 when selecting an Orchard anchor.
This commit is contained in:
Charlie O'Keefe 2022-05-13 16:44:48 -06:00 committed by GitHub
commit 3f09cfa00a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

1
.gitignore vendored
View File

@ -33,6 +33,7 @@ build-aux/test-driver
config.log
config.status
configure
configure~
libtool
src/config/bitcoin-config.h
src/config/bitcoin-config.h.in

View File

@ -5283,10 +5283,15 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
std::optional<uint256> orchardAnchor;
auto nAnchorDepth = std::min((unsigned int) nMinDepth, nAnchorConfirmations);
if ((ztxoSelector.SelectsOrchard() || nOrchardOutputs > 0) && nAnchorDepth == 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot select Orchard notes or send to Orchard recipients when minconf=0.");
}
if (!ztxoSelector.SelectsSprout() && nAnchorDepth > 0) {
auto orchardAnchorHeight = nextBlockHeight - nAnchorDepth;
if (chainparams.GetConsensus().NetworkUpgradeActive(orchardAnchorHeight, Consensus::UPGRADE_NU5)) {
orchardAnchor = chainActive[orchardAnchorHeight]->hashFinalOrchardRoot;
auto anchorBlockIndex = chainActive[orchardAnchorHeight];
assert(anchorBlockIndex != nullptr);
orchardAnchor = anchorBlockIndex->hashFinalOrchardRoot;
}
}
TransactionBuilder builder(chainparams.GetConsensus(), nextBlockHeight, orchardAnchor, pwalletMain);
@ -5522,7 +5527,12 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
}
},
[&](const libzcash::UnifiedAddress& ua) {
// OK
if (!ua.GetSaplingReceiver().has_value()) {
throw JSONRPCError(
RPC_VERIFY_REJECTED,
"Only Sapling shielding is currently supported by z_shieldcoinbase. "
"Use z_sendmany with a transaction amount that results in no change for Orchard shielding.");
}
}
}, destaddress.value());
} else {
@ -5641,11 +5651,13 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
// Builder (used if Sapling addresses are involved)
std::optional<uint256> orchardAnchor;
if (canopyActive) {
if (nAnchorConfirmations > 0) {
// Allow Orchard recipients by setting an Orchard anchor.
auto orchardAnchorHeight = nextBlockHeight - nAnchorConfirmations;
if (Params().GetConsensus().NetworkUpgradeActive(orchardAnchorHeight, Consensus::UPGRADE_NU5)) {
orchardAnchor = chainActive[orchardAnchorHeight]->hashFinalOrchardRoot;
auto anchorBlockIndex = chainActive[orchardAnchorHeight];
assert(anchorBlockIndex != nullptr);
orchardAnchor = anchorBlockIndex->hashFinalOrchardRoot;
}
}
TransactionBuilder builder = TransactionBuilder(
@ -6118,13 +6130,13 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
std::optional<TransactionBuilder> builder;
if (isToSaplingZaddr || saplingNoteInputs.size() > 0) {
std::optional<uint256> orchardAnchor;
if (!isSproutShielded) {
if (!isSproutShielded && nAnchorConfirmations > 0) {
// Allow Orchard recipients by setting an Orchard anchor.
// TODO: Add an orchardAnchorHeight field to ZTXOSelector so we can ensure the
// same anchor is used for witnesses of any selected Orchard note.
auto orchardAnchorHeight = nextBlockHeight - nAnchorConfirmations;
if (Params().GetConsensus().NetworkUpgradeActive(orchardAnchorHeight, Consensus::UPGRADE_NU5)) {
orchardAnchor = chainActive[orchardAnchorHeight]->hashFinalOrchardRoot;
auto anchorBlockIndex = chainActive[orchardAnchorHeight];
assert(anchorBlockIndex != nullptr);
orchardAnchor = anchorBlockIndex->hashFinalOrchardRoot;
}
}
builder = TransactionBuilder(Params().GetConsensus(), nextBlockHeight, orchardAnchor, pwalletMain);