From b77ec3e710c3e01024d6e651a60ff0b017124a6f Mon Sep 17 00:00:00 2001 From: warrows Date: Sun, 27 Oct 2019 14:57:08 +0100 Subject: [PATCH 01/16] [Node] Remove a call to IsSuperMajority Block version 4 is enforced starting at block 1 so rules from version 3 should always be enforced. There is no reason to run the (kinda resource intensive) test IsSuperMajority. --- src/main.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bd0aa261b..ad6bf84e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4337,14 +4337,10 @@ 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())) { - 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"); - } + 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"); } LogPrint("debug", "ContextualCheckBlock returning true"); return true; From 57c96c7cc6b2db89224e1272e27f01924e47977f Mon Sep 17 00:00:00 2001 From: Stamek Date: Wed, 19 Aug 2020 21:46:50 +0300 Subject: [PATCH 02/16] [Node] Replace IsSuperMajority with height checks BIP65 was enabled with block version 5. We now use block version 6. It makes sense to save a bit of performance by simply checking for height activation instead of looking for a super majority. --- src/chainparams.cpp | 2 ++ src/chainparams.h | 2 ++ src/main.cpp | 16 ++++++++-------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a04cdea5d..73a3a0dc9 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -169,6 +169,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; @@ -294,6 +295,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; diff --git a/src/chainparams.h b/src/chainparams.h index 9a135e3df..b8e587821 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -144,6 +144,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; } @@ -210,6 +211,7 @@ class CChainParams int nZerocoinStartTime; int nZerocoinRequiredStakeDepth; int64_t nProposalEstablishmentTime; + int nBIP65ActivationHeight; // // int nBlockEnforceSerialRange; int nBlockRecalculateAccumulators; diff --git a/src/main.cpp b/src/main.cpp index ad6bf84e3..f5a9d42ad 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,9 +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()); + fCLTVIsActivated = pindex->pprev->nHeight >= Params().BIP65ActivationHeight(); } // Do not allow blocks that contain transactions which 'overwrite' older transactions, @@ -3068,7 +3068,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)) From c78bbda7ea486d575bc3421a3892ee1193a99f09 Mon Sep 17 00:00:00 2001 From: Stamek Date: Thu, 20 Aug 2020 00:00:36 +0300 Subject: [PATCH 03/16] [Consensus] Reject outdated blocks by enforcement height --- src/main.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f5a9d42ad..86df89831 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4290,11 +4290,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; From 716f69985321661b0e655651ac4b823257b27002 Mon Sep 17 00:00:00 2001 From: Stamek Date: Thu, 20 Aug 2020 00:36:28 +0300 Subject: [PATCH 04/16] [Core] Remove IsSuperMajority --- src/chain.h | 7 ------- src/chainparams.cpp | 12 ------------ src/chainparams.h | 9 --------- src/main.cpp | 12 ------------ src/rpc/blockchain.cpp | 40 +++++++++++++++++++--------------------- 5 files changed, 19 insertions(+), 61 deletions(-) diff --git a/src/chain.h b/src/chain.h index 4a4defbb1..4793c387d 100644 --- a/src/chain.h +++ b/src/chain.h @@ -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 73a3a0dc9..c07aa896b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -138,9 +138,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; @@ -272,9 +269,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; @@ -370,9 +364,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; @@ -453,9 +444,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 b8e587821..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 */ @@ -159,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; @@ -235,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/main.cpp b/src/main.cpp index 86df89831..68f9009fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4704,18 +4704,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); } 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; } - From 994ce56067b4f739f14d026998888d9a46b47d44 Mon Sep 17 00:00:00 2001 From: Stamek Date: Thu, 20 Aug 2020 01:14:51 +0300 Subject: [PATCH 05/16] Update checkpoints --- src/chainparams.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c07aa896b..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 }; From 87ced407c73ff114d104c157831f1e7ca3a064d4 Mon Sep 17 00:00:00 2001 From: furszy Date: Sun, 2 Aug 2020 19:31:19 -0300 Subject: [PATCH 06/16] [Core] Remove BIP30 check A bit of history ---- Two transactions can have the same txid if their parents are identical, since the txids of the parents are included in a transaction. Coinbases have no parents, so it used to be possible for two of them to be identical. Further, by building on duplicate coinbases, duplicate normal transactions were possible as well (http://r6.ca/blog/20120206T005236Z.html). In order to remove the possibility of having duplicate transaction ids, Bitcoin introduced, with BIP30, the following consensus rule: - Blocks are not allowed to contain a transaction whose identifier matches that of an earlier, not-fully-spent transaction in the same chain. [[1](https://github.com/bitcoin/bips/blob/master/bip-0030.mediawiki)] This rule was enforced by verifying (in `ConnectBlock`) that none of the transactions in the block was overwriting an already existent non-pruned CCoins entry. BIP34 was later added in Bitcoin to enforce better transaction uniqueness, with the update of block version to 2, which introduced the following consensus rule: - the first serialized element in the scriptSig of coinbase transactions must be the height of the chain. [[2](https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki)] After the complete activation of BIP34, there seemed to be no longer need for the check in `ConnectBlock`, added for BIP30, as duplicated coinbases were rendered impossible with BIP34 (bitcoin/bitcoin#6931). This assumption was later revisited, when several blocks were found on Bitcoin's main chain (before BIP34 activation), having coinbase scripts with an height higher than the current chain height (and higher than the BIP34 activation height). Thus, coinbases for blocks at these "future" heights would have given the opportunity for BIP30 to be violated even with BIP34 enforced (bitcoin/bitcoin#12204). Squorum has BIP30 and BIP34 consensus rules already implemented since the chain start. The first block after the genesis (height=1) has version 4. However the code still has the (somewhat expensive) BIP30 check in `ConnectBlock`, which wasn't needed at all, given the full enforcement of BIP34 since the start of the chain. This commit removes it. *Side Note*: Even without BIP34, with Proof-of-Stake, coinbase transactions have empty scriptPubKey (thus unspendable outputs), therefore there would have been no need for BIP30 checks in any case (at least after PoS activation height). --- src/chain.h | 2 +- src/main.cpp | 19 ------------------- test/functional/feature_block.py | 17 ----------------- 3 files changed, 1 insertion(+), 37 deletions(-) diff --git a/src/chain.h b/src/chain.h index 4793c387d..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, diff --git a/src/main.cpp b/src/main.cpp index 68f9009fe..b1befb30b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2911,25 +2911,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin fCLTVIsActivated = pindex->pprev->nHeight >= Params().BIP65ActivationHeight(); } - // 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"); - } - CCheckQueueControl control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL); int64_t nTimeStart = GetTimeMicros(); 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) # From 9a7a03f0904d1b599b0157741c1fa50eaf11eead Mon Sep 17 00:00:00 2001 From: Stamek Date: Sat, 22 Aug 2020 17:26:26 +0300 Subject: [PATCH 07/16] Disable zerocoin tracking --- src/main.cpp | 6 +++--- src/timedata.h | 2 +- src/txdb.cpp | 10 ++++++---- src/wallet/walletdb.cpp | 24 ++++++++++++------------ src/zsqr/accumulators.cpp | 13 +------------ src/zsqr/zsqrtracker.cpp | 8 ++++---- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b1befb30b..46576586b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3178,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)) 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 > > 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; } From 6d3fdc6b0191a60ec303f8aa0231090b3f793499 Mon Sep 17 00:00:00 2001 From: Stamek Date: Sat, 22 Aug 2020 17:29:41 +0300 Subject: [PATCH 08/16] Remove ThreadPriority --- src/miner.cpp | 7 ++++--- src/net.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 992d49990..5083e0736 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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; { From d4682c97eb451be4a612527f0498afcebf3b8f73 Mon Sep 17 00:00:00 2001 From: Stamek Date: Sat, 22 Aug 2020 17:32:12 +0300 Subject: [PATCH 09/16] Fix staking --- src/kernel.cpp | 4 ++-- src/wallet/wallet.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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/wallet/wallet.cpp b/src/wallet/wallet.cpp index 778709667..95a50dc50 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2379,10 +2379,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 From 4c681c4eda4b812c7a3e7bc9eb46c72cb79d4530 Mon Sep 17 00:00:00 2001 From: Stamek Date: Sat, 22 Aug 2020 18:07:48 +0300 Subject: [PATCH 10/16] [Consensus] spork 15 activation + protocol version bump. --- src/main.cpp | 10 +++++----- src/version.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 46576586b..2c3870859 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6751,13 +6751,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/version.h b/src/version.h index aebd4a7c9..d73e8f509 100644 --- a/src/version.h +++ b/src/version.h @@ -13,7 +13,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 71030; +static const int PROTOCOL_VERSION = 71031; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; @@ -22,8 +22,8 @@ static const int INIT_PROTO_VERSION = 209; static const int GETHEADERS_VERSION = 70077; //! disconnect from peers older than this proto version -static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 71029; -static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 71030; +static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 71030; +static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 71031; //! masternodes older than this proto version use old strMessage format for mnannounce static const int MIN_PEER_MNANNOUNCE = 71030; From f8c636c1cce4e90fa96cee38efe19c1aec957dac Mon Sep 17 00:00:00 2001 From: Stamek Date: Sat, 22 Aug 2020 19:57:47 +0300 Subject: [PATCH 11/16] Fix testnet --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 5083e0736..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); } From 5c14bd77971fce398a067f008c913a7defecd2fd Mon Sep 17 00:00:00 2001 From: Stamek Date: Sat, 22 Aug 2020 22:09:53 +0300 Subject: [PATCH 12/16] Fix test --- test/functional/interface_rest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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') From af29139ede6429b9bb9518dca1da5596764c4f8b Mon Sep 17 00:00:00 2001 From: furszy Date: Tue, 29 Oct 2019 16:50:05 -0300 Subject: [PATCH 13/16] [Bug] Fix contextCheckBlock for the first block that it's a v1 block. --- src/main.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2c3870859..309eab372 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4320,10 +4320,13 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn } // Enforce block.nVersion=2 rule that the coinbase starts with serialized block height - 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"); + 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"); + } } LogPrint("debug", "ContextualCheckBlock returning true"); return true; From ce251778e6d6fee902c9b04c300f49a31d7c7b52 Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Thu, 17 Mar 2016 12:48:05 -0400 Subject: [PATCH 14/16] Fix calculation of balances and available coins. No longer consider coins which aren't in our mempool. Add test for regression in abandonconflict.py --- src/wallet/wallet.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 95a50dc50..dd52bc8c6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1545,7 +1545,7 @@ CAmount CWallet::GetUnconfirmedBalance() 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->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) { From 50020be8caa2912eef337e183ad3fa9a7314b3ed Mon Sep 17 00:00:00 2001 From: furszy Date: Wed, 23 Oct 2019 19:11:49 -0300 Subject: [PATCH 15/16] [GUI] Segfault for a bad cast of the parent widget in the escape key press event. --- src/qt/coincontroltreewidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 2b42962f5e909c94d5913a92571899fa4687c6b5 Mon Sep 17 00:00:00 2001 From: Stamek Date: Sun, 23 Aug 2020 13:29:36 +0300 Subject: [PATCH 16/16] Disable Mintpool --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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");