diff --git a/src/config.cpp b/src/config.cpp index 130953f6ee..246244939f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1,97 +1,100 @@ // Copyright (c) 2017 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "config.h" #include "chainparams.h" -#include "consensus/consensus.h" +#include "consensus/consensus.h" // DEFAULT_MAX_BLOCK_SIZE #include "globals.h" +#include "policy/policy.h" // DEFAULT_BLOCK_PRIORITY_PERCENTAGE -GlobalConfig::GlobalConfig() : useCashAddr(false) {} +GlobalConfig::GlobalConfig() + : useCashAddr(false), nMaxBlockSize(DEFAULT_MAX_BLOCK_SIZE), + nBlockPriorityPercentage(DEFAULT_BLOCK_PRIORITY_PERCENTAGE) {} bool GlobalConfig::SetMaxBlockSize(uint64_t maxBlockSize) { // Do not allow maxBlockSize to be set below historic 1MB limit // It cannot be equal either because of the "must be big" UAHF rule. if (maxBlockSize <= LEGACY_MAX_BLOCK_SIZE) { return false; } nMaxBlockSize = maxBlockSize; return true; } uint64_t GlobalConfig::GetMaxBlockSize() const { return nMaxBlockSize; } bool GlobalConfig::SetBlockPriorityPercentage(int64_t blockPriorityPercentage) { // blockPriorityPercentage has to belong to [0..100] if ((blockPriorityPercentage < 0) || (blockPriorityPercentage > 100)) { return false; } nBlockPriorityPercentage = blockPriorityPercentage; return true; } uint8_t GlobalConfig::GetBlockPriorityPercentage() const { return nBlockPriorityPercentage; } const CChainParams &GlobalConfig::GetChainParams() const { return Params(); } static GlobalConfig gConfig; const Config &GetConfig() { return gConfig; } void GlobalConfig::SetCashAddrEncoding(bool c) { useCashAddr = c; } bool GlobalConfig::UseCashAddrEncoding() const { return useCashAddr; } DummyConfig::DummyConfig() : chainParams(CreateChainParams(CBaseChainParams::REGTEST)) {} DummyConfig::DummyConfig(std::string net) : chainParams(CreateChainParams(net)) {} void DummyConfig::SetChainParams(std::string net) { chainParams = CreateChainParams(net); } void GlobalConfig::SetExcessUTXOCharge(Amount fee) { excessUTXOCharge = fee; } Amount GlobalConfig::GetExcessUTXOCharge() const { return excessUTXOCharge; } void GlobalConfig::SetMinFeePerKB(CFeeRate fee) { feePerKB = fee; } CFeeRate GlobalConfig::GetMinFeePerKB() const { return feePerKB; } void GlobalConfig::SetRPCUserAndPassword(std::string userAndPassword) { rpcUserAndPassword = userAndPassword; } std::string GlobalConfig::GetRPCUserAndPassword() const { return rpcUserAndPassword; } void GlobalConfig::SetRPCCORSDomain(std::string corsDomain) { rpcCORSDomain = corsDomain; } std::string GlobalConfig::GetRPCCORSDomain() const { return rpcCORSDomain; } diff --git a/src/config.h b/src/config.h index 4790d90e15..cfe9fc800e 100644 --- a/src/config.h +++ b/src/config.h @@ -1,116 +1,120 @@ // Copyright (c) 2017 Amaury SÉCHET // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_CONFIG_H #define BITCOIN_CONFIG_H #include "amount.h" #include "feerate.h" #include #include #include #include class CChainParams; class Config : public boost::noncopyable { public: virtual bool SetMaxBlockSize(uint64_t maxBlockSize) = 0; virtual uint64_t GetMaxBlockSize() const = 0; virtual bool SetBlockPriorityPercentage(int64_t blockPriorityPercentage) = 0; virtual uint8_t GetBlockPriorityPercentage() const = 0; 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; virtual void SetMinFeePerKB(CFeeRate amt) = 0; virtual CFeeRate GetMinFeePerKB() const = 0; virtual void SetRPCUserAndPassword(std::string userAndPassword) = 0; virtual std::string GetRPCUserAndPassword() const = 0; virtual void SetRPCCORSDomain(std::string corsDomain) = 0; virtual std::string GetRPCCORSDomain() const = 0; }; class GlobalConfig final : public Config { public: GlobalConfig(); bool SetMaxBlockSize(uint64_t maxBlockSize) override; uint64_t GetMaxBlockSize() const override; bool SetBlockPriorityPercentage(int64_t blockPriorityPercentage) override; uint8_t GetBlockPriorityPercentage() const override; const CChainParams &GetChainParams() const override; void SetCashAddrEncoding(bool) override; bool UseCashAddrEncoding() const override; void SetExcessUTXOCharge(Amount) override; Amount GetExcessUTXOCharge() const override; void SetMinFeePerKB(CFeeRate amt) override; CFeeRate GetMinFeePerKB() const override; void SetRPCUserAndPassword(std::string userAndPassword) override; std::string GetRPCUserAndPassword() const override; void SetRPCCORSDomain(std::string corsDomain) override; std::string GetRPCCORSDomain() const override; private: bool useCashAddr; Amount excessUTXOCharge; CFeeRate feePerKB; /** RPC authentication configs */ // Pre-base64-encoded authentication token, with user and password separated // by a colon. std::string rpcUserAndPassword; // CORS domain, the allowed Origin std::string rpcCORSDomain; + + /** The largest block size this node will accept. */ + uint64_t nMaxBlockSize; + uint64_t nBlockPriorityPercentage; }; // Dummy for subclassing in unittests class DummyConfig : public Config { public: DummyConfig(); DummyConfig(std::string net); bool SetMaxBlockSize(uint64_t maxBlockSize) override { return false; } uint64_t GetMaxBlockSize() const override { return 0; } bool SetBlockPriorityPercentage(int64_t blockPriorityPercentage) override { return false; } uint8_t GetBlockPriorityPercentage() const override { return 0; } void SetChainParams(std::string net); const CChainParams &GetChainParams() const override { return *chainParams; } void SetCashAddrEncoding(bool) override {} bool UseCashAddrEncoding() const override { return false; } void SetExcessUTXOCharge(Amount amt) override {} Amount GetExcessUTXOCharge() const override { return Amount::zero(); } void SetMinFeePerKB(CFeeRate amt) override{}; CFeeRate GetMinFeePerKB() const override { return CFeeRate(Amount::zero()); } void SetRPCUserAndPassword(std::string userAndPassword) override{}; std::string GetRPCUserAndPassword() const override { return ""; }; void SetRPCCORSDomain(std::string corsDomain) override{}; std::string GetRPCCORSDomain() const override { return ""; }; private: std::unique_ptr chainParams; }; // Temporary woraround. const Config &GetConfig(); #endif diff --git a/src/globals.cpp b/src/globals.cpp index 75db5b7737..bb7c7191db 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -1,12 +1,8 @@ // Copyright (c) 2017 Amaury SÉCHET // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "globals.h" #include "consensus/consensus.h" #include "policy/policy.h" - -uint64_t nMaxBlockSize = DEFAULT_MAX_BLOCK_SIZE; -uint64_t nBlockPriorityPercentage = DEFAULT_BLOCK_PRIORITY_PERCENTAGE; - diff --git a/src/globals.h b/src/globals.h index 7732ae6372..e3cfb24e53 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,15 +1,11 @@ // Copyright (c) 2017 Amaury SÉCHET // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_GLOBALS_H #define BITCOIN_GLOBALS_H #include #include -/** The largest block size this node will accept. */ -extern uint64_t nMaxBlockSize; -extern uint64_t nBlockPriorityPercentage; - #endif // BITCOIN_GLOBALS_H