Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ BITCOIN_CORE_H = \
interfaces/wallet.h \
kernel/blockmanager_opts.h \
kernel/chain.h \
kernel/chainparams.h \
kernel/chainstatemanager_opts.h \
kernel/checks.h \
kernel/coinstats.h \
Expand Down Expand Up @@ -994,6 +995,7 @@ libbitcoin_common_a_SOURCES = \
external_signer.cpp \
governance/common.cpp \
init/common.cpp \
kernel/chainparams.cpp \
key.cpp \
key_io.cpp \
llmq/core_write.cpp \
Expand Down Expand Up @@ -1309,6 +1311,7 @@ libdashkernel_la_SOURCES = \
instantsend/lock.cpp \
kernel/chain.cpp \
kernel/checks.cpp \
kernel/chainparams.cpp \
kernel/coinstats.cpp \
kernel/context.cpp \
kernel/cs_main.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/active/dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <util/helpers.h>

#include <chain.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <validation.h>

Expand Down
5 changes: 3 additions & 2 deletions src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//
// It is part of the libbitcoinkernel project.

#include <kernel/chainparams.h>
#include <kernel/checks.h>
#include <kernel/context.h>
#include <kernel/validation_cache_sizes.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ int main(int argc, char* argv[])

// SETUP: Misc Globals
SelectParams(CBaseChainParams::MAIN);
const CChainParams& chainparams = Params();
auto chainparams = CChainParams::Main();

kernel::Context kernel_context{};
// We can't use a goto here, but we can use an assert since none of the
Expand Down Expand Up @@ -91,7 +92,7 @@ int main(int argc, char* argv[])

// SETUP: Chainstate
const ChainstateManager::Options chainman_opts{
.chainparams = chainparams,
.chainparams = *chainparams,
};
ChainstateManager chainman{chainman_opts};

Expand Down
1 change: 1 addition & 0 deletions src/chainlock/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <chainlock/clsig.h>
#include <chainlock/handler.h>
#include <chainparams.h>
#include <instantsend/instantsend.h>
#include <llmq/signing_shares.h>
#include <masternode/sync.h>
Expand Down
1,284 changes: 92 additions & 1,192 deletions src/chainparams.cpp

Large diffs are not rendered by default.

182 changes: 4 additions & 178 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef BITCOIN_CHAINPARAMS_H
#define BITCOIN_CHAINPARAMS_H

#include <kernel/chainparams.h>

#include <chainparamsbase.h>
#include <consensus/params.h>
#include <llmq/params.h>
Expand All @@ -14,189 +16,13 @@
#include <protocol.h>
#include <util/hash_type.h>

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

typedef std::map<int, uint256> MapCheckpoints;

struct CCheckpointData {
MapCheckpoints mapCheckpoints;

int GetHeight() const {
const auto& final_checkpoint = mapCheckpoints.rbegin();
return final_checkpoint->first /* height */;
}
};

struct AssumeutxoHash : public BaseHash<uint256> {
explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
};

struct EvoSnapshotHash : public BaseHash<uint256> {
explicit EvoSnapshotHash(const uint256& hash) : BaseHash(hash) {}
};

/**
* 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.
const AssumeutxoHash hash_serialized;

//! The expected single-SHA256 hash of the canonical Dash evo section.
const EvoSnapshotHash evo_hash;

//! 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>;

/**
* Holds various statistics on transactions within a chain. Used to estimate
* verification progress during chain sync.
*
* See also: CChainParams::TxData, GuessVerificationProgress.
*/
struct ChainTxData {
int64_t nTime;
int64_t nTxCount;
double dTxRate;
};

/**
* CChainParams defines various tweakable parameters of a given instance of the
* Dash system.
*/
class CChainParams
{
public:
enum Base58Type {
PUBKEY_ADDRESS,
SCRIPT_ADDRESS,
SECRET_KEY, // BIP16
EXT_PUBLIC_KEY, // BIP32
EXT_SECRET_KEY, // BIP32

MAX_BASE58_TYPES
};

const Consensus::Params& GetConsensus() const { return consensus; }
const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
uint16_t GetDefaultPort() const { return nDefaultPort; }
uint16_t GetDefaultPort(Network net) const
{
return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
}
uint16_t GetDefaultPort(const std::string& addr) const
{
CNetAddr a;
return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
}
uint16_t GetDefaultPlatformP2PPort() const { return nDefaultPlatformP2PPort; }
uint16_t GetDefaultPlatformHTTPPort() const { return nDefaultPlatformHTTPPort; }

const CBlock& GenesisBlock() const { return genesis; }
const CBlock& DevNetGenesisBlock() const { return devnetGenesis; }
/** Default value for -checkmempool and -checkblockindex argument */
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
/** Require addresses specified with "-externalip" parameter to be routable */
bool RequireRoutableExternalIP() const { return fRequireRoutableExternalIP; }
/** If this chain allows time to be mocked */
bool IsMockableChain() const { return m_is_mockable_chain; }
/** If this chain is exclusively used for testing */
bool IsTestChain() const { return m_is_test_chain; }
uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
/** 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; }
/** Whether it is possible to mine blocks on demand (no retargeting) */
bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
/** Allow multiple addresses to be selected from the same network group (e.g. 192.168.x.x) */
bool AllowMultipleAddressesFromGroup() const { return fAllowMultipleAddressesFromGroup; }
/** How long to wait until we allow retrying of a LLMQ connection */
int LLMQConnectionRetryTimeout() const { return nLLMQConnectionRetryTimeout; }
/** Return the network string */
std::string NetworkIDString() const { return strNetworkID; }
/** Return the list of hostnames to look up for DNS seeds */
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
/** DIP-18 Platform address bech32m HRP: "dash" on mainnet, "tdash" on test chains */
const std::string& Bech32PlatformHRP() const { return bech32_platform_hrp; }
int ExtCoinType() const { return nExtCoinType; }
const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
const CCheckpointData& Checkpoints() const { return checkpointData; }

//! Get allowed assumeutxo configuration.
//! @see ChainstateManager
const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }

const ChainTxData& TxData() const { return chainTxData; }
void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight);
void UpdateDIP8Parameters(int nActivationHeight);
void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock);
void UpdateLLMQInstantSend(Consensus::LLMQType llmqType);
/**
* Validate params for Masternodes EHF
*
* @param[in] nBit The version bit to update
* @param[in] timePast The block time to validate if release is already time-outed
* @return Whether params are legit and params are updated (if release is known)
*/
bool IsValidMNActivation(int nBit, int64_t timePast) const;
int PoolMinParticipants() const { return nPoolMinParticipants; }
int PoolMaxParticipants() const { return nPoolMaxParticipants; }
int FulfilledRequestExpireTime() const { return nFulfilledRequestExpireTime; }
const std::string& SporkAddress() const { return strSporkAddress; }
int CreditPoolPeriodBlocks() const { return nCreditPoolPeriodBlocks; }
[[nodiscard]] std::optional<Consensus::LLMQParams> GetLLMQ(Consensus::LLMQType llmqType) const;

protected:
CChainParams() {}

Consensus::Params consensus;
CMessageHeader::MessageStartChars pchMessageStart;
uint16_t nDefaultPort;
uint64_t nPruneAfterHeight;
uint64_t m_assumed_blockchain_size;
uint64_t m_assumed_chain_state_size;
std::vector<std::string> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
std::string bech32_platform_hrp;
int nExtCoinType;
std::string strNetworkID;
CBlock genesis;
CBlock devnetGenesis;
std::vector<uint8_t> vFixedSeeds;
bool fDefaultConsistencyChecks;
bool fRequireRoutableExternalIP;
bool m_is_test_chain;
bool fAllowMultipleAddressesFromGroup;
bool m_is_mockable_chain;
int nLLMQConnectionRetryTimeout;
CCheckpointData checkpointData;
MapAssumeutxo m_assumeutxo_data;
ChainTxData chainTxData;
int nPoolMinParticipants;
int nPoolMaxParticipants;
int nFulfilledRequestExpireTime;
std::string strSporkAddress;
uint16_t nDefaultPlatformP2PPort;
uint16_t nDefaultPlatformHTTPPort;
/// The number of blocks the credit pool tracks; 576 (one day) on mainnet, reduced on regtest
int nCreditPoolPeriodBlocks;

void AddLLMQ(Consensus::LLMQType llmqType);
};

/**
* Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
* @returns a CChainParams* of the chosen chain.
Expand Down
32 changes: 32 additions & 0 deletions src/deploymentinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <consensus/params.h>

#include <string_view>

const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = {
{
/*.name =*/ "testdummy",
Expand Down Expand Up @@ -58,3 +60,33 @@ std::string DeploymentName(Consensus::BuriedDeployment dep)
} // no default case, so the compiler can warn about missing cases
return "";
}

std::optional<Consensus::BuriedDeployment> GetBuriedDeployment(const std::string_view name)
{
if (name == "bip147") {
return Consensus::BuriedDeployment::DEPLOYMENT_BIP147;
} else if (name == "bip34") {
return Consensus::BuriedDeployment::DEPLOYMENT_HEIGHTINCB;
} else if (name == "dersig") {
return Consensus::BuriedDeployment::DEPLOYMENT_DERSIG;
} else if (name == "cltv") {
return Consensus::BuriedDeployment::DEPLOYMENT_CLTV;
} else if (name == "csv") {
return Consensus::BuriedDeployment::DEPLOYMENT_CSV;
} else if (name == "brr") {
return Consensus::BuriedDeployment::DEPLOYMENT_BRR;
} else if (name == "dip0001") {
return Consensus::BuriedDeployment::DEPLOYMENT_DIP0001;
} else if (name == "dip0008") {
return Consensus::BuriedDeployment::DEPLOYMENT_DIP0008;
} else if (name == "dip0024") {
return Consensus::BuriedDeployment::DEPLOYMENT_DIP0024;
} else if (name == "v19") {
return Consensus::BuriedDeployment::DEPLOYMENT_V19;
} else if (name == "v20") {
return Consensus::BuriedDeployment::DEPLOYMENT_V20;
} else if (name == "mn_rr") {
return Consensus::BuriedDeployment::DEPLOYMENT_MN_RR;
}
return std::nullopt;
}
3 changes: 3 additions & 0 deletions src/deploymentinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <consensus/params.h>

#include <optional>
#include <string>

struct VBDeploymentInfo {
Expand All @@ -26,4 +27,6 @@ inline std::string DeploymentName(Consensus::DeploymentPos pos)
return VersionBitsDeploymentInfo[pos].name;
}

std::optional<Consensus::BuriedDeployment> GetBuriedDeployment(const std::string_view deployment_name);

#endif // BITCOIN_DEPLOYMENTINFO_H
1 change: 1 addition & 0 deletions src/instantsend/net_instantsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <bls/bls_batchverifier.h>
#include <chainlock/chainlock.h>
#include <chainparams.h>
#include <consensus/params.h>
#include <cxxtimer.hpp>
#include <instantsend/instantsend.h>
Expand Down
Loading
Loading