From fd91f099f4f30ef658515b14d41ca888e394eadd Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 29 Jun 2021 14:40:26 -0600 Subject: [PATCH] Rename tx.valueBalance -> tx.valueBalanceSapling --- src/gtest/test_checktransaction.cpp | 24 ++++++++-------- src/gtest/test_transaction_builder.cpp | 18 ++++++------ src/main.cpp | 34 +++++++++++------------ src/miner.cpp | 14 +++++----- src/primitives/transaction.cpp | 38 +++++++++++++------------- src/primitives/transaction.h | 22 +++++++-------- src/rpc/rawtransaction.cpp | 12 ++++---- src/script/interpreter.cpp | 6 ++-- src/test/sighash_tests.cpp | 2 +- src/transaction_builder.cpp | 8 +++--- src/wallet/gtest/test_wallet.cpp | 6 ++-- src/wallet/rpcwallet.cpp | 4 +-- src/wallet/wallet.cpp | 26 +++++++++--------- 13 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/gtest/test_checktransaction.cpp b/src/gtest/test_checktransaction.cpp index bfc4181e1..cf0ee056a 100644 --- a/src/gtest/test_checktransaction.cpp +++ b/src/gtest/test_checktransaction.cpp @@ -324,7 +324,7 @@ TEST(ChecktransactionTests, BadTxnsTxouttotalToolargeOutputs) { TEST(ChecktransactionTests, ValueBalanceNonZero) { CMutableTransaction mtx = GetValidTransaction(); - mtx.valueBalance = 10; + mtx.valueBalanceSapling = 10; CTransaction tx(mtx); @@ -336,7 +336,7 @@ TEST(ChecktransactionTests, ValueBalanceNonZero) { TEST(ChecktransactionTests, PositiveValueBalanceTooLarge) { CMutableTransaction mtx = GetValidTransaction(); mtx.vShieldedSpend.resize(1); - mtx.valueBalance = MAX_MONEY + 1; + mtx.valueBalanceSapling = MAX_MONEY + 1; CTransaction tx(mtx); @@ -348,7 +348,7 @@ TEST(ChecktransactionTests, PositiveValueBalanceTooLarge) { TEST(ChecktransactionTests, NegativeValueBalanceTooLarge) { CMutableTransaction mtx = GetValidTransaction(); mtx.vShieldedSpend.resize(1); - mtx.valueBalance = -(MAX_MONEY + 1); + mtx.valueBalanceSapling = -(MAX_MONEY + 1); CTransaction tx(mtx); @@ -361,7 +361,7 @@ TEST(ChecktransactionTests, ValueBalanceOverflowsTotal) { CMutableTransaction mtx = GetValidTransaction(); mtx.vShieldedSpend.resize(1); mtx.vout[0].nValue = 1; - mtx.valueBalance = -MAX_MONEY; + mtx.valueBalanceSapling = -MAX_MONEY; CTransaction tx(mtx); @@ -859,7 +859,7 @@ TEST(ChecktransactionTests, SaplingSproutInputSumsTooLarge) { EXPECT_TRUE(CheckTransactionWithoutProofVerification(tx, state)); } - mtx.valueBalance = (MAX_MONEY / 2) + 10; + mtx.valueBalanceSapling = (MAX_MONEY / 2) + 10; { UNSAFE_CTransaction tx(mtx); @@ -1221,7 +1221,7 @@ TEST(ChecktransactionTests, HeartwoodAcceptsShieldedCoinbase) { RegtestDeactivateHeartwood(); } -// Check that the consensus rules relevant to valueBalance, vShieldedOutput, and +// Check that the consensus rules relevant to valueBalanceSapling, vShieldedOutput, and // bindingSig from https://zips.z.cash/protocol/protocol.pdf#txnencoding are // applied to coinbase transactions. TEST(ChecktransactionTests, HeartwoodEnforcesSaplingRulesOnShieldedCoinbase) { @@ -1242,10 +1242,10 @@ TEST(ChecktransactionTests, HeartwoodEnforcesSaplingRulesOnShieldedCoinbase) { mtx.vin[0].prevout.SetNull(); mtx.vin[0].scriptSig << 123; mtx.vJoinSplit.resize(0); - mtx.valueBalance = -1000; + mtx.valueBalanceSapling = -1000; // Coinbase transaction should fail non-contextual checks with no shielded - // outputs and non-zero valueBalance. + // outputs and non-zero valueBalanceSapling. { CTransaction tx(mtx); EXPECT_TRUE(tx.IsCoinBase()); @@ -1261,10 +1261,10 @@ TEST(ChecktransactionTests, HeartwoodEnforcesSaplingRulesOnShieldedCoinbase) { librustzcash_sapling_proving_ctx_free(ctx); mtx.vShieldedOutput.push_back(odesc); - // Coinbase transaction should fail non-contextual checks with valueBalance + // Coinbase transaction should fail non-contextual checks with valueBalanceSapling // out of range. { - mtx.valueBalance = MAX_MONEY + 1; + mtx.valueBalanceSapling = MAX_MONEY + 1; EXPECT_THROW((CTransaction(mtx)), std::ios_base::failure); UNSAFE_CTransaction tx(mtx); EXPECT_TRUE(tx.IsCoinBase()); @@ -1274,7 +1274,7 @@ TEST(ChecktransactionTests, HeartwoodEnforcesSaplingRulesOnShieldedCoinbase) { EXPECT_FALSE(CheckTransactionWithoutProofVerification(tx, state)); } { - mtx.valueBalance = -MAX_MONEY - 1; + mtx.valueBalanceSapling = -MAX_MONEY - 1; EXPECT_THROW((CTransaction(mtx)), std::ios_base::failure); UNSAFE_CTransaction tx(mtx); EXPECT_TRUE(tx.IsCoinBase()); @@ -1284,7 +1284,7 @@ TEST(ChecktransactionTests, HeartwoodEnforcesSaplingRulesOnShieldedCoinbase) { EXPECT_FALSE(CheckTransactionWithoutProofVerification(tx, state)); } - mtx.valueBalance = -1000; + mtx.valueBalanceSapling = -1000; CTransaction tx(mtx); EXPECT_TRUE(tx.IsCoinBase()); diff --git a/src/gtest/test_transaction_builder.cpp b/src/gtest/test_transaction_builder.cpp index bef75d05b..7b8d41009 100644 --- a/src/gtest/test_transaction_builder.cpp +++ b/src/gtest/test_transaction_builder.cpp @@ -102,7 +102,7 @@ TEST(TransactionBuilder, TransparentToSapling) EXPECT_EQ(tx.vJoinSplit.size(), 0); EXPECT_EQ(tx.vShieldedSpend.size(), 0); EXPECT_EQ(tx.vShieldedOutput.size(), 1); - EXPECT_EQ(tx.valueBalance, -40000); + EXPECT_EQ(tx.valueBalanceSapling, -40000); CValidationState state; EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 2, true)); @@ -139,7 +139,7 @@ TEST(TransactionBuilder, SaplingToSapling) { EXPECT_EQ(tx.vJoinSplit.size(), 0); EXPECT_EQ(tx.vShieldedSpend.size(), 1); EXPECT_EQ(tx.vShieldedOutput.size(), 2); - EXPECT_EQ(tx.valueBalance, 10000); + EXPECT_EQ(tx.valueBalanceSapling, 10000); CValidationState state; EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 3, true)); @@ -177,7 +177,7 @@ TEST(TransactionBuilder, SaplingToSprout) { EXPECT_EQ(tx.vJoinSplit[0].vpub_new, 0); EXPECT_EQ(tx.vShieldedSpend.size(), 1); EXPECT_EQ(tx.vShieldedOutput.size(), 1); - EXPECT_EQ(tx.valueBalance, 35000); + EXPECT_EQ(tx.valueBalanceSapling, 35000); CValidationState state; EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 3, true)); @@ -238,7 +238,7 @@ TEST(TransactionBuilder, SproutToSproutAndSapling) { EXPECT_EQ(tx.vJoinSplit[2].vpub_new, 10000); EXPECT_EQ(tx.vShieldedSpend.size(), 0); EXPECT_EQ(tx.vShieldedOutput.size(), 1); - EXPECT_EQ(tx.valueBalance, -5000); + EXPECT_EQ(tx.valueBalanceSapling, -5000); CValidationState state; EXPECT_TRUE(ContextualCheckTransaction(tx, state, Params(), 4, true)); @@ -365,7 +365,7 @@ TEST(TransactionBuilder, ChangeOutput) EXPECT_EQ(tx.vJoinSplit.size(), 0); EXPECT_EQ(tx.vShieldedSpend.size(), 1); EXPECT_EQ(tx.vShieldedOutput.size(), 1); - EXPECT_EQ(tx.valueBalance, -15000); + EXPECT_EQ(tx.valueBalanceSapling, -15000); } // Change to a Sapling address @@ -380,7 +380,7 @@ TEST(TransactionBuilder, ChangeOutput) EXPECT_EQ(tx.vJoinSplit.size(), 0); EXPECT_EQ(tx.vShieldedSpend.size(), 0); EXPECT_EQ(tx.vShieldedOutput.size(), 1); - EXPECT_EQ(tx.valueBalance, -15000); + EXPECT_EQ(tx.valueBalanceSapling, -15000); } // Change to a transparent address @@ -395,7 +395,7 @@ TEST(TransactionBuilder, ChangeOutput) EXPECT_EQ(tx.vJoinSplit.size(), 0); EXPECT_EQ(tx.vShieldedSpend.size(), 0); EXPECT_EQ(tx.vShieldedOutput.size(), 0); - EXPECT_EQ(tx.valueBalance, 0); + EXPECT_EQ(tx.valueBalanceSapling, 0); EXPECT_EQ(tx.vout[0].nValue, 15000); } @@ -427,7 +427,7 @@ TEST(TransactionBuilder, SetFee) EXPECT_EQ(tx.vJoinSplit.size(), 0); EXPECT_EQ(tx.vShieldedSpend.size(), 1); EXPECT_EQ(tx.vShieldedOutput.size(), 2); - EXPECT_EQ(tx.valueBalance, 10000); + EXPECT_EQ(tx.valueBalanceSapling, 10000); } // Configured fee @@ -443,7 +443,7 @@ TEST(TransactionBuilder, SetFee) EXPECT_EQ(tx.vJoinSplit.size(), 0); EXPECT_EQ(tx.vShieldedSpend.size(), 1); EXPECT_EQ(tx.vShieldedOutput.size(), 2); - EXPECT_EQ(tx.valueBalance, 20000); + EXPECT_EQ(tx.valueBalanceSapling, 20000); } // Revert to default diff --git a/src/main.cpp b/src/main.cpp index ebc0eddc2..067167802 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1290,7 +1290,7 @@ bool ContextualCheckTransaction( if (!librustzcash_sapling_final_check( ctx, - tx.valueBalance, + tx.valueBalanceSapling, tx.bindingSig.begin(), dataToBeSigned.begin() )) @@ -1454,21 +1454,21 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio REJECT_INVALID, "bad-txns-txouttotal-toolarge"); } - // Check for non-zero valueBalance when there are no Sapling inputs or outputs - if (tx.vShieldedSpend.empty() && tx.vShieldedOutput.empty() && tx.valueBalance != 0) { // XXX value balance ffi - return state.DoS(100, error("CheckTransaction(): tx.valueBalance has no sources or sinks"), + // Check for non-zero valueBalanceSapling when there are no Sapling inputs or outputs + if (tx.vShieldedSpend.empty() && tx.vShieldedOutput.empty() && tx.valueBalanceSapling != 0) { // XXX value balance ffi + return state.DoS(100, error("CheckTransaction(): tx.valueBalanceSapling has no sources or sinks"), REJECT_INVALID, "bad-txns-valuebalance-nonzero"); } - // Check for overflow valueBalance XXX rename to sapling value balance, add orchard value balance checks - if (tx.valueBalance > MAX_MONEY || tx.valueBalance < -MAX_MONEY) { // XXX need value balance ffi - return state.DoS(100, error("CheckTransaction(): abs(tx.valueBalance) too large"), + // Check for overflow valueBalanceSapling XXX rename to sapling value balance, add orchard value balance checks + if (tx.valueBalanceSapling > MAX_MONEY || tx.valueBalanceSapling < -MAX_MONEY) { // XXX need value balance ffi + return state.DoS(100, error("CheckTransaction(): abs(tx.valueBalanceSapling) too large"), REJECT_INVALID, "bad-txns-valuebalance-toolarge"); } - if (tx.valueBalance <= 0) { - // NB: negative valueBalance "takes" money from the transparent value pool just as outputs do - nValueOut += -tx.valueBalance; + if (tx.valueBalanceSapling <= 0) { + // NB: negative valueBalanceSapling "takes" money from the transparent value pool just as outputs do + nValueOut += -tx.valueBalanceSapling; if (!MoneyRange(nValueOut)) { return state.DoS(100, error("CheckTransaction(): txout total out of range"), @@ -1528,9 +1528,9 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio } // Also check for Sapling - if (tx.valueBalance >= 0) { - // NB: positive valueBalance "adds" money to the transparent value pool, just as inputs do - nValueIn += tx.valueBalance; + if (tx.valueBalanceSapling >= 0) { + // NB: positive valueBalanceSapling "adds" money to the transparent value pool, just as inputs do + nValueIn += tx.valueBalanceSapling; if (!MoneyRange(nValueIn)) { return state.DoS(100, error("CheckTransaction(): txin total out of range"), @@ -4252,13 +4252,13 @@ bool ReceivedBlockTransactions( CAmount saplingValue = 0; CAmount orchardValue = 0; for (auto tx : block.vtx) { - // Negative valueBalance "takes" money from the transparent value pool - // and adds it to the Sapling value pool. Positive valueBalance "gives" + // Negative valueBalanceSapling "takes" money from the transparent value pool + // and adds it to the Sapling value pool. Positive valueBalanceSapling "gives" // money to the transparent value pool, removing from the Sapling value // pool. So we invert the sign here. - saplingValue += -tx.valueBalance; + saplingValue += -tx.valueBalanceSapling; - // Orchard valueBalance behaves the same way as Sapling valueBalance. + // valueBalanceOrchard behaves the same way as valueBalanceSapling. orchardValue += -tx.GetOrchardBundle().GetValueBalance(); for (auto js : tx.vJoinSplit) { diff --git a/src/miner.cpp b/src/miner.cpp index 6dd0678ec..9166533aa 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -126,13 +126,13 @@ class AddFundingStreamValueToTx { private: CMutableTransaction &mtx; - void* ctx; + void* ctx; const CAmount fundingStreamValue; const libzcash::Zip212Enabled zip212Enabled; public: AddFundingStreamValueToTx( - CMutableTransaction &mtx, - void* ctx, + CMutableTransaction &mtx, + void* ctx, const CAmount fundingStreamValue, const libzcash::Zip212Enabled zip212Enabled): mtx(mtx), ctx(ctx), fundingStreamValue(fundingStreamValue), zip212Enabled(zip212Enabled) {} @@ -144,7 +144,7 @@ public: auto odesc = output.Build(ctx); if (odesc) { mtx.vShieldedOutput.push_back(odesc.value()); - mtx.valueBalance -= fundingStreamValue; + mtx.valueBalanceSapling -= fundingStreamValue; return true; } else { return false; @@ -231,7 +231,7 @@ public: bool success = librustzcash_sapling_binding_sig( ctx, - mtx.valueBalance, + mtx.valueBalanceSapling, dataToBeSigned.begin(), mtx.bindingSig.data()); @@ -248,7 +248,7 @@ public: auto ctx = librustzcash_sapling_proving_ctx_init(); auto miner_reward = SetFoundersRewardAndGetMinerValue(ctx); - mtx.valueBalance -= miner_reward; + mtx.valueBalanceSapling -= miner_reward; uint256 ovk; @@ -543,7 +543,7 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre CAmount saplingValueDummy = saplingValue; CAmount orchardValueDummy = orchardValue; - saplingValueDummy += -tx.valueBalance; + saplingValueDummy += -tx.valueBalanceSapling; orchardValueDummy += -tx.GetOrchardBundle().GetValueBalance(); for (auto js : tx.vJoinSplit) { diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index e97c3601f..152c0d6c0 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -14,9 +14,9 @@ SaplingBundle::SaplingBundle( const std::vector& vShieldedSpend, const std::vector& vShieldedOutput, - const CAmount& valueBalance, + const CAmount& valueBalanceSapling, const binding_sig_t& bindingSig) - : valueBalanceSapling(valueBalance), bindingSigSapling(bindingSig) + : valueBalanceSapling(valueBalanceSapling), bindingSigSapling(bindingSig) { for (auto &spend : vShieldedSpend) { vSpendsSapling.emplace_back(spend.cv, spend.nullifier, spend.rk); @@ -127,11 +127,11 @@ std::string CTxOut::ToString() const } -CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::SPROUT_MIN_CURRENT_VERSION), fOverwintered(false), nVersionGroupId(0), nExpiryHeight(0), nLockTime(0), valueBalance(0) {} +CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::SPROUT_MIN_CURRENT_VERSION), fOverwintered(false), nVersionGroupId(0), nExpiryHeight(0), nLockTime(0), valueBalanceSapling(0) {} CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.nVersion), fOverwintered(tx.fOverwintered), nVersionGroupId(tx.nVersionGroupId), nExpiryHeight(tx.nExpiryHeight), nConsensusBranchId(tx.GetConsensusBranchId()), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), - valueBalance(tx.valueBalance), vShieldedSpend(tx.vShieldedSpend), vShieldedOutput(tx.vShieldedOutput), + valueBalanceSapling(tx.valueBalanceSapling), vShieldedSpend(tx.vShieldedSpend), vShieldedOutput(tx.vShieldedOutput), orchardBundle(tx.GetOrchardBundle()), vJoinSplit(tx.vJoinSplit), joinSplitPubKey(tx.joinSplitPubKey), joinSplitSig(tx.joinSplitSig), bindingSig(tx.bindingSig) @@ -188,7 +188,7 @@ CTransaction::CTransaction() : nVersion(CTransaction::SPROUT_MIN_CURRENT_VERSION fOverwintered(false), nVersionGroupId(0), nExpiryHeight(0), nConsensusBranchId(std::nullopt), vin(), vout(), nLockTime(0), - valueBalance(0), vShieldedSpend(), vShieldedOutput(), + valueBalanceSapling(0), vShieldedSpend(), vShieldedOutput(), orchardBundle(), vJoinSplit(), joinSplitPubKey(), joinSplitSig(), bindingSig() { } @@ -196,7 +196,7 @@ CTransaction::CTransaction() : nVersion(CTransaction::SPROUT_MIN_CURRENT_VERSION CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), fOverwintered(tx.fOverwintered), nVersionGroupId(tx.nVersionGroupId), nExpiryHeight(tx.nExpiryHeight), nConsensusBranchId(tx.nConsensusBranchId), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), - valueBalance(tx.valueBalance), vShieldedSpend(tx.vShieldedSpend), vShieldedOutput(tx.vShieldedOutput), + valueBalanceSapling(tx.valueBalanceSapling), vShieldedSpend(tx.vShieldedSpend), vShieldedOutput(tx.vShieldedOutput), orchardBundle(tx.orchardBundle), vJoinSplit(tx.vJoinSplit), joinSplitPubKey(tx.joinSplitPubKey), joinSplitSig(tx.joinSplitSig), bindingSig(tx.bindingSig) @@ -211,7 +211,7 @@ CTransaction::CTransaction( bool evilDeveloperFlag) : nVersion(tx.nVersion), fOverwintered(tx.fOverwintered), nVersionGroupId(tx.nVersionGroupId), nExpiryHeight(tx.nExpiryHeight), nConsensusBranchId(tx.nConsensusBranchId), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), - valueBalance(tx.valueBalance), vShieldedSpend(tx.vShieldedSpend), vShieldedOutput(tx.vShieldedOutput), + valueBalanceSapling(tx.valueBalanceSapling), vShieldedSpend(tx.vShieldedSpend), vShieldedOutput(tx.vShieldedOutput), orchardBundle(tx.orchardBundle), vJoinSplit(tx.vJoinSplit), joinSplitPubKey(tx.joinSplitPubKey), joinSplitSig(tx.joinSplitSig), bindingSig(tx.bindingSig) @@ -224,7 +224,7 @@ CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), nConsensusBranchId(tx.nConsensusBranchId), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), nExpiryHeight(tx.nExpiryHeight), - valueBalance(tx.valueBalance), + valueBalanceSapling(tx.valueBalanceSapling), vShieldedSpend(std::move(tx.vShieldedSpend)), vShieldedOutput(std::move(tx.vShieldedOutput)), orchardBundle(std::move(tx.orchardBundle)), vJoinSplit(std::move(tx.vJoinSplit)), @@ -243,7 +243,7 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) { *const_cast*>(&vout) = tx.vout; *const_cast(&nLockTime) = tx.nLockTime; *const_cast(&nExpiryHeight) = tx.nExpiryHeight; - *const_cast(&valueBalance) = tx.valueBalance; + *const_cast(&valueBalanceSapling) = tx.valueBalanceSapling; *const_cast*>(&vShieldedSpend) = tx.vShieldedSpend; *const_cast*>(&vShieldedOutput) = tx.vShieldedOutput; orchardBundle = tx.orchardBundle; @@ -266,11 +266,11 @@ CAmount CTransaction::GetValueOut() const throw std::runtime_error("CTransaction::GetValueOut(): value out of range"); } - if (valueBalance <= 0) { - // NB: negative valueBalance "takes" money from the transparent value pool just as outputs do - nValueOut += -valueBalance; + if (valueBalanceSapling <= 0) { + // NB: negative valueBalanceSapling "takes" money from the transparent value pool just as outputs do + nValueOut += -valueBalanceSapling; - if (!MoneyRange(-valueBalance) || !MoneyRange(nValueOut)) { + if (!MoneyRange(-valueBalanceSapling) || !MoneyRange(nValueOut)) { throw std::runtime_error("CTransaction::GetValueOut(): value out of range"); } } @@ -290,11 +290,11 @@ CAmount CTransaction::GetShieldedValueIn() const { CAmount nValue = 0; - if (valueBalance >= 0) { - // NB: positive valueBalance "gives" money to the transparent value pool just as inputs do - nValue += valueBalance; + if (valueBalanceSapling >= 0) { + // NB: positive valueBalanceSapling "gives" money to the transparent value pool just as inputs do + nValue += valueBalanceSapling; - if (!MoneyRange(valueBalance) || !MoneyRange(nValue)) { + if (!MoneyRange(valueBalanceSapling) || !MoneyRange(nValue)) { throw std::runtime_error("CTransaction::GetShieldedValueIn(): value out of range"); } } @@ -348,7 +348,7 @@ std::string CTransaction::ToString() const vout.size(), nLockTime); } else if (nVersion >= SAPLING_MIN_TX_VERSION) { - str += strprintf("CTransaction(hash=%s, ver=%d, fOverwintered=%d, nVersionGroupId=%08x, vin.size=%u, vout.size=%u, nLockTime=%u, nExpiryHeight=%u, valueBalance=%u, vShieldedSpend.size=%u, vShieldedOutput.size=%u)\n", + str += strprintf("CTransaction(hash=%s, ver=%d, fOverwintered=%d, nVersionGroupId=%08x, vin.size=%u, vout.size=%u, nLockTime=%u, nExpiryHeight=%u, valueBalanceSapling=%u, vShieldedSpend.size=%u, vShieldedOutput.size=%u)\n", GetHash().ToString().substr(0,10), nVersion, fOverwintered, @@ -357,7 +357,7 @@ std::string CTransaction::ToString() const vout.size(), nLockTime, nExpiryHeight, - valueBalance, + valueBalanceSapling, vShieldedSpend.size(), vShieldedOutput.size()); } else if (nVersion >= 3) { diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 8fda69058..ad6c38621 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -715,7 +715,7 @@ public: const std::vector vout; const uint32_t nLockTime; const uint32_t nExpiryHeight; - const CAmount valueBalance; + const CAmount valueBalanceSapling; const std::vector vShieldedSpend; const std::vector vShieldedOutput; const std::vector vJoinSplit; @@ -797,13 +797,13 @@ public: saplingBundle.GetV4ShieldedSpend(); *const_cast*>(&vShieldedOutput) = saplingBundle.GetV4ShieldedOutput(); - *const_cast(&valueBalance) = saplingBundle.valueBalanceSapling; + *const_cast(&valueBalanceSapling) = saplingBundle.valueBalanceSapling; *const_cast(&bindingSig) = saplingBundle.bindingSigSapling; } else { SaplingBundle saplingBundle( vShieldedSpend, vShieldedOutput, - valueBalance, + valueBalanceSapling, bindingSig); READWRITE(saplingBundle); } @@ -819,7 +819,7 @@ public: READWRITE(*const_cast(&nExpiryHeight)); } if (isSaplingV4 || isFuture) { - READWRITE(*const_cast(&valueBalance)); + READWRITE(*const_cast(&valueBalanceSapling)); READWRITE(*const_cast*>(&vShieldedSpend)); READWRITE(*const_cast*>(&vShieldedOutput)); } @@ -885,16 +885,16 @@ public: * it is (e.g. if vpub_new is non-zero the joinSplit is "giving value" to * the outputs in the transaction). Similarly, we can think of the Sapling * shielded part of the transaction as an input or output according to - * whether valueBalance - the sum of shielded input values minus the sum of + * whether valueBalanceSapling - the sum of shielded input values minus the sum of * shielded output values - is positive or negative. */ - // Return sum of txouts, (negative valueBalance or zero) and JoinSplit vpub_old. + // Return sum of txouts, (negative valueBalanceSapling or zero) and JoinSplit vpub_old. CAmount GetValueOut() const; // GetValueIn() is a method on CCoinsViewCache, because // inputs must be known to compute value in. - // Return sum of (positive valueBalance or zero) and JoinSplit vpub_new + // Return sum of (positive valueBalanceSapling or zero) and JoinSplit vpub_new CAmount GetShieldedValueIn() const; // Compute priority, given priority of inputs and (optionally) tx size @@ -934,7 +934,7 @@ struct CMutableTransaction std::vector vout; uint32_t nLockTime; uint32_t nExpiryHeight; - CAmount valueBalance; + CAmount valueBalanceSapling; std::vector vShieldedSpend; std::vector vShieldedOutput; OrchardBundle orchardBundle; @@ -1005,13 +1005,13 @@ struct CMutableTransaction READWRITE(saplingBundle); vShieldedSpend = saplingBundle.GetV4ShieldedSpend(); vShieldedOutput = saplingBundle.GetV4ShieldedOutput(); - valueBalance = saplingBundle.valueBalanceSapling; + valueBalanceSapling = saplingBundle.valueBalanceSapling; bindingSig = saplingBundle.bindingSigSapling; } else { SaplingBundle saplingBundle( vShieldedSpend, vShieldedOutput, - valueBalance, + valueBalanceSapling, bindingSig); READWRITE(saplingBundle); } @@ -1027,7 +1027,7 @@ struct CMutableTransaction READWRITE(nExpiryHeight); } if (isSaplingV4 || isFuture) { - READWRITE(valueBalance); + READWRITE(valueBalanceSapling); READWRITE(vShieldedSpend); READWRITE(vShieldedOutput); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 37f150580..123ea6c3b 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -227,8 +227,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) entry.pushKV("vjoinsplit", vjoinsplit); if (tx.fOverwintered && tx.nVersion >= SAPLING_TX_VERSION) { - entry.pushKV("valueBalance", ValueFromAmount(tx.valueBalance)); - entry.pushKV("valueBalanceZat", tx.valueBalance); + entry.pushKV("valueBalance", ValueFromAmount(tx.valueBalanceSapling)); + entry.pushKV("valueBalanceZat", tx.valueBalanceSapling); UniValue vspenddesc = TxShieldedSpendsToJSON(tx); entry.pushKV("vShieldedSpend", vspenddesc); UniValue voutputdesc = TxShieldedOutputsToJSON(tx); @@ -594,7 +594,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range"); rawTx.nLockTime = nLockTime; } - + if (params.size() > 3 && !params[3].isNull()) { if (Params().GetConsensus().NetworkUpgradeActive(nextBlockHeight, Consensus::UPGRADE_OVERWINTER)) { int64_t nExpiryHeight = params[3].get_int64(); @@ -1017,7 +1017,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp) } bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE); - // Use the approximate release height if it is greater so offline nodes + // Use the approximate release height if it is greater so offline nodes // have a better estimation of the current height and will be more likely to // determine the correct consensus branch ID. Regtest mode ignores release height. int chainHeight = chainActive.Height() + 1; @@ -1032,8 +1032,8 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp) if (!IsConsensusBranchId(consensusBranchId)) { throw runtime_error(params[4].get_str() + " is not a valid consensus branch id"); } - } - + } + // Script verification errors UniValue vErrors(UniValue::VARR); diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 27d073b03..1caeb4d59 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -94,7 +94,7 @@ bool static IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) { * Where R and S are not negative (their first byte has its highest bit not set), and not * excessively padded (do not start with a 0 byte, unless an otherwise negative number follows, * in which case a single 0 byte is necessary and even required). - * + * * See https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623 * * This function is consensus-critical since BIP66. @@ -134,7 +134,7 @@ bool static IsValidSignatureEncoding(const std::vector &sig) { // Verify that the length of the signature matches the sum of the length // of the elements. if ((size_t)(lenR + lenS + 7) != sig.size()) return false; - + // Check whether the R element is an integer. if (sig[2] != 0x02) return false; @@ -1288,7 +1288,7 @@ uint256 SignatureHash( ss << txTo.nExpiryHeight; if (sigversion == SIGVERSION_SAPLING) { // Sapling value balance - ss << txTo.valueBalance; + ss << txTo.valueBalanceSapling; } // Sighash type ss << nHashType; diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index 050832512..2edd37af2 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -147,7 +147,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle, uint32_t co RandomScript(txout.scriptPubKey); } if (tx.nVersionGroupId == SAPLING_VERSION_GROUP_ID) { - tx.valueBalance = insecure_rand() % 100000000; + tx.valueBalanceSapling = insecure_rand() % 100000000; for (int spend = 0; spend < shielded_spends; spend++) { SpendDescription sdesc; zcash_test_harness_random_jubjub_point(sdesc.cv.begin()); diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 4d0841223..ed0788d9d 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -199,7 +199,7 @@ void TransactionBuilder::AddSaplingSpend( } spends.emplace_back(expsk, note, anchor, witness); - mtx.valueBalance += note.value(); + mtx.valueBalanceSapling += note.value(); } void TransactionBuilder::AddSaplingOutput( @@ -221,7 +221,7 @@ void TransactionBuilder::AddSaplingOutput( auto note = libzcash::SaplingNote(to, value, zip_212_enabled); outputs.emplace_back(ovk, note, memo); - mtx.valueBalance -= value; + mtx.valueBalanceSapling -= value; } void TransactionBuilder::AddSproutInput( @@ -307,7 +307,7 @@ TransactionBuilderResult TransactionBuilder::Build() // // Valid change - CAmount change = mtx.valueBalance - fee; + CAmount change = mtx.valueBalanceSapling - fee; for (auto jsInput : jsInputs) { change += jsInput.note.value(); } @@ -460,7 +460,7 @@ TransactionBuilderResult TransactionBuilder::Build() } librustzcash_sapling_binding_sig( ctx, - mtx.valueBalance, + mtx.valueBalanceSapling, dataToBeSigned.begin(), mtx.bindingSig.data()); diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 2604148dd..a831a92e5 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -1106,7 +1106,7 @@ TEST(WalletTests, SpentSaplingNoteIsFromMe) { EXPECT_EQ(tx2.vJoinSplit.size(), 0); EXPECT_EQ(tx2.vShieldedSpend.size(), 1); EXPECT_EQ(tx2.vShieldedOutput.size(), 2); - EXPECT_EQ(tx2.valueBalance, 10000); + EXPECT_EQ(tx2.valueBalanceSapling, 10000); CWalletTx wtx2 {&wallet, tx2}; @@ -1973,7 +1973,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) { EXPECT_EQ(tx1.vJoinSplit.size(), 0); EXPECT_EQ(tx1.vShieldedSpend.size(), 0); EXPECT_EQ(tx1.vShieldedOutput.size(), 1); - EXPECT_EQ(tx1.valueBalance, -40000); + EXPECT_EQ(tx1.valueBalanceSapling, -40000); CWalletTx wtx {&wallet, tx1}; @@ -2027,7 +2027,7 @@ TEST(WalletTests, MarkAffectedSaplingTransactionsDirty) { EXPECT_EQ(tx2.vJoinSplit.size(), 0); EXPECT_EQ(tx2.vShieldedSpend.size(), 1); EXPECT_EQ(tx2.vShieldedOutput.size(), 2); - EXPECT_EQ(tx2.valueBalance, 10000); + EXPECT_EQ(tx2.valueBalanceSapling, 10000); CWalletTx wtx2 {&wallet, tx2}; auto hash2 = wtx2.GetHash(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fd97d5191..f7bbc3d68 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4423,10 +4423,10 @@ UniValue z_getmigrationstatus(const UniValue& params, bool fHelp) { // A transaction is "finalized" iff it has at least 10 confirmations. // TODO: subject to change, if the recommended number of confirmations changes. if (tx.GetDepthInMainChain() >= 10) { - finalizedMigratedAmount -= tx.valueBalance; + finalizedMigratedAmount -= tx.valueBalanceSapling; ++numFinalizedMigrationTxs; } else { - unfinalizedMigratedAmount -= tx.valueBalance; + unfinalizedMigratedAmount -= tx.valueBalanceSapling; } // If the transaction is in the mempool it will not be associated with a block yet if (tx.hashBlock.IsNull() || mapBlockIndex[tx.hashBlock] == nullptr) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5e2675d26..aa972ff1a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -158,7 +158,7 @@ SaplingPaymentAddress CWallet::GenerateNewSaplingZKey() return xsk.DefaultAddress(); } -// Add spending key to keystore +// Add spending key to keystore bool CWallet::AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &sk) { AssertLockHeld(cs_wallet); // mapSaplingZKeyMetadata @@ -166,7 +166,7 @@ bool CWallet::AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &sk) if (!CCryptoKeyStore::AddSaplingSpendingKey(sk)) { return false; } - + if (!fFileBacked) { return true; } @@ -175,7 +175,7 @@ bool CWallet::AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &sk) auto ivk = sk.expsk.full_viewing_key().in_viewing_key(); return CWalletDB(strWalletFile).WriteSaplingZKey(ivk, sk, mapSaplingZKeyMetadata[ivk]); } - + return true; } @@ -614,7 +614,7 @@ void CWallet::ChainTipAdded(const CBlockIndex *pindex, } } -void CWallet::ChainTip(const CBlockIndex *pindex, +void CWallet::ChainTip(const CBlockIndex *pindex, const CBlock *pblock, std::optional> added) { @@ -1276,7 +1276,7 @@ void DecrementNoteWitnesses(NoteDataMap& noteDataMap, int indexHeight, int64_t n if (nd->witnesses.size() > 0) { nd->witnesses.pop_front(); } - // indexHeight is the height of the block being removed, so + // indexHeight is the height of the block being removed, so // the new witness cache height is one below it. nd->witnessHeight = indexHeight - 1; } @@ -2602,14 +2602,14 @@ void CWalletTx::GetAmounts(list& listReceived, } } - // If we sent utxos from this transaction, create output for value taken from (negative valueBalance) - // or added (positive valueBalance) to the transparent value pool by Sapling shielding and unshielding. + // If we sent utxos from this transaction, create output for value taken from (negative valueBalanceSapling) + // or added (positive valueBalanceSapling) to the transparent value pool by Sapling shielding and unshielding. if (isFromMyTaddr) { - if (valueBalance < 0) { - COutputEntry output = {CNoDestination(), -valueBalance, (int) vout.size()}; + if (valueBalanceSapling < 0) { + COutputEntry output = {CNoDestination(), -valueBalanceSapling, (int) vout.size()}; listSent.push_back(output); - } else if (valueBalance > 0) { - COutputEntry output = {CNoDestination(), valueBalance, (int) vout.size()}; + } else if (valueBalanceSapling > 0) { + COutputEntry output = {CNoDestination(), valueBalanceSapling, (int) vout.size()}; listReceived.push_back(output); } } @@ -5045,7 +5045,7 @@ void CWallet::GetFilteredNotes( } /** - * Find notes in the wallet filtered by payment addresses, min depth, max depth, + * Find notes in the wallet filtered by payment addresses, min depth, max depth, * if the note is spent, if a spending key is required, and if the notes are locked. * These notes are decrypted and added to the output parameter vector, outEntries. */ @@ -5366,7 +5366,7 @@ KeyAddResult AddSpendingKeyToWallet::operator()(const libzcash::SaplingExtendedS m_wallet->mapSaplingZKeyMetadata[ivk].seedFp = seedFp; } return KeyAdded; - } + } } }