@@ -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
0 commit comments