Skip to content

Commit

Permalink
7 day CLTV activation
Browse files Browse the repository at this point in the history
Signed-off-by: cevap <dev@i2pmail.org>
  • Loading branch information
presstab authored and Cevap Master committed Dec 2, 2018
1 parent f674a63 commit 1173a21
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class CMainParams : public CChainParams
bnProofOfStakeLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
nSubsidyHalvingInterval = 210000;
nMaxReorganizationDepth = 100;
nEnforceBlockUpgradeMajority = 1080;
nRejectBlockOutdatedMajority = 1368;
nToCheckBlockUpgradeMajority = 1440;
nEnforceBlockUpgradeMajority = 8100; // 75%
nRejectBlockOutdatedMajority = 10260; // 95%
nToCheckBlockUpgradeMajority = 10800; // Approximate expected amount of blocks in 7 days (1440*7.5)
nMinerThreads = 0;
nTargetTimespanMidas = 7 * 24 * 60 * 60; // 1 week
nTargetTimespanDGW = 1 * 60; // ION: 1 day
Expand Down Expand Up @@ -278,9 +278,9 @@ class CTestNetParams : public CMainParams
pchMessageStart[3] = 0x69;
vAlertPubKey = ParseHex("0432f3e3c6c8ce236579b3223debc2b684f0ffa14fd3fe6813eafe3f3dd3b45664d1efbdfe43441edc83d1c4507ab9bd395c8134797e04457965031a4b6413bb1a");
nDefaultPort = 27170;
nEnforceBlockUpgradeMajority = 51;
nRejectBlockOutdatedMajority = 75;
nToCheckBlockUpgradeMajority = 100;
nEnforceBlockUpgradeMajority = 4320; // 75%
nRejectBlockOutdatedMajority = 5472; // 95%
nToCheckBlockUpgradeMajority = 5760; // 4 days
nMinerThreads = 0;
nTargetTimespanMidas = 7 * 24 * 60 * 60; // 1 week
nTargetTimespanDGW = 1 * 60; // ion: 1 day
Expand Down
6 changes: 0 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,12 +1424,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview);
pcoinsTip = new CCoinsViewCache(pcoinscatcher);

bool fIsActiveCLTV;
if (!pblocktree->ReadFlag("CLTVHasMajority", fIsActiveCLTV))
fCLTVHasMajority = false;
else
fCLTVHasMajority = fIsActiveCLTV;

if (fReindex)
pblocktree->WriteReindexing(true);

Expand Down
23 changes: 11 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ bool fAlerts = DEFAULT_ALERTS;

unsigned int nStakeMinAge = 60 * 60;
int64_t nReserveBalance = 0;
bool fCLTVHasMajority = false;

/** Fees smaller than this (in uion) are considered zero fee (for relaying and mining)
* We are ~100 times smaller then bitcoin now (2015-06-23), set minRelayTxFee only 10 times higher
Expand Down Expand Up @@ -1376,6 +1375,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
hash.ToString(),
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);


bool fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority());

// Check against previous transactions
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
int flags = STANDARD_SCRIPT_VERIFY_FLAGS;
Expand Down Expand Up @@ -1583,6 +1585,8 @@ bool AcceptableInputs(CTxMemPool& pool, CValidationState& state, const CTransact
hash.ToString(),
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);

bool fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority());

// Check against previous transactions
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
int flags = STANDARD_SCRIPT_VERIFY_FLAGS;
Expand Down Expand Up @@ -2525,9 +2529,6 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
// move best block pointer to prevout block
view.SetBestBlock(pindex->pprev->GetBlockHash());

// Check if supermajority for CLTV has changed.
fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority());

if (!fVerifyingBlocks) {
//if block is an accumulator checkpoint block, remove checkpoint and checksums from db
uint256 nCheckpoint = pindex->nAccumulatorCheckpoint;
Expand Down Expand Up @@ -2887,6 +2888,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin

bool fScriptChecks = pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate();

// If scripts won't be checked anyways, don't bother seeing if CLTV is activated
bool fCLTVHasMajority = false;
if (fScriptChecks && pindex->pprev) {
fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, pindex->pprev, Params().EnforceBlockUpgradeMajority());
}

// Do not allow blocks that contain transactions which 'overwrite' older transactions,
// unless those are already completely spent.
// If such overwrites are allowed, coinbases and transactions depending upon those
Expand Down Expand Up @@ -3187,12 +3194,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
mapZerocoinspends.erase(it);
}

// If CLTV hasn't been activated check for a supermajority upon accepting new block.
if (!fCLTVHasMajority && CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority())) {
fCLTVHasMajority = true;
LogPrintf("CHECKLOCKTIMEVERIFY achieved supermajority! Transactions that use CLTV will now be verified.\n");
}

return true;
}

Expand Down Expand Up @@ -3243,8 +3244,6 @@ bool static FlushStateToDisk(CValidationState& state, FlushStateMode mode)
setDirtyBlockIndex.erase(it++);
}

pblocktree->WriteFlag("CLTVHasMajority", fCLTVHasMajority);

pblocktree->Sync();
// Finally flush the chainstate (which may refer to block index entries).
if (!pcoinsTip->Flush())
Expand Down
1 change: 0 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ extern unsigned int nCoinCacheSize;
extern CFeeRate minRelayTxFee;
extern bool fAlerts;
extern bool fVerifyingBlocks;
extern bool fCLTVHasMajority;

extern bool fLargeWorkForkFound;
extern bool fLargeWorkInvalidChainFound;
Expand Down
6 changes: 0 additions & 6 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
if (Params().MineBlocksOnDemand())
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);

// Make sure to create the correct block version after zerocoin is enabled
bool fZerocoinActive = GetAdjustedTime() >= Params().Zerocoin_StartTime();
if (fZerocoinActive)
pblock->nVersion = 8;
else
pblock->nVersion = 7;

pblock->nVersion = 9; // Supports CLTV activation

// Create coinbase tx
Expand Down

0 comments on commit 1173a21

Please sign in to comment.