@@ -169,15 +169,30 @@ class CTxOut
169169 // which has units satoshis-per-kilobyte.
170170 // If you'd pay more than 1/3 in fees
171171 // to spend something, then we consider it dust.
172- // A typical spendable txout is 34 bytes big, and will
172+ // A typical spendable non-segwit txout is 34 bytes big, and will
173173 // need a CTxIn of at least 148 bytes to spend:
174174 // so dust is a spendable txout less than
175- // 546*minRelayTxFee/1000 (in satoshis)
175+ // 546*minRelayTxFee/1000 (in satoshis).
176+ // A typical spendable segwit txout is 31 bytes big, and will
177+ // need a CTxIn of at least 67 bytes to spend:
178+ // so dust is a spendable txout less than
179+ // 294*minRelayTxFee/1000 (in satoshis).
176180 if (scriptPubKey.IsUnspendable ())
177181 return 0 ;
178182
179- size_t nSize = GetSerializeSize (SER_DISK,0 )+148u ;
180- return 3 *minRelayTxFee.GetFee (nSize);
183+ size_t nSize = GetSerializeSize (SER_DISK, 0 );
184+ int witnessversion = 0 ;
185+ std::vector<unsigned char > witnessprogram;
186+
187+ if (scriptPubKey.IsWitnessProgram (witnessversion, witnessprogram)) {
188+ // sum the sizes of the parts of a transaction input
189+ // with 75% segwit discount applied to the script size.
190+ nSize += (32 + 4 + 1 + (107 / WITNESS_SCALE_FACTOR) + 4 );
191+ } else {
192+ nSize += (32 + 4 + 1 + 107 + 4 ); // the 148 mentioned above
193+ }
194+
195+ return 3 * minRelayTxFee.GetFee (nSize);
181196 }
182197
183198 bool IsDust (const CFeeRate &minRelayTxFee) const
0 commit comments