@@ -2889,20 +2889,11 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
2889
2889
nChangePosInOut = -1 ;
2890
2890
}
2891
2891
2892
- // Fill vin
2892
+ // Dummy fill vin for maximum size estimation
2893
2893
//
2894
- // Note how the sequence number is set to non-maxint so that
2895
- // the nLockTime set above actually works.
2896
- //
2897
- // BIP125 defines opt-in RBF as any nSequence < maxint-1, so
2898
- // we use the highest possible value in that range (maxint-2)
2899
- // to avoid conflicting with other possible uses of nSequence,
2900
- // and in the spirit of "smallest possible change from prior
2901
- // behavior."
2902
- const uint32_t nSequence = coin_control.signalRbf ? MAX_BIP125_RBF_SEQUENCE : (CTxIn::SEQUENCE_FINAL - 1 );
2903
- for (const auto & coin : setCoins)
2904
- txNew.vin .push_back (CTxIn (coin.outpoint ,CScript (),
2905
- nSequence));
2894
+ for (const auto & coin : setCoins) {
2895
+ txNew.vin .push_back (CTxIn (coin.outpoint ,CScript ()));
2896
+ }
2906
2897
2907
2898
nBytes = CalculateMaximumSignedTxSize (txNew, this );
2908
2899
if (nBytes < 0 ) {
@@ -2992,11 +2983,29 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
2992
2983
2993
2984
if (nChangePosInOut == -1 ) reservekey.ReturnKey (); // Return any reserved key if we don't have change
2994
2985
2986
+ // Shuffle selected coins and fill in final vin
2987
+ txNew.vin .clear ();
2988
+ std::vector<CInputCoin> selected_coins (setCoins.begin (), setCoins.end ());
2989
+ std::shuffle (selected_coins.begin (), selected_coins.end (), FastRandomContext ());
2990
+
2991
+ // Note how the sequence number is set to non-maxint so that
2992
+ // the nLockTime set above actually works.
2993
+ //
2994
+ // BIP125 defines opt-in RBF as any nSequence < maxint-1, so
2995
+ // we use the highest possible value in that range (maxint-2)
2996
+ // to avoid conflicting with other possible uses of nSequence,
2997
+ // and in the spirit of "smallest possible change from prior
2998
+ // behavior."
2999
+ const uint32_t nSequence = coin_control.signalRbf ? MAX_BIP125_RBF_SEQUENCE : (CTxIn::SEQUENCE_FINAL - 1 );
3000
+ for (const auto & coin : selected_coins) {
3001
+ txNew.vin .push_back (CTxIn (coin.outpoint , CScript (), nSequence));
3002
+ }
3003
+
2995
3004
if (sign)
2996
3005
{
2997
3006
CTransaction txNewConst (txNew);
2998
3007
int nIn = 0 ;
2999
- for (const auto & coin : setCoins )
3008
+ for (const auto & coin : selected_coins )
3000
3009
{
3001
3010
const CScript& scriptPubKey = coin.txout .scriptPubKey ;
3002
3011
SignatureData sigdata;
0 commit comments