Skip to content

Commit 0aad1f1

Browse files
zathras-cryptodexX7
authored andcommitted
Exempt unspendable transaction outputs from dust checks
Since unspendable outputs can't be spent, there is no threshold at which it would be uneconomic to spend them. This primarily targets transaction outputs with `OP_RETURN`. --- Initially based on: commit 9cf0ae26350033d43d5dd3c95054c0d1b1641eda Author: zathras-crypto <[email protected]> Date: Wed Mar 25 02:04:02 2015 -0700 Changes: - cherry-picked on top of bitcoin:master - added RPC test for fundrawtransaction
1 parent ed789ce commit 0aad1f1

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

qa/rpc-tests/fundrawtransaction.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,22 @@ def run_test(self):
524524
self.sync_all()
525525
assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance()) #0.19+block reward
526526

527+
#####################################################
528+
# test fundrawtransaction with OP_RETURN and no vin #
529+
#####################################################
530+
531+
rawtx = "0100000000010000000000000000066a047465737400000000"
532+
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
533+
534+
assert_equal(len(dec_tx['vin']), 0)
535+
assert_equal(len(dec_tx['vout']), 1)
536+
537+
rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
538+
dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
539+
540+
assert_greater_than(len(dec_tx['vin']), 0) # at least one vin
541+
assert_equal(len(dec_tx['vout']), 2) # one change output added
542+
527543

528544
if __name__ == '__main__':
529545
RawTransactionsTest().main()

src/primitives/transaction.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,13 @@ class CTxOut
146146
// which has units satoshis-per-kilobyte.
147147
// If you'd pay more than 1/3 in fees
148148
// to spend something, then we consider it dust.
149-
// A typical txout is 34 bytes big, and will
149+
// A typical spendable txout is 34 bytes big, and will
150150
// need a CTxIn of at least 148 bytes to spend:
151-
// so dust is a txout less than 546 satoshis
151+
// so dust is a spendable txout less than 546 satoshis
152152
// with default minRelayTxFee.
153+
if (scriptPubKey.IsUnspendable())
154+
return 0;
155+
153156
size_t nSize = GetSerializeSize(SER_DISK,0)+148u;
154157
return 3*minRelayTxFee.GetFee(nSize);
155158
}

0 commit comments

Comments
 (0)