PIVX Core  5.6.99
P2P Digital Currency
params.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_CONSENSUS_PARAMS_H
7 #define PIVX_CONSENSUS_PARAMS_H
8 
9 #include "amount.h"
10 #include "libzerocoin/Params.h"
11 #include "optional.h"
12 #include "uint256.h"
13 #include <map>
14 #include <string>
15 
16 namespace Consensus {
17 
26 enum UpgradeIndex : uint32_t {
43  // NOTE: Also add new upgrades to NetworkUpgradeInfo in upgrades.cpp
45 };
46 
52 
57 
67  static constexpr int ALWAYS_ACTIVE = 0;
68 
74  static constexpr int NO_ACTIVATION_HEIGHT = -1;
75 
87 };
88 
89 enum LLMQType : uint8_t
90 {
91  LLMQ_NONE = 0xff,
92 
93  LLMQ_50_60 = 1, // 50 members, 30 (60%) threshold, one per hour
94  LLMQ_400_60 = 2, // 400 members, 240 (60%) threshold, one every 12 hours
95  LLMQ_400_85 = 3, // 400 members, 340 (85%) threshold, one every 24 hours
96 
97  // for testing only
98  LLMQ_TEST = 100, // 3 members, 2 (66%) threshold, one per hour. Params might differ when -llmqtestparams is used
99 };
100 
101 // Configures a LLMQ and its DKG
102 // See https://github.com/dashpay/dips/blob/master/dip-0006.md for more details
103 struct LLMQParams {
105 
106  // not consensus critical, only used in logging, RPC and UI
107  std::string name;
108 
109  // the size of the quorum, e.g. 50 or 400
110  int size;
111 
112  // The minimum number of valid members after the DKK. If less members are determined valid, no commitment can be
113  // created. Should be higher then the threshold to allow some room for failing nodes, otherwise quorum might end up
114  // not being able to ever created a recovered signature if more nodes fail after the DKG
115  int minSize;
116 
117  // The threshold required to recover a final signature. Should be at least 50%+1 of the quorum size. This value
118  // also controls the size of the public key verification vector and has a large influence on the performance of
119  // recovery. It also influences the amount of minimum messages that need to be exchanged for a single signing session.
120  // This value has the most influence on the security of the quorum. The number of total malicious masternodes
121  // required to negatively influence signing sessions highly correlates to the threshold percentage.
123 
124  // The interval in number blocks for DKGs and the creation of LLMQs. If set to 60 for example, a DKG will start
125  // every 60 blocks, which is approximately once every hour.
127 
128  // The number of blocks per phase in a DKG session. There are 6 phases plus the mining phase that need to be processed
129  // per DKG. Set this value to a number of blocks so that each phase has enough time to propagate all required
130  // messages to all members before the next phase starts. If blocks are produced too fast, whole DKG sessions will
131  // fail.
133 
134  // The starting block inside the DKG interval for when mining of commitments starts. The value is inclusive.
135  // Starting from this block, the inclusion of (possibly null) commitments is enforced until the first non-null
136  // commitment is mined. The chosen value should be at least 5 * dkgPhaseBlocks so that it starts right after the
137  // finalization phase.
139 
140  // The ending block inside the DKG interval for when mining of commitments ends. The value is inclusive.
141  // Choose a value so that miners have enough time to receive the commitment and mine it. Also take into consideration
142  // that miners might omit real commitments and revert to always including null commitments. The mining window should
143  // be large enough so that other miners have a chance to produce a block containing a non-null commitment. The window
144  // should at the same time not be too large so that not too much space is wasted with null commitments in case a DKG
145  // session failed.
147 
148  // In the complaint phase, members will vote on other members being bad (missing valid contribution). If at least
149  // dkgBadVotesThreshold have voted for another member to be bad, it will considered to be bad by all other members
150  // as well. This serves as a protection against late-comers who send their contribution on the bring of
151  // phase-transition, which would otherwise result in inconsistent views of the valid members set
153 
154  // Number of quorums to consider "active" for signing sessions
156 
157  // Used for intra-quorum communication. This is the number of quorums for which we should keep old connections. This
158  // should be at least one more then the active quorums set.
160 
161  // How many members should we try to send all sigShares to before we give up.
163 
164  // The limit of blocks up until where the dkg qfc will be accepted.
166 };
167 
171 struct Params {
193  int64_t nTargetSpacing;
196 
197  // spork keys
198  std::string strSporkPubKey;
199  std::string strSporkPubKeyOld;
202 
203  // height-based activations
207 
208  // validation by-pass
210  unsigned int nPivxBadBlockBits;
211 
212  // Map with network updates
214 
215  int64_t TargetTimespan(const bool fV2 = true) const { return fV2 ? nTargetTimespanV2 : nTargetTimespan; }
216  uint256 ProofOfStakeLimit(const bool fV2) const { return fV2 ? posLimitV2 : posLimitV1; }
217  bool MoneyRange(const CAmount& nValue) const { return (nValue >= 0 && nValue <= nMaxMoneyOut); }
218  bool IsTimeProtocolV2(const int nHeight) const { return NetworkUpgradeActive(nHeight, UPGRADE_V4_0); }
220 
221  int FutureBlockTimeDrift(const int nHeight) const
222  {
223  // PoS (TimeV2): 14 seconds
224  if (IsTimeProtocolV2(nHeight)) return nTimeSlotLength - 1;
225  // PoS (TimeV1): 3 minutes - PoW: 2 hours
227  }
228 
229  bool IsValidBlockTimeStamp(const int64_t nTime, const int nHeight) const
230  {
231  // Before time protocol V2, blocks can have arbitrary timestamps
232  if (!IsTimeProtocolV2(nHeight)) return true;
233  // Time protocol v2 requires time in slots
234  return (nTime % nTimeSlotLength) == 0;
235  }
236 
237  bool HasStakeMinAgeOrDepth(const int contextHeight, const uint32_t contextTime,
238  const int utxoFromBlockHeight, const uint32_t utxoFromBlockTime) const
239  {
240  // before stake modifier V2, we require the utxo to be nStakeMinAge old
241  if (!NetworkUpgradeActive(contextHeight, Consensus::UPGRADE_V3_4))
242  return (utxoFromBlockTime + nStakeMinAge <= contextTime);
243  // with stake modifier V2+, we require the utxo to be nStakeMinDepth deep in the chain
244  return (contextHeight - utxoFromBlockHeight >= nStakeMinDepth);
245  }
246 
247 
248  /*
249  * (Legacy) Zerocoin consensus params
250  */
251  std::string ZC_Modulus; // parsed in Zerocoin_Params (either as hex or dec string)
259 
261  {
262  static CBigNum bnHexModulus = 0;
263  if (!bnHexModulus) bnHexModulus.SetHex(ZC_Modulus);
264  static libzerocoin::ZerocoinParams ZCParamsHex = libzerocoin::ZerocoinParams(bnHexModulus);
265  static CBigNum bnDecModulus = 0;
266  if (!bnDecModulus) bnDecModulus.SetDec(ZC_Modulus);
267  static libzerocoin::ZerocoinParams ZCParamsDec = libzerocoin::ZerocoinParams(bnDecModulus);
268  return (useModulusV1 ? &ZCParamsHex : &ZCParamsDec);
269  }
270 
276  bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const;
277 
278  // LLMQ
279  std::map<LLMQType, LLMQParams> llmqs;
280  Optional<LLMQParams> GetLLMQParams(uint8_t llmqtype) const;
282 };
283 } // namespace Consensus
284 
285 #endif // PIVX_CONSENSUS_PARAMS_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
C++ wrapper for BIGNUM.
Definition: bignum.h:35
void SetDec(const std::string &str)
Definition: bignum.cpp:164
void SetHex(const std::string &str)
Definition: bignum.cpp:336
256-bit opaque blob.
Definition: uint256.h:138
Parameter classes for Zerocoin.
UpgradeIndex
Index into Params.vUpgrades and NetworkUpgradeInfo.
Definition: params.h:26
@ UPGRADE_TESTDUMMY
Definition: params.h:42
@ UPGRADE_V4_0
Definition: params.h:35
@ BASE_NETWORK
Definition: params.h:27
@ UPGRADE_V3_4
Definition: params.h:34
@ UPGRADE_V6_0
Definition: params.h:41
@ UPGRADE_V5_3
Definition: params.h:38
@ MAX_NETWORK_UPGRADES
Definition: params.h:44
@ UPGRADE_POS_V2
Definition: params.h:29
@ UPGRADE_POS
Definition: params.h:28
@ UPGRADE_V5_0
Definition: params.h:36
@ UPGRADE_V5_5
Definition: params.h:39
@ UPGRADE_BIP65
Definition: params.h:32
@ UPGRADE_ZC_V2
Definition: params.h:31
@ UPGRADE_V5_2
Definition: params.h:37
@ UPGRADE_V5_6
Definition: params.h:40
@ UPGRADE_ZC_PUBLIC
Definition: params.h:33
@ UPGRADE_ZC
Definition: params.h:30
LLMQType
Definition: params.h:90
@ LLMQ_400_85
Definition: params.h:95
@ LLMQ_NONE
Definition: params.h:91
@ LLMQ_50_60
Definition: params.h:93
@ LLMQ_TEST
Definition: params.h:98
@ LLMQ_400_60
Definition: params.h:94
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
int signingActiveQuorumCount
Definition: params.h:155
std::string name
Definition: params.h:107
int nProtocolVersion
The first protocol version which will understand the new consensus rules.
Definition: params.h:51
static constexpr int ALWAYS_ACTIVE
Special value for nActivationHeight indicating that the upgrade is always active.
Definition: params.h:67
int nActivationHeight
Height of the first block for which the new consensus rules will be active.
Definition: params.h:56
static constexpr int NO_ACTIVATION_HEIGHT
Special value for nActivationHeight indicating that the upgrade will never activate.
Definition: params.h:74
Optional< uint256 > hashActivationBlock
The hash of the block at height nActivationHeight, if known.
Definition: params.h:86
Parameters that influence chain consensus.
Definition: params.h:171
uint256 posLimitV1
Definition: params.h:176
int64_t nTime_EnforceNewSporkKey
Definition: params.h:200
LLMQType llmqTypeChainLocks
Definition: params.h:281
uint256 ProofOfStakeLimit(const bool fV2) const
Definition: params.h:216
int ZC_MinMintConfirmations
Definition: params.h:254
CAmount ZC_MinMintFee
Definition: params.h:255
CAmount nNewMNBlockReward
Definition: params.h:187
int ZC_MinStakeDepth
Definition: params.h:256
int64_t nTargetTimespanV2
Definition: params.h:192
uint256 posLimitV2
Definition: params.h:177
int nMNCollateralMinConf
Definition: params.h:185
CAmount nMaxMoneyOut
Definition: params.h:183
CAmount nMNCollateralAmt
Definition: params.h:184
int ZC_MaxSpendsPerTx
Definition: params.h:253
int64_t nPivxBadBlockTime
Definition: params.h:209
int64_t nTargetTimespan
Definition: params.h:191
bool IsTimeProtocolV2(const int nHeight) const
Definition: params.h:218
int nTimeSlotLength
Definition: params.h:194
CAmount nMNBlockReward
Definition: params.h:186
std::string ZC_Modulus
Definition: params.h:251
int nFutureTimeDriftPoS
Definition: params.h:182
int64_t nProposalEstablishmentTime
Definition: params.h:188
int64_t nTargetSpacing
Definition: params.h:193
uint256 hashGenesisBlock
Definition: params.h:172
NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]
Definition: params.h:213
bool fPowNoRetargeting
Definition: params.h:174
int64_t nTime_RejectOldSporkKey
Definition: params.h:201
bool HasStakeMinAgeOrDepth(const int contextHeight, const uint32_t contextTime, const int utxoFromBlockHeight, const uint32_t utxoFromBlockTime) const
Definition: params.h:237
Optional< LLMQParams > GetLLMQParams(uint8_t llmqtype) const
Definition: params.cpp:25
std::string strSporkPubKey
Definition: params.h:198
int64_t TargetTimespan(const bool fV2=true) const
Definition: params.h:215
int ZC_HeightStart
Definition: params.h:258
std::string strSporkPubKeyOld
Definition: params.h:199
int ZC_MaxPublicSpendsPerTx
Definition: params.h:252
int MasternodeCollateralMinConf() const
Definition: params.h:219
uint256 powLimit
Definition: params.h:175
bool IsValidBlockTimeStamp(const int64_t nTime, const int nHeight) const
Definition: params.h:229
int nCoinbaseMaturity
Definition: params.h:180
libzerocoin::ZerocoinParams * Zerocoin_Params(bool useModulusV1) const
Definition: params.h:260
int FutureBlockTimeDrift(const int nHeight) const
Definition: params.h:221
unsigned int nPivxBadBlockBits
Definition: params.h:210
int nMaxProposalPayments
Definition: params.h:195
bool MoneyRange(const CAmount &nValue) const
Definition: params.h:217
int nBudgetFeeConfirmations
Definition: params.h:179
int height_last_ZC_WrappedSerials
Definition: params.h:206
int nStakeMinDepth
Definition: params.h:190
int height_last_ZC_AccumCheckpoint
Definition: params.h:205
bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const
Returns true if the given network upgrade is active as of the given block height.
Definition: params.cpp:12
int nBudgetCycleBlocks
Definition: params.h:178
int height_last_invalid_UTXO
Definition: params.h:204
int nFutureTimeDriftPoW
Definition: params.h:181
bool fPowAllowMinDifficultyBlocks
Definition: params.h:173
std::map< LLMQType, LLMQParams > llmqs
Definition: params.h:279