[build] Move policy settings to new src/policy/settings unit

This moves the following policy settings functions and globals to a new
src/policy/settings unit in lib_server:

- `incrementalRelayFee`
- `dustRelayFee`
- `nBytesPerSigOp`
- `fIsBareMultisigStd`

These settings are only required by the node and should not be accessed
by other libraries.
This commit is contained in:
John Newbery 2019-04-02 14:14:58 -04:00
parent fdf8888b6f
commit 4a75c9d651
15 changed files with 47 additions and 14 deletions

View file

@ -164,6 +164,7 @@ BITCOIN_CORE_H = \
policy/fees.h \ policy/fees.h \
policy/policy.h \ policy/policy.h \
policy/rbf.h \ policy/rbf.h \
policy/settings.h \
pow.h \ pow.h \
protocol.h \ protocol.h \
psbt.h \ psbt.h \
@ -269,8 +270,8 @@ libbitcoin_server_a_SOURCES = \
noui.cpp \ noui.cpp \
outputtype.cpp \ outputtype.cpp \
policy/fees.cpp \ policy/fees.cpp \
policy/policy.cpp \
policy/rbf.cpp \ policy/rbf.cpp \
policy/settings.cpp \
pow.cpp \ pow.cpp \
rest.cpp \ rest.cpp \
rpc/blockchain.cpp \ rpc/blockchain.cpp \
@ -436,6 +437,7 @@ libbitcoin_common_a_SOURCES = \
netaddress.cpp \ netaddress.cpp \
netbase.cpp \ netbase.cpp \
policy/feerate.cpp \ policy/feerate.cpp \
policy/policy.cpp \
protocol.cpp \ protocol.cpp \
psbt.cpp \ psbt.cpp \
scheduler.cpp \ scheduler.cpp \

View file

@ -31,6 +31,7 @@
#include <policy/feerate.h> #include <policy/feerate.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/settings.h>
#include <rpc/server.h> #include <rpc/server.h>
#include <rpc/register.h> #include <rpc/register.h>
#include <rpc/blockchain.h> #include <rpc/blockchain.h>

View file

@ -13,6 +13,7 @@
#include <policy/fees.h> #include <policy/fees.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/rbf.h> #include <policy/rbf.h>
#include <policy/settings.h>
#include <primitives/block.h> #include <primitives/block.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <protocol.h> #include <protocol.h>

View file

@ -20,6 +20,7 @@
#include <policy/feerate.h> #include <policy/feerate.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/settings.h>
#include <primitives/block.h> #include <primitives/block.h>
#include <rpc/server.h> #include <rpc/server.h>
#include <scheduler.h> #include <scheduler.h>

View file

@ -10,6 +10,7 @@
#include <consensus/validation.h> #include <consensus/validation.h>
#include <validation.h> #include <validation.h>
#include <coins.h> #include <coins.h>
#include <policy/settings.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <util/system.h> #include <util/system.h>
#include <util/strencodings.h> #include <util/strencodings.h>
@ -239,10 +240,6 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
return true; return true;
} }
CFeeRate incrementalRelayFee = CFeeRate(DEFAULT_INCREMENTAL_RELAY_FEE);
CFeeRate dustRelayFee = CFeeRate(DUST_RELAY_TX_FEE);
unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP;
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost) int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
{ {
return (std::max(nWeight, nSigOpCost * nBytesPerSigOp) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR; return (std::max(nWeight, nSigOpCost * nBytesPerSigOp) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR;

View file

@ -34,6 +34,8 @@ static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000; static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000;
/** Default for -bytespersigop */ /** Default for -bytespersigop */
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20; static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
/** Default for -permitbaremultisig */
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
/** The maximum number of witness stack items in a standard P2WSH script */ /** The maximum number of witness stack items in a standard P2WSH script */
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100; static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100;
/** The maximum size of each witness stack item in a standard P2WSH script */ /** The maximum size of each witness stack item in a standard P2WSH script */
@ -98,10 +100,6 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
*/ */
bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs); bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
extern CFeeRate incrementalRelayFee;
extern CFeeRate dustRelayFee;
extern unsigned int nBytesPerSigOp;
/** Compute the virtual transaction size (weight reinterpreted as bytes). */ /** Compute the virtual transaction size (weight reinterpreted as bytes). */
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost); int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost);
int64_t GetVirtualTransactionSize(const CTransaction& tx, int64_t nSigOpCost = 0); int64_t GetVirtualTransactionSize(const CTransaction& tx, int64_t nSigOpCost = 0);

14
src/policy/settings.cpp Normal file
View file

@ -0,0 +1,14 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <policy/settings.h>
#include <policy/feerate.h>
#include <policy/policy.h>
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;

17
src/policy/settings.h Normal file
View file

@ -0,0 +1,17 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_POLICY_SETTINGS_H
#define BITCOIN_POLICY_SETTINGS_H
class CFeeRate;
// Policy settings which are configurable at runtime.
extern CFeeRate incrementalRelayFee;
extern CFeeRate dustRelayFee;
extern unsigned int nBytesPerSigOp;
extern bool fIsBareMultisigStd;
#endif // BITCOIN_POLICY_SETTINGS_H

View file

@ -12,6 +12,7 @@
#include <net_processing.h> #include <net_processing.h>
#include <netbase.h> #include <netbase.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/settings.h>
#include <rpc/protocol.h> #include <rpc/protocol.h>
#include <rpc/util.h> #include <rpc/util.h>
#include <sync.h> #include <sync.h>

View file

@ -10,6 +10,7 @@
#include <policy/policy.h> #include <policy/policy.h>
#include <script/script.h> #include <script/script.h>
#include <script/script_error.h> #include <script/script_error.h>
#include <policy/settings.h>
#include <script/sign.h> #include <script/sign.h>
#include <script/ismine.h> #include <script/ismine.h>
#include <test/test_bitcoin.h> #include <test/test_bitcoin.h>

View file

@ -15,6 +15,7 @@
#include <keystore.h> #include <keystore.h>
#include <validation.h> #include <validation.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/settings.h>
#include <script/script.h> #include <script/script.h>
#include <script/sign.h> #include <script/sign.h>
#include <script/script_error.h> #include <script/script_error.h>

View file

@ -11,6 +11,7 @@
#include <validation.h> #include <validation.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <policy/settings.h>
#include <reverse_iterator.h> #include <reverse_iterator.h>
#include <streams.h> #include <streams.h>
#include <timedata.h> #include <timedata.h>

View file

@ -22,6 +22,7 @@
#include <policy/fees.h> #include <policy/fees.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/rbf.h> #include <policy/rbf.h>
#include <policy/settings.h>
#include <pow.h> #include <pow.h>
#include <primitives/block.h> #include <primitives/block.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
@ -237,7 +238,6 @@ std::atomic_bool fImporting(false);
std::atomic_bool fReindex(false); std::atomic_bool fReindex(false);
bool fHavePruned = false; bool fHavePruned = false;
bool fPruneMode = false; bool fPruneMode = false;
bool fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
bool fRequireStandard = true; bool fRequireStandard = true;
bool fCheckBlockIndex = false; bool fCheckBlockIndex = false;
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED; bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;

View file

@ -114,8 +114,6 @@ static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
/** Maximum age of our tip in seconds for us to be considered current for fee estimation */ /** Maximum age of our tip in seconds for us to be considered current for fee estimation */
static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60; static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
/** Default for -permitbaremultisig */
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
static const bool DEFAULT_CHECKPOINTS_ENABLED = true; static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
static const bool DEFAULT_TXINDEX = false; static const bool DEFAULT_TXINDEX = false;
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100; static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
@ -159,7 +157,6 @@ extern uint256 g_best_block;
extern std::atomic_bool fImporting; extern std::atomic_bool fImporting;
extern std::atomic_bool fReindex; extern std::atomic_bool fReindex;
extern int nScriptCheckThreads; extern int nScriptCheckThreads;
extern bool fIsBareMultisigStd;
extern bool fRequireStandard; extern bool fRequireStandard;
extern bool fCheckBlockIndex; extern bool fCheckBlockIndex;
extern bool fCheckpointsEnabled; extern bool fCheckpointsEnabled;

View file

@ -13,7 +13,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"checkpoints -> validation -> checkpoints" "checkpoints -> validation -> checkpoints"
"index/txindex -> validation -> index/txindex" "index/txindex -> validation -> index/txindex"
"policy/fees -> txmempool -> policy/fees" "policy/fees -> txmempool -> policy/fees"
"policy/policy -> validation -> policy/policy" "policy/policy -> policy/settings -> policy/policy"
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel" "qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel"
"qt/bantablemodel -> qt/clientmodel -> qt/bantablemodel" "qt/bantablemodel -> qt/clientmodel -> qt/bantablemodel"
"qt/bitcoingui -> qt/utilitydialog -> qt/bitcoingui" "qt/bitcoingui -> qt/utilitydialog -> qt/bitcoingui"
@ -31,6 +31,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"wallet/fees -> wallet/wallet -> wallet/fees" "wallet/fees -> wallet/wallet -> wallet/fees"
"wallet/wallet -> wallet/walletdb -> wallet/wallet" "wallet/wallet -> wallet/walletdb -> wallet/wallet"
"policy/fees -> policy/policy -> validation -> policy/fees" "policy/fees -> policy/policy -> validation -> policy/fees"
"policy/policy -> validation -> policy/policy"
"policy/rbf -> txmempool -> validation -> policy/rbf" "policy/rbf -> txmempool -> validation -> policy/rbf"
"qt/addressbookpage -> qt/bitcoingui -> qt/walletview -> qt/addressbookpage" "qt/addressbookpage -> qt/bitcoingui -> qt/walletview -> qt/addressbookpage"
"qt/guiutil -> qt/walletmodel -> qt/optionsmodel -> qt/guiutil" "qt/guiutil -> qt/walletmodel -> qt/optionsmodel -> qt/guiutil"