From 5f46a7d0689ff1457b016fdf0de89e5153058864 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 13 Oct 2015 19:23:11 +0200 Subject: [PATCH 1/3] transaction_tests: Be more strict checking dust * Don't allow off-by-one or more * Make clear dust is coupled with minRelayTxFee * Check rounding for odd values --- src/primitives/transaction.h | 4 ++-- src/test/transaction_tests.cpp | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 2a457cdae..98882d315 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -143,8 +143,8 @@ public: // to spend something, then we consider it dust. // A typical spendable txout is 34 bytes big, and will // need a CTxIn of at least 148 bytes to spend: - // so dust is a spendable txout less than 546 satoshis - // with default minRelayTxFee. + // so dust is a spendable txout less than + // 546*minRelayTxFee/1000 (in satoshis) if (scriptPubKey.IsUnspendable()) return 0; diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index f9423bc0d..c840f4c9f 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -342,11 +342,26 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) string reason; BOOST_CHECK(IsStandardTx(t, reason)); - t.vout[0].nValue = 501; // dust + // Check dust with default relay fee: + CAmount nDustThreshold = 182 * minRelayTxFee.GetFeePerK()/1000 * 3; + BOOST_CHECK_EQUAL(nDustThreshold, 546); + // dust: + t.vout[0].nValue = nDustThreshold - 1; BOOST_CHECK(!IsStandardTx(t, reason)); + // not dust: + t.vout[0].nValue = nDustThreshold; + BOOST_CHECK(IsStandardTx(t, reason)); - t.vout[0].nValue = 2730; // not dust + // Check dust with odd relay fee to verify rounding: + // nDustThreshold = 182 * 1234 / 1000 * 3 + minRelayTxFee = CFeeRate(1234); + // dust: + t.vout[0].nValue = 672 - 1; + BOOST_CHECK(!IsStandardTx(t, reason)); + // not dust: + t.vout[0].nValue = 672; BOOST_CHECK(IsStandardTx(t, reason)); + minRelayTxFee = CFeeRate(1000); t.vout[0].scriptPubKey = CScript() << OP_1; BOOST_CHECK(!IsStandardTx(t, reason)); From 536766c903c8dc84e6709e4bd387aad5acf8e433 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 27 Oct 2015 17:21:43 +0100 Subject: [PATCH 2/3] [trivial] New DEFAULT_MIN_RELAY_TX_FEE = 1000 --- src/main.cpp | 2 +- src/main.h | 2 ++ src/test/transaction_tests.cpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9016fe42a..9212b309d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,7 @@ uint64_t nPruneTarget = 0; bool fAlerts = DEFAULT_ALERTS; /** Fees smaller than this (in satoshi) are considered zero fee (for relaying, mining and transaction creation) */ -CFeeRate minRelayTxFee = CFeeRate(1000); +CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); CTxMemPool mempool(::minRelayTxFee); diff --git a/src/main.h b/src/main.h index 273a45086..0a7944092 100644 --- a/src/main.h +++ b/src/main.h @@ -41,6 +41,8 @@ struct CNodeStateStats; /** Default for accepting alerts from the P2P network. */ static const bool DEFAULT_ALERTS = true; +/** Default for -minrelaytxfee, minimum relay fee for transactions */ +static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000; /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; /** Default for -limitancestorcount, max number of in-mempool ancestors */ diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index c840f4c9f..fb0df1aff 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) // not dust: t.vout[0].nValue = 672; BOOST_CHECK(IsStandardTx(t, reason)); - minRelayTxFee = CFeeRate(1000); + minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); t.vout[0].scriptPubKey = CScript() << OP_1; BOOST_CHECK(!IsStandardTx(t, reason)); From e20d9245e58bafdab51105c985478ccb3e0c9095 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 6 Nov 2015 08:33:14 +0100 Subject: [PATCH 3/3] [trivial] init: Use defaults MIN_RELAY_TX_FEE & TRANSACTION_MAXFEE --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 8fdafa392..5f2dc8bf2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -385,7 +385,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), 1)); strUsage += HelpMessageOpt("-txconfirmtarget=", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET)); strUsage += HelpMessageOpt("-maxtxfee=", strprintf(_("Maximum total fees (in %s) to use in a single wallet transaction; setting this too low may abort large transactions (default: %s)"), - CURRENCY_UNIT, FormatMoney(maxTxFee))); + CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MAXFEE))); strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format on startup")); strUsage += HelpMessageOpt("-wallet=", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), "wallet.dat")); strUsage += HelpMessageOpt("-walletbroadcast", _("Make the wallet broadcast transactions") + " " + strprintf(_("(default: %u)"), true)); @@ -440,7 +440,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-maxsigcachesize=", strprintf("Limit size of signature cache to entries (default: %u)", 50000)); } strUsage += HelpMessageOpt("-minrelaytxfee=", strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)"), - CURRENCY_UNIT, FormatMoney(::minRelayTxFee.GetFeePerK()))); + CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE))); strUsage += HelpMessageOpt("-printtoconsole", _("Send trace/debug info to console instead of debug.log file")); if (showDebug) {