Skip to content

Commit

Permalink
Monacoin: Apply patches by @wakiyamap
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptcoin-junkey committed Feb 20, 2021
1 parent b693b99 commit 6f795b9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
20 changes: 13 additions & 7 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ class CMainParams : public CChainParams {
CMainParams() {
strNetworkID = "main";
consensus.nSubsidyHalvingInterval = 1051200;
consensus.BIP16Height = 0;
consensus.BIP16Exception = uint256S("ff9f1c0116d19de7c9963845e129f9ed1bfc0b376eb54fd7afa42e0d418c8bb6");
consensus.BIP34Height = 0;
consensus.BIP34Hash = uint256S("ff9f1c0116d19de7c9963845e129f9ed1bfc0b376eb54fd7afa42e0d418c8bb6");
consensus.BIP65Height = 977760;
consensus.BIP66Height = 977760;
consensus.SegwitHeight = 977760;
consensus.BIP65Height = 977759;
consensus.BIP66Height = 977759;
consensus.CSVHeight = 977760; // 00cdaf76200737d9a7f94cc058fb132868c18c50c0342c77fc5a5bf0ee78be0c
consensus.SegwitHeight = 977760; // 00cdaf76200737d9a7f94cc058fb132868c18c50c0342c77fc5a5bf0ee78be0c
consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 1.1 * 24 * 60 * 60; // 1.1 days
consensus.nPowTargetSpacing = 1.5 * 60; // 1.5 minutes
Expand Down Expand Up @@ -172,11 +173,13 @@ class CTestNetParams : public CChainParams {
CTestNetParams() {
strNetworkID = "test";
consensus.nSubsidyHalvingInterval = 1051200;
consensus.BIP16Height = 0; // always enforce P2SH BIP16 on regtest
consensus.BIP16Exception = uint256S("a2b106ceba3be0c6d097b2a6a6aacf9d638ba8258ae478158f449c321061e0b2"); // always enforce P2SH BIP16 on regtest
consensus.BIP34Height = 0;
consensus.BIP34Hash = uint256S("a2b106ceba3be0c6d097b2a6a6aacf9d638ba8258ae478158f449c321061e0b2");
consensus.BIP65Height = -1;
consensus.BIP66Height = -1;
consensus.CSVHeight = 300; // 746481baefad145d7309a8b44dca1acce5d6442988afbae2595796cae9ae1eb2
consensus.SegwitHeight = 300; // 746481baefad145d7309a8b44dca1acce5d6442988afbae2595796cae9ae1eb2
consensus.powLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 1.1 * 24 * 60 * 60; // 1.1 days
consensus.nPowTargetSpacing = 1.5 * 60; // 1.5 minutes
Expand All @@ -185,7 +188,10 @@ class CTestNetParams : public CChainParams {
consensus.fPowNoRetargeting = false;
consensus.nRuleChangeActivationThreshold = 75; // 75% for testchains
consensus.nMinerConfirmationWindow = 100; // nPowTargetTimespan / nPowTargetSpacing

consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000535d5fc3c9d2");

Expand Down Expand Up @@ -262,7 +268,7 @@ class CRegTestParams : public CChainParams {
explicit CRegTestParams(const ArgsManager& args) {
strNetworkID = "regtest";
consensus.nSubsidyHalvingInterval = 150;
consensus.BIP16Height = 0;
consensus.BIP16Exception = uint256();
consensus.BIP34Height = -1; // BIP34 has not activated on regtest (Used in functional tests)
consensus.BIP34Hash = uint256();
consensus.BIP65Height = -1; // BIP65 activated on regtest (Used in functional tests)
Expand Down
4 changes: 2 additions & 2 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ struct BIP9Deployment {
struct Params {
uint256 hashGenesisBlock;
int nSubsidyHalvingInterval;
/** Block height at which BIP16 becomes active */
int BIP16Height;
/* Block hash that is excepted from BIP16 enforcement */
uint256 BIP16Exception;
/** Block height and hash at which BIP34 becomes active */
int BIP34Height;
uint256 BIP34Hash;
Expand Down
2 changes: 0 additions & 2 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF

// Retarget
arith_uint256 bnNew;
arith_uint256 bnOld;
bnNew.SetCompact(pindexLast->nBits);
bnOld = bnNew;
// Monacoin: intermediate uint256 can overflow by 1 bit
const arith_uint256 bnPowLimit = UintToArith256(params.powLimit);
bool fShift = bnNew.bits() > bnPowLimit.bits() - 1;
Expand Down
4 changes: 2 additions & 2 deletions src/primitives/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ uint256 CBlockHeader::GetPoWHash(bool bLyra2REv2) const
{
uint256 thash;
if(bLyra2REv2){
lyra2re2_hash(BEGIN(nVersion), BEGIN(thash));
lyra2re2_hash((char *) &nVersion, (char *) &thash);
}
else{
scrypt_1024_1_1_256(BEGIN(nVersion), BEGIN(thash));
scrypt_1024_1_1_256((char *) &nVersion, (char *) &thash);
}
return thash;
}
Expand Down
21 changes: 14 additions & 7 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,8 +1836,15 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens

unsigned int flags = SCRIPT_VERIFY_NONE;

// Start enforcing P2SH (BIP16)
if (pindex->nHeight >= consensusparams.BIP16Height) {
// BIP16 didn't become active until Apr 1 2012 (on mainnet, and
// retroactively applied to testnet)
// However, only one historical block violated the P2SH rules (on both
// mainnet and testnet), so for simplicity, always leave P2SH
// on except for the one violating block.
if (consensusparams.BIP16Exception.IsNull() || // no bip16 exception on this chain
pindex->phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
*pindex->phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
{
flags |= SCRIPT_VERIFY_P2SH;
}

Expand Down Expand Up @@ -3236,11 +3243,10 @@ static bool FindUndoPos(CValidationState &state, int nFile, FlatFilePos &pos, un
static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true)
{
// Get prev block index
CBlockIndex* pindexPrev = NULL;
int nHeight = 0;
BlockMap::iterator mi = ::BlockIndex().find(block.hashPrevBlock);
if (mi != ::BlockIndex().end()) {
pindexPrev = (*mi).second;
LOCK(cs_main);
CBlockIndex* pindexPrev = LookupBlockIndex(block.hashPrevBlock);
if (pindexPrev != NULL) {
nHeight = pindexPrev->nHeight + 1;
}

Expand Down Expand Up @@ -4700,7 +4706,8 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
std::multimap<uint256, FlatFilePos>::iterator it = range.first;
std::shared_ptr<CBlock> pblockrecursive = std::make_shared<CBlock>();
uint256 hash = block.GetHash();
int nHeight = ::BlockIndex()[hash]->nHeight;
LOCK(cs_main);
int nHeight = LookupBlockIndex(hash)->nHeight;
if (ReadBlockFromDisk(*pblockrecursive, it->second, nHeight, chainparams.GetConsensus()))
{
LogPrint(BCLog::REINDEX, "%s: Processing out of order child %s of %s\n", __func__, pblockrecursive->GetHash().ToString(),
Expand Down

0 comments on commit 6f795b9

Please sign in to comment.