diff --git a/src/config.h b/src/config.h --- a/src/config.h +++ b/src/config.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_CONFIG_H #define BITCOIN_CONFIG_H +#include "amount.h" + #include #include @@ -21,6 +23,9 @@ virtual const CChainParams &GetChainParams() const = 0; virtual void SetCashAddrEncoding(bool) = 0; virtual bool UseCashAddrEncoding() const = 0; + + virtual void SetExcessUTXOCharge(Amount amt) = 0; + virtual Amount GetExcessUTXOCharge() const = 0; }; class GlobalConfig final : public Config { @@ -34,8 +39,12 @@ void SetCashAddrEncoding(bool) override; bool UseCashAddrEncoding() const override; + void SetExcessUTXOCharge(Amount) override; + Amount GetExcessUTXOCharge() const override; + private: bool useCashAddr; + Amount excessUTXOCharge; }; // Dummy for subclassing in unittests @@ -50,6 +59,9 @@ const CChainParams &GetChainParams() const override; void SetCashAddrEncoding(bool) override {} bool UseCashAddrEncoding() const override { return false; } + + void SetExcessUTXOCharge(Amount amt) override {} + Amount GetExcessUTXOCharge() const override { return Amount(0); } }; // Temporary woraround. diff --git a/src/config.cpp b/src/config.cpp --- a/src/config.cpp +++ b/src/config.cpp @@ -54,6 +54,13 @@ return useCashAddr; } +void GlobalConfig::SetExcessUTXOCharge(Amount fee) { + excessUTXOCharge = fee; +} +Amount GlobalConfig::GetExcessUTXOCharge() const { + return excessUTXOCharge; +} + const CChainParams &DummyConfig::GetChainParams() const { return Params(CBaseChainParams::REGTEST); } diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -724,6 +724,11 @@ "block download (default: %u)", DEFAULT_MAX_TIP_AGE)); } + strUsage += HelpMessageOpt( + "-excesseutxocharge=", + strprintf(_("Fees (in %s/kB) to charge per utxo created for" + "relaying, and mining (default: %s)"), + CURRENCY_UNIT, FormatMoney(DEFAULT_UTXO_FEE))); strUsage += HelpMessageOpt( "-minrelaytxfee=", strprintf( @@ -1481,6 +1486,18 @@ nConnectTimeout = GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); if (nConnectTimeout <= 0) nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; + // Obtain the amount to charge excess UTXO + if (IsArgSet("-excesseutxocharge")) { + Amount n(0); + auto parsed = ParseMoney(GetArg("-excesseutxocharge", ""), n); + if (!parsed || Amount(0) > n) + return InitError(AmountErrMsg("excesseutxocharge", + GetArg("-excesseutxocharge", ""))); + config.SetExcessUTXOCharge(n); + } else { + config.SetExcessUTXOCharge(DEFAULT_UTXO_FEE); + } + // Fee-per-kilobyte amount considered the same as "free". If you are mining, // be careful setting this: if you set it to zero then a transaction spammer // can cheaply fill blocks using 1-satoshi-fee transactions. It should be diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -56,6 +56,8 @@ static const bool DEFAULT_WHITELISTFORCERELAY = true; /** Default for -minrelaytxfee, minimum relay fee for transactions */ static const Amount DEFAULT_MIN_RELAY_TX_FEE(1000); +/** Default for -excesseutxocharge for transactions transactions */ +static const Amount DEFAULT_UTXO_FEE(0); //! -maxtxfee default static const Amount DEFAULT_TRANSACTION_MAXFEE(COIN / 10); //! Discourage users to set fees higher than this amount (in satoshis) per kB @@ -185,6 +187,9 @@ extern bool fCheckpointsEnabled; extern size_t nCoinCacheUsage; +/** Amount to charge for creation of excessive utxos */ +extern Amount excessUTXOCharge; + /** A fee rate smaller than this is considered zero fee (for relaying, mining * and transaction creation) */ extern CFeeRate minRelayTxFee;