Skip to content

Commit

Permalink
Merge #991: [RPC][Wallet] Create multiple transactions with one command.
Browse files Browse the repository at this point in the history
a872b41 Create multiple transactions with one command. (Zannick)

Pull request description:

  ## Details

  RPC send commands have a new argument `inputs_per_tx` that controls whether the amount specified can be split across multiple transactions. This value ranges from 0 (default) to 32 (an upper bound designed to prevent transactions larger than can be accepted). When set to 0, attempts to fit the send in one transaction as per previous behavior.

  The sends are interpreted to mean that the recipient will receive the sent amount, but under the hood the transactions are created as if `subtractfeefromamount` was specified. In particular, if the send needs to be split into `n > 1` transactions, the outputs of the first `n - 1` are randomly reduced to account for the fee (and the shortfall from the inputs).

  Coins are selected using a sliding window that prioritizes cleaning up small utxos (dust) over using fewer inputs, and thus transactions built this way will tend toward having more inputs. This is beneficial for ringct staking (keeping larger coins intact and reducing the amount of small utxos). The smallest utxo is always included if possible to prevent the amount of small utxos from increasing with usage.

  ## Tested
  On regtest some months ago.

Tree-SHA512: 8b6b0b7fccdb16507da321c371b8075fdecae5f53ca2fb95a49a8d8edb6104c3c7d26270c0f029a99bf0aff4fe6a15c9e0b0fdfad372ab8166b619ce2ac38f98
  • Loading branch information
codeofalltrades committed Apr 23, 2022
2 parents 7c8bee1 + a872b41 commit c81d57f
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 139 deletions.
4 changes: 2 additions & 2 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,12 @@ class WalletImpl : public Wallet
break;
}
case OUTPUT_CT:
if (0 != pwalletAnon->AddBlindedInputs(wtx, rtx, recipients, !fCheckFeeOnly, nFeeRet, &coin_control, fail_reason))
if (0 != pwalletAnon->AddBlindedInputs(wtx, rtx, recipients, !fCheckFeeOnly, 0, nFeeRet, &coin_control, fail_reason))
fFailed = true;
break;
case OUTPUT_RINGCT:
if (!pwalletAnon->AddAnonInputs(wtx, rtx, recipients, !fCheckFeeOnly, nRingSize,
nInputsPerSig, nFeeRet, &coin_control, fail_reason))
nInputsPerSig, 0, nFeeRet, &coin_control, fail_reason))
fFailed = true;
break;
default:
Expand Down
277 changes: 241 additions & 36 deletions src/veil/ringct/anonwallet.cpp

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions src/veil/ringct/anonwallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ class AnonWallet
CAmount &nFeeRet, const CCoinControl *coinControl, std::string &sError, bool fZerocoinInputs, CAmount nInputValue);

int AddBlindedInputs(CWalletTx &wtx, CTransactionRecord &rtx, std::vector<CTempRecipient> &vecSend, bool sign,
CAmount &nFeeRet, const CCoinControl *coinControl, std::string &sError);
size_t nMaximumInputs, CAmount &nFeeRet, const CCoinControl *coinControl, std::string &sError);
int AddBlindedInputs_Inner(CWalletTx &wtx, CTransactionRecord &rtx, std::vector<CTempRecipient> &vecSend, bool sign,
CAmount &nFeeRet, const CCoinControl *coinControl, std::string &sError);
size_t nMaximumInputs, CAmount &nFeeRet, const CCoinControl *coinControl, std::string &sError);


bool PlaceRealOutputs(std::vector<std::vector<int64_t> > &vMI, size_t &nSecretColumn, size_t nRingSize, std::set<int64_t> &setHave,
Expand All @@ -240,10 +240,10 @@ class AnonWallet

bool IsMyAnonInput(const CTxIn& txin, COutPoint& myOutpoint);
bool AddAnonInputs_Inner(CWalletTx &wtx, CTransactionRecord &rtx, std::vector<CTempRecipient> &vecSend,
bool sign, size_t nRingSize, size_t nInputsPerSig, CAmount &nFeeRet,
bool sign, size_t nRingSize, size_t nInputsPerSig, size_t nMaximumInputs, CAmount &nFeeRet,
const CCoinControl *coinControl, std::string &sError, bool fZerocoinInputs, CAmount nInputValue);
bool AddAnonInputs(CWalletTx &wtx, CTransactionRecord &rtx, std::vector<CTempRecipient> &vecSend,
bool sign, size_t nRingSize, size_t nInputsPerSig, CAmount &nFeeRet,
bool sign, size_t nRingSize, size_t nInputsPerSig, size_t nMaximumInputs, CAmount &nFeeRet,
const CCoinControl *coinControl, std::string &sError, bool fZerocoinInputs = false,
CAmount nInputValue = 0);

Expand Down Expand Up @@ -322,15 +322,23 @@ class AnonWallet
* populate vCoins with vector of available COutputs.
*/
void AvailableBlindedCoins(std::vector<COutputR>& vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t& nMaximumCount = 0, const int& nMinDepth = 0, const int& nMaxDepth = 0x7FFFFFFF, bool fIncludeImmature=false) const;
bool SelectBlindedCoins(const std::vector<COutputR>& vAvailableCoins, const CAmount& nTargetValue, std::vector<std::pair<MapRecords_t::const_iterator,unsigned int> > &setCoinsRet, CAmount &nValueRet, const CCoinControl *coinControl = nullptr) const;
/**
* Returns a list of coins for a single transaction based on the target value and allowed number of inputs.
*/
bool SelectBlindedCoins(const std::vector<COutputR>& vAvailableCoins, const CAmount& nTargetValue, size_t nMaximumCount, std::vector<std::pair<MapRecords_t::const_iterator,unsigned int> > &setCoinsRet, CAmount &nValueRet, const CCoinControl *coinControl = nullptr) const;

void AvailableAnonCoins(std::vector<COutputR> &vCoins, bool fOnlySafe=true, const CCoinControl *coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t& nMaximumCount = 0, const int& nMinDepth = 0, const int& nMaxDepth = 0x7FFFFFFF, bool fIncludeImmature=false) const;

/**
* Return list of available coins and locked coins grouped by non-change output address.
*/

bool SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibilityFilter& eligibility_filter, std::vector<COutputR> vCoins, std::vector<std::pair<MapRecords_t::const_iterator,unsigned int> > &setCoinsRet, CAmount &nValueRet) const;
bool SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibilityFilter& eligibility_filter, std::vector<COutputR> &vCoins, std::vector<std::pair<MapRecords_t::const_iterator,unsigned int> > &setCoinsRet, CAmount &nValueRet) const;
/**
* Like SelectCoinsMinConf, but always selects at most nMaximumCount coins,
* with the intention of being put in a single tx that partially accomplishes the target to be sent.
*/
bool SelectCoinsForOneTx(const CAmount& nTargetValue, const CoinEligibilityFilter& eligibility_filter, std::vector<COutputR> &vCoins, size_t nMaximumCount, std::vector<std::pair<MapRecords_t::const_iterator,unsigned int> > &setCoinsRet, CAmount &nValueRet) const;

bool IsSpent(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);

Expand Down
Loading

0 comments on commit c81d57f

Please sign in to comment.