aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2018-01-07 22:56:53 +0000
committerRoss Nicoll <[email protected]>2018-09-19 21:09:16 +0100
commit18850d359bbc4d3333d9f1ac33607242d205c2ce (patch)
tree45cb5ac9949143efb71ddd7f3f7f4cf8c152df2d /src/wallet
parentVerify when doing 'backupwallet' that destination is not the same path of the... (diff)
downloaddiscoin-18850d359bbc4d3333d9f1ac33607242d205c2ce.tar.xz
discoin-18850d359bbc4d3333d9f1ac33607242d205c2ce.zip
Add Dogecoin current fee calculation logic (#1413)
Introduces 1 COIN/kb fees, rounded up to the next 1 COIN.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/rpcwallet.cpp6
-rw-r--r--src/wallet/test/wallet_tests.cpp38
-rw-r--r--src/wallet/wallet.cpp25
-rw-r--r--src/wallet/wallet.h15
4 files changed, 68 insertions, 16 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index d6b6d0142..ec00160c6 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -2829,7 +2829,7 @@ UniValue bumpfee(const JSONRPCRequest& request)
}
} else if (options.exists("totalFee")) {
totalFee = options["totalFee"].get_int64();
- CAmount requiredFee = CWallet::GetRequiredFee(maxNewTxSize);
+ CAmount requiredFee = CWallet::GetRequiredFee(*wtx.tx, maxNewTxSize);
if (totalFee < requiredFee ) {
throw JSONRPCError(RPC_INVALID_PARAMETER,
strprintf("Insufficient totalFee (cannot be less than required fee %s)",
@@ -2866,11 +2866,11 @@ UniValue bumpfee(const JSONRPCRequest& request)
} else {
// if user specified a confirm target then don't consider any global payTxFee
if (specifiedConfirmTarget) {
- nNewFee = CWallet::GetMinimumFee(maxNewTxSize, newConfirmTarget, mempool, CAmount(0));
+ nNewFee = CWallet::GetMinimumFee(*wtx.tx, maxNewTxSize, newConfirmTarget, mempool, CAmount(0));
}
// otherwise use the regular wallet logic to select payTxFee or default confirm target
else {
- nNewFee = CWallet::GetMinimumFee(maxNewTxSize, newConfirmTarget, mempool);
+ nNewFee = CWallet::GetMinimumFee(*wtx.tx, maxNewTxSize, newConfirmTarget, mempool);
}
nNewFeeRate = CFeeRate(nNewFee, maxNewTxSize);
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index 2fbcc3414..c6e10f34f 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include "txmempool.h"
#include "wallet/wallet.h"
#include <set>
@@ -434,7 +435,7 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain240Setup)
// greater or equal than key birthday. Previously there was a bug where
// importwallet RPC would start the scan at the latest block with timestamp less
// than or equal to key birthday.
-BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
+BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain240Setup)
{
CWallet *pwalletMainBackup = ::pwalletMain;
LOCK(cs_main);
@@ -490,4 +491,39 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
::pwalletMain = pwalletMainBackup;
}
+BOOST_AUTO_TEST_CASE(GetMinimumFee_test)
+{
+ uint64_t value = 1000 * COIN; // 1,000 DOGE
+
+ CMutableTransaction tx;
+ CTxMemPool pool(payTxFee);
+ CTxOut txout1(value, (CScript)vector<unsigned char>(24, 0));
+ tx.vout.push_back(txout1);
+
+ int64_t nMinTxFee = COIN;
+
+ BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 250, 0, pool), nMinTxFee);
+ BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1000, 0, pool), 2 * nMinTxFee);
+ BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1999, 0, pool), 2 * nMinTxFee);
+}
+
+BOOST_AUTO_TEST_CASE(GetMinimumFee_dust_test)
+{
+ // Derived from main net TX 3d6ec3ae2aca3ae0a6c65074fd8ee888cd7ed262f2cbaa25d33861989324a14e
+ CMutableTransaction tx;
+ CTxMemPool pool(payTxFee);
+ CTxOut txout1(139496846, (CScript)vector<unsigned char>(24, 0)); // Regular output
+ CTxOut txout2(15499649, (CScript)vector<unsigned char>(24, 0)); // Dust output
+ tx.vout.push_back(txout1);
+ tx.vout.push_back(txout2);
+
+ int64_t nMinTxFee = COIN;
+
+ // Confirm dust penalty fees are added on
+
+ BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 963, 0, pool), 2 * nMinTxFee);
+ BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1000, 0, pool), 3 * nMinTxFee);
+ BOOST_CHECK_EQUAL(CWallet::GetMinimumFee(tx, 1999, 0, pool), 3 * nMinTxFee);
+}
+
BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 0e09dc70d..b34cbae3a 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -8,6 +8,7 @@
#include "base58.h"
#include "checkpoints.h"
#include "chain.h"
+#include "dogecoin.h"
#include "wallet/coincontrol.h"
#include "consensus/consensus.h"
#include "consensus/validation.h"
@@ -2636,7 +2637,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
break;
}
- CAmount nFeeNeeded = GetMinimumFee(nBytes, currentConfirmationTarget, mempool);
+ CAmount nFeeNeeded = GetMinimumFee(txNew, nBytes, currentConfirmationTarget, mempool);
if (coinControl && nFeeNeeded > 0 && coinControl->nMinimumTotalFee > nFeeNeeded) {
nFeeNeeded = coinControl->nMinimumTotalFee;
}
@@ -2805,18 +2806,30 @@ bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB *pwa
return true;
}
+CAmount CWallet::GetRequiredFee(const CMutableTransaction& tx, unsigned int nTxBytes)
+{
+ // Dogecoin: Round TX bytes up to the next 1,000 bytes
+ nTxBytes += 1000 - (nTxBytes % 1000);
+
+ // Dogecoin: Add an increased fee for each dust output
+ return std::max(minTxFee.GetFee(nTxBytes) + GetDogecoinDustFee(tx.vout, minTxFee), ::minRelayTxFee.GetFee(nTxBytes));
+}
+
CAmount CWallet::GetRequiredFee(unsigned int nTxBytes)
{
+ // Dogecoin: Round TX bytes up to the next 1,000 bytes
+ nTxBytes += 1000 - (nTxBytes % 1000);
+
return std::max(minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFee(nTxBytes));
}
-CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
+CAmount CWallet::GetMinimumFee(const CMutableTransaction& tx, unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
{
// payTxFee is the user-set global for desired feerate
- return GetMinimumFee(nTxBytes, nConfirmTarget, pool, payTxFee.GetFee(nTxBytes));
+ return GetMinimumFee(tx, nTxBytes, nConfirmTarget, pool, payTxFee.GetFee(nTxBytes));
}
-CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, CAmount targetFee)
+CAmount CWallet::GetMinimumFee(const CMutableTransaction& tx, unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, CAmount targetFee)
{
CAmount nFeeNeeded = targetFee;
// User didn't set: use -txconfirmtarget to estimate...
@@ -2828,7 +2841,7 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
nFeeNeeded = fallbackFee.GetFee(nTxBytes);
}
// prevent user from paying a fee below minRelayTxFee or minTxFee
- nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(nTxBytes));
+ nFeeNeeded = std::max(nFeeNeeded, GetRequiredFee(tx, nTxBytes));
// But always obey the maximum
if (nFeeNeeded > maxTxFee)
nFeeNeeded = maxTxFee;
@@ -2836,8 +2849,6 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
}
-
-
DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
{
if (!fFileBacked)
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 8cf4a83ae..16588721c 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -47,11 +47,11 @@ static const unsigned int DEFAULT_KEYPOOL_SIZE = 100;
//! -paytxfee default
static const CAmount DEFAULT_TRANSACTION_FEE = 0;
//! -fallbackfee default
-static const CAmount DEFAULT_FALLBACK_FEE = 20000;
+static const CAmount DEFAULT_FALLBACK_FEE = COIN * 20;
//! -mintxfee default
-static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
+static const CAmount DEFAULT_TRANSACTION_MINFEE = COIN;
//! minimum recommended increment for BIP 125 replacement txs
-static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
+static const CAmount WALLET_INCREMENTAL_RELAY_FEE = COIN * 5;
//! target minimum change amount
static const CAmount MIN_CHANGE = CENT;
//! final minimum change amount after paying for fees
@@ -749,16 +749,21 @@ public:
* Estimate the minimum fee considering user set parameters
* and the required fee
*/
- static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
+ static CAmount GetMinimumFee(const CMutableTransaction& tx, unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
/**
* Estimate the minimum fee considering required fee and targetFee or if 0
* then fee estimation for nConfirmTarget
*/
- static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, CAmount targetFee);
+ static CAmount GetMinimumFee(const CMutableTransaction& tx, unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool, CAmount targetFee);
/**
* Return the minimum required fee taking into account the
* floating relay fee and user set minimum transaction fee
*/
+ static CAmount GetRequiredFee(const CMutableTransaction& tx, unsigned int nTxBytes);
+ /**
+ * Return the minimum required fee taking into account the
+ * floating relay fee and user set minimum transaction fee, but not the Dogecoin dust fee.
+ */
static CAmount GetRequiredFee(unsigned int nTxBytes);
bool NewKeyPool();