From 8f850c60faee9291443106fca5bdd1757eaa6c0b Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 17 Sep 2017 19:00:44 +0300 Subject: [PATCH] Lower tx fees 10x (#1632) * Lower tx fees 10x * add DEFAULT_DIP0001_*FEE constants --- src/dsnotificationinterface.cpp | 13 +++++++++++++ src/init.cpp | 4 ++-- src/instantx.cpp | 2 +- src/test/transaction_tests.cpp | 2 +- src/txmempool.cpp | 8 ++++++++ src/txmempool.h | 1 + src/validation.cpp | 2 +- src/validation.h | 4 +++- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 4 +++- 10 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/dsnotificationinterface.cpp b/src/dsnotificationinterface.cpp index 65f99b576..f45252564 100644 --- a/src/dsnotificationinterface.cpp +++ b/src/dsnotificationinterface.cpp @@ -9,6 +9,7 @@ #include "masternode-payments.h" #include "masternode-sync.h" #include "privatesend-client.h" +#include "txmempool.h" void CDSNotificationInterface::InitializeCurrentBlockTip() { @@ -39,9 +40,21 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con // DIP0001 updates + bool fDIP0001ActiveAtTipTmp = fDIP0001ActiveAtTip; // Update global flags fDIP0001LockedInAtTip = (VersionBitsState(pindexNew, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0001, versionbitscache) == THRESHOLD_LOCKED_IN); fDIP0001ActiveAtTip = (VersionBitsState(pindexNew, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0001, versionbitscache) == THRESHOLD_ACTIVE); + + // Update min fees only if activation changed and we are using default minRelayTxFee + if (fDIP0001ActiveAtTipTmp != fDIP0001ActiveAtTip) { + if (!mapArgs.count("-minrelaytxfee")) { + ::minRelayTxFee = CFeeRate(fDIP0001ActiveAtTip ? DEFAULT_DIP0001_MIN_RELAY_TX_FEE : DEFAULT_LEGACY_MIN_RELAY_TX_FEE); + mempool.UpdateMinFee(::minRelayTxFee); + } + if (!mapArgs.count("-mintxfee")) { + CWallet::minTxFee = CFeeRate(fDIP0001ActiveAtTip ? DEFAULT_DIP0001_TRANSACTION_MINFEE : DEFAULT_LEGACY_TRANSACTION_MINFEE); + } + } } void CDSNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock) diff --git a/src/init.cpp b/src/init.cpp index 6ea1dd043..01536dfbc 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -478,7 +478,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-fallbackfee=", strprintf(_("A fee rate (in %s/kB) that will be used when fee estimation has insufficient data (default: %s)"), CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE))); strUsage += HelpMessageOpt("-mintxfee=", strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)"), - CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MINFEE))); + CURRENCY_UNIT, FormatMoney(DEFAULT_LEGACY_TRANSACTION_MINFEE))); strUsage += HelpMessageOpt("-paytxfee=", strprintf(_("Fee (in %s/kB) to add to transactions you send (default: %s)"), CURRENCY_UNIT, FormatMoney(payTxFee.GetFeePerK()))); strUsage += HelpMessageOpt("-rescan", _("Rescan the block chain for missing wallet transactions on startup")); @@ -567,7 +567,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-maxsigcachesize=", strprintf("Limit size of signature cache to MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_SIZE)); } 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(DEFAULT_MIN_RELAY_TX_FEE))); + CURRENCY_UNIT, FormatMoney(DEFAULT_LEGACY_MIN_RELAY_TX_FEE))); strUsage += HelpMessageOpt("-printtoconsole", _("Send trace/debug info to console instead of debug.log file")); strUsage += HelpMessageOpt("-printtodebuglog", strprintf(_("Send trace/debug info to debug.log file (default: %u)"), 1)); if (showDebug) diff --git a/src/instantx.cpp b/src/instantx.cpp index 3a7f99cf2..324f7cfc5 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -970,7 +970,7 @@ bool CTxLockRequest::IsValid() const CAmount CTxLockRequest::GetMinFee() const { - CAmount nMinFee = MIN_FEE; + CAmount nMinFee = fDIP0001ActiveAtTip ? MIN_FEE / 10 : MIN_FEE; return std::max(nMinFee, CAmount(vin.size() * nMinFee)); } diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index facbd329d..eb4078bda 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) // not dust: t.vout[0].nValue = 6735; BOOST_CHECK(IsStandardTx(t, reason)); - minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); + minRelayTxFee = CFeeRate(DEFAULT_LEGACY_MIN_RELAY_TX_FEE); t.vout[0].scriptPubKey = CScript() << OP_1; BOOST_CHECK(!IsStandardTx(t, reason)); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 6ac7b2aa0..e0df59c8e 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1097,6 +1097,14 @@ CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const { return std::max(CFeeRate(rollingMinimumFeeRate), minReasonableRelayFee); } +void CTxMemPool::UpdateMinFee(const CFeeRate& _minReasonableRelayFee) +{ + LOCK(cs); + delete minerPolicyEstimator; + minerPolicyEstimator = new CBlockPolicyEstimator(_minReasonableRelayFee); + minReasonableRelayFee = _minReasonableRelayFee; +} + void CTxMemPool::trackPackageRemoved(const CFeeRate& rate) { AssertLockHeld(cs); if (rate.GetFeePerK() > rollingMinimumFeeRate) { diff --git a/src/txmempool.h b/src/txmempool.h index 5f61c3de5..89f7283c8 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -537,6 +537,7 @@ public: * would otherwise be half of this, it is set to 0 instead. */ CFeeRate GetMinFee(size_t sizelimit) const; + void UpdateMinFee(const CFeeRate& _minReasonableRelayFee); /** Remove transactions from the mempool until its dynamic size is <= sizelimit. * pvNoSpendsRemaining, if set, will be populated with the list of transactions diff --git a/src/validation.cpp b/src/validation.cpp index a313ea8bd..faceb909c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -91,7 +91,7 @@ std::atomic fDIP0001ActiveAtTip{false}; uint256 hashAssumeValid; /** Fees smaller than this (in duffs) are considered zero fee (for relaying, mining and transaction creation) */ -CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); +CFeeRate minRelayTxFee = CFeeRate(DEFAULT_LEGACY_MIN_RELAY_TX_FEE); CTxMemPool mempool(::minRelayTxFee); map mapRejectedBlocks GUARDED_BY(cs_main); diff --git a/src/validation.h b/src/validation.h index 8347b0754..4d0224d3c 100644 --- a/src/validation.h +++ b/src/validation.h @@ -56,8 +56,10 @@ static const bool DEFAULT_WHITELISTFORCERELAY = true; /** Default for -minrelaytxfee, minimum relay fee for transactions * We are ~100 times smaller then bitcoin now (2016-03-01), set minRelayTxFee only 10 times higher * so it's still 10 times lower comparing to bitcoin. + * 2017-07: we are 10x smaller now, let's lower defaults 10x via the same BIP9 bit as DIP0001 */ -static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 10000; // was 1000 +static const unsigned int DEFAULT_LEGACY_MIN_RELAY_TX_FEE = 10000; // was 1000 +static const unsigned int DEFAULT_DIP0001_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/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4fc520357..4d2522709 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -52,7 +52,7 @@ bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS; * Fees smaller than this (in duffs) are considered zero fee (for transaction creation) * Override with -mintxfee */ -CFeeRate CWallet::minTxFee = CFeeRate(DEFAULT_TRANSACTION_MINFEE); +CFeeRate CWallet::minTxFee = CFeeRate(DEFAULT_LEGACY_TRANSACTION_MINFEE); /** * If fee estimation does not have enough data to provide estimates, use this fee instead. * Has no effect if not using fee estimation diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 8c8349053..4fcf5d4eb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -53,8 +53,10 @@ static const CAmount DEFAULT_FALLBACK_FEE = 20000; /** * We are ~100 times smaller then bitcoin now (2016-03-01), set minTxFee 10 times higher * so it's still 10 times lower comparing to bitcoin. + * 2017-07: we are 10x smaller now, let's lower defaults 10x via the same BIP9 bit as DIP0001 */ -static const CAmount DEFAULT_TRANSACTION_MINFEE = 10000; // was 1000 +static const CAmount DEFAULT_LEGACY_TRANSACTION_MINFEE = 10000; // was 1000 +static const CAmount DEFAULT_DIP0001_TRANSACTION_MINFEE = 1000; //! -maxtxfee default static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.2 * COIN; // "smallest denom" + X * "denom tails" //! minimum change amount