Skip to content

Commit

Permalink
add min fee enforcement and set it at 0.1rtm per kb
Browse files Browse the repository at this point in the history
  • Loading branch information
npq7721 committed Sep 24, 2024
1 parent d94533d commit 02e6305
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 10 deletions.
6 changes: 3 additions & 3 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
snapshot-version=2.0.3.99-SNAPSHOT
release-version=2.0.3.00
candidate-version=2.0.3.00-candidate
snapshot-version=2.0.4.99-SNAPSHOT
release-version=2.0.4.00
candidate-version=2.0.4.00-candidate
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 03)
define(_CLIENT_VERSION_REVISION, 04)
define(_CLIENT_VERSION_BUILD, 99)
define(_CLIENT_VERSION_IS_RELEASE, false)
define(_COPYRIGHT_YEAR, 2024)
Expand Down
16 changes: 16 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,22 @@ class CTestNetParams : public CChainParams {
VoteThreshold(85, 85, 1), // minerThreshold
VoteThreshold(85, 85, 1)) // nodeThreshold
);
updateManager.Add(
Update(EUpdate::MIN_FEE_VOTING, std::string("Min fee Voting"),
3, // bit
1440, // roundSize
263520, // startHeight
1, // votingPeriod
365, // votingMaxRounds
1, // gracePeriod
true, // forceUpdate
VoteThreshold(0, 0, 1), // minerThreshold
VoteThreshold(0, 0, 1), // nodeThreshold
false,
264341
)
);


// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x0"); // 0
Expand Down
8 changes: 8 additions & 0 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <consensus/validation.h>
#include <validation.h>

#include <chainparams.h>
#include <future/fee.h>
Expand Down Expand Up @@ -395,6 +396,13 @@ bool Consensus::CheckTxInputs(const CTransaction &tx, CValidationState &state, c
if (!checkSpecialTxFee(tx, txfee, specialTxFee, fFeeVerify)) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-wrong-future-fee-or-not-enable");
}
bool isMinFeeEnforceActive = Updates().IsMinFeeEnforceActive(::ChainActive().Tip());
if(tx.vin.size() > 0 && isMinFeeEnforceActive) {
size_t nSize = GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
if(txfee < enforcedMinRelayTxFee.GetFee(nSize)) {
return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "min relay fee not met");
}
}

if (txfee < 0) {
return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-too-low", false,
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ namespace interfaces {
return ::mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
}

CFeeRate relayMinFee() override { return ::minRelayTxFee; }
CFeeRate relayMinFee() override {
bool isMinFeeEnforceActive = Updates().IsMinFeeEnforceActive(::ChainActive().Tip());
return isMinFeeEnforceActive ? ::enforcedMinRelayTxFee : ::minRelayTxFee;
}

CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }

Expand Down
2 changes: 1 addition & 1 deletion src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
* standard and should be done with care and ideally rarely. It makes sense to
* only increase the dust limit after prior releases were already not creating
* outputs below the new threshold */
static const unsigned int DUST_RELAY_TX_FEE = 3000;
static const unsigned int DUST_RELAY_TX_FEE = 0.3 * COIN;
/**
* Standard script verification flags that standard transactions will comply
* with. However scripts violating these flags may still be present in valid
Expand Down
5 changes: 4 additions & 1 deletion src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <validation.h>
#include <version.h>
#include <warnings.h>
#include <chainparams.h>

#include <univalue.h>

Expand Down Expand Up @@ -589,8 +590,10 @@ UniValue getnetworkinfo(const JSONRPCRequest &request) {
}
obj.pushKV("socketevents", strSocketEvents);
}
bool isMinFeeEnforceActive = Updates().IsMinFeeEnforceActive(::ChainActive().Tip());
UniValue minRelayFeeAmount = isMinFeeEnforceActive ? ValueFromAmount(::enforcedMinRelayTxFee.GetFeePerK()) : ValueFromAmount(::minRelayTxFee.GetFeePerK());
obj.pushKV("networks", GetNetworksInfo());
obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()));
obj.pushKV("relayfee", minRelayFeeAmount);
obj.pushKV("incrementalfee", ValueFromAmount(::incrementalRelayFee.GetFeePerK()));
UniValue localAddresses(UniValue::VARR);
{
Expand Down
4 changes: 4 additions & 0 deletions src/update/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ bool UpdateManager::IsAssetsActive(const CBlockIndex *blockIndex) {
return IsActive(EUpdate::ROUND_VOTING, blockIndex);
}

bool UpdateManager::IsMinFeeEnforceActive(const CBlockIndex *blockIndex) {
return IsActive(EUpdate::MIN_FEE_VOTING, blockIndex);
}

StateInfo UpdateManager::State(enum EUpdate eUpdate, const CBlockIndex *blockIndex) {
const Update *update = GetUpdate(eUpdate);
VoteStats voteStats = {VoteResult(), VoteResult(), 0, 0, false, false};
Expand Down
2 changes: 2 additions & 0 deletions src/update/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum class EUpdate {
DEPLOYMENT_V17 = 0,
ROUND_VOTING = 1,
QUORUMS_200_8 = 2,
MIN_FEE_VOTING = 3,

MAX_VERSION_BITS_DEPLOYMENTS
};
Expand Down Expand Up @@ -347,6 +348,7 @@ class UpdateManager {
bool IsActive(enum EUpdate eUpdate, const CBlockIndex *blockIndex);

bool IsAssetsActive(const CBlockIndex *blockIndex);
bool IsMinFeeEnforceActive(const CBlockIndex *blockIndex);

StateInfo State(enum EUpdate eUpdate, const CBlockIndex *blockIndex);

Expand Down
1 change: 1 addition & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ uint256 hashAssumeValid;
arith_uint256 nMinimumChainWork;

CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
const CFeeRate enforcedMinRelayTxFee = CFeeRate(MIN_RELAY_TX_FEE);

CBlockPolicyEstimator feeEstimator;
CTxMemPool mempool(&feeEstimator);
Expand Down
2 changes: 2 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static const bool DEFAULT_WHITELISTRELAY = true;
static const bool DEFAULT_WHITELISTFORCERELAY = true;
/** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
static const unsigned int MIN_RELAY_TX_FEE = 0.1 * COIN;
/** Default for -limitancestorcount, max number of in-mempool ancestors */
static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
/** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
Expand Down Expand Up @@ -202,6 +203,7 @@ extern bool fCheckBlockIndex;
extern bool fCheckpointsEnabled;
/** A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) */
extern CFeeRate minRelayTxFee;
extern const CFeeRate enforcedMinRelayTxFee;
/** If the tip is older than this (in seconds), the node is considered to be in initial block download. */
extern int64_t nMaxTipAge;

Expand Down
4 changes: 3 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4614,7 +4614,9 @@ bool CWallet::CreateTransaction(const std::vector <CRecipient> &vecSend, CTransa

// If we made it here and we aren't even able to meet the relay fee on the next pass, give up
// because we must be at the maximum allowed fee.
if (nFee < ::minRelayTxFee.GetFee(nBytes)) {
bool isMinFeeEnforceActive = Updates().IsMinFeeEnforceActive(::ChainActive().Tip());
CFeeRate minRelayFeeRate = isMinFeeEnforceActive ? ::enforcedMinRelayTxFee : ::minRelayTxFee;
if (nFee < minRelayFeeRate.GetFee(nBytes)) {
strFailReason = _("Transaction too large for fee policy");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
static const bool DEFAULT_WALLETBROADCAST = true;
static const bool DEFAULT_DISABLE_WALLET = false;
//! -maxtxfee default
static const CAmount DEFAULT_TRANSACTION_MAXFEE = COIN / 10;
static const CAmount DEFAULT_TRANSACTION_MAXFEE = 1000 * COIN;
//! Discourage users to set fees higher than this amount (in duffs) per kB
static const CAmount HIGH_TX_FEE_PER_KB = COIN / 100;
static const CAmount HIGH_TX_FEE_PER_KB = 100 * COIN;
//! -maxtxfee will warn if called with a higher fee than this amount (in duffs)
static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB;

Expand Down

0 comments on commit 02e6305

Please sign in to comment.