2013-05-07 09:16:25 -04:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2020-04-16 13:14:08 -04:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2014-10-25 06:24:16 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-05-07 09:16:25 -04:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#ifndef BITCOIN_CHAINPARAMS_H
|
|
|
|
#define BITCOIN_CHAINPARAMS_H
|
2013-05-07 09:16:25 -04:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <chainparamsbase.h>
|
|
|
|
#include <consensus/params.h>
|
|
|
|
#include <primitives/block.h>
|
|
|
|
#include <protocol.h>
|
2021-04-04 08:20:13 -04:00
|
|
|
#include <util/hash_type.h>
|
2013-05-07 09:16:25 -04:00
|
|
|
|
2015-05-21 22:50:01 -03:00
|
|
|
#include <memory>
|
2013-05-07 09:16:25 -04:00
|
|
|
#include <vector>
|
|
|
|
|
2015-06-05 16:36:34 -03:00
|
|
|
typedef std::map<int, uint256> MapCheckpoints;
|
|
|
|
|
|
|
|
struct CCheckpointData {
|
|
|
|
MapCheckpoints mapCheckpoints;
|
2020-06-10 19:57:58 -04:00
|
|
|
|
|
|
|
int GetHeight() const {
|
|
|
|
const auto& final_checkpoint = mapCheckpoints.rbegin();
|
|
|
|
return final_checkpoint->first /* height */;
|
|
|
|
}
|
2017-01-04 12:31:56 -03:00
|
|
|
};
|
|
|
|
|
2021-04-04 08:20:13 -04:00
|
|
|
struct AssumeutxoHash : public BaseHash<uint256> {
|
|
|
|
explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
|
|
|
|
};
|
|
|
|
|
2019-04-25 11:09:29 -04:00
|
|
|
/**
|
|
|
|
* Holds configuration for use during UTXO snapshot load and validation. The contents
|
|
|
|
* here are security critical, since they dictate which UTXO snapshots are recognized
|
|
|
|
* as valid.
|
|
|
|
*/
|
|
|
|
struct AssumeutxoData {
|
|
|
|
//! The expected hash of the deserialized UTXO set.
|
2021-04-04 08:20:13 -04:00
|
|
|
const AssumeutxoHash hash_serialized;
|
2019-04-25 11:09:29 -04:00
|
|
|
|
|
|
|
//! Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
|
|
|
|
//!
|
|
|
|
//! We need to hardcode the value here because this is computed cumulatively using block data,
|
|
|
|
//! which we do not necessarily have at the time of snapshot load.
|
|
|
|
const unsigned int nChainTx;
|
|
|
|
};
|
|
|
|
|
|
|
|
using MapAssumeutxo = std::map<int, const AssumeutxoData>;
|
|
|
|
|
2018-04-17 18:15:20 -03:00
|
|
|
/**
|
|
|
|
* Holds various statistics on transactions within a chain. Used to estimate
|
|
|
|
* verification progress during chain sync.
|
|
|
|
*
|
|
|
|
* See also: CChainParams::TxData, GuessVerificationProgress.
|
|
|
|
*/
|
2017-01-04 12:31:56 -03:00
|
|
|
struct ChainTxData {
|
2018-07-29 13:36:35 -04:00
|
|
|
int64_t nTime; //!< UNIX timestamp of last known number of transactions
|
|
|
|
int64_t nTxCount; //!< total number of transactions between genesis and that timestamp
|
|
|
|
double dTxRate; //!< estimated number of transactions per second after that timestamp
|
2015-06-05 16:36:34 -03:00
|
|
|
};
|
2015-01-24 01:40:50 -03:00
|
|
|
|
2013-05-07 09:16:25 -04:00
|
|
|
/**
|
|
|
|
* CChainParams defines various tweakable parameters of a given instance of the
|
2021-03-23 17:29:17 -03:00
|
|
|
* Bitcoin system.
|
2013-05-07 09:16:25 -04:00
|
|
|
*/
|
|
|
|
class CChainParams
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Base58Type {
|
|
|
|
PUBKEY_ADDRESS,
|
|
|
|
SCRIPT_ADDRESS,
|
|
|
|
SECRET_KEY,
|
2013-07-14 19:05:25 -04:00
|
|
|
EXT_PUBLIC_KEY,
|
|
|
|
EXT_SECRET_KEY,
|
2013-05-07 09:16:25 -04:00
|
|
|
|
|
|
|
MAX_BASE58_TYPES
|
|
|
|
};
|
|
|
|
|
2015-02-11 07:58:11 -03:00
|
|
|
const Consensus::Params& GetConsensus() const { return consensus; }
|
2014-10-27 21:24:31 -03:00
|
|
|
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
|
2021-03-01 17:35:28 -03:00
|
|
|
uint16_t GetDefaultPort() const { return nDefaultPort; }
|
2014-03-22 15:52:26 -03:00
|
|
|
|
2014-06-10 13:33:12 -04:00
|
|
|
const CBlock& GenesisBlock() const { return genesis; }
|
2015-03-13 13:25:34 -03:00
|
|
|
/** Default value for -checkmempool and -checkblockindex argument */
|
|
|
|
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
|
2015-04-28 11:47:17 -03:00
|
|
|
/** Policy: Filter transactions that do not match well-defined patterns */
|
2014-06-04 06:51:29 -04:00
|
|
|
bool RequireStandard() const { return fRequireStandard; }
|
2019-07-16 16:24:42 -04:00
|
|
|
/** If this chain is exclusively used for testing */
|
2019-04-24 17:55:58 -04:00
|
|
|
bool IsTestChain() const { return m_is_test_chain; }
|
2020-02-07 01:17:28 -03:00
|
|
|
/** If this chain allows time to be mocked */
|
|
|
|
bool IsMockableChain() const { return m_is_mockable_chain; }
|
2015-11-27 11:12:08 -03:00
|
|
|
uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
|
2018-10-07 09:11:36 -03:00
|
|
|
/** Minimum free space (in GB) needed for data directory */
|
|
|
|
uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; }
|
|
|
|
/** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/
|
|
|
|
uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
|
2019-04-23 17:32:29 -04:00
|
|
|
/** Whether it is possible to mine blocks on demand (no retargeting) */
|
|
|
|
bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
|
2019-10-28 14:33:40 -03:00
|
|
|
/** Return the network string */
|
2014-06-11 06:23:49 -04:00
|
|
|
std::string NetworkIDString() const { return strNetworkID; }
|
2017-10-19 18:32:45 -03:00
|
|
|
/** Return the list of hostnames to look up for DNS seeds */
|
|
|
|
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
|
2014-06-04 06:51:29 -04:00
|
|
|
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
|
2017-08-25 23:55:52 -03:00
|
|
|
const std::string& Bech32HRP() const { return bech32_hrp; }
|
2021-03-31 08:29:24 -03:00
|
|
|
const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
|
2015-06-05 16:36:34 -03:00
|
|
|
const CCheckpointData& Checkpoints() const { return checkpointData; }
|
2019-04-25 11:09:29 -04:00
|
|
|
|
|
|
|
//! Get allowed assumeutxo configuration.
|
|
|
|
//! @see ChainstateManager
|
|
|
|
const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }
|
|
|
|
|
2017-01-04 12:31:56 -03:00
|
|
|
const ChainTxData& TxData() const { return chainTxData; }
|
2013-05-07 09:16:25 -04:00
|
|
|
protected:
|
2013-10-15 07:13:54 -03:00
|
|
|
CChainParams() {}
|
2013-05-07 09:16:25 -04:00
|
|
|
|
2015-02-11 07:58:11 -03:00
|
|
|
Consensus::Params consensus;
|
2014-10-27 21:24:31 -03:00
|
|
|
CMessageHeader::MessageStartChars pchMessageStart;
|
2021-03-01 17:35:28 -03:00
|
|
|
uint16_t nDefaultPort;
|
Add block pruning functionality
This adds a -prune=N option to bitcoind, which if set to N>0 will enable block
file pruning. When pruning is enabled, block and undo files will be deleted to
try to keep total space used by those files to below the prune target (N, in
MB) specified by the user, subject to some constraints:
- The last 288 blocks on the main chain are always kept (MIN_BLOCKS_TO_KEEP),
- N must be at least 550MB (chosen as a value for the target that could
reasonably be met, with some assumptions about block sizes, orphan rates,
etc; see comment in main.h),
- No blocks are pruned until chainActive is at least 100,000 blocks long (on
mainnet; defined separately for mainnet, testnet, and regtest in chainparams
as nPruneAfterHeight).
This unsets NODE_NETWORK if pruning is enabled.
Also included is an RPC test for pruning (pruning.py).
Thanks to @rdponticelli for earlier work on this feature; this is based in
part off that work.
2015-02-23 16:27:44 -03:00
|
|
|
uint64_t nPruneAfterHeight;
|
2018-10-07 09:11:36 -03:00
|
|
|
uint64_t m_assumed_blockchain_size;
|
|
|
|
uint64_t m_assumed_chain_state_size;
|
2017-10-19 18:32:45 -03:00
|
|
|
std::vector<std::string> vSeeds;
|
2013-06-22 20:33:47 -04:00
|
|
|
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
|
2017-08-25 23:55:52 -03:00
|
|
|
std::string bech32_hrp;
|
2014-06-11 06:23:49 -04:00
|
|
|
std::string strNetworkID;
|
2014-06-04 06:51:29 -04:00
|
|
|
CBlock genesis;
|
2021-03-31 08:29:24 -03:00
|
|
|
std::vector<uint8_t> vFixedSeeds;
|
2015-03-13 13:25:34 -03:00
|
|
|
bool fDefaultConsistencyChecks;
|
2014-06-04 06:51:29 -04:00
|
|
|
bool fRequireStandard;
|
2019-04-24 17:55:58 -04:00
|
|
|
bool m_is_test_chain;
|
2020-02-07 01:17:28 -03:00
|
|
|
bool m_is_mockable_chain;
|
2015-06-05 16:36:34 -03:00
|
|
|
CCheckpointData checkpointData;
|
2019-04-25 11:09:29 -04:00
|
|
|
MapAssumeutxo m_assumeutxo_data;
|
2017-01-04 12:31:56 -03:00
|
|
|
ChainTxData chainTxData;
|
2013-05-07 09:16:25 -04:00
|
|
|
};
|
|
|
|
|
2015-05-21 22:50:01 -03:00
|
|
|
/**
|
|
|
|
* Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
|
|
|
|
* @returns a CChainParams* of the chosen chain.
|
|
|
|
* @throws a std::runtime_error if the chain is not supported.
|
|
|
|
*/
|
2020-09-24 10:11:27 -03:00
|
|
|
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain);
|
2015-05-21 22:50:01 -03:00
|
|
|
|
2013-05-07 09:16:25 -04:00
|
|
|
/**
|
2015-04-28 11:48:28 -03:00
|
|
|
* Return the currently selected parameters. This won't change after app
|
|
|
|
* startup, except for unit tests.
|
2013-05-07 09:16:25 -04:00
|
|
|
*/
|
|
|
|
const CChainParams &Params();
|
|
|
|
|
|
|
|
/**
|
2019-10-28 14:33:40 -03:00
|
|
|
* Sets the params returned by Params() to those for the given chain name.
|
2015-06-30 16:39:49 -03:00
|
|
|
* @throws std::runtime_error when the chain is not supported.
|
2013-05-07 09:16:25 -04:00
|
|
|
*/
|
2015-06-30 16:39:49 -03:00
|
|
|
void SelectParams(const std::string& chain);
|
2013-05-07 09:16:25 -04:00
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#endif // BITCOIN_CHAINPARAMS_H
|