Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][Refactor] Use shield nomenclature instead of shielded #2077

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ BITCOIN_TESTS += \
SAPLING_TESTS +=\
test/librust/sapling_rpc_wallet_tests.cpp \
test/librust/sapling_wallet_tests.cpp \
wallet/test/wallet_shielded_balances_tests.cpp
wallet/test/wallet_shield_balances_tests.cpp
endif

test_test_pivx_SOURCES = $(BITCOIN_TEST_SUITE) $(BITCOIN_TESTS) $(SAPLING_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
Expand Down
18 changes: 9 additions & 9 deletions src/addressbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ namespace AddressBook {
const std::string DELEGATOR{"delegator"};
const std::string COLD_STAKING{"coldstaking"};
const std::string COLD_STAKING_SEND{"coldstaking_send"};
const std::string SHIELDED_RECEIVE{"shielded_receive"};
const std::string SHIELDED_SEND{"shielded_spend"};
const std::string SHIELD_RECEIVE{"shield_receive"};
const std::string SHIELD_SEND{"shield_spend"};
}

bool IsColdStakingPurpose(const std::string& purpose) {
return purpose == AddressBookPurpose::COLD_STAKING
|| purpose == AddressBookPurpose::COLD_STAKING_SEND;
}

bool IsShieldedPurpose(const std::string& purpose) {
return purpose == AddressBookPurpose::SHIELDED_RECEIVE
|| purpose == AddressBookPurpose::SHIELDED_SEND;
bool IsShieldPurpose(const std::string& purpose) {
return purpose == AddressBookPurpose::SHIELD_RECEIVE
|| purpose == AddressBookPurpose::SHIELD_SEND;
}

bool CAddressBookData::isSendColdStakingPurpose() const {
Expand All @@ -41,12 +41,12 @@ namespace AddressBook {
return purpose == AddressBookPurpose::RECEIVE;
}

bool CAddressBookData::isShieldedReceivePurpose() const {
return purpose == AddressBookPurpose::SHIELDED_RECEIVE;
bool CAddressBookData::isShieldReceivePurpose() const {
return purpose == AddressBookPurpose::SHIELD_RECEIVE;
}

bool CAddressBookData::isShielded() const {
return IsShieldedPurpose(purpose);
bool CAddressBookData::isShield() const {
return IsShieldPurpose(purpose);
}


Expand Down
10 changes: 5 additions & 5 deletions src/addressbook.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ namespace AddressBook {
extern const std::string DELEGATOR;
extern const std::string COLD_STAKING;
extern const std::string COLD_STAKING_SEND;
extern const std::string SHIELDED_RECEIVE;
extern const std::string SHIELDED_SEND;
extern const std::string SHIELD_RECEIVE;
extern const std::string SHIELD_SEND;
}

bool IsColdStakingPurpose(const std::string& purpose);
bool IsShieldedPurpose(const std::string& purpose);
bool IsShieldPurpose(const std::string& purpose);

/** Address book data */
class CAddressBookData {
Expand All @@ -42,8 +42,8 @@ namespace AddressBook {
bool isSendColdStakingPurpose() const;
bool isSendPurpose() const;
bool isReceivePurpose() const;
bool isShieldedReceivePurpose() const;
bool isShielded() const;
bool isShieldReceivePurpose() const;
bool isShield() const;
};

}
Expand Down
18 changes: 9 additions & 9 deletions src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
nResult += AccessCoin(tx.vin[i].prevout).out.nValue;

// Sapling
nResult += tx.GetShieldedValueIn();
nResult += tx.GetShieldValueIn();

return nResult;
}
Expand All @@ -361,11 +361,11 @@ double CCoinsViewCache::GetPriority(const CTransaction& tx, int nHeight, CAmount
return 0.0;


// Shielded transfers do not reveal any information about the value or age of a note, so we
// Shield transfers do not reveal any information about the value or age of a note, so we
// cannot apply the priority algorithm used for transparent utxos. Instead, we just
// use the maximum priority for all (partially or fully) shielded transactions.
// (Note that coinbase/coinstakes transactions cannot contain Sapling shielded Spends or Outputs.)
if (tx.IsShieldedTx()) {
// use the maximum priority for all (partially or fully) shield transactions.
// (Note that coinbase/coinstakes transactions cannot contain Sapling shield Spends or Outputs.)
if (tx.IsShieldTx()) {
return INF_PRIORITY;
}

Expand Down Expand Up @@ -565,7 +565,7 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) {

void CCoinsViewCache::SetNullifiers(const CTransaction& tx, bool spent) {
if (tx.sapData) {
for (const SpendDescription& spendDescription : tx.sapData->vShieldedSpend) {
for (const SpendDescription& spendDescription : tx.sapData->vShieldSpend) {
std::pair<CNullifiersMap::iterator, bool> ret = cacheSaplingNullifiers.insert(
std::make_pair(spendDescription.nullifier, CNullifiersCacheEntry()));
ret.first->second.entered = spent;
Expand All @@ -580,10 +580,10 @@ uint256 CCoinsViewCache::GetBestAnchor() const {
return hashSaplingAnchor;
}

bool CCoinsViewCache::HaveShieldedRequirements(const CTransaction& tx) const
bool CCoinsViewCache::HaveShieldRequirements(const CTransaction& tx) const
{
if (tx.IsShieldedTx()) {
for (const SpendDescription &spendDescription : tx.sapData->vShieldedSpend) {
if (tx.IsShieldTx()) {
for (const SpendDescription &spendDescription : tx.sapData->vShieldSpend) {
if (GetNullifier(spendDescription.nullifier)) // Prevent double spends
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class CCoinsViewCache : public CCoinsViewBacked
void SetNullifiers(const CTransaction& tx, bool spent);

//! Check whether all sapling spend requirements (anchors/nullifiers) are satisfied
bool HaveShieldedRequirements(const CTransaction& tx) const;
bool HaveShieldRequirements(const CTransaction& tx) const;

// Standard CCoinsView methods
bool GetCoin(const COutPoint& outpoint, Coin& coin) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/consensus/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ static const unsigned int MAX_BLOCK_SIZE_LEGACY = 1000000;
/** The maximum size of a transaction after Sapling activation (network rule) */
static const unsigned int MAX_TX_SIZE_AFTER_SAPLING = 400000;

/** The maximum cumulative size of all Shielded txes inside a block */
static const unsigned int MAX_BLOCK_SHIELDED_TXES_SIZE = 750000;
/** The maximum cumulative size of all Shield txes inside a block */
static const unsigned int MAX_BLOCK_SHIELD_TXES_SIZE = 750000;

/** The maximum allowed number of signature check operations in a block (network rule) */
static const unsigned int MAX_BLOCK_SIGOPS_CURRENT = MAX_BLOCK_SIZE_CURRENT / 50;
Expand Down
10 changes: 5 additions & 5 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fRejectBadUTXO, CValidationState& state, bool fFakeSerialAttack, bool fColdStakingActive, bool fSaplingActive)
{
// Basic checks that don't depend on any context
// Transactions containing empty `vin` must have non-empty `vShieldedSpend`.
if (tx.vin.empty() && (tx.sapData && tx.sapData->vShieldedSpend.empty()))
// Transactions containing empty `vin` must have non-empty `vShieldSpend`.
if (tx.vin.empty() && (tx.sapData && tx.sapData->vShieldSpend.empty()))
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty");
// Transactions containing empty `vout` must have non-empty `vShieldedOutput`.
if (tx.vout.empty() && (tx.sapData && tx.sapData->vShieldedOutput.empty()))
// Transactions containing empty `vout` must have non-empty `vShieldOutput`.
if (tx.vout.empty() && (tx.sapData && tx.sapData->vShieldOutput.empty()))
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty");

// Version check
Expand All @@ -78,7 +78,7 @@ bool CheckTransaction(const CTransaction& tx, bool fZerocoinActive, bool fReject
// Size limits
static_assert(MAX_BLOCK_SIZE_CURRENT >= MAX_TX_SIZE_AFTER_SAPLING, "Max block size must be bigger than max TX size"); // sanity
static_assert(MAX_TX_SIZE_AFTER_SAPLING > MAX_ZEROCOIN_TX_SIZE, "New max TX size must be bigger than old max TX size"); // sanity
const unsigned int nMaxSize = tx.IsShieldedTx() ? MAX_TX_SIZE_AFTER_SAPLING : MAX_ZEROCOIN_TX_SIZE;
const unsigned int nMaxSize = tx.IsShieldTx() ? MAX_TX_SIZE_AFTER_SAPLING : MAX_ZEROCOIN_TX_SIZE;
if (tx.GetTotalSize() > nMaxSize) {
return state.DoS(10, false, REJECT_INVALID, "bad-txns-oversize");
}
Expand Down
14 changes: 7 additions & 7 deletions src/destination_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ namespace Standard {

CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking)
{
bool isShielded = false;
return DecodeDestination(strAddress, isStaking, isShielded);
bool isShield = false;
return DecodeDestination(strAddress, isStaking, isShield);
}

// agregar isShielded
CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isShielded)
// agregar isShield
CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isShield)
{
CWDestination dest;
CTxDestination regDest = ::DecodeDestination(strAddress, isStaking);
if (!IsValidDestination(regDest)) {
const auto sapDest = KeyIO::DecodeSaplingPaymentAddress(strAddress);
if (sapDest) {
isShielded = true;
isShield = true;
return *sapDest;
}
}
Expand All @@ -46,15 +46,15 @@ namespace Standard {

bool IsValidDestination(const CWDestination& address)
{
// Only regular base58 addresses and shielded addresses accepted here for now
// Only regular base58 addresses and shield addresses accepted here for now
const libzcash::SaplingPaymentAddress *dest1 = boost::get<libzcash::SaplingPaymentAddress>(&address);
if (dest1) return true;

const CTxDestination *dest = boost::get<CTxDestination>(&address);
return dest && ::IsValidDestination(*dest);
}

const libzcash::SaplingPaymentAddress* GetShieldedDestination(const CWDestination& dest)
const libzcash::SaplingPaymentAddress* GetShieldDestination(const CWDestination& dest)
{
return boost::get<libzcash::SaplingPaymentAddress>(&dest);
}
Expand Down
6 changes: 3 additions & 3 deletions src/destination_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "script/standard.h"

// Regular + shielded addresses variant.
// Regular + shield addresses variant.
typedef boost::variant<CTxDestination, libzcash::SaplingPaymentAddress> CWDestination;

namespace Standard {
Expand All @@ -16,12 +16,12 @@ namespace Standard {

CWDestination DecodeDestination(const std::string& strAddress);
CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking);
CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isShielded);
CWDestination DecodeDestination(const std::string& strAddress, bool& isStaking, bool& isShield);

bool IsValidDestination(const CWDestination& dest);

// boost::get wrapper
const libzcash::SaplingPaymentAddress* GetShieldedDestination(const CWDestination& dest);
const libzcash::SaplingPaymentAddress* GetShieldDestination(const CWDestination& dest);
const CTxDestination * GetTransparentDestination(const CWDestination& dest);

} // End Standard namespace
Expand Down
4 changes: 2 additions & 2 deletions src/interface/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace interfaces {
}
result.delegate_balance = m_wallet.GetDelegatedBalance();
result.coldstaked_balance = m_wallet.GetColdStakingBalance();
result.shielded_balance = m_wallet.GetAvailableShieldedBalance();
result.unconfirmed_shielded_balance = m_wallet.GetUnconfirmedShieldedBalance();
result.shield_balance = m_wallet.GetAvailableShieldBalance();
result.unconfirmed_shield_balance = m_wallet.GetUnconfirmedShieldBalance();
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/interface/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct WalletBalances
CAmount immature_watch_only_balance{0};
CAmount delegate_balance{0};
CAmount coldstaked_balance{0};
CAmount shielded_balance{0};
CAmount unconfirmed_shielded_balance{0};
CAmount shield_balance{0};
CAmount unconfirmed_shield_balance{0};

bool balanceChanged(const WalletBalances& prev) const
{
Expand All @@ -33,7 +33,7 @@ struct WalletBalances
unconfirmed_watch_only_balance != prev.unconfirmed_watch_only_balance ||
immature_watch_only_balance != prev.immature_watch_only_balance ||
delegate_balance != prev.delegate_balance || coldstaked_balance != prev.coldstaked_balance ||
shielded_balance != prev.shielded_balance || unconfirmed_shielded_balance != prev.unconfirmed_shielded_balance;
shield_balance != prev.shield_balance || unconfirmed_shield_balance != prev.unconfirmed_shield_balance;
}
};

Expand Down
16 changes: 8 additions & 8 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
if (tx.IsCoinBase() || tx.IsCoinStake() || !IsFinalTx(tx, nHeight)){
continue;
}
if(sporkManager.IsSporkActive(SPORK_20_SAPLING_MAINTENANCE) && tx.IsShieldedTx()){
if(sporkManager.IsSporkActive(SPORK_20_SAPLING_MAINTENANCE) && tx.IsShieldTx()){
continue;
}

Expand Down Expand Up @@ -303,8 +303,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
int nBlockSigOps = 100;
bool fSortedByFee = (nBlockPrioritySize <= 0);

// Keep track of block space used for shielded txes
unsigned int nSizeShielded = 0;
// Keep track of block space used for shield txes
unsigned int nSizeShield = 0;

TxPriorityCompare comparer(fSortedByFee);
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
Expand All @@ -324,8 +324,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
if (nBlockSize + nTxSize >= nBlockMaxSize)
continue;

const bool isShielded = tx.IsShieldedTx();
if (isShielded && nSizeShielded + nTxSize > MAX_BLOCK_SHIELDED_TXES_SIZE)
const bool isShield = tx.IsShieldTx();
if (isShield && nSizeShield + nTxSize > MAX_BLOCK_SHIELD_TXES_SIZE)
continue;

// Legacy limits on sigOps:
Expand Down Expand Up @@ -379,7 +379,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
++nBlockTx;
nBlockSigOps += nTxSigOps;
nFees += nTxFees;
if (isShielded) nSizeShielded += nTxSize;
if (isShield) nSizeShield += nTxSize;

if (fPrintPriority) {
LogPrintf("priority %.1f fee %s txid %s\n",
Expand Down Expand Up @@ -419,8 +419,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,

// Update the Sapling commitment tree.
for (const auto &tx : pblock->vtx) {
if (tx->IsShieldedTx()) {
for (const OutputDescription &odesc : tx->sapData->vShieldedOutput) {
if (tx->IsShieldTx()) {
for (const OutputDescription &odesc : tx->sapData->vShieldOutput) {
sapling_tree.append(odesc.cmu);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate& _minRelayFee)

void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool fCurrentEstimate)
{
if(entry.HasZerocoins() || entry.IsShielded()) {
if(entry.HasZerocoins() || entry.IsShield()) {
// Zerocoin spends/mints had fixed feerate. Skip them for the estimates.
return;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo

void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry)
{
if(entry.HasZerocoins() || entry.IsShielded()) {
if(entry.HasZerocoins() || entry.IsShield()) {
// Zerocoin spends/mints had fixed feerate. Skip them for the estimates.
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/policy/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee)
return (txout.nValue < GetDustThreshold(txout, dustRelayFee));
}

CAmount GetShieldedDustThreshold(const CFeeRate& dustRelayFee)
CAmount GetShieldDustThreshold(const CFeeRate& dustRelayFee)
{
unsigned int K = DEFAULT_SHIELDEDTXFEE_K; // Fixed (1000) for now
unsigned int K = DEFAULT_SHIELDTXFEE_K; // Fixed (1000) for now
return 3 * K * dustRelayFee.GetFee(SPENDDESCRIPTION_SIZE +
CTXOUT_REGULAR_SIZE +
BINDINGSIG_SIZE);
Expand Down Expand Up @@ -134,7 +134,7 @@ bool IsStandardTx(const CTransaction& tx, int nBlockHeight, std::string& reason)
// computing signature hashes is O(ninputs*txsize). Limiting transactions
// to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks.
unsigned int sz = tx.GetTotalSize();
unsigned int nMaxSize = tx.IsShieldedTx() ? MAX_TX_SIZE_AFTER_SAPLING :
unsigned int nMaxSize = tx.IsShieldTx() ? MAX_TX_SIZE_AFTER_SAPLING :
tx.ContainsZerocoins() ? MAX_ZEROCOIN_TX_SIZE : MAX_STANDARD_TX_SIZE;
if (sz >= nMaxSize) {
reason = "tx-size";
Expand Down
2 changes: 1 addition & 1 deletion src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);

CAmount GetDustThreshold(const CFeeRate& dustRelayFee);
CAmount GetShieldedDustThreshold(const CFeeRate& dustRelayFee);
CAmount GetShieldDustThreshold(const CFeeRate& dustRelayFee);

bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);

Expand Down
8 changes: 4 additions & 4 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ CAmount CTransaction::GetValueOut() const
return nValueOut;
}

CAmount CTransaction::GetShieldedValueIn() const
CAmount CTransaction::GetShieldValueIn() const
{
CAmount nValue = 0;

Expand Down Expand Up @@ -326,10 +326,10 @@ std::string CTransaction::ToString() const
<< ", vin.size=" << vin.size()
<< ", vout.size=" << vout.size()
<< ", nLockTime=" << nLockTime;
if (IsShieldedTx()) {
if (IsShieldTx()) {
ss << ", valueBalance=" << sapData->valueBalance
<< ", vShieldedSpend.size=" << sapData->vShieldedSpend.size()
<< ", vShieldedOutput.size=" << sapData->vShieldedOutput.size();
<< ", vShieldSpend.size=" << sapData->vShieldSpend.size()
<< ", vShieldOutput.size=" << sapData->vShieldOutput.size();
}
if (IsSpecialTx()) {
ss << ", extraPayload.size=" << extraPayload->size();
Expand Down
Loading