diff --git a/src/chain.h b/src/chain.h index 4a4defbb1..c8623e476 100644 --- a/src/chain.h +++ b/src/chain.h @@ -80,7 +80,7 @@ enum BlockStatus { */ BLOCK_VALID_TRANSACTIONS = 3, - //! Outputs do not overspend inputs, no double spends, coinbase output ok, immature coinbase spends, BIP30. + //! Outputs do not overspend inputs, no double spends, coinbase output ok, immature coinbase spends. //! Implies all parents are also at least CHAIN. BLOCK_VALID_CHAIN = 4, @@ -385,13 +385,6 @@ class CBlockIndex nFlags |= BLOCK_STAKE_MODIFIER; } - /** - * Returns true if there are nRequired or more blocks of minVersion or above - * in the last Params().ToCheckBlockUpgradeMajority() blocks, starting at pstart - * and going backwards. - */ - static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired); - std::string ToString() const { return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)", diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a04cdea5d..f693b6c02 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -60,12 +60,13 @@ static Checkpoints::MapCheckpoints mapCheckpoints = (32848, uint256("352431d65a69b3425ce508cfbbff077c8fdc2833a84e6e239f0ba8e7300e9744")) (31562, uint256("7738a178f95139b2cd6b2120b19584cc17a2a28a00962b5d28978cd199427821")) (126438, uint256("7f0c69501d91e4a4ed413bf9942972cf489e79034a0af4a6440fa513c037140d")) - (862000, uint256("18f02da3b76f9d66474a890438344b0587a2f2b2272e845fa940e4e2cf83ca3c")); + (862000, uint256("18f02da3b76f9d66474a890438344b0587a2f2b2272e845fa940e4e2cf83ca3c")) + (1011360, uint256("a3b68cc2be16360617c1fb6d672ad16f66e8f2c1cae5441c198a8c8121249a6c")); static const Checkpoints::CCheckpointData data = { &mapCheckpoints, - 1588866189, // * UNIX timestamp of last checkpoint block - 1790696, // * total number of transactions between genesis and last checkpoint + 1597873950, // * UNIX timestamp of last checkpoint block + 2133199, // * total number of transactions between genesis and last checkpoint // (the tx=... number in the SetBestChain debug.log lines) 2000 // * estimated number of transactions per day after checkpoint }; @@ -138,9 +139,6 @@ class CMainParams : public CChainParams bnProofOfWorkLimit = ~uint256(0) >> 20; // sQuorum starting difficulty is 1 / 2^12 nSubsidyHalvingInterval = 210240; nMaxReorganizationDepth = 100; - nEnforceBlockUpgradeMajority = 8100; // 75% - nRejectBlockOutdatedMajority = 10260; // 95% - nToCheckBlockUpgradeMajority = 10800; // Approximate expected amount of blocks in 7 days (1440*7.5) nMinerThreads = 0; nTargetSpacing = 1 * 60; // 1 minute nMaturity = 100; @@ -169,6 +167,7 @@ class CMainParams : public CChainParams nEnforceNewSporkKey = 1537963200; // (PIVX: 1525158000) //!> Sporks signed after (GMT): Wednesday, September 26,2018 12:00 PM must use the new spork key nRejectOldSporkKey = 1537966800; // (PIVX: 1527811200) //!> Fully reject old spork key after (GMT): Wednesday, September 26,2018 12:00 PM nBlockStakeModifierlV2 = 1130000; + nBIP65ActivationHeight = 1000000; // Public coin spend enforcement nPublicZCSpends = 999999999; @@ -271,9 +270,6 @@ class CTestNetParams : public CMainParams pchMessageStart[3] = 0x0e; vAlertPubKey = ParseHex(""); nDefaultPort = 19009; - nEnforceBlockUpgradeMajority = 4320; // 75% - nRejectBlockOutdatedMajority = 5472; // 95% - nToCheckBlockUpgradeMajority = 5760; // 4 days nMinerThreads = 0; nTargetSpacing = 1 * 60; // sQuorum: 1 minute nLastPOWBlock = 400; @@ -294,6 +290,7 @@ class CTestNetParams : public CMainParams nEnforceNewSporkKey = 1537963200; // (PIVX: 1525158000) //!> Sporks signed after (GMT): Wednesday, September 26,2018 12:00 PM must use the new spork key nRejectOldSporkKey = 1537966800; // (PIVX: 1527811200) //!> Fully reject old spork key after (GMT): Wednesday, September 26,2018 12:00 PM nBlockStakeModifierlV2 = 1000; + nBIP65ActivationHeight = 1000; // Public coin spend enforcement nPublicZCSpends = 999999999; @@ -368,9 +365,6 @@ class CRegTestParams : public CTestNetParams pchMessageStart[3] = 0x0e; nDefaultPort = 19004; nSubsidyHalvingInterval = 150; - nEnforceBlockUpgradeMajority = 750; - nRejectBlockOutdatedMajority = 950; - nToCheckBlockUpgradeMajority = 1000; nMinerThreads = 1; nTargetSpacing = 1 * 60; // sQuorum: 1 minutes bnProofOfWorkLimit = ~uint256(0) >> 1; @@ -451,9 +445,6 @@ class CUnitTestParams : public CMainParams, public CModifiableParams //! Published setters to allow changing values in unit test cases virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) { nSubsidyHalvingInterval = anSubsidyHalvingInterval; } - virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority) { nEnforceBlockUpgradeMajority = anEnforceBlockUpgradeMajority; } - virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority) { nRejectBlockOutdatedMajority = anRejectBlockOutdatedMajority; } - virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority) { nToCheckBlockUpgradeMajority = anToCheckBlockUpgradeMajority; } virtual void setDefaultConsistencyChecks(bool afDefaultConsistencyChecks) { fDefaultConsistencyChecks = afDefaultConsistencyChecks; } virtual void setAllowMinDifficultyBlocks(bool afAllowMinDifficultyBlocks) { fAllowMinDifficultyBlocks = afAllowMinDifficultyBlocks; } virtual void setSkipProofOfWorkCheck(bool afSkipProofOfWorkCheck) { fSkipProofOfWorkCheck = afSkipProofOfWorkCheck; } diff --git a/src/chainparams.h b/src/chainparams.h index 9a135e3df..586d47264 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -56,9 +56,6 @@ class CChainParams const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; } int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; } /** Used to check majorities for block version upgrade */ - int EnforceBlockUpgradeMajority() const { return nEnforceBlockUpgradeMajority; } - int RejectBlockOutdatedMajority() const { return nRejectBlockOutdatedMajority; } - int ToCheckBlockUpgradeMajority() const { return nToCheckBlockUpgradeMajority; } int MaxReorganizationDepth() const { return nMaxReorganizationDepth; } /** Used if GenerateBitcoins is called with a negative number of threads */ @@ -144,6 +141,7 @@ class CChainParams // int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; } int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; } bool IsStakeModifierV2(const int nHeight) const { return nHeight >= nBlockStakeModifierlV2; } + int BIP65ActivationHeight() const { return nBIP65ActivationHeight; } int Zerocoin_Block_Public_Spend_Enabled() const { return nPublicZCSpends; } @@ -158,9 +156,6 @@ class CChainParams uint256 bnProofOfWorkLimit; int nMaxReorganizationDepth; int nSubsidyHalvingInterval; - int nEnforceBlockUpgradeMajority; - int nRejectBlockOutdatedMajority; - int nToCheckBlockUpgradeMajority; int64_t nTargetSpacing; int nLastPOWBlock; int64_t nsQuorumBadBlockTime; @@ -210,6 +205,7 @@ class CChainParams int nZerocoinStartTime; int nZerocoinRequiredStakeDepth; int64_t nProposalEstablishmentTime; + int nBIP65ActivationHeight; // // int nBlockEnforceSerialRange; int nBlockRecalculateAccumulators; @@ -233,9 +229,6 @@ class CModifiableParams public: //! Published setters to allow changing values in unit test cases virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) = 0; - virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority) = 0; - virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority) = 0; - virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority) = 0; virtual void setDefaultConsistencyChecks(bool aDefaultConsistencyChecks) = 0; virtual void setAllowMinDifficultyBlocks(bool aAllowMinDifficultyBlocks) = 0; virtual void setSkipProofOfWorkCheck(bool aSkipProofOfWorkCheck) = 0; diff --git a/src/init.cpp b/src/init.cpp index 70c39a9d0..c4fb1f812 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1722,8 +1722,8 @@ bool AppInit2() //Load zerocoin mint hashes to memory pwalletMain->zsqrTracker->Init(); - zwalletMain->LoadMintPoolFromDB(); - zwalletMain->SyncWithChain(); + //zwalletMain->LoadMintPoolFromDB(); + //zwalletMain->SyncWithChain(); } // (!fDisableWallet) #else // ENABLE_WALLET LogPrintf("No wallet compiled in!\n"); diff --git a/src/kernel.cpp b/src/kernel.cpp index 6d4e57561..471dcd17e 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -368,11 +368,11 @@ bool Stake(const CBlockIndex* pindexPrev, CStakeInput* stakeInput, unsigned int // iterate the hashing bool fSuccess = false; - const unsigned int nHashDrift = 60; + const unsigned int nHashDrift = 30; unsigned int nTryTime = nTimeTx - 1; // iterate from nTimeTx up to nTimeTx + nHashDrift // but not after the max allowed future blocktime drift (3 minutes for PoS) - const unsigned int maxTime = std::min(nTimeTx + nHashDrift, Params().MaxFutureBlockTime(GetAdjustedTime(), true)); + const unsigned int maxTime = std::min(nTimeTx + nHashDrift, Params().MaxFutureBlockTime(GetAdjustedTime(), true) - 30); while (nTryTime < maxTime) { diff --git a/src/main.cpp b/src/main.cpp index bd0aa261b..309eab372 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1575,12 +1575,12 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa nFees, ::minRelayTxFee.GetFee(nSize) * 10000); } - bool fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority()); + bool fCLTVIsActivated = chainActive.Tip()->nHeight >= Params().BIP65ActivationHeight(); // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. int flags = STANDARD_SCRIPT_VERIFY_FLAGS; - if (fCLTVHasMajority) + if (fCLTVIsActivated) flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; if (!CheckInputs(tx, state, view, true, flags, true)) { return error("AcceptToMemoryPool: : ConnectInputs failed %s", hash.ToString()); @@ -1596,7 +1596,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa // invalid blocks, however allowing such transactions into the mempool // can be exploited as a DoS attack. flags = MANDATORY_SCRIPT_VERIFY_FLAGS; - if (fCLTVHasMajority) + if (fCLTVIsActivated) flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; if (!CheckInputs(tx, state, view, true, flags, true)) { return error("AcceptToMemoryPool: : BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString()); @@ -1785,12 +1785,12 @@ bool AcceptableInputs(CTxMemPool& pool, CValidationState& state, const CTransact hash.ToString(), nFees, ::minRelayTxFee.GetFee(nSize) * 10000); - bool fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority()); + bool fCLTVIsActivated = chainActive.Tip()->nHeight >= Params().BIP65ActivationHeight(); // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. int flags = STANDARD_SCRIPT_VERIFY_FLAGS; - if (fCLTVHasMajority) + if (fCLTVIsActivated) flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; if (!CheckInputs(tx, state, view, false, flags, true)) { return error("AcceptableInputs: : ConnectInputs failed %s", hash.ToString()); @@ -2906,28 +2906,9 @@ 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; + bool fCLTVIsActivated = 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 - // can be duplicated to remove the ability to spend the first instance -- even after - // being sent to another address. - // See BIP30 and http://r6.ca/blog/20120206T005236Z.html for more information. - // This logic is not necessary for memory pool transactions, as AcceptToMemoryPool - // already refuses previously-known transaction ids entirely. - // This rule was originally applied all blocks whose timestamp was after March 15, 2012, 0:00 UTC. - // Now that the whole chain is irreversibly beyond that time it is applied to all blocks except the - // two in the chain that violate it. This prevents exploiting the issue against nodes in their - // initial block download. - for (const CTransaction& tx : block.vtx) { - const CCoins* coins = view.AccessCoins(tx.GetHash()); - if (coins && !coins->IsPruned()) - return state.DoS(100, error("ConnectBlock() : tried to overwrite transaction"), - REJECT_INVALID, "bad-txns-BIP30"); + fCLTVIsActivated = pindex->pprev->nHeight >= Params().BIP65ActivationHeight(); } CCheckQueueControl control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL); @@ -3068,7 +3049,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin std::vector vChecks; unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG; - if (fCLTVHasMajority) + if (fCLTVIsActivated) flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; if (!CheckInputs(tx, state, view, fScriptChecks, flags, false, nScriptCheckThreads ? &vChecks : NULL)) @@ -3197,11 +3178,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } // Flush spend/mint info to disk - if (!zerocoinDB->WriteCoinSpendBatch(vSpends)) return state.Abort(("Failed to record coin serials to database")); - if (!zerocoinDB->WriteCoinMintBatch(vMints)) return state.Abort(("Failed to record new mints to database")); + //if (!zerocoinDB->WriteCoinSpendBatch(vSpends)) return state.Abort(("Failed to record coin serials to database")); + //if (!zerocoinDB->WriteCoinMintBatch(vMints)) return state.Abort(("Failed to record new mints to database")); //Record accumulator checksums - DatabaseChecksums(mapAccumulators); + //DatabaseChecksums(mapAccumulators); if (fTxIndex) if (!pblocktree->WriteTxIndex(vPos)) @@ -4290,11 +4271,13 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta if (pcheckpoint && nHeight < pcheckpoint->nHeight) return state.DoS(0, error("%s : forked chain older than last checkpoint (height %d)", __func__, nHeight)); - // Reject block.nVersion=1, ..., CURRENT_VERSION-1 blocks when 95% (75% on testnet) of the network has upgraded: - for (int version = 2; version <= CBlockHeader::CURRENT_VERSION; version++) { - if (block.nVersion < version && CBlockIndex::IsSuperMajority(version, pindexPrev, Params().RejectBlockOutdatedMajority())) { - return state.Invalid(error("%s : rejected nVersion=%d block", __func__, block.nVersion), REJECT_OBSOLETE, "bad-version"); - } + // Reject outdated version blocks + if ((block.nVersion < 4 && nHeight >= 1) || + (block.nVersion < 5 && nHeight >= Params().BIP65ActivationHeight()) || + (block.nVersion < 6 && Params().IsStakeModifierV2(nHeight))) + { + std::string stringErr = strprintf("rejected block version %d at height %d", block.nVersion, nHeight); + return state.Invalid(error("%s : %s", __func__, stringErr), REJECT_OBSOLETE, stringErr); } return true; @@ -4337,13 +4320,12 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn } // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height - // if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet): - if (block.nVersion >= 2 && - CBlockIndex::IsSuperMajority(2, pindexPrev, Params().EnforceBlockUpgradeMajority())) { + if (pindexPrev) { // pindexPrev is only null on the first block which is a version 1 block. CScript expect = CScript() << nHeight; if (block.vtx[0].vin[0].scriptSig.size() < expect.size() || !std::equal(expect.begin(), expect.end(), block.vtx[0].vin[0].scriptSig.begin())) { - return state.DoS(100, error("%s : block height mismatch in coinbase", __func__), REJECT_INVALID, "bad-cb-height"); + return state.DoS(100, error("%s : block height mismatch in coinbase", __func__), REJECT_INVALID, + "bad-cb-height"); } } LogPrint("debug", "ContextualCheckBlock returning true"); @@ -4706,18 +4688,6 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, return true; } -bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired) -{ - unsigned int nToCheck = Params().ToCheckBlockUpgradeMajority(); - unsigned int nFound = 0; - for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++) { - if (pstart->nVersion >= minVersion) - ++nFound; - pstart = pstart->pprev; - } - return (nFound >= nRequired); -} - /** Turn the lowest '1' bit in the binary representation of a number into a '0'. */ int static inline InvertLowestOne(int n) { return n & (n - 1); } @@ -6784,13 +6754,13 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR int ActiveProtocol() { // SPORK_14 is used for 71030 (v1.0+) - if (IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) - return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; - - // SPORK_15 was used for 71020 (v0.15+), commented out now. - //if (IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2)) + //if (IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) // return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; + // SPORK_15 is used for 71031 + if (IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2)) + return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; + return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT; } diff --git a/src/miner.cpp b/src/miner.cpp index 992d49990..1c521a20f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -143,7 +143,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, if (fZerocoinActive) pblock->nVersion = 5; else - pblock->nVersion = 3; + pblock->nVersion = 4; pblock->nVersion = GetArg("-blockversion", pblock->nVersion); } @@ -641,7 +641,7 @@ int nMintableLastCheck = 0; void BitcoinMiner(CWallet* pwallet, bool fProofOfStake) { LogPrintf("sQuorumMiner started\n"); - SetThreadPriority(THREAD_PRIORITY_LOWEST); + //SetThreadPriority(THREAD_PRIORITY_LOWEST); RenameThread("squorum-miner"); // Each thread has its own key and counter @@ -712,12 +712,12 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake) //Stake miner main if (fProofOfStake) { - SetThreadPriority(THREAD_PRIORITY_NORMAL); + //SetThreadPriority(THREAD_PRIORITY_NORMAL); if (!ProcessBlockFound(pblock, *pwallet)) { fLastLoopOrphan = true; continue; } - SetThreadPriority(THREAD_PRIORITY_LOWEST); + //SetThreadPriority(THREAD_PRIORITY_LOWEST); continue; } @@ -807,6 +807,7 @@ void static ThreadBitcoinMiner(void* parg) { boost::this_thread::interruption_point(); CWallet* pwallet = (CWallet*)parg; + SetThreadPriority(THREAD_PRIORITY_LOWEST); try { BitcoinMiner(pwallet, false); boost::this_thread::interruption_point(); diff --git a/src/net.cpp b/src/net.cpp index c97667193..5b7961137 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1497,7 +1497,7 @@ void ThreadMessageHandler() boost::mutex condition_mutex; boost::unique_lock lock(condition_mutex); - SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); + //SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL); while (true) { std::vector vNodesCopy; { diff --git a/src/qt/coincontroltreewidget.cpp b/src/qt/coincontroltreewidget.cpp index ea6c3dfd2..156dafd6d 100644 --- a/src/qt/coincontroltreewidget.cpp +++ b/src/qt/coincontroltreewidget.cpp @@ -23,7 +23,7 @@ void CoinControlTreeWidget::keyPressEvent(QKeyEvent* event) } else if (event->key() == Qt::Key_Escape) // press esc -> close dialog { event->ignore(); - CoinControlDialog* coinControlDialog = (CoinControlDialog*)this->parentWidget(); + auto* coinControlDialog = (CoinControlDialog*) this->parentWidget()->parentWidget(); coinControlDialog->done(QDialog::Accepted); } else { this->QTreeWidget::keyPressEvent(event); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 8271187f1..328ca16bc 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -860,21 +860,25 @@ UniValue verifychain(const UniValue& params, bool fHelp) } /** Implementation of IsSuperMajority with better feedback */ -static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired) +static UniValue SoftForkMajorityDesc(int version, CBlockIndex* pindex) { - int nFound = 0; - CBlockIndex* pstart = pindex; - for (int i = 0; i < Params().ToCheckBlockUpgradeMajority() && pstart != NULL; i++) - { - if (pstart->nVersion >= minVersion) - ++nFound; - pstart = pstart->pprev; - } UniValue rv(UniValue::VOBJ); - rv.push_back(Pair("status", nFound >= nRequired)); - rv.push_back(Pair("found", nFound)); - rv.push_back(Pair("required", nRequired)); - rv.push_back(Pair("window", Params().ToCheckBlockUpgradeMajority())); + bool activated = false; + switch(version) { + case 1: + case 2: + case 3: + case 4: + activated = pindex->nHeight >= 1; + break; + case 5: + activated = pindex->nHeight >= Params().BIP65ActivationHeight(); + break; + case 6: + activated = Params().IsStakeModifierV2(pindex->nHeight); + break; + } + rv.push_back(Pair("status", activated)); return rv; } static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex) @@ -882,8 +886,7 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* UniValue rv(UniValue::VOBJ); rv.push_back(Pair("id", name)); rv.push_back(Pair("version", version)); - rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, Params().EnforceBlockUpgradeMajority()))); - rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, Params().RejectBlockOutdatedMajority()))); + rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex))); return rv; } @@ -907,13 +910,9 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) " {\n" " \"id\": \"xxxx\", (string) name of softfork\n" " \"version\": xx, (numeric) block version\n" - " \"enforce\": { (object) progress toward enforcing the softfork rules for new-version blocks\n" + " \"reject\": { (object) progress toward rejecting pre-softfork blocks\n" " \"status\": xx, (boolean) true if threshold reached\n" - " \"found\": xx, (numeric) number of blocks with the new version found\n" - " \"required\": xx, (numeric) number of blocks required to trigger\n" - " \"window\": xx, (numeric) maximum size of examined window of recent blocks\n" " },\n" - " \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n" " }, ...\n" " ]\n" "}\n" @@ -1688,4 +1687,3 @@ UniValue getblockindexstats(const UniValue& params, bool fHelp) { return ret; } - diff --git a/src/timedata.h b/src/timedata.h index 09ee5fe75..8f0eac8ff 100644 --- a/src/timedata.h +++ b/src/timedata.h @@ -71,6 +71,6 @@ class CMedianFilter /** Functions to keep track of adjusted P2P time */ int64_t GetTimeOffset(); int64_t GetAdjustedTime(); -void AddTimeData(const CNetAddr& ip, int64_t nTime); +void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample); #endif // BITCOIN_TIMEDATA_H diff --git a/src/txdb.cpp b/src/txdb.cpp index 2fb36f22c..b8c9f28cd 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -299,7 +299,7 @@ CZerocoinDB::CZerocoinDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDB bool CZerocoinDB::WriteCoinMintBatch(const std::vector >& mintInfo) { - CLevelDBBatch batch; +/* CLevelDBBatch batch; size_t count = 0; for (std::vector >::const_iterator it=mintInfo.begin(); it != mintInfo.end(); it++) { libzerocoin::PublicCoin pubCoin = it->first; @@ -309,7 +309,8 @@ bool CZerocoinDB::WriteCoinMintBatch(const std::vector >& spendInfo) { - CLevelDBBatch batch; +/* CLevelDBBatch batch; size_t count = 0; for (std::vector >::const_iterator it=spendInfo.begin(); it != spendInfo.end(); it++) { CBigNum bnSerial = it->first.getCoinSerialNumber(); @@ -342,7 +343,8 @@ bool CZerocoinDB::WriteCoinSpendBatch(const std::vector::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; - if (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0)) + if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool()) nTotal += pcoin->GetAvailableCredit(); } } @@ -1587,7 +1587,7 @@ CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const LOCK2(cs_main, cs_wallet); for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; - if (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0)) + if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && pcoin->InMempool()) nTotal += pcoin->GetAvailableWatchOnlyCredit(); } } @@ -1660,6 +1660,11 @@ void CWallet::AvailableCoins( if (nDepth == 0 && !pcoin->InMempool()) continue; + // We should not consider coins which aren't at least in our mempool + // It's possible for these to be conflicted via ancestors which we may never be able to detect + if (nDepth == 0 && !pcoin->InMempool()) + continue; + for (unsigned int i = 0; i < pcoin->vout.size(); i++) { bool found = false; if (nCoinType == ONLY_DENOMINATED) { @@ -2379,10 +2384,10 @@ bool CWallet::CreateCoinStake( // Block time. nTxNewTime = GetAdjustedTime(); // If the block time is in the future, then starts there. - if (pindexPrev->nTime > nTxNewTime) { +/* if (pindexPrev->nTime > nTxNewTime) { nTxNewTime = pindexPrev->nTime; } - +*/ for (std::unique_ptr& stakeInput : listInputs) { nCredit = 0; // Make sure the wallet is unlocked and shutdown hasn't been requested diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index f26595245..0b50be0c9 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1486,7 +1486,7 @@ bool CWalletDB::ErasePrecompute(const uint256& hash) std::map > > CWalletDB::MapMintPool() { std::map > > mapPool; - Dbc* pcursor = GetCursor(); +/* Dbc* pcursor = GetCursor(); if (!pcursor) throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor"); unsigned int fFlags = DB_SET_RANGE; @@ -1534,7 +1534,7 @@ std::map > > CWalletDB::MapMin } } - pcursor->close(); + pcursor->close();*/ return mapPool; } @@ -1542,7 +1542,7 @@ std::map > > CWalletDB::MapMin std::list CWalletDB::ListDeterministicMints() { std::list listMints; - Dbc* pcursor = GetCursor(); +/* Dbc* pcursor = GetCursor(); if (!pcursor) throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor"); unsigned int fFlags = DB_SET_RANGE; @@ -1578,14 +1578,14 @@ std::list CWalletDB::ListDeterministicMints() listMints.emplace_back(mint); } - pcursor->close(); + pcursor->close();*/ return listMints; } std::list CWalletDB::ListMintedCoins() { std::list listPubCoin; - Dbc* pcursor = GetCursor(); +/* Dbc* pcursor = GetCursor(); if (!pcursor) throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor"); unsigned int fFlags = DB_SET_RANGE; @@ -1623,14 +1623,14 @@ std::list CWalletDB::ListMintedCoins() listPubCoin.emplace_back(mint); } - pcursor->close(); + pcursor->close();*/ return listPubCoin; } std::list CWalletDB::ListSpentCoins() { std::list listCoinSpend; - Dbc* pcursor = GetCursor(); +/* Dbc* pcursor = GetCursor(); if (!pcursor) throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor"); unsigned int fFlags = DB_SET_RANGE; @@ -1666,7 +1666,7 @@ std::list CWalletDB::ListSpentCoins() listCoinSpend.push_back(zerocoinSpendItem); } - pcursor->close(); + pcursor->close();*/ return listCoinSpend; } @@ -1685,7 +1685,7 @@ std::list CWalletDB::ListSpentCoinsSerial() std::list CWalletDB::ListArchivedZerocoins() { std::list listMints; - Dbc* pcursor = GetCursor(); +/* Dbc* pcursor = GetCursor(); if (!pcursor) throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor"); unsigned int fFlags = DB_SET_RANGE; @@ -1721,14 +1721,14 @@ std::list CWalletDB::ListArchivedZerocoins() listMints.push_back(mint); } - pcursor->close(); + pcursor->close();*/ return listMints; } std::list CWalletDB::ListArchivedDeterministicMints() { std::list listMints; - Dbc* pcursor = GetCursor(); +/* Dbc* pcursor = GetCursor(); if (!pcursor) throw std::runtime_error(std::string(__func__)+" : cannot create DB cursor"); unsigned int fFlags = DB_SET_RANGE; @@ -1764,6 +1764,6 @@ std::list CWalletDB::ListArchivedDeterministicMints() listMints.emplace_back(dMint); } - pcursor->close(); + pcursor->close();*/ return listMints; } diff --git a/src/zsqr/accumulators.cpp b/src/zsqr/accumulators.cpp index a95a05e42..129174cca 100644 --- a/src/zsqr/accumulators.cpp +++ b/src/zsqr/accumulators.cpp @@ -68,18 +68,7 @@ int GetChecksumHeight(uint32_t nChecksum, libzerocoin::CoinDenomination denomina bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, bool fMemoryOnly, CBigNum& bnAccValue) { - if (mapAccumulatorValues.count(nChecksum)) { - bnAccValue = mapAccumulatorValues.at(nChecksum); - return true; - } - - if (fMemoryOnly) - return false; - - if (!zerocoinDB->ReadAccumulatorValue(nChecksum, bnAccValue)) { - bnAccValue = 0; - } - + bnAccValue = 0; return true; } diff --git a/src/zsqr/zsqrtracker.cpp b/src/zsqr/zsqrtracker.cpp index a36647a9c..b4f1e491c 100644 --- a/src/zsqr/zsqrtracker.cpp +++ b/src/zsqr/zsqrtracker.cpp @@ -463,7 +463,7 @@ bool CzSQRTracker::UpdateStatusInternal(const std::set& setMempool, CMi std::set CzSQRTracker::ListMints(bool fUnusedOnly, bool fMatureOnly, bool fUpdateStatus, bool fWrongSeed, bool fExcludeV1) { - CWalletDB walletdb(strWalletFile); +/* CWalletDB walletdb(strWalletFile); if (fUpdateStatus) { std::list listMintsDB = walletdb.ListMintedCoins(); for (auto& mint : listMintsDB) @@ -482,9 +482,9 @@ std::set CzSQRTracker::ListMints(bool fUnusedOnly, bool fMatureOnly, LogPrint("zero", "%s: added %d dzsqr from DB\n", __func__, listDeterministicDB.size()); } - std::vector vOverWrite; + std::vector vOverWrite;*/ std::set setMints; - std::set setMempool; +/* std::set setMempool; { LOCK(mempool.cs); mempool.getTransactions(setMempool); @@ -526,7 +526,7 @@ std::set CzSQRTracker::ListMints(bool fUnusedOnly, bool fMatureOnly, //overwrite any updates for (CMintMeta& meta : vOverWrite) - UpdateState(meta); + UpdateState(meta);*/ return setMints; } diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index aa0de69a7..a0909dc24 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -829,23 +829,6 @@ def update_block(block_number, new_transactions): yield accepted() save_spendable_output() - # Test BIP30 - # - # -> b39 (11) -> b42 (12) -> b43 (13) -> b53 (14) -> b55 (15) -> b57 (16) -> b60 (17) - # \-> b61 (18) - # - # Blocks are not allowed to contain a transaction whose id matches that of an earlier, - # not-fully-spent transaction in the same chain. To test, make identical coinbases; - # the second one should be rejected. - # - tip(60) - b61 = block(61, spend=out[18]) - b61.vtx[0].vin[0].scriptSig = b60.vtx[0].vin[0].scriptSig #equalize the coinbases - b61.vtx[0].rehash() - b61 = update_block(61, []) - assert_equal(b60.vtx[0].serialize(), b61.vtx[0].serialize()) - yield rejected(RejectResult(16, b'bad-txns-BIP30')) - # Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests) # diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index 25809d9bd..a0622a4e0 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -204,30 +204,30 @@ def run_test(self): # check binary format response = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+"bin", True) assert_equal(response.status, 200) - assert_greater_than(int(response.getheader('content-length')), 80) + assert_greater_than(int(response.getheader('content-length')), 112) response_str = response.read() # compare with block header response_header = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"bin", True) assert_equal(response_header.status, 200) - assert_equal(int(response_header.getheader('content-length')), 80) + assert_equal(int(response_header.getheader('content-length')), 112) response_header_str = response_header.read() - assert_equal(response_str[0:80], response_header_str) + assert_equal(response_str[0:112], response_header_str) # check block hex format response_hex = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+"hex", True) assert_equal(response_hex.status, 200) - assert_greater_than(int(response_hex.getheader('content-length')), 160) + assert_greater_than(int(response_hex.getheader('content-length')), 192) response_hex_str = response_hex.read() - assert_equal(encode(response_str, "hex_codec")[0:160], response_hex_str[0:160]) + assert_equal(encode(response_str, "hex_codec")[0:192], response_hex_str[0:192]) # compare with hex block header response_header_hex = http_get_call(url.hostname, url.port, '/rest/headers/1/'+bb_hash+self.FORMAT_SEPARATOR+"hex", True) assert_equal(response_header_hex.status, 200) - assert_greater_than(int(response_header_hex.getheader('content-length')), 160) + assert_greater_than(int(response_header_hex.getheader('content-length')), 192) response_header_hex_str = response_header_hex.read() - assert_equal(response_hex_str[0:160], response_header_hex_str[0:160]) - assert_equal(encode(response_header_str, "hex_codec")[0:160], response_header_hex_str[0:160]) + assert_equal(response_hex_str[0:192], response_header_hex_str[0:192]) + assert_equal(encode(response_header_str, "hex_codec")[0:192], response_header_hex_str[0:192]) # check json format block_json_string = http_get_call(url.hostname, url.port, '/rest/block/'+bb_hash+self.FORMAT_SEPARATOR+'json')