Skip to content

Commit

Permalink
Port kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Jun 11, 2024
1 parent 2f80fae commit 79358e4
Show file tree
Hide file tree
Showing 11 changed files with 509 additions and 185 deletions.
1 change: 1 addition & 0 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Coin

//! whether containing transaction was a coinbase
unsigned int fCoinBase : 1;
unsigned int fCoinStake : 1;

//! at which height this containing transaction was included in the active block chain
uint32_t nHeight : 31;
Expand Down
10 changes: 2 additions & 8 deletions src/consensus/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ typedef int64_t CAmount;

/** The amount of satoshis in one BTC. */
static constexpr CAmount COIN = 100000000;
static constexpr CAmount CENT = 1000000;

/** No amount larger than this (in satoshi) is valid.
*
* Note that this constant is *not* the total money supply, which in Bitcoin
* currently happens to be less than 21,000,000 BTC for various reasons, but
* rather a sanity check. As this sanity check is used by consensus-critical
* validation code, the exact value of the MAX_MONEY constant is consensus
* critical; in unusual circumstances like a(nother) overflow bug that allowed
* for the creation of coins out of thin air modification could lead to a fork.
* */
static constexpr CAmount MAX_MONEY = 21000000 * COIN;
static constexpr CAmount MAX_MONEY = 107822406 * COIN + 25 * (COIN / 100);
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

#endif // BITCOIN_CONSENSUS_AMOUNT_H
9 changes: 7 additions & 2 deletions src/consensus/merkle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ uint256 BlockMerkleRoot(const CBlock& block, bool* mutated)
return ComputeMerkleRoot(std::move(leaves), mutated);
}

uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated)
uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated, bool* pfProofOfStake)
{
bool fProofOfStake = pfProofOfStake ? *pfProofOfStake : block.IsProofOfStake();
std::vector<uint256> leaves;
leaves.resize(block.vtx.size());
leaves[0].SetNull(); // The witness hash of the coinbase is 0.
for (size_t s = 1; s < block.vtx.size(); s++) {
if(fProofOfStake)
{
leaves[1].SetNull(); // The witness hash of the coinstake is 0.
}
for (size_t s = 1 + (fProofOfStake ? 1 : 0); s < block.vtx.size(); s++) {
leaves[s] = block.vtx[s]->GetWitnessHash();
}
return ComputeMerkleRoot(std::move(leaves), mutated);
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/merkle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ uint256 BlockMerkleRoot(const CBlock& block, bool* mutated = nullptr);
* Compute the Merkle root of the witness transactions in a block.
* *mutated is set to true if a duplicated subtree was found.
*/
uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated = nullptr);
uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated = nullptr, bool* pfProofOfStake = nullptr);

#endif // BITCOIN_CONSENSUS_MERKLE_H
96 changes: 96 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct BIP9Deployment {
struct Params {
uint256 hashGenesisBlock;
int nSubsidyHalvingInterval;
int nSubsidyHalvingIntervalV2;
/**
* Hashes of blocks that
* - are known to be consensus valid, and
Expand All @@ -97,6 +98,24 @@ struct Params {
/** Don't warn about unknown BIP 9 activations below this height.
* This prevents us from warning about the CSV and segwit activations. */
int MinBIP9WarningHeight;
/** Block height at which QIP5 becomes active */
int QIP5Height;
/** Block height at which QIP6 becomes active */
int QIP6Height;
/** Block height at which QIP7 becomes active */
int QIP7Height;
/** Block height at which QIP9 becomes active */
int QIP9Height;
/** Block height at which Offline Staking becomes active */
int nOfflineStakeHeight;
/** Block height at which Reduce Block Time becomes active */
int nReduceBlocktimeHeight;
/** Block height at which EVM Muir Glacier fork becomes active */
int nMuirGlacierHeight;
/** Block height at which EVM London fork becomes active */
int nLondonHeight;
/** Block height at which EVM Shanghai fork becomes active */
int nShanghaiHeight;
/**
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
Expand All @@ -107,10 +126,17 @@ struct Params {
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS];
/** Proof of work parameters */
uint256 powLimit;
uint256 posLimit;
uint256 QIP9PosLimit;
uint256 RBTPosLimit;
bool fPowAllowMinDifficultyBlocks;
bool fPowNoRetargeting;
bool fPoSNoRetargeting;
int64_t nPowTargetSpacing;
int64_t nRBTPowTargetSpacing;
int64_t nPowTargetTimespan;
int64_t nPowTargetTimespanV2;
int64_t nRBTPowTargetTimespan;
std::chrono::seconds PowTargetSpacing() const
{
return std::chrono::seconds{nPowTargetSpacing};
Expand Down Expand Up @@ -144,6 +170,76 @@ struct Params {
} // no default case, so the compiler can warn about missing cases
return std::numeric_limits<int>::max();
}

int nLastPOWBlock;
int nFirstMPoSBlock;
int nMPoSRewardRecipients;
int nFixUTXOCacheHFHeight;
int nEnableHeaderSignatureHeight;
/** Block sync-checkpoint span*/
int nCheckpointSpan;
int nRBTCheckpointSpan;
uint160 delegationsAddress;
int nLastMPoSBlock;
int nLastBigReward;
uint32_t nStakeTimestampMask;
uint32_t nRBTStakeTimestampMask;
int64_t nBlocktimeDownscaleFactor;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
int nCoinbaseMaturity;
int nRBTCoinbaseMaturity;
int64_t StakeTimestampMask(int height) const
{
return height < nReduceBlocktimeHeight ? nStakeTimestampMask : nRBTStakeTimestampMask;
}
int64_t MinStakeTimestampMask() const
{
return nRBTStakeTimestampMask;
}
int SubsidyHalvingInterval(int height) const
{
return height < nReduceBlocktimeHeight ? nSubsidyHalvingInterval : nSubsidyHalvingIntervalV2;
}
int64_t BlocktimeDownscaleFactor(int height) const
{
return height < nReduceBlocktimeHeight ? 1 : nBlocktimeDownscaleFactor;
}
int64_t TargetSpacing(int height) const
{
return height < nReduceBlocktimeHeight ? nPowTargetSpacing : nRBTPowTargetSpacing;
}
int SubsidyHalvingWeight(int height) const
{
if(height <= nLastBigReward)
return 0;

int blocktimeDownscaleFactor = BlocktimeDownscaleFactor(height);
int blockCount = height - nLastBigReward;
int beforeDownscale = blocktimeDownscaleFactor == 1 ? 0 : nReduceBlocktimeHeight - nLastBigReward - 1;
int subsidyHalvingWeight = blockCount - beforeDownscale + beforeDownscale * blocktimeDownscaleFactor;
return subsidyHalvingWeight;
}
int64_t TimestampDownscaleFactor(int height) const
{
return height < nReduceBlocktimeHeight ? 1 : (nStakeTimestampMask + 1) / (nRBTStakeTimestampMask + 1);
}
int64_t TargetTimespan(int height) const
{
return height < QIP9Height ? nPowTargetTimespan :
(height < nReduceBlocktimeHeight ? nPowTargetTimespanV2 : nRBTPowTargetTimespan);
}
int CheckpointSpan(int height) const
{
return height < nReduceBlocktimeHeight ? nCheckpointSpan : nRBTCheckpointSpan;
}
int CoinbaseMaturity(int height) const
{
return height < nReduceBlocktimeHeight ? nCoinbaseMaturity : nRBTCoinbaseMaturity;
}
int MaxCheckpointSpan() const
{
return nCheckpointSpan <= nRBTCheckpointSpan ? nRBTCheckpointSpan : nCheckpointSpan;
}
};

} // namespace Consensus
Expand Down
Loading

0 comments on commit 79358e4

Please sign in to comment.