Skip to content

Commit

Permalink
Merge rwconf_policy-26+knots
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Mar 25, 2024
2 parents 4d81fce + b25c95c commit 904069a
Show file tree
Hide file tree
Showing 20 changed files with 947 additions and 39 deletions.
20 changes: 19 additions & 1 deletion src/init.cpp
Expand Up @@ -136,6 +136,7 @@ using node::ShouldPersistMempool;
using node::ImportBlocks;
using node::VerifyLoadedChainstate;

static constexpr bool DEFAULT_COREPOLICY{false};
static constexpr bool DEFAULT_PROXYRANDOMIZE{true};
static constexpr bool DEFAULT_REST_ENABLE{false};
static constexpr bool DEFAULT_I2P_ACCEPT_INCOMING{true};
Expand Down Expand Up @@ -458,6 +459,7 @@ void SetupServerArgs(ArgsManager& argsman)
argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-confrw=<file>", strprintf("Specify read/write configuration file. Relative paths will be prefixed by the network-specific datadir location (default: %s)", BITCOIN_RW_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-corepolicy", strprintf("Use Bitcoin Core policy defaults (default: %u)", DEFAULT_COREPOLICY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (%d to %d, default: %d). In addition, unused mempool memory is shared for this cache (see -maxmempool).", nMinDbCache, nMaxDbCache, nDefaultDbCache), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
Expand Down Expand Up @@ -641,7 +643,7 @@ void SetupServerArgs(ArgsManager& argsman)
ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-maxscriptsize", strprintf("Maximum size of scripts we relay and mine (default: %s)", DEFAULT_SCRIPT_SIZE_POLICY_LIMIT), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-mempoolfullrbf", strprintf("Accept transaction replace-by-fee without requiring replaceability signaling (default: %u)", (DEFAULT_MEMPOOL_RBF_POLICY == RBFPolicy::Always)), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-mempoolreplacement", strprintf("Set to 0 to disable RBF entirely, \"fee,optin\" to honour RBF opt-out signal, or \"fee,-optin\" to always RBF aka full RBF (default: %s)", "fee,optin"), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-mempoolreplacement", strprintf("Set to 0 to disable RBF entirely, \"fee,optin\" to honour RBF opt-out signal, or \"fee,-optin\" to always RBF aka full RBF (default: %s)", "fee,-optin"), ArgsManager::ALLOW_ANY, OptionsCategory::NODE_RELAY);
argsman.AddArg("-permitbarepubkey", strprintf("Relay legacy pubkey outputs (default: %u)", DEFAULT_PERMIT_BAREPUBKEY), ArgsManager::ALLOW_ANY,
OptionsCategory::NODE_RELAY);
argsman.AddArg("-permitbaremultisig", strprintf("Relay non-P2SH multisig (default: %u)", DEFAULT_PERMIT_BAREMULTISIG), ArgsManager::ALLOW_ANY,
Expand Down Expand Up @@ -736,6 +738,22 @@ static bool AppInitServers(NodeContext& node)
// Parameter interaction based on rules
void InitParameterInteraction(ArgsManager& args)
{
if (args.GetBoolArg("-corepolicy", DEFAULT_COREPOLICY)) {
args.SoftSetArg("-acceptnonstddatacarrier", "1");
args.SoftSetArg("-bytespersigopstrict", "0");
args.SoftSetArg("-permitbarepubkey", "1");
args.SoftSetArg("-permitbaremultisig", "1");
args.SoftSetArg("-datacarriercost", "0.25");
args.SoftSetArg("-datacarrierfullcount", "0");
args.SoftSetArg("-datacarriersize", "83");
args.SoftSetArg("-maxscriptsize", strprintf("%s", std::numeric_limits<unsigned int>::max()));
args.SoftSetArg("-mempoolreplacement", args.GetBoolArg("-mempoolfullrbf", false) ? "fee,-optin" : "fee,optin");
args.SoftSetArg("-spkreuse", "allow");
args.SoftSetArg("-blockprioritysize", "0");
args.SoftSetArg("-blockmaxsize", "4000000");
args.SoftSetArg("-blockmaxweight", "3996000");
}

// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
if (args.IsArgSet("-bind")) {
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/node.h
Expand Up @@ -27,6 +27,7 @@ class BanMan;
class CFeeRate;
class CNetAddr;
class CNodeStats;
class CTxMemPool;
class Coin;
class RPCTimerInterface;
class UniValue;
Expand Down Expand Up @@ -161,6 +162,8 @@ class Node
//! Get total bytes sent.
virtual int64_t getTotalBytesSent() = 0;

virtual CTxMemPool& mempool() = 0;

//! Get mempool size.
virtual size_t getMempoolSize() = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/kernel/mempool_options.h
Expand Up @@ -25,9 +25,9 @@ static constexpr unsigned int DEFAULT_BLOCKSONLY_MAX_MEMPOOL_SIZE_MB{5};
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
static constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY_HOURS{336};
/** Default for -mempoolreplacement; must update docs in init.cpp manually */
static constexpr RBFPolicy DEFAULT_MEMPOOL_RBF_POLICY{RBFPolicy::OptIn};
static constexpr RBFPolicy DEFAULT_MEMPOOL_RBF_POLICY{RBFPolicy::Always};
/** Default for -acceptnonstddatacarrier */
static constexpr bool DEFAULT_ACCEPT_NON_STD_DATACARRIER{true};
static constexpr bool DEFAULT_ACCEPT_NON_STD_DATACARRIER{false};
/** Default for -acceptnonstdtxn */
static constexpr bool DEFAULT_ACCEPT_NON_STD_TXN{false};

Expand Down
7 changes: 7 additions & 0 deletions src/net_processing.cpp
Expand Up @@ -508,6 +508,7 @@ class PeerManagerImpl final : public PeerManager
std::optional<std::string> FetchBlock(NodeId peer_id, const uint256& hash, const CBlockIndex* block_index) override
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void LimitOrphanTxSize(unsigned int nMaxOrphans) override;
bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; }
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
Expand Down Expand Up @@ -1735,6 +1736,12 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
return true;
}

void PeerManagerImpl::LimitOrphanTxSize(unsigned int nMaxOrphans)
{
LOCK(cs_main);
m_orphanage.LimitOrphans(nMaxOrphans);
}

int PeerManagerImpl::GetNumberOfPeersWithValidatedDownloads() const
{
AssertLockHeld(m_chainman.GetMutex());
Expand Down
2 changes: 2 additions & 0 deletions src/net_processing.h
Expand Up @@ -7,6 +7,7 @@
#define BITCOIN_NET_PROCESSING_H

#include <net.h>
#include <threadsafety.h>
#include <validationinterface.h>

class AddrMan;
Expand Down Expand Up @@ -84,6 +85,7 @@ class PeerManager : public CValidationInterface, public NetEventsInterface

/** Get statistics from node state */
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
virtual void LimitOrphanTxSize(unsigned int nMaxOrphans) = 0;

/** Whether this node ignores txs received over p2p. */
virtual bool IgnoresIncomingTxs() = 0;
Expand Down
1 change: 1 addition & 0 deletions src/node/interfaces.cpp
Expand Up @@ -412,6 +412,7 @@ class NodeImpl : public Node
}
ArgsManager& args() { return *Assert(Assert(m_context)->args); }
ChainstateManager& chainman() { return *Assert(m_context->chainman); }
CTxMemPool& mempool() override { return *Assert(m_context->mempool); }
NodeContext* m_context{nullptr};
};

Expand Down
4 changes: 2 additions & 2 deletions src/node/miner.cpp
Expand Up @@ -59,8 +59,8 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)

static BlockAssembler::Options ClampOptions(BlockAssembler::Options options)
{
// Limit weight to between 4K and DEFAULT_BLOCK_MAX_WEIGHT for sanity:
options.nBlockMaxWeight = std::clamp<size_t>(options.nBlockMaxWeight, 4000, DEFAULT_BLOCK_MAX_WEIGHT);
// Limit weight to between 4K and MAX_BLOCK_WEIGHT-4k for sanity:
options.nBlockMaxWeight = std::clamp<size_t>(options.nBlockMaxWeight, 4000, MAX_BLOCK_WEIGHT - 4000);
// Limit size to between 1K and MAX_BLOCK_SERIALIZED_SIZE-1K for sanity:
options.nBlockMaxSize = std::clamp<size_t>(options.nBlockMaxSize, 1000, MAX_BLOCK_SERIALIZED_SIZE - 1000);
// Whether we need to account for byte usage (in addition to weight usage)
Expand Down
22 changes: 11 additions & 11 deletions src/policy/policy.h
Expand Up @@ -22,13 +22,13 @@ class CFeeRate;
class CScript;

/** Default for -blockmaxsize, which controls the maximum size of block the mining code will create **/
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = MAX_BLOCK_SERIALIZED_SIZE;
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 300000;
/** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 0;
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 100000;
/** Minimum priority for transactions to be accepted into the priority area **/
static const double MINIMUM_TX_PRIORITY = COIN * 144 / 250;
/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT - 4000};
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{DEFAULT_BLOCK_MAX_SIZE * WITNESS_SCALE_FACTOR};
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1000};
/** The maximum weight for transactions we're willing to relay/mine */
Expand All @@ -42,17 +42,17 @@ static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/
/** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{1000};
/** Default for -maxscriptsize */
static constexpr unsigned int DEFAULT_SCRIPT_SIZE_POLICY_LIMIT{std::numeric_limits<unsigned int>::max()};
static constexpr unsigned int DEFAULT_SCRIPT_SIZE_POLICY_LIMIT{1650};
/** Default for -bytespersigop */
static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20};
/** Default for -bytespersigopstrict */
static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP_STRICT{20};
/** Default for -datacarriercost (multiplied by WITNESS_SCALE_FACTOR) */
static constexpr unsigned int DEFAULT_WEIGHT_PER_DATA_BYTE{1};
static constexpr unsigned int DEFAULT_WEIGHT_PER_DATA_BYTE{4};
/** Default for -permitbarepubkey */
static constexpr bool DEFAULT_PERMIT_BAREPUBKEY{true};
static constexpr bool DEFAULT_PERMIT_BAREPUBKEY{false};
/** Default for -permitbaremultisig */
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{true};
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{false};
/** The maximum number of witness stack items in a standard P2WSH script */
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100};
/** The maximum size in bytes of each witness stack item in a standard P2WSH script */
Expand Down Expand Up @@ -84,12 +84,12 @@ static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT_KVB{101};
/** Default for -datacarrier */
static const bool DEFAULT_ACCEPT_DATACARRIER = true;
/**
* Default setting for -datacarriersize. 80 bytes of data, +1 for OP_RETURN,
* +2 for the pushdata opcodes.
* Default setting for -datacarriersize. 40 bytes of data, +1 for OP_RETURN,
* +1 for the pushdata opcode.
*/
static const unsigned int MAX_OP_RETURN_RELAY = 83;
static constexpr unsigned int MAX_OP_RETURN_RELAY{42};
/** Default for -datacarrierfullcount */
static constexpr bool DEFAULT_DATACARRIER_FULLCOUNT{false};
static constexpr bool DEFAULT_DATACARRIER_FULLCOUNT{true};
/**
* 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

0 comments on commit 904069a

Please sign in to comment.