Skip to content

Commit

Permalink
Merge pull request #1276 from rnicoll/1.10-fees
Browse files Browse the repository at this point in the history
Correct fee calculations to match legacy Dogecoin
  • Loading branch information
langerhans committed Sep 8, 2015
2 parents 070af08 + ce196a9 commit f5c4d8b
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/dogecoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusP
int64_t GetDogecoinDustFee(const std::vector<CTxOut> &vout, CFeeRate &baseFeeRate) {
int64_t nFee = 0;

// To limit dust spam, add base fee for each output less than DUST_SOFT_LIMIT
// To limit dust spam, add base fee for each dust output
BOOST_FOREACH(const CTxOut& txout, vout)
if (txout.IsDust(::minRelayTxFee))
// if (txout.IsDust(::minRelayTxFee))
if (txout.nValue < COIN)
nFee += baseFeeRate.GetFeePerK();

return nFee;
Expand Down
11 changes: 8 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-salvagewallet", _("Attempt to recover private keys from a corrupt wallet.dat") + " " + _("on startup"));
strUsage += HelpMessageOpt("-sendfreetransactions", strprintf(_("Send transactions as zero-fee transactions if possible (default: %u)"), 0));
strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), 1));
strUsage += HelpMessageOpt("-txconfirmtarget=<n>", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET));
// Dogecoin: Disable TX confirm target as the dust prevention fees make
// the fee estimation code produce bizarre results.
// strUsage += HelpMessageOpt("-txconfirmtarget=<n>", 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=<amt>", strprintf(_("Maximum total fees to use in a single wallet transaction; setting this too low may abort large transactions (default: %s)"),
FormatMoney(maxTxFee)));
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format") + " " + _("on startup"));
Expand All @@ -355,7 +357,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-walletnotify=<cmd>", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)"));
strUsage += HelpMessageOpt("-zapwallettxes=<mode>", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));

#endif

strUsage += HelpMessageGroup(_("Debugging/Testing options:"));
Expand Down Expand Up @@ -869,7 +871,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
mapArgs["-maxtxfee"], ::minRelayTxFee.ToString()));
}
}
nTxConfirmTarget = GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);

// Dogecoin: Disable txconfirmtarget
// nTxConfirmTarget = GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET;
bSpendZeroConfChange = GetBoolArg("-spendzeroconfchange", true);
fSendFreeTransactions = GetBoolArg("-sendfreetransactions", false);

Expand Down
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,16 +872,15 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
CAmount nMinFee = ::minRelayTxFee.GetFee(nBytes);
nMinFee += GetDogecoinDustFee(tx.vout, ::minRelayTxFee);

// Dogecoin: Disable free transactions
/* if (fAllowFree)
if (fAllowFree)
{
// There is a free transaction area in blocks created by most miners,
// * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000
// to be considered to fall into this category. We don't want to encourage sending
// multiple transactions instead of one big transaction to avoid fees.
if (nBytes < (DEFAULT_BLOCK_PRIORITY_SIZE - 1000))
nMinFee = 0;
} */
}

if (!MoneyRange(nMinFee))
nMinFee = MAX_MONEY;
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct CNodeStateStats;
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 750000;
static const unsigned int DEFAULT_BLOCK_MIN_SIZE = 0;
/** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 50000;
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 27000;
/** Default for accepting alerts from the P2P network. */
static const bool DEFAULT_ALERTS = true;
/** The maximum size for transactions we're willing to relay/mine */
Expand Down
11 changes: 8 additions & 3 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,18 @@ class CTxOut
// need a CTxIn of at least 148 bytes to spend:
// so dust is a txout less than 546 satoshis
// with default minRelayTxFee.
size_t nSize = GetSerializeSize(SER_DISK,0)+148u;
return 3*minRelayTxFee.GetFee(nSize);
// size_t nSize = GetSerializeSize(SER_DISK,0)+148u;
// return 3*minRelayTxFee.GetFee(nSize);
// Dogecoin: Dust is 1 COIN
return COIN;
}

bool IsDust(const CFeeRate &minRelayTxFee) const
{
return (nValue < GetDustThreshold(minRelayTxFee));
// Dogecoin: IsDust() detection disabled, allows any valid dust to be relayed.
// The fees imposed on each dust txo is considered sufficient spam deterrant.
// return (nValue < GetDustThreshold(minRelayTxFee));
return false;
}

friend bool operator==(const CTxOut& a, const CTxOut& b)
Expand Down
22 changes: 12 additions & 10 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,15 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
nPayFee = CWallet::GetMinimumFee(txDummy, nBytes, nTxConfirmTarget, mempool);

// Allow free?
double dPriorityNeeded = mempoolEstimatePriority;
if (dPriorityNeeded <= 0)
dPriorityNeeded = AllowFreeThreshold(); // not enough data, back to hard-coded
fAllowFree = (dPriority >= dPriorityNeeded);
// Dogecoin: No free transactions
// double dPriorityNeeded = mempoolEstimatePriority;
// if (dPriorityNeeded <= 0)
// dPriorityNeeded = AllowFreeThreshold(); // not enough data, back to hard-coded
// fAllowFree = (dPriority >= dPriorityNeeded);

if (fSendFreeTransactions)
if (fAllowFree && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE)
nPayFee = 0;
// if (fSendFreeTransactions)
// if (fAllowFree && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE)
// nPayFee = 0;

if (nPayAmount > 0)
{
Expand All @@ -570,16 +571,17 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
if (nChange > 0 && nChange < CENT)
{
CTxOut txout(nChange, (CScript)vector<unsigned char>(24, 0));
if (txout.IsDust(::minRelayTxFee))
{
// Dogecoin: Anything below 1 DOGE is considered dust
// if (txout.IsDust(::minRelayTxFee))
// {
if (CoinControlDialog::fSubtractFeeFromAmount) // dust-change will be raised until no dust
nChange = txout.GetDustThreshold(::minRelayTxFee);
else
{
nPayFee += nChange;
nChange = 0;
}
}
//}
}

if (nChange == 0 && !CoinControlDialog::fSubtractFeeFromAmount)
Expand Down
5 changes: 3 additions & 2 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
string reason;
BOOST_CHECK(IsStandardTx(t, reason));

t.vout[0].nValue = 501; // dust
BOOST_CHECK(!IsStandardTx(t, reason));
// Dogecoin: Dogecoin allows dust transactions
// t.vout[0].nValue = 501; // dust
// BOOST_CHECK(!IsStandardTx(t, reason));

t.vout[0].nValue = COIN; // not dust
BOOST_CHECK(IsStandardTx(t, reason));
Expand Down
10 changes: 6 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,8 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
dPriority = wtxNew.ComputePriority(dPriority, nBytes);

// Can we complete this as a free transaction?
if (fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE)
// Dogecoin: Disable free transactions
/* if (fSendFreeTransactions && nBytes <= MAX_FREE_TRANSACTION_CREATE_SIZE)
{
// Not enough fee: enough priority?
double dPriorityNeeded = mempool.estimatePriority(nTxConfirmTarget);
Expand All @@ -1934,7 +1935,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
// Small enough, and priority high enough, to send for free
if (dPriorityNeeded > 0 && dPriority >= dPriorityNeeded)
break;
}
} */

CAmount nFeeNeeded = GetMinimumFee(txNew, nBytes, nTxConfirmTarget, mempool);

Expand Down Expand Up @@ -2023,8 +2024,9 @@ CAmount CWallet::GetMinimumFee(const CMutableTransaction& tx, unsigned int nTxBy
if (fPayAtLeastCustomFee && nFeeNeeded > 0 && nFeeNeeded < payTxFee.GetFeePerK())
nFeeNeeded = payTxFee.GetFeePerK();
// User didn't set: use -txconfirmtarget to estimate...
if (nFeeNeeded == 0)
nFeeNeeded = pool.estimateFee(nConfirmTarget).GetFee(nTxBytes);
// Dogecoin: Disable txconfirmtarget
//if (nFeeNeeded == 0)
// nFeeNeeded = pool.estimateFee(nConfirmTarget).GetFee(nTxBytes);
// ... unless we don't have enough mempool data, in which case fall
// back to a hard-coded fee
if (nFeeNeeded == 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ extern bool fPayAtLeastCustomFee;
//! -paytxfee default
static const CAmount DEFAULT_TRANSACTION_FEE = 0;
//! -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB
static const CAmount nHighTransactionFeeWarning = 10 * COIN;
static const CAmount nHighTransactionFeeWarning = 25 * COIN;
//! -maxtxfee default
static const CAmount DEFAULT_TRANSACTION_MAXFEE = 100 * COIN;
static const CAmount DEFAULT_TRANSACTION_MAXFEE = 250 * COIN;
//! -txconfirmtarget default
static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 2;
//! -maxtxfee will warn if called with a higher fee than this amount (in satoshis)
static const CAmount nHighTransactionMaxFeeWarning = 100 * nHighTransactionFeeWarning;
//! Largest (in bytes) free transaction we're willing to create
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 0;

class CAccountingEntry;
class CBlockIndex;
Expand Down

0 comments on commit f5c4d8b

Please sign in to comment.