Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@ bool AppInitParameterInteraction()
fAcceptDatacarrier = gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
nMaxDatacarrierBytes = gArgs.GetArg("-datacarriersize", nMaxDatacarrierBytes);

g_package_limits.m_ancestor_limit = gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
g_package_limits.m_ancestor_size_limit = gArgs.GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT)*1000;
g_package_limits.m_descendant_limit = gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
g_package_limits.m_descendant_size_limit = gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT)*1000;

// Option to startup with mocktime set (used for regression testing):
SetMockTime(gArgs.GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op

Expand Down
12 changes: 8 additions & 4 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,19 @@ class ChainImpl : public Chain
{
::mempool.GetTransactionAncestry(txid, ancestors, descendants);
}
PackageLimits getPackageLimits() override
{
return g_package_limits;
}
bool checkChainLimits(const CTransactionRef& tx) override
{
LockPoints lp;
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
CTxMemPool::setEntries ancestors;
auto limit_ancestor_count = gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
auto limit_ancestor_size = gArgs.GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT) * 1000;
auto limit_descendant_count = gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
auto limit_descendant_size = gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000;
auto limit_ancestor_count = g_package_limits.m_ancestor_limit;
auto limit_ancestor_size = g_package_limits.m_ancestor_size_limit;
auto limit_descendant_count = g_package_limits.m_descendant_limit;
auto limit_descendant_size = g_package_limits.m_descendant_size_limit;
std::string unused_error_string;
LOCK(::mempool.cs);
return ::mempool.CalculateMemPoolAncestors(entry, ancestors, limit_ancestor_count, limit_ancestor_size,
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class uint256;
enum class RBFTransactionState;
struct CBlockLocator;
struct FeeCalculation;
struct PackageLimits;

namespace interfaces {

Expand Down Expand Up @@ -163,6 +164,9 @@ class Chain
//! Calculate mempool ancestor and descendant counts for the given transaction.
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0;

//! Get the node's mempool transaction package limits.
virtual PackageLimits getPackageLimits() = 0;

//! Check if transaction will pass the mempool's chain limits.
virtual bool checkChainLimits(const CTransactionRef& tx) = 0;

Expand Down
7 changes: 7 additions & 0 deletions src/policy/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ bool fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
CFeeRate incrementalRelayFee = CFeeRate(DEFAULT_INCREMENTAL_RELAY_FEE);
CFeeRate dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP;

PackageLimits g_package_limits {
DEFAULT_ANCESTOR_LIMIT,
DEFAULT_ANCESTOR_SIZE_LIMIT,
DEFAULT_DESCENDANT_LIMIT,
DEFAULT_DESCENDANT_SIZE_LIMIT
};
18 changes: 18 additions & 0 deletions src/policy/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

#include <policy/policy.h>

/** 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 */
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
/** Default for -limitdescendantcount, max number of in-mempool descendants */
static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;

class CFeeRate;
class CTransaction;

Expand All @@ -17,6 +26,15 @@ extern CFeeRate dustRelayFee;
extern unsigned int nBytesPerSigOp;
extern bool fIsBareMultisigStd;

struct PackageLimits {
unsigned int m_ancestor_limit;
unsigned int m_ancestor_size_limit;
unsigned int m_descendant_limit;
unsigned int m_descendant_size_limit;
};

extern PackageLimits g_package_limits;

static inline bool IsStandardTx(const CTransaction& tx, std::string& reason)
{
return IsStandardTx(tx, ::fIsBareMultisigStd, ::dustRelayFee, reason);
Expand Down
8 changes: 4 additions & 4 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ class MemPoolAccept
{
public:
MemPoolAccept(CTxMemPool& mempool) : m_pool(mempool), m_view(&m_dummy), m_viewmempool(&::ChainstateActive().CoinsTip(), m_pool),
m_limit_ancestors(gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT)),
m_limit_ancestor_size(gArgs.GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT)*1000),
m_limit_descendants(gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT)),
m_limit_descendant_size(gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT)*1000) {}
m_limit_ancestors(g_package_limits.m_ancestor_limit),
m_limit_ancestor_size(g_package_limits.m_ancestor_size_limit),
m_limit_descendants(g_package_limits.m_descendant_limit),
m_limit_descendant_size(g_package_limits.m_descendant_size_limit) {}

// We put the arguments we're handed into a struct, so we can pass them
// around easier.
Expand Down
8 changes: 0 additions & 8 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ struct LockPoints;

/** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
/** 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 */
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
/** Default for -limitdescendantcount, max number of in-mempool descendants */
static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
/** Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants */
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
/**
* An extra transaction can be added to a package, as long as it only has one
* ancestor and is no larger than this. Not really any reason to make this
Expand Down
7 changes: 4 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <key_io.h>
#include <policy/fees.h>
#include <policy/policy.h>
#include <policy/settings.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <script/descriptor.h>
Expand All @@ -27,7 +28,6 @@
#include <util/rbf.h>
#include <util/translation.h>
#include <util/validation.h>
#include <validation.h>
#include <wallet/coincontrol.h>
#include <wallet/fees.h>

Expand Down Expand Up @@ -2739,8 +2739,9 @@ bool CWallet::SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAm
}
std::vector<OutputGroup> groups = GroupOutputs(vCoins, !coin_control.m_avoid_partial_spends);

size_t max_ancestors = (size_t)std::max<int64_t>(1, gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT));
size_t max_descendants = (size_t)std::max<int64_t>(1, gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT));
auto package_limits = chain().getPackageLimits();
size_t max_ancestors = (size_t)std::max<int64_t>(1, package_limits.m_ancestor_limit);
size_t max_descendants = (size_t)std::max<int64_t>(1, package_limits.m_descendant_limit);
bool fRejectLongChains = gArgs.GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS);

bool res = nTargetValue <= nValueFromPresetInputs ||
Expand Down