Skip to content

Commit 9ef8031

Browse files
committed
[Wallet] Account for extra payload sizes in Fund/CreateTransaction
1 parent 517fe0c commit 9ef8031

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,6 +2864,9 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov
28642864
coinControl.fOverrideFeeRate = overrideEstimatedFeeRate;
28652865
coinControl.nFeeRate = specificFeeRate;
28662866

2867+
const int nExtraSize = tx.isSaplingVersion() ?
2868+
(int)(GetSerializeSizeNetwork(tx.sapData) + GetSerializeSizeNetwork(tx.extraPayload)) : 0;
2869+
28672870
for (const CTxIn& txin : tx.vin) {
28682871
coinControl.Select(txin.prevout);
28692872
}
@@ -2874,8 +2877,9 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, bool ov
28742877

28752878
CReserveKey reservekey(this);
28762879
CTransactionRef wtx;
2877-
if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, ALL_COINS, false))
2880+
if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosInOut, strFailReason, &coinControl, ALL_COINS, false, 0, false, nullptr, nExtraSize)) {
28782881
return false;
2882+
}
28792883

28802884
if (nChangePosInOut != -1) {
28812885
tx.vout.insert(tx.vout.begin() + nChangePosInOut, wtx->vout[nChangePosInOut]);
@@ -2906,7 +2910,8 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
29062910
bool sign,
29072911
CAmount nFeePay,
29082912
bool fIncludeDelegated,
2909-
bool* fStakeDelegationVoided)
2913+
bool* fStakeDelegationVoided,
2914+
int nExtraSize)
29102915
{
29112916
CAmount nValue = 0;
29122917
int nChangePosRequest = nChangePosInOut;
@@ -3057,7 +3062,8 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend,
30573062
nIn++;
30583063
}
30593064

3060-
const unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
3065+
// account for additional payloads in fee calculation
3066+
const unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION) + nExtraSize;
30613067
CAmount nFeeNeeded = std::max(nFeePay, GetMinimumFee(nBytes, nTxConfirmTarget, mempool));
30623068

30633069
// Remove scriptSigs to eliminate the fee calculation dummy signatures

src/wallet/wallet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,9 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
10051005
bool sign = true,
10061006
CAmount nFeePay = 0,
10071007
bool fIncludeDelegated = false,
1008-
bool* fStakeDelegationVoided = nullptr);
1008+
bool* fStakeDelegationVoided = nullptr,
1009+
int nExtraSize = 0);
1010+
10091011
bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue, CTransactionRef& tx, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl = NULL, AvailableCoinsType coin_type = ALL_COINS, CAmount nFeePay = 0, bool fIncludeDelegated = false);
10101012

10111013
// enumeration for CommitResult (return status of CommitTransaction)

0 commit comments

Comments
 (0)