From 8576a425cb888921cf4118af16f129686c5471ce Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 13 Aug 2020 19:17:11 -0400 Subject: [PATCH 01/14] Version 3.0.0.1 dev - Increase time between blocks at block 2977924 or when network has reached 95% upgrade threshold - Change block time to 4 minutes - Set block reward to 6 on activation of new time - Adjust new block enforce policy to 24 hour span --- .editorconfig | 11 +++++++++++ configure.ac | 4 ++-- src/chainparams.cpp | 15 ++++++++++----- src/chainparams.h | 12 ++++++++++++ src/main.cpp | 32 ++++++++++++++++++-------------- src/pow.cpp | 19 +++++++++++++++---- src/primitives/block.h | 2 +- 7 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..536b3c3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab diff --git a/configure.ac b/configure.ac index efe514a..941a8f1 100755 --- a/configure.ac +++ b/configure.ac @@ -2,10 +2,10 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N) AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 3) define(_CLIENT_VERSION_MINOR, 0) -define(_CLIENT_VERSION_REVISION, 0) +define(_CLIENT_VERSION_REVISION, 1) define(_CLIENT_VERSION_BUILD, 0) define(_CLIENT_VERSION_IS_RELEASE, true) -define(_COPYRIGHT_YEAR, 2019) +define(_COPYRIGHT_YEAR, 2020) AC_INIT([Ohmcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[www.ohmcoin.io],[ohmcoin]) AC_CONFIG_SRCDIR([src/main.cpp]) AC_CONFIG_HEADERS([src/config/ohmcoin-config.h]) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 4d21778..1df3f88 100755 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -393,15 +393,20 @@ class CMainParams : public CChainParams nDefaultPort = 52020; bnProofOfWorkLimit = ~uint256(0) >> 20; nMaxReorganizationDepth = 100; - nEnforceBlockUpgradeMajority = 750; - nRejectBlockOutdatedMajority = 950; - nToCheckBlockUpgradeMajority = 1000; + nEnforceBlockUpgradeMajority = 2250; + nRejectBlockOutdatedMajority = 2850; + nToCheckBlockUpgradeMajority = 3000; // 24 hours (legacy) nMinerThreads = 0; - nTargetTimespan = 1 * 30; // OHMC: 30 Seconds - nTargetSpacing = 1 * 30; // OHMC: 30 Seconds nMaturity = 4; nKarmanodeCountDrift = 20; nMaxMoneyOut = 30000000 * COIN; + /* Legacy Blocktime */ + nTargetTimespanLegacy = 1 * 60 * 40; // OHMC: 40 Minutes + nTargetSpacingLegacy = 1 * 30; // OHMC: 30 Seconds + /* New Blocktime */ + nTargetTimespan = 1 * 60 * 60 * 2; // OHMC New: 120 Minutes + nTargetSpacing = 1 * 60 * 4; // OHMC New: 240 Seconds + nDisableLegacyTimeHeight = 2977924; // Height legacy blocktime disables /** Height or Time Based Activations **/ nLastPOWBlock = 1001; diff --git a/src/chainparams.h b/src/chainparams.h index 9771041..5661eb4 100755 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -71,11 +71,20 @@ class CChainParams bool SkipProofOfWorkCheck() const { return fSkipProofOfWorkCheck; } /** Make standard checks */ bool RequireStandard() const { return fRequireStandard; } + /** Legacy blocktime setting */ + int64_t TargetTimespanLegacy() const { return nTargetTimespanLegacy; } + int64_t TargetSpacingLegacy() const { return nTargetSpacingLegacy; } + int64_t IntervalLegacy() const { return nTargetTimespanLegacy / nTargetSpacingLegacy; } + /** New blocktime setting */ int64_t TargetTimespan() const { return nTargetTimespan; } int64_t TargetSpacing() const { return nTargetSpacing; } int64_t Interval() const { return nTargetTimespan / nTargetSpacing; } + /** Disable Legacy Blocktime Height */ + int DisableLegacyTimeHeight() const { return nDisableLegacyTimeHeight; } + /** Majurity Checks */ int COINBASE_MATURITY() const { return nMaturity; } unsigned int StakeMaturity() const { return nStakeMaturity; } + /** Max Money Checks */ CAmount MaxMoneyOut() const { return nMaxMoneyOut; } /** The karmanode count that we will allow the see-saw reward payments to be off by */ int KarmanodeCountDrift() const { return nKarmanodeCountDrift; } @@ -129,6 +138,9 @@ class CChainParams int nToCheckBlockUpgradeMajority; int64_t nTargetTimespan; int64_t nTargetSpacing; + int64_t nTargetTimespanLegacy; + int64_t nTargetSpacingLegacy; + int nDisableLegacyTimeHeight; int nLastPOWBlock; int nKarmanodeCountDrift; int nMaturity; diff --git a/src/main.cpp b/src/main.cpp index 95b1909..a8d79a6 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2170,8 +2170,9 @@ double ConvertBitsToDouble(unsigned int nBits) int64_t GetBlockValue(int nHeight) { - if (nHeight < 1001 && nHeight > 0) + if (nHeight < 1001 && nHeight > 0) { return 30000 * COIN; + } if (nHeight == 0) { return 1 * COIN; @@ -2184,17 +2185,14 @@ int64_t GetBlockValue(int nHeight) } else if (nHeight <= 2373122 && nHeight >= 1941122) { return 0.125 * COIN; } else if (nHeight <= 2977923 && nHeight >= 2373123) { - return 0.0625 * COIN; - } else if (nHeight <= 4029124 && nHeight >= 2977924) { - return 0.03125 * COIN; - } else if (nHeight <= 6131525 && nHeight >= 4029125) { - return 0.015625 * COIN; - } else if (nHeight <= 8233926 && nHeight >= 6131526) { - return 0.0078125 * COIN; - } else if (nHeight <= 10336327 && nHeight >= 8233927) { - return 0.00390625 * COIN; - } else if (nHeight >= 10336328) { - return 0.001953125 * COIN; + bool bVerAct = CBlockIndex::IsSuperMajority(7, pindexLast, Params().RejectBlockOutdatedMajority()); + if (bVerAct) { + return 6 * COIN; + } else { + return 0.0625 * COIN; + } + } else if (nHeight >= Params().DisableLegacyTimeHeight()) { + return 6 * COIN; } else { return 1 * COIN; } @@ -4563,6 +4561,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta REJECT_OBSOLETE, "bad-version"); } + // Reject block.nVersion=6 blocks or lower when 95% (75% on testnet) of the network has upgraded: + if (block.nVersion < 7 && CBlockIndex::IsSuperMajority(7, pindexPrev, Params().RejectBlockOutdatedMajority())) { + return state.Invalid(error("%s : rejected nVersion=%d block", __func__, block.nVersion), + REJECT_OBSOLETE, "bad-version"); + } + return true; } @@ -7327,7 +7331,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // timeout. We compensate for in-flight blocks to prevent killing off peers due to our own downstream link // being saturated. We only count validated in-flight blocks so peers can't advertize nonexisting block hashes // to unreasonably increase our timeout. - if (!pto->fDisconnect && state.vBlocksInFlight.size() > 0 && state.vBlocksInFlight.front().nTime < nNow - 500000 * Params().TargetSpacing() * (4 + state.vBlocksInFlight.front().nValidatedQueuedBefore)) { + if (!pto->fDisconnect && state.vBlocksInFlight.size() > 0 && state.vBlocksInFlight.front().nTime < nNow - 500000 * Params().TargetSpacingLegacy() * (4 + state.vBlocksInFlight.front().nValidatedQueuedBefore)) { LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", state.vBlocksInFlight.front().hash.ToString(), pto->id); pto->fDisconnect = true; } @@ -7454,4 +7458,4 @@ class CMainCleanup mapOrphanTransactions.clear(); mapOrphanTransactionsByPrev.clear(); } -} instance_of_cmaincleanup; \ No newline at end of file +} instance_of_cmaincleanup; diff --git a/src/pow.cpp b/src/pow.cpp index bbfb319..d95f6c0 100755 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -37,8 +37,20 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexLast->nHeight > Params().LAST_POW_BLOCK()) { uint256 bnTargetLimit = (~uint256(0) >> 24); - int64_t nTargetSpacing = 30; - int64_t nTargetTimespan = 60 * 40; + // Block time targeting + int64_t nTargetSpacing = Params().TargetSpacingLegacy(); + int64_t nTargetTimespan = Params().TargetTimespanLegacy(); + int64_t nInterval = Params().IntervalLegacy(); + + // New time activation check + bool bVerAct = CBlockIndex::IsSuperMajority(7, pindexLast, Params().RejectBlockOutdatedMajority()); + bool bHeightReach = pindexLast->nHeight >= Params().DisableLegacyTimeHeight(); + // Actiavte on 95% upgrade threshold, or forced by block height set. + if (bVerAct || bHeightReach) { + nTargetSpacing = Params().TargetSpacing(); + nTargetTimespan = Params().TargetTimespan(); + nInterval = Params().Interval(); + } int64_t nActualSpacing = 0; if (pindexLast->nHeight != 0) @@ -52,7 +64,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead uint256 bnNew; bnNew.SetCompact(pindexLast->nBits); - int64_t nInterval = nTargetTimespan / nTargetSpacing; bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing); bnNew /= ((nInterval + 1) * nTargetSpacing); @@ -92,7 +103,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead uint256 bnNew(PastDifficultyAverage); - int64_t _nTargetTimespan = CountBlocks * Params().TargetSpacing(); + int64_t _nTargetTimespan = CountBlocks * nTargetSpacing; if (nActualTimespan < _nTargetTimespan / 3) nActualTimespan = _nTargetTimespan / 3; diff --git a/src/primitives/block.h b/src/primitives/block.h index a924ea8..8a89a3e 100755 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -26,7 +26,7 @@ class CBlockHeader { public: // header - static const int32_t CURRENT_VERSION=6; + static const int32_t CURRENT_VERSION = 7; int32_t nVersion; uint256 hashPrevBlock; uint256 hashMerkleRoot; From 9e87f619ce844b331ab6c0592b21b5148fcc7d21 Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 13 Aug 2020 20:08:42 -0400 Subject: [PATCH 02/14] fix flag check for; add fIgnoreLegacyBlocks --- src/main.cpp | 7 +++++-- src/main.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a8d79a6..4e7adb5 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,6 +94,7 @@ bool fAddrIndex = true; bool fIsBareMultisigStd = true; bool fCheckBlockIndex = false; bool fVerifyingBlocks = false; +bool fIgnoreLegacyBlocks = false; unsigned int nCoinCacheSize = 5000; unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP; bool fAlerts = DEFAULT_ALERTS; @@ -2185,8 +2186,7 @@ int64_t GetBlockValue(int nHeight) } else if (nHeight <= 2373122 && nHeight >= 1941122) { return 0.125 * COIN; } else if (nHeight <= 2977923 && nHeight >= 2373123) { - bool bVerAct = CBlockIndex::IsSuperMajority(7, pindexLast, Params().RejectBlockOutdatedMajority()); - if (bVerAct) { + if (fIgnoreLegacyBlocks) { return 6 * COIN; } else { return 0.0625 * COIN; @@ -4941,6 +4941,9 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, return state.Error(std::string("System error: ") + e.what()); } + /* Update storage varaible for ignoring legacy blocks (version 6 and prior) */ + fIgnoreLegacyBlocks = CBlockIndex::IsSuperMajority(7, pindex, Params().RejectBlockOutdatedMajority()); + return true; } diff --git a/src/main.h b/src/main.h index 3b3ea15..5ffc4fc 100755 --- a/src/main.h +++ b/src/main.h @@ -151,6 +151,7 @@ extern unsigned int nCoinCacheSize; extern CFeeRate minRelayTxFee; extern bool fAlerts; extern bool fVerifyingBlocks; +extern bool fIgnoreLegacyBlocks; extern bool fLargeWorkForkFound; extern bool fLargeWorkInvalidChainFound; @@ -659,4 +660,4 @@ struct CBlockTemplate { int64_t GetVirtualTransactionSize(const CTransaction& tx); int64_t GetVirtualTransactionSize(int64_t nCost); -#endif // BITCOIN_MAIN_H \ No newline at end of file +#endif // BITCOIN_MAIN_H From e9ece02d9f94ca443c664543ca00064f99d30b24 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 14 Aug 2020 00:04:04 -0400 Subject: [PATCH 03/14] move variable out of if statement, fix compile. --- src/pow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index d95f6c0..a33f463 100755 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -35,10 +35,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return Params().ProofOfWorkLimit().GetCompact(); } + // Target block time spacing + int64_t nTargetSpacing = Params().TargetSpacingLegacy(); + if (pindexLast->nHeight > Params().LAST_POW_BLOCK()) { uint256 bnTargetLimit = (~uint256(0) >> 24); // Block time targeting - int64_t nTargetSpacing = Params().TargetSpacingLegacy(); int64_t nTargetTimespan = Params().TargetTimespanLegacy(); int64_t nInterval = Params().IntervalLegacy(); From f68d8871ad0810d38d2d0167c04f4a2c791cd75b Mon Sep 17 00:00:00 2001 From: Crypto Pliskin <13294167+2a5A1Ghu1@users.noreply.github.com> Date: Fri, 14 Aug 2020 17:27:14 -0700 Subject: [PATCH 04/14] Improve2 (#54) * WIP: upgrade network upgrade features; testnet fixes.. * add this back for now.. * add missed file, optional.h * more imports * adjust imports for consensus.h * correction * fix moar missing imports * add missing vars and fixes * missing header declare * changes.. * update makefile * need this here too.. * fixed compile * further fixed. Co-authored-by: Jon --- src/Makefile.am | 5 ++ src/chainparams.cpp | 71 +++++++++++++++++-- src/chainparams.h | 8 +++ src/consensus/params.cpp | 26 +++++++ src/consensus/params.h | 73 ++++++++++++++++++++ src/consensus/upgrades.cpp | 136 +++++++++++++++++++++++++++++++++++++ src/consensus/upgrades.h | 85 +++++++++++++++++++++++ src/init.cpp | 46 ++++++++++++- src/init.h | 2 +- src/main.cpp | 29 +++++++- src/optional.h | 17 +++++ src/rpcblockchain.cpp | 111 ++++++++++++++++++++++++++++++ 12 files changed, 596 insertions(+), 13 deletions(-) create mode 100644 src/consensus/params.cpp create mode 100644 src/consensus/upgrades.cpp create mode 100644 src/consensus/upgrades.h create mode 100644 src/optional.h diff --git a/src/Makefile.am b/src/Makefile.am index c417edf..0c3c36a 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -116,6 +116,8 @@ BITCOIN_CORE_H = \ compat/sanity.h \ consensus/merkle.h \ consensus/validation.h \ + consensus/params.h \ + consensus/upgrades.h \ compressor.h \ primitives/block.h \ primitives/deterministicmint.h \ @@ -219,6 +221,8 @@ libbitcoin_server_a_SOURCES = \ checkpoints.cpp \ httprpc.cpp \ httpserver.cpp \ + consensus/params.cpp \ + consensus/upgrades.cpp \ init.cpp \ leveldbwrapper.cpp \ main.cpp \ @@ -364,6 +368,7 @@ libbitcoin_common_a_SOURCES = \ coins.cpp \ compressor.cpp \ consensus/merkle.cpp \ + consensus/upgrades.cpp \ primitives/block.cpp \ primitives/deterministicmint.cpp \ primitives/transaction.cpp \ diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1df3f88..c5c005f 100755 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -492,6 +492,18 @@ class CMainParams : public CChainParams nDefaultSecurityLevel = 100; //full security level for accumulators nZerocoinHeaderVersion = 6; //Block headers must be this version once zerocoin is active nBudgetFeeConfirmations = 3; // Number of confirmations for the finalization fee + + // Network upgrades + consensus.vUpgrades[Consensus::BASE_NETWORK].nActivationHeight = + Consensus::NetworkUpgrade::ALWAYS_ACTIVE; + consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nActivationHeight = 2977924; + consensus.vUpgrades[Consensus::UPGRADE_V3_1_DUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_V3_2_DUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + } const Checkpoints::CCheckpointData& Checkpoints() const @@ -521,20 +533,26 @@ class CTestNetParams : public CMainParams nRejectBlockOutdatedMajority = 75; nToCheckBlockUpgradeMajority = 100; nMinerThreads = 0; - nTargetTimespan = 1 * 60; // Ohmcoin: 1 day - nTargetSpacing = 1 * 10; // Ohmcoin: 1 minute + /* Legacy Blocktime */ + nTargetTimespanLegacy = 1 * 60 * 40; // OHMC: 40 Minutes + nTargetSpacingLegacy = 1 * 22; // OHMC: 22 Seconds + /* New Blocktime */ + nTargetTimespan = 1 * 60 * 60 * 1; // OHMC New: 60 Minutes + nTargetSpacing = 1 * 60 * 2; // OHMC New: 120 Seconds + nDisableLegacyTimeHeight = 33001; // Height legacy blocktime disables + nMaturity = 15; nKarmanodeCountDrift = 4; nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT nMaxMoneyOut = 43199500 * COIN; nLastPOWBlock = 200; - nZerocoinStartHeight = 200; + nZerocoinStartHeight = 999999999; nZerocoinLastOldParams = 50000; //! Modify the testnet genesis block so the timestamp is valid for a later start. - genesis.nTime = 1454124731; - genesis.nNonce = 2402015; + genesis.nTime = 1597378077; + genesis.nNonce = 8142020; hashGenesisBlock = genesis.GetHash(); //assert(hashGenesisBlock == uint256("0xfab709a0c107fe7cf6b0d552c514ef3228f9e0f107cd3c9b2fcea96512342cd8")); @@ -568,6 +586,17 @@ class CTestNetParams : public CMainParams strObfuscationPoolDummyAddress = "y57cqfGRkekRyDRNeJiLtYVEbvhXrNbmox"; nBudgetFeeConfirmations = 3; // Number of confirmations for the finalization fee. We have to make this very short // here because we only have a 8 block finalization window on testnet + + // Network upgrades + consensus.vUpgrades[Consensus::BASE_NETWORK].nActivationHeight = + Consensus::NetworkUpgrade::ALWAYS_ACTIVE; + consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nActivationHeight = 33001; + consensus.vUpgrades[Consensus::UPGRADE_V3_1_DUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_V3_2_DUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; } const Checkpoints::CCheckpointData& Checkpoints() const { @@ -595,8 +624,13 @@ class CRegTestParams : public CTestNetParams nRejectBlockOutdatedMajority = 950; nToCheckBlockUpgradeMajority = 1000; nMinerThreads = 1; - nTargetTimespan = 24 * 60 * 60; // Ohmcoin: 1 day - nTargetSpacing = 1 * 60; // Ohmcoin: 1 minutes + /* Legacy Blocktime */ + nTargetTimespanLegacy = 1 * 60 * 60 * 24; // OHMC: 24 Hours + nTargetSpacingLegacy = 1 * 30; // OHMC: 22 Seconds + /* New Blocktime */ + nTargetTimespan = 1 * 60 * 60 * 2; // OHMC New: 120 Minutes + nTargetSpacing = 1 * 60 * 4; // OHMC New: 240 Seconds + nDisableLegacyTimeHeight = 33001; // Height legacy blocktime disables bnProofOfWorkLimit = ~uint256(0) >> 1; genesis.nTime = 1454124731; genesis.nBits = 0x207fffff; @@ -628,11 +662,29 @@ class CRegTestParams : public CTestNetParams // "PublicKey": "04866dc02c998b7e1ab16fe14e0d86554595da90c36acb706a4d763b58ed0edb1f82c87e3ced065c5b299b26e12496956b9e5f9f19aa008b5c46229b15477c875a" // } strSporkKey = "04866dc02c998b7e1ab16fe14e0d86554595da90c36acb706a4d763b58ed0edb1f82c87e3ced065c5b299b26e12496956b9e5f9f19aa008b5c46229b15477c875a"; + + // Network upgrades + consensus.vUpgrades[Consensus::BASE_NETWORK].nActivationHeight = + Consensus::NetworkUpgrade::ALWAYS_ACTIVE; + consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nActivationHeight = 33001; + consensus.vUpgrades[Consensus::UPGRADE_V3_1_DUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_V3_2_DUMMY].nActivationHeight = + Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; } + const Checkpoints::CCheckpointData& Checkpoints() const { return dataRegtest; } + + void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight) + { + assert(idx > Consensus::BASE_NETWORK && idx < Consensus::MAX_NETWORK_UPGRADES); + consensus.vUpgrades[idx].nActivationHeight = nActivationHeight; + } }; static CRegTestParams regTestParams; @@ -720,3 +772,8 @@ bool SelectParamsFromCommandLine() SelectParams(network); return true; } + +void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight) +{ + regTestParams.UpdateNetworkUpgradeParameters(idx, nActivationHeight); +} diff --git a/src/chainparams.h b/src/chainparams.h index 5661eb4..9d6d5b5 100755 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -11,6 +11,7 @@ #include "chainparamsbase.h" #include "checkpoints.h" #include "primitives/block.h" +#include "consensus/params.h" #include "protocol.h" #include "uint256.h" @@ -46,6 +47,7 @@ class CChainParams }; const uint256& HashGenesisBlock() const { return hashGenesisBlock; } + const Consensus::Params& GetConsensus() const { return consensus; } const MessageStartChars& MessageStart() const { return pchMessageStart; } const std::vector& AlertKey() const { return vAlertPubKey; } int GetDefaultPort() const { return nDefaultPort; } @@ -154,6 +156,7 @@ class CChainParams CBaseChainParams::Network networkID; std::string strNetworkID; CBlock genesis; + Consensus::Params consensus; std::vector vFixedSeeds; bool fMiningRequiresPeers; bool fAllowMinDifficultyBlocks; @@ -219,4 +222,9 @@ void SelectParams(CBaseChainParams::Network network); */ bool SelectParamsFromCommandLine(); +/** + * Allows modifying the network upgrade regtest parameters. + */ +void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight); + #endif // BITCOIN_CHAINPARAMS_H diff --git a/src/consensus/params.cpp b/src/consensus/params.cpp new file mode 100644 index 0000000..5675308 --- /dev/null +++ b/src/consensus/params.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2019 The Zcash developers +// Copyright (c) 2020 The PIVX developers +// Copyright (c) 2020 The OHMC developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or https://www.opensource.org/licenses/mit-license.php . + +#include "consensus/params.h" +#include "consensus/upgrades.h" +#include "util.h" + +namespace Consensus { + +bool Params::NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const +{ + if (idx >= Consensus::MAX_NETWORK_UPGRADES) + return error("%s: Upgrade index out of bounds: %d >= %d", + __func__, idx, Consensus::MAX_NETWORK_UPGRADES); + + if (nHeight < 0) + return error("%s: Requested state for upgrade %s at negative height %d", + __func__, NetworkUpgradeInfo[idx].strName, nHeight); + + return NetworkUpgradeState(nHeight, *this, idx) == UPGRADE_ACTIVE; +} + +} // End consensus namespace diff --git a/src/consensus/params.h b/src/consensus/params.h index e85949f..71001a9 100755 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -1,17 +1,80 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2020 The PIVX developers +// Copyright (c) 2020 The OHMC developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_CONSENSUS_PARAMS_H #define BITCOIN_CONSENSUS_PARAMS_H +#include "optional.h" #include "uint256.h" #include #include namespace Consensus { +/** +* Index into Params.vUpgrades and NetworkUpgradeInfo +* +* Being array indices, these MUST be numbered consecutively. +* +* The order of these indices MUST match the order of the upgrades on-chain, as +* several functions depend on the enum being sorted. +*/ +enum UpgradeIndex : uint32_t { + BASE_NETWORK, // Base Network + UPGRADE_V3_0_BLOCKTIME, // Blocktime consensus change + UPGRADE_V3_1_DUMMY, + UPGRADE_V3_2_DUMMY, + UPGRADE_TESTDUMMY, + // NOTE: Also add new upgrades to NetworkUpgradeInfo in upgrades.cpp + MAX_NETWORK_UPGRADES +}; + +struct NetworkUpgrade { + /** + * The first protocol version which will understand the new consensus rules + */ + int nProtocolVersion; + + /** + * Height of the first block for which the new consensus rules will be active + */ + int nActivationHeight; + + /** + * Special value for nActivationHeight indicating that the upgrade is always active. + * This is useful for testing, as it means tests don't need to deal with the activation + * process (namely, faking a chain of somewhat-arbitrary length). + * + * New blockchains that want to enable upgrade rules from the beginning can also use + * this value. However, additional care must be taken to ensure the genesis block + * satisfies the enabled rules. + */ + static constexpr int ALWAYS_ACTIVE = 0; + + /** + * Special value for nActivationHeight indicating that the upgrade will never activate. + * This is useful when adding upgrade code that has a testnet activation height, but + * should remain disabled on mainnet. + */ + static constexpr int NO_ACTIVATION_HEIGHT = -1; + + /** + * The hash of the block at height nActivationHeight, if known. This is set manually + * after a network upgrade activates. + * + * We use this in IsInitialBlockDownload to detect whether we are potentially being + * fed a fake alternate chain. We use NU activation blocks for this purpose instead of + * the checkpoint blocks, because network upgrades (should) have significantly more + * scrutiny than regular releases. nMinimumChainWork MUST be set to at least the chain + * work of this block, otherwise this detection will have false positives. + */ + Optional hashActivationBlock; +}; + enum DeploymentPos { DEPLOYMENT_TESTDUMMY, @@ -84,6 +147,16 @@ struct Params { int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } uint256 nMinimumChainWork; uint256 defaultAssumeValid; + + // Map with network updates + NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]; + + /** + * Returns true if the given network upgrade is active as of the given block + * height. Caller must check that the height is >= 0 (and handle unknown + * heights). + */ + bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const; }; } // namespace Consensus diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp new file mode 100644 index 0000000..329a538 --- /dev/null +++ b/src/consensus/upgrades.cpp @@ -0,0 +1,136 @@ +// Copyright (c) 2018 The Zcash developers +// Copyright (c) 2020 The PIVX developers +// Copyright (c) 2020 The OHMC developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "consensus/upgrades.h" + +/** + * General information about each network upgrade. + * Ordered by Consensus::UpgradeIndex. + * + * If the upgrade name has many words, use the '_' character to divide them. + * We are using it in the -nuparams startup arg and input it with spaces is just ugly. + */ +const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES] = { + { + /*.strName =*/ "Base", + /*.strInfo =*/ "OHMC network", + }, + { + /*.strName =*/ "v3_0_blocktime", + /*.strInfo =*/ "Activation of OHMC version 3.0 Block Time upgrade", + }, + { + /*.strName =*/ "v3_1_dummy", + /*.strInfo =*/ "Placeholder for future OHMC version 3.1 upgrade", + }, + { + /*.strName =*/ "v3_2_dummy", + /*.strInfo =*/ "Placeholder for future OHMC version 3.2 upgrade", + }, + { + /*.strName =*/ "Test_dummy", + /*.strInfo =*/ "Test dummy info", + }, +}; + +UpgradeState NetworkUpgradeState( + int nHeight, + const Consensus::Params& params, + Consensus::UpgradeIndex idx) +{ + assert(nHeight >= 0); + assert(idx >= Consensus::BASE_NETWORK && idx < Consensus::MAX_NETWORK_UPGRADES); + auto nActivationHeight = params.vUpgrades[idx].nActivationHeight; + + if (nActivationHeight == Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT) { + return UPGRADE_DISABLED; + } else if (nHeight >= nActivationHeight) { + // From ZIP200: + // + // ACTIVATION_HEIGHT + // The block height at which the network upgrade rules will come into effect. + // + // For removal of ambiguity, the block at height ACTIVATION_HEIGHT - 1 is + // subject to the pre-upgrade consensus rules. + return UPGRADE_ACTIVE; + } else { + return UPGRADE_PENDING; + } +} + +bool NetworkUpgradeActive( + int nHeight, + const Consensus::Params& params, + Consensus::UpgradeIndex idx) +{ + return NetworkUpgradeState(nHeight, params, idx) == UPGRADE_ACTIVE; +} + +int CurrentEpoch(int nHeight, const Consensus::Params& params) { + for (auto idxInt = Consensus::MAX_NETWORK_UPGRADES - 1; idxInt > Consensus::BASE_NETWORK; idxInt--) { + if (NetworkUpgradeActive(nHeight, params, Consensus::UpgradeIndex(idxInt))) { + return idxInt; + } + } + return Consensus::BASE_NETWORK; +} + +bool IsActivationHeight( + int nHeight, + const Consensus::Params& params, + Consensus::UpgradeIndex idx) +{ + assert(idx >= Consensus::BASE_NETWORK && idx < Consensus::MAX_NETWORK_UPGRADES); + + // Don't count BASE_NETWORK as an activation height + if (idx == Consensus::BASE_NETWORK) { + return false; + } + + return nHeight >= 0 && nHeight == params.vUpgrades[idx].nActivationHeight; +} + +bool IsActivationHeightForAnyUpgrade( + int nHeight, + const Consensus::Params& params) +{ + if (nHeight < 0) { + return false; + } + + for (int idx = Consensus::BASE_NETWORK + 1; idx < (int) Consensus::MAX_NETWORK_UPGRADES; idx++) { + if (nHeight == params.vUpgrades[idx].nActivationHeight) + return true; + } + + return false; +} + +Optional NextEpoch(int nHeight, const Consensus::Params& params) { + if (nHeight < 0) { + return nullopt; + } + + // BASE_NETWORK is never pending + for (auto idx = Consensus::BASE_NETWORK + 1; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) { + if (NetworkUpgradeState(nHeight, params, Consensus::UpgradeIndex(idx)) == UPGRADE_PENDING) { + return idx; + } + } + + return nullopt; +} + +Optional NextActivationHeight( + int nHeight, + const Consensus::Params& params) +{ + auto idx = NextEpoch(nHeight, params); + if (idx) { + return params.vUpgrades[idx.get()].nActivationHeight; + } + return nullopt; +} diff --git a/src/consensus/upgrades.h b/src/consensus/upgrades.h new file mode 100644 index 0000000..4f0f071 --- /dev/null +++ b/src/consensus/upgrades.h @@ -0,0 +1,85 @@ +// Copyright (c) 2018 The Zcash developers +// Copyright (c) 2020 The PIVX developers +// Copyright (c) 2020 The OHMC developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_CONSENSUS_UPGRADES_H +#define BITCOIN_CONSENSUS_UPGRADES_H + +#include "consensus/params.h" +#include "optional.h" + +enum UpgradeState { + UPGRADE_DISABLED, + UPGRADE_PENDING, + UPGRADE_ACTIVE +}; + +struct NUInfo { + /** User-facing name for the upgrade */ + std::string strName; + /** User-facing information string about the upgrade */ + std::string strInfo; +}; + +extern const struct NUInfo NetworkUpgradeInfo[]; + +/** + * Checks the state of a given network upgrade based on block height. + * Caller must check that the height is >= 0 (and handle unknown heights). + */ +UpgradeState NetworkUpgradeState( + int nHeight, + const Consensus::Params& params, + Consensus::UpgradeIndex idx); + +/** + * Returns true if the given network upgrade is active as of the given block + * height. Caller must check that the height is >= 0 (and handle unknown + * heights). + */ +bool NetworkUpgradeActive( + int nHeight, + const Consensus::Params& params, + Consensus::UpgradeIndex idx); + +/** + * Returns the index of the most recent upgrade as of the given block height + * (corresponding to the current "epoch"). Consensus::BASE_NETWORK is the + * default value if no upgrades are active. Caller must check that the height + * is >= 0 (and handle unknown heights). + */ +int CurrentEpoch(int nHeight, const Consensus::Params& params); + +/** + * Returns true if the given block height is the activation height for the given + * upgrade. + */ +bool IsActivationHeight( + int nHeight, + const Consensus::Params& params, + Consensus::UpgradeIndex upgrade); + +/** + * Returns true if the given block height is the activation height for any upgrade. + */ +bool IsActivationHeightForAnyUpgrade( + int nHeight, + const Consensus::Params& params); + +/** + * Returns the index of the next upgrade after the given block height, or + * nullopt if there are no more known upgrades. + */ +Optional NextEpoch(int nHeight, const Consensus::Params& params); + +/** + * Returns the activation height for the next upgrade after the given block height, + * or nullopt if there are no more known upgrades. + */ +Optional NextActivationHeight( + int nHeight, + const Consensus::Params& params); + +#endif // PIVX_CONSENSUS_UPGRADES_H diff --git a/src/init.cpp b/src/init.cpp index c9d5008..4ca0252 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -18,6 +18,7 @@ #include "amount.h" #include "checkpoints.h" #include "compat/sanity.h" +#include "consensus/upgrades.h" #include "consensus/validation.h" #include "httpserver.h" #include "httprpc.h" @@ -56,6 +57,9 @@ #include #endif +#include +#include + #include #include #include @@ -726,6 +730,42 @@ bool AppInitServers(boost::thread_group& threadGroup) return true; } +bool InitNUParams() +{ + if (!mapMultiArgs["-nuparams"].empty()) { + // Allow overriding network upgrade parameters for testing + if (Params().NetworkIDString() != "regtest") { + return InitError("Network upgrade parameters may only be overridden on regtest."); + } + const std::vector& deployments = mapMultiArgs["-nuparams"]; + for (auto i : deployments) { + std::vector vDeploymentParams; + boost::split(vDeploymentParams, i, boost::is_any_of(":")); + if (vDeploymentParams.size() != 2) { + return InitError("Network upgrade parameters malformed, expecting hexBranchId:activationHeight"); + } + int nActivationHeight; + if (!ParseInt32(vDeploymentParams[1], &nActivationHeight)) { + return InitError(strprintf("Invalid nActivationHeight (%s)", vDeploymentParams[1])); + } + bool found = false; + // Exclude base network from upgrades + for (auto j = Consensus::BASE_NETWORK + 1; j < Consensus::MAX_NETWORK_UPGRADES; ++j) { + if (vDeploymentParams[0] == NetworkUpgradeInfo[j].strName) { + UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex(j), nActivationHeight); + found = true; + LogPrintf("Setting network upgrade activation parameters for %s to height=%d\n", vDeploymentParams[0], nActivationHeight); + break; + } + } + if (!found) { + return InitError(strprintf("Invalid network upgrade (%s)", vDeploymentParams[0])); + } + } + } + return true; +} + /** Initialize ohmcoin. * @pre Parameters should be parsed and config file should be read. */ @@ -993,10 +1033,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS); - if (GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS)) nLocalServices |= NODE_BLOOM; + if (!InitNUParams()) + return false; + // ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log // Sanity check @@ -2008,4 +2050,4 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) #endif return !fRequestShutdown; -} \ No newline at end of file +} diff --git a/src/init.h b/src/init.h index 02f83fd..02c1a84 100755 --- a/src/init.h +++ b/src/init.h @@ -39,4 +39,4 @@ std::string HelpMessage(HelpMessageMode mode); /** Returns licensing information (for -version) */ std::string LicenseInfo(); -#endif // BITCOIN_INIT_H \ No newline at end of file +#endif // BITCOIN_INIT_H diff --git a/src/main.cpp b/src/main.cpp index 4e7adb5..0e946f6 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2175,6 +2175,22 @@ int64_t GetBlockValue(int nHeight) return 30000 * COIN; } + if (Params().NetworkID() == CBaseChainParams::TESTNET) { + if (nHeight <= 3000 && nHeight >= 1001) { + return 1 * COIN; + } else if (nHeight <= 33001 && nHeight >= 3001) { + if (fIgnoreLegacyBlocks) { + return 6 * COIN; + } else { + return 3.14159 * COIN; + } + } else if (nHeight >= Params().DisableLegacyTimeHeight()) { + return 6 * COIN; + } else { + return 1 * COIN; + } + } + if (nHeight == 0) { return 1 * COIN; } else if (nHeight <= 904320 && nHeight >= 1000) { @@ -4511,6 +4527,7 @@ bool CheckWork(const CBlock block, CBlockIndex* const pindexPrev) bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex* const pindexPrev) { + const Consensus::Params& consensus = Params().GetConsensus(); uint256 hash = block.GetHash(); if (hash == Params().HashGenesisBlock()) @@ -4543,8 +4560,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta return state.DoS(0, error("%s : forked chain older than last checkpoint (height %d)", __func__, nHeight)); // Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded: - if (block.nVersion < 2 && - CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority())) { + if (block.nVersion < 2 && CBlockIndex::IsSuperMajority(2, pindexPrev, Params().RejectBlockOutdatedMajority())) { return state.Invalid(error("%s : rejected nVersion=1 block", __func__), REJECT_OBSOLETE, "bad-version"); } @@ -4562,9 +4578,16 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Reject block.nVersion=6 blocks or lower when 95% (75% on testnet) of the network has upgraded: - if (block.nVersion < 7 && CBlockIndex::IsSuperMajority(7, pindexPrev, Params().RejectBlockOutdatedMajority())) { + /*if (block.nVersion < 7 && CBlockIndex::IsSuperMajority(7, 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 < 7 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME)) + { + std::string stringErr = strprintf("rejected block version %d at height %d", block.nVersion, nHeight); + return state.Invalid(false, REJECT_OBSOLETE, "bad-version", stringErr); } return true; diff --git a/src/optional.h b/src/optional.h new file mode 100644 index 0000000..1614c89 --- /dev/null +++ b/src/optional.h @@ -0,0 +1,17 @@ +// Copyright (c) 2017 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_OPTIONAL_H +#define BITCOIN_OPTIONAL_H + +#include + +//! Substitute for C++17 std::optional +template +using Optional = boost::optional; + +//! Substitute for C++17 std::nullopt +static auto& nullopt = boost::none; + +#endif // BITCOIN_OPTIONAL_H diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c34e72a..9056ea8 100755 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -9,16 +9,20 @@ #include "checkpoints.h" #include "clientversion.h" #include "consensus/validation.h" +#include "consensus/upgrades.h" #include "main.h" #include "rpcserver.h" #include "sync.h" #include "txdb.h" #include "util.h" #include "utilmoneystr.h" +#include "kernel.h" #include #include +#include "karmanodeman.h" + using namespace std; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, bool include_hex, int serialize_flags); @@ -82,6 +86,10 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) { UniValue result(UniValue::VOBJ); + int64_t KNPayment = GetKarmanodePayment(blockindex->nHeight, GetBlockValue(blockindex->nHeight)); + int64_t StakerPayment = blockindex->nMint - KNPayment; + double KNRewardPercent = floor(((double)KNPayment / (double)blockindex->nMint) * 100); + result.push_back(Pair("hash", block.GetHash().GetHex())); int confirmations = -1; // Only report confirmations if the block is on the main chain @@ -117,6 +125,16 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx if (pnext) result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex())); + result.push_back(Pair("flags", strprintf("%s", blockindex->IsProofOfStake() ? "proof-of-stake" : "proof-of-work"))); + result.push_back(Pair("nflags:", strprintf("%i", blockindex->nFlags))); + result.push_back(Pair("mint", ValueFromAmount(GetBlockValue(blockindex->nHeight)))); + + result.push_back(Pair("knReward", ValueFromAmount(KNPayment))); + result.push_back(Pair("knRewardPercent", KNRewardPercent)); + result.push_back(Pair("stakerPayment", ValueFromAmount(StakerPayment))); + result.push_back(Pair("modifier", strprintf("%16x", blockindex->nStakeModifier))); + result.push_back(Pair("modifierchecksum", strprintf("%08x", GetStakeModifierChecksum(blockindex)))); + result.push_back(Pair("moneysupply",ValueFromAmount(blockindex->nMoneySupply))); UniValue zohmcObj(UniValue::VOBJ); @@ -550,6 +568,72 @@ UniValue verifychain(const UniValue& params, bool fHelp) return fVerified; } +/** Implementation of IsSuperMajority with better feedback */ +static UniValue SoftForkMajorityDesc(int version, CBlockIndex* pindex, const Consensus::Params& consensusParams) +{ + UniValue rv(UniValue::VOBJ); + Consensus::UpgradeIndex idx; + switch(version) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + idx = Consensus::BASE_NETWORK; + break; + case 7: + idx = Consensus::UPGRADE_V3_0_BLOCKTIME; + break; + default: + rv.push_back(Pair("status", false)); + return rv; + } + rv.push_back(Pair("status", consensusParams.NetworkUpgradeActive(pindex->nHeight, idx))); + return rv; +} +static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex) +{ + const Consensus::Params& consensus = Params().GetConsensus(); + UniValue rv(UniValue::VOBJ); + rv.push_back(Pair("id", name)); + rv.push_back(Pair("version", version)); + rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, consensus))); + return rv; +} + +static UniValue NetworkUpgradeDesc(const Consensus::Params& consensusParams, Consensus::UpgradeIndex idx, int height) +{ + UniValue rv(UniValue::VOBJ); + auto upgrade = NetworkUpgradeInfo[idx]; + rv.push_back(Pair("activationheight", consensusParams.vUpgrades[idx].nActivationHeight)); + switch (NetworkUpgradeState(height, consensusParams, idx)) { + case UPGRADE_DISABLED: rv.push_back(Pair("status", "disabled")); break; + case UPGRADE_PENDING: rv.push_back(Pair("status", "pending")); break; + case UPGRADE_ACTIVE: rv.push_back(Pair("status", "active")); break; + } + rv.push_back(Pair("info", upgrade.strInfo)); + return rv; +} + +void NetworkUpgradeDescPushBack( + UniValue& networkUpgrades, + const Consensus::Params& consensusParams, + Consensus::UpgradeIndex idx, + int height) +{ + // Network upgrades with an activation height of NO_ACTIVATION_HEIGHT are + // hidden. This is used when network upgrade implementations are merged + // without specifying the activation height. + if (consensusParams.vUpgrades[idx].nActivationHeight != Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT) { + std::string name = NetworkUpgradeInfo[idx].strName; + std::replace(name.begin(), name.end(), '_', ' '); // Beautify the name + networkUpgrades.push_back(Pair( + name, + NetworkUpgradeDesc(consensusParams, idx, height))); + } +} + UniValue getblockchaininfo(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -565,12 +649,29 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" + " \"softforks\": [ (array) status of softforks in progress\n" + " {\n" + " \"id\": \"xxxx\", (string) name of softfork\n" + " \"version\": xx, (numeric) block version\n" + " \"reject\": { (object) progress toward rejecting pre-softfork blocks\n" + " \"status\": xx, (boolean) true if threshold reached\n" + " },\n" + " }, ...\n" + " ],\n" + " \"upgrades\": { (object) status of network upgrades\n" + " \"name\" : { (string) name of upgrade\n" + " \"activationheight\": xxxxxx, (numeric) block height of activation\n" + " \"status\": \"xxxx\", (string) status of upgrade\n" + " \"info\": \"xxxx\", (string) additional information about upgrade\n" + " }, ...\n" "}\n" "\nExamples:\n" + HelpExampleCli("getblockchaininfo", "") + HelpExampleRpc("getblockchaininfo", "")); LOCK(cs_main); + const Consensus::Params& consensusParams = Params().GetConsensus(); + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); @@ -579,6 +680,16 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip()))); obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); + CBlockIndex* tip = chainActive.Tip(); + UniValue softforks(UniValue::VARR); + //softforks.push_back(SoftForkDesc("blocktime", 7, tip)); + obj.push_back(Pair("softforks", softforks)); + UniValue upgrades(UniValue::VOBJ); + for (int i = Consensus::BASE_NETWORK + 1; i < (int) Consensus::MAX_NETWORK_UPGRADES; i++) { + NetworkUpgradeDescPushBack(upgrades, consensusParams, Consensus::UpgradeIndex(i), tip->nHeight); + } + obj.push_back(Pair("upgrades", upgrades)); + return obj; } From c44e2479cec1a673c2e264ef0ff5c17f9c1607a7 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 17:20:55 -0400 Subject: [PATCH 05/14] Zerocoin is not active; Actually use new block version parameter.. --- src/miner.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 1538b7a..968d307 100755 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,13 +120,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, // transaction (which in most cases can be a no-op). bool fIncludeWitness = IsSporkActive(SPORK_20_SEGWIT_ACTIVATION); - // Make sure to create the correct block version after zerocoin is enabled - bool fZerocoinActive = chainActive.Height() >= Params().Zerocoin_StartHeight(); - if (fZerocoinActive) - pblock->nVersion = 6; - else - pblock->nVersion = 5; - // Create coinbase tx CMutableTransaction txNew; txNew.vin.resize(1); From c30c07f3da744082a8f3c12bcb9f78ff9ed1e62f Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 17:23:23 -0400 Subject: [PATCH 06/14] Don't do this, zerocoin not active.. --- src/primitives/block.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/primitives/block.h b/src/primitives/block.h index 8a89a3e..57742e4 100755 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -53,8 +53,8 @@ class CBlockHeader READWRITE(nNonce); //zerocoin active, header changes to include accumulator checksum - if(nVersion > 5) - READWRITE(nAccumulatorCheckpoint); + /*if(nVersion > 5) + READWRITE(nAccumulatorCheckpoint);*/ } void SetNull() From 64b604afd63dae6547a510d108124a1cb2e50538 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 17:30:10 -0400 Subject: [PATCH 07/14] remove or fix zerocoin at some later point. --- src/miner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 968d307..6bcef24 100755 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -119,6 +119,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, // TODO: replace this with a call to main to assess validity of a mempool // transaction (which in most cases can be a no-op). bool fIncludeWitness = IsSporkActive(SPORK_20_SEGWIT_ACTIVATION); + + bool fZerocoinActive = false; // we don't have zerocoin... TODO: Remove! // Create coinbase tx CMutableTransaction txNew; From 4038bd6961b1eccc8547232ab3e31d27a5f3fa24 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 18:48:06 -0400 Subject: [PATCH 08/14] zerocoin is off. --- src/chainparams.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c5c005f..37e4f7f 100755 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -413,8 +413,6 @@ class CMainParams : public CChainParams nModifierUpdateBlock = 615800; - nZerocoinStartHeight = 999999999; - /** * Build the genesis block. Note that the output of the genesis coinbase cannot * be spent as it did not originally exist in the database. @@ -482,7 +480,7 @@ class CMainParams : public CChainParams "8441436038339044149526344321901146575444541784240209246165157233507787077498171257724679629263863563732899121548" "31438167899885040445364023527381951378636564391212010397122822120720357"; - + nZerocoinStartHeight = 999999999; nZerocoinLastOldParams = 99999999; // Updated to defer zerocoin v2 for further testing. nMaxZerocoinSpendsPerTransaction = 7; // Assume about 20kb each @@ -490,7 +488,7 @@ class CMainParams : public CChainParams nMintRequiredConfirmations = 20; //the maximum amount of confirmations until accumulated in 19 nRequiredAccumulation = 1; nDefaultSecurityLevel = 100; //full security level for accumulators - nZerocoinHeaderVersion = 6; //Block headers must be this version once zerocoin is active + nZerocoinHeaderVersion = 99; //Block headers must be this version once zerocoin is active nBudgetFeeConfirmations = 3; // Number of confirmations for the finalization fee // Network upgrades From fa039d845ac57e93aa00e76d857bd4ecc3c8f386 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 21:32:29 -0400 Subject: [PATCH 09/14] Adjust new block version update to use protocol version Prepare for removal of zercoin; refactoring.. Implement sporks to enforce new version lock ins. --- src/chainparams.cpp | 10 +++++--- src/chainparams.h | 3 --- src/consensus/params.h | 3 ++- src/consensus/upgrades.cpp | 4 +++ src/main.cpp | 52 +++++++++++++++++++------------------- src/main.h | 1 - src/miner.cpp | 13 +++++++++- src/pow.cpp | 8 +++--- src/primitives/block.h | 2 +- src/spork.h | 19 +++++++++----- src/version.h | 6 +++-- 11 files changed, 71 insertions(+), 50 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 37e4f7f..a2f0348 100755 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -406,7 +406,6 @@ class CMainParams : public CChainParams /* New Blocktime */ nTargetTimespan = 1 * 60 * 60 * 2; // OHMC New: 120 Minutes nTargetSpacing = 1 * 60 * 4; // OHMC New: 240 Seconds - nDisableLegacyTimeHeight = 2977924; // Height legacy blocktime disables /** Height or Time Based Activations **/ nLastPOWBlock = 1001; @@ -497,6 +496,9 @@ class CMainParams : public CChainParams consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nActivationHeight = 2977924; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nProtocolVersion = 71020; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKREWARD].nActivationHeight = 2977924; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKREWARD].nProtocolVersion = 71020; consensus.vUpgrades[Consensus::UPGRADE_V3_1_DUMMY].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; consensus.vUpgrades[Consensus::UPGRADE_V3_2_DUMMY].nActivationHeight = @@ -537,7 +539,6 @@ class CTestNetParams : public CMainParams /* New Blocktime */ nTargetTimespan = 1 * 60 * 60 * 1; // OHMC New: 60 Minutes nTargetSpacing = 1 * 60 * 2; // OHMC New: 120 Seconds - nDisableLegacyTimeHeight = 33001; // Height legacy blocktime disables nMaturity = 15; nKarmanodeCountDrift = 4; @@ -591,6 +592,7 @@ class CTestNetParams : public CMainParams consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nActivationHeight = 33001; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKREWARD].nActivationHeight = 33002; consensus.vUpgrades[Consensus::UPGRADE_V3_1_DUMMY].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; consensus.vUpgrades[Consensus::UPGRADE_V3_2_DUMMY].nActivationHeight = @@ -628,7 +630,6 @@ class CRegTestParams : public CTestNetParams /* New Blocktime */ nTargetTimespan = 1 * 60 * 60 * 2; // OHMC New: 120 Minutes nTargetSpacing = 1 * 60 * 4; // OHMC New: 240 Seconds - nDisableLegacyTimeHeight = 33001; // Height legacy blocktime disables bnProofOfWorkLimit = ~uint256(0) >> 1; genesis.nTime = 1454124731; genesis.nBits = 0x207fffff; @@ -666,7 +667,8 @@ class CRegTestParams : public CTestNetParams Consensus::NetworkUpgrade::ALWAYS_ACTIVE; consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; - consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nActivationHeight = 33001; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKTIME].nActivationHeight = 33002; + consensus.vUpgrades[Consensus::UPGRADE_V3_0_BLOCKREWARD].nActivationHeight = 33002; consensus.vUpgrades[Consensus::UPGRADE_V3_1_DUMMY].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; consensus.vUpgrades[Consensus::UPGRADE_V3_2_DUMMY].nActivationHeight = diff --git a/src/chainparams.h b/src/chainparams.h index 9d6d5b5..1ac49a3 100755 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -81,8 +81,6 @@ class CChainParams int64_t TargetTimespan() const { return nTargetTimespan; } int64_t TargetSpacing() const { return nTargetSpacing; } int64_t Interval() const { return nTargetTimespan / nTargetSpacing; } - /** Disable Legacy Blocktime Height */ - int DisableLegacyTimeHeight() const { return nDisableLegacyTimeHeight; } /** Majurity Checks */ int COINBASE_MATURITY() const { return nMaturity; } unsigned int StakeMaturity() const { return nStakeMaturity; } @@ -142,7 +140,6 @@ class CChainParams int64_t nTargetSpacing; int64_t nTargetTimespanLegacy; int64_t nTargetSpacingLegacy; - int nDisableLegacyTimeHeight; int nLastPOWBlock; int nKarmanodeCountDrift; int nMaturity; diff --git a/src/consensus/params.h b/src/consensus/params.h index 71001a9..5cf4b8d 100755 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -25,7 +25,8 @@ namespace Consensus { */ enum UpgradeIndex : uint32_t { BASE_NETWORK, // Base Network - UPGRADE_V3_0_BLOCKTIME, // Blocktime consensus change + UPGRADE_V3_0_BLOCKTIME, // Block time consensus change + UPGRADE_V3_0_BLOCKREWARD, // Block reward consensus change UPGRADE_V3_1_DUMMY, UPGRADE_V3_2_DUMMY, UPGRADE_TESTDUMMY, diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index 329a538..207fd48 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -22,6 +22,10 @@ const struct NUInfo NetworkUpgradeInfo[Consensus::MAX_NETWORK_UPGRADES] = { /*.strName =*/ "v3_0_blocktime", /*.strInfo =*/ "Activation of OHMC version 3.0 Block Time upgrade", }, + { + /*.strName =*/ "v3_0_blockreward", + /*.strInfo =*/ "Activation of OHMC version 3.0 Block Reward upgrade", + }, { /*.strName =*/ "v3_1_dummy", /*.strInfo =*/ "Placeholder for future OHMC version 3.1 upgrade", diff --git a/src/main.cpp b/src/main.cpp index 0e946f6..b82c7d4 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,7 +94,6 @@ bool fAddrIndex = true; bool fIsBareMultisigStd = true; bool fCheckBlockIndex = false; bool fVerifyingBlocks = false; -bool fIgnoreLegacyBlocks = false; unsigned int nCoinCacheSize = 5000; unsigned int nBytesPerSigOp = DEFAULT_BYTES_PER_SIGOP; bool fAlerts = DEFAULT_ALERTS; @@ -2175,17 +2174,18 @@ int64_t GetBlockValue(int nHeight) return 30000 * COIN; } + bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKREWARD); + if (Params().NetworkID() == CBaseChainParams::TESTNET) { if (nHeight <= 3000 && nHeight >= 1001) { return 1 * COIN; } else if (nHeight <= 33001 && nHeight >= 3001) { - if (fIgnoreLegacyBlocks) { - return 6 * COIN; - } else { - return 3.14159 * COIN; - } - } else if (nHeight >= Params().DisableLegacyTimeHeight()) { - return 6 * COIN; + return 3.14159 * COIN; + } else if (nHeight >= 33002) { + if (fUpgradeActiveV3) { + return 6 * COIN; + } + return 3 * COIN; } else { return 1 * COIN; } @@ -2202,13 +2202,12 @@ int64_t GetBlockValue(int nHeight) } else if (nHeight <= 2373122 && nHeight >= 1941122) { return 0.125 * COIN; } else if (nHeight <= 2977923 && nHeight >= 2373123) { - if (fIgnoreLegacyBlocks) { - return 6 * COIN; - } else { - return 0.0625 * COIN; - } - } else if (nHeight >= Params().DisableLegacyTimeHeight()) { - return 6 * COIN; + return 0.0625 * COIN; + } else if (nHeight >= 2373124) { + if (fUpgradeActiveV3) { + return 6 * COIN; + } + return 3 * COIN; } else { return 1 * COIN; } @@ -4577,14 +4576,10 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta REJECT_OBSOLETE, "bad-version"); } - // Reject block.nVersion=6 blocks or lower when 95% (75% on testnet) of the network has upgraded: - /*if (block.nVersion < 7 && CBlockIndex::IsSuperMajority(7, 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 < 7 && consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME)) + if ((block.nVersion < 6 && nHeight >= 1) && + (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME)) || + (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKREWARD))) { std::string stringErr = strprintf("rejected block version %d at height %d", block.nVersion, nHeight); return state.Invalid(false, REJECT_OBSOLETE, "bad-version", stringErr); @@ -4964,9 +4959,6 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, return state.Error(std::string("System error: ") + e.what()); } - /* Update storage varaible for ignoring legacy blocks (version 6 and prior) */ - fIgnoreLegacyBlocks = CBlockIndex::IsSuperMajority(7, pindex, Params().RejectBlockOutdatedMajority()); - return true; } @@ -7065,8 +7057,16 @@ int ActiveProtocol() // own ModifierUpgradeBlock() { - if (IsSporkActive(SPORK_18_NEW_PROTOCOL_ENFORCEMENT_5)) + if (IsSporkActive(SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6)) + // Enforce protocol 71025 or higher.. return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; + if (IsSporkActive(SPORK_23_NEW_BLOCKTIME_ENFORCEMENT)) + // Enforce protocol 71020 and greater. + return MIN_PEER_VERSION_ADJ_BLOCKTIME; + if (IsSporkActive(SPORK_18_NEW_PROTOCOL_ENFORCEMENT_5)) + // Enforce protocol 71011 + return MIN_PEER_MNANNOUNCE; + // Default protocol return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT; } diff --git a/src/main.h b/src/main.h index 5ffc4fc..d9c1721 100755 --- a/src/main.h +++ b/src/main.h @@ -151,7 +151,6 @@ extern unsigned int nCoinCacheSize; extern CFeeRate minRelayTxFee; extern bool fAlerts; extern bool fVerifyingBlocks; -extern bool fIgnoreLegacyBlocks; extern bool fLargeWorkForkFound; extern bool fLargeWorkInvalidChainFound; diff --git a/src/miner.cpp b/src/miner.cpp index 6bcef24..7891574 100755 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -119,9 +119,20 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, // TODO: replace this with a call to main to assess validity of a mempool // transaction (which in most cases can be a no-op). bool fIncludeWitness = IsSporkActive(SPORK_20_SEGWIT_ACTIVATION); - + + // Blocktime and Reward update. + bool fEnforceBlockTimeUpdate = IsSporkActive(SPORK_23_NEW_BLOCKTIME_ENFORCEMENT); + bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); bool fZerocoinActive = false; // we don't have zerocoin... TODO: Remove! + if (!fUpgradeActiveV3) { + pblock->nVersion = 5; + } else { + if (!fEnforceBlockTimeUpdate) { + pblock->nVersion = 6; + } + } + // Create coinbase tx CMutableTransaction txNew; txNew.vin.resize(1); diff --git a/src/pow.cpp b/src/pow.cpp index a33f463..ad31b26 100755 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -45,10 +45,10 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead int64_t nInterval = Params().IntervalLegacy(); // New time activation check - bool bVerAct = CBlockIndex::IsSuperMajority(7, pindexLast, Params().RejectBlockOutdatedMajority()); - bool bHeightReach = pindexLast->nHeight >= Params().DisableLegacyTimeHeight(); - // Actiavte on 95% upgrade threshold, or forced by block height set. - if (bVerAct || bHeightReach) { + bool fVerAct = CBlockIndex::IsSuperMajority(6, pindexLast, Params().RejectBlockOutdatedMajority()); + bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); + // Actiavte on 95% upgrade threshold, or forced by upgrade block height. + if (fVerAct || fUpgradeActiveV3) { nTargetSpacing = Params().TargetSpacing(); nTargetTimespan = Params().TargetTimespan(); nInterval = Params().Interval(); diff --git a/src/primitives/block.h b/src/primitives/block.h index 57742e4..6a07e08 100755 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -26,7 +26,7 @@ class CBlockHeader { public: // header - static const int32_t CURRENT_VERSION = 7; + static const int32_t CURRENT_VERSION = 7; // NOTE: If increment this, make sure to adjust miner.cpp !!! int32_t nVersion; uint256 hashPrevBlock; uint256 hashMerkleRoot; diff --git a/src/spork.h b/src/spork.h index 1ed895b..1e1274b 100755 --- a/src/spork.h +++ b/src/spork.h @@ -27,7 +27,7 @@ using namespace boost; Sporks 11,12, and 16 to be removed with 1st zerocoin release */ #define SPORK_START 10001 -#define SPORK_END 10021 +#define SPORK_END 10023 #define SPORK_2_SWIFTTX 10001 #define SPORK_3_SWIFTTX_BLOCK_FILTERING 10002 @@ -48,14 +48,16 @@ using namespace boost; #define SPORK_20_SEGWIT_ACTIVATION 10019 #define SPORK_21_SEGWIT_ON_COINBASE 10020 #define SPORK_22_ZEROCOIN_MAINTENANCE_MODE 10021 +#define SPORK_23_NEW_BLOCKTIME_ENFORCEMENT 10022 +#define SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6 10023 #define SPORK_2_SWIFTTX_DEFAULT 978307200 //2001-1-1 #define SPORK_3_SWIFTTX_BLOCK_FILTERING_DEFAULT 1424217600 //2015-2-18 #define SPORK_5_MAX_VALUE_DEFAULT 1000 //1000 OHMC -#define SPORK_7_KARMANODE_SCANNING_DEFAULT 978307200 //2001-1-1 -#define SPORK_8_KARMANODE_PAYMENT_ENFORCEMENT_DEFAULT 4070908800 //OFF -#define SPORK_9_KARMANODE_BUDGET_ENFORCEMENT_DEFAULT 4070908800 //OFF -#define SPORK_10_KARMANODE_PAY_UPDATED_NODES_DEFAULT 4070908800 //OFF +#define SPORK_7_KARMANODE_SCANNING_DEFAULT 978307200 //2001-1-1 +#define SPORK_8_KARMANODE_PAYMENT_ENFORCEMENT_DEFAULT 4070908800 //OFF +#define SPORK_9_KARMANODE_BUDGET_ENFORCEMENT_DEFAULT 4070908800 //OFF +#define SPORK_10_KARMANODE_PAY_UPDATED_NODES_DEFAULT 4070908800 //OFF //#define SPORK_11_LOCK_INVALID_UTXO_DEFAULT 4070908800 //OFF - NOTE: this is block height not time! #define SPORK_13_ENABLE_SUPERBLOCKS_DEFAULT 4070908800 //OFF #define SPORK_14_NEW_PROTOCOL_ENFORCEMENT_DEFAULT 4070908800 //ON @@ -66,9 +68,12 @@ using namespace boost; #define SPORK_19_MN_WINNER_MINIMUM_AGE_DEFAULT 8000 // Age in seconds. This should be > KARMANODE_REMOVAL_SECONDS to avoid // misconfigured new nodes in the list. // Set this to zero to emulate classic behaviour -#define SPORK_20_SEGWIT_ACTIVATION_DEFAULT 4070908800 //OFF -#define SPORK_21_SEGWIT_ON_COINBASE_DEFAULT 4070908800 //OFF +#define SPORK_20_SEGWIT_ACTIVATION_DEFAULT 4070908800 //OFF +#define SPORK_21_SEGWIT_ON_COINBASE_DEFAULT 4070908800 //OFF #define SPORK_22_ZEROCOIN_MAINTENANCE_MODE_DEFAULT 4070908800 //OFF +// Sporks that forces new blocktime upgrade and protocol 71020 +#define SPORK_23_NEW_BLOCKTIME_ENFORCEMENT_DEFAULT 4070908800 //OFF DEFAULT +#define SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6_DEFAULT 4070908800 //OFF DEFAULT class CSporkMessage; class CSporkManager; diff --git a/src/version.h b/src/version.h index 60a7837..863acfd 100755 --- a/src/version.h +++ b/src/version.h @@ -12,7 +12,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 71011; +static const int PROTOCOL_VERSION = 71025; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; @@ -22,7 +22,7 @@ static const int GETHEADERS_VERSION = 70077; //! disconnect from peers older than this proto version static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 71010; -static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 71011; +static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 71025; static const int MIN_PEER_VERSION_FIXED_SIGTIME = 70004; @@ -42,5 +42,7 @@ static const int MEMPOOL_GD_VERSION = 60002; //! "filter*" commands are disabled without NODE_BLOOM after and including this version static const int NO_BLOOM_VERSION = 70005; +//! In this version, the blocktime and reward structure were changed +static const int MIN_PEER_VERSION_ADJ_BLOCKTIME = 71020; #endif // BITCOIN_VERSION_H From d14646831ded9767405ad324f89d466bc5625a69 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 21:37:21 -0400 Subject: [PATCH 10/14] fix compile issues --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b82c7d4..a8af1c6 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -2174,6 +2174,7 @@ int64_t GetBlockValue(int nHeight) return 30000 * COIN; } + const Consensus::Params& consensus = Params().GetConsensus(); bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKREWARD); if (Params().NetworkID() == CBaseChainParams::TESTNET) { @@ -4578,8 +4579,8 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Reject outdated version blocks if ((block.nVersion < 6 && nHeight >= 1) && - (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME)) || - (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKREWARD))) + (consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME) || + consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKREWARD))) { std::string stringErr = strprintf("rejected block version %d at height %d", block.nVersion, nHeight); return state.Invalid(false, REJECT_OBSOLETE, "bad-version", stringErr); From 98caf9ec91ebd6f32894aa1cbc22819eee04d495 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 21:40:10 -0400 Subject: [PATCH 11/14] get height for tip --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 7891574..10cf5d8 100755 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -122,7 +122,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, // Blocktime and Reward update. bool fEnforceBlockTimeUpdate = IsSporkActive(SPORK_23_NEW_BLOCKTIME_ENFORCEMENT); - bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); + bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(chainActive.Tip()->nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); bool fZerocoinActive = false; // we don't have zerocoin... TODO: Remove! if (!fUpgradeActiveV3) { From 8d79c093096767260be44d69ecc305ba874fdb67 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 21:41:58 -0400 Subject: [PATCH 12/14] get consensus params --- src/miner.cpp | 2 +- src/pow.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 10cf5d8..bce77db 100755 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -122,7 +122,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, // Blocktime and Reward update. bool fEnforceBlockTimeUpdate = IsSporkActive(SPORK_23_NEW_BLOCKTIME_ENFORCEMENT); - bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(chainActive.Tip()->nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); + bool fUpgradeActiveV3 = Params().GetConsensus().NetworkUpgradeActive(chainActive.Tip()->nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); bool fZerocoinActive = false; // we don't have zerocoin... TODO: Remove! if (!fUpgradeActiveV3) { diff --git a/src/pow.cpp b/src/pow.cpp index ad31b26..5fccf30 100755 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -46,7 +46,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // New time activation check bool fVerAct = CBlockIndex::IsSuperMajority(6, pindexLast, Params().RejectBlockOutdatedMajority()); - bool fUpgradeActiveV3 = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); + bool fUpgradeActiveV3 = Params().GetConsensus().NetworkUpgradeActive(pindexLast->nHeight, Consensus::UPGRADE_V3_0_BLOCKTIME); // Actiavte on 95% upgrade threshold, or forced by upgrade block height. if (fVerAct || fUpgradeActiveV3) { nTargetSpacing = Params().TargetSpacing(); From 4a7b68c8c539ec88dcd815b3631c6fab6bf36c57 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 22:03:02 -0400 Subject: [PATCH 13/14] add missing spork info --- src/spork.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/spork.cpp b/src/spork.cpp index bab0550..47a4bfe 100755 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -136,6 +136,8 @@ int64_t GetSporkValue(int nSporkID) if (nSporkID == SPORK_20_SEGWIT_ACTIVATION) r = SPORK_20_SEGWIT_ACTIVATION_DEFAULT; if (nSporkID == SPORK_21_SEGWIT_ON_COINBASE) r = SPORK_21_SEGWIT_ON_COINBASE_DEFAULT; if (nSporkID == SPORK_22_ZEROCOIN_MAINTENANCE_MODE) r = SPORK_22_ZEROCOIN_MAINTENANCE_MODE_DEFAULT; + if (nSporkID == SPORK_23_NEW_BLOCKTIME_ENFORCEMENT) r = SPORK_23_NEW_BLOCKTIME_ENFORCEMENT_DEFAULT; + if (nSporkID == SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6) r = SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6_DEFAULT; if (r == -1) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID); @@ -287,6 +289,8 @@ int CSporkManager::GetSporkIDByName(std::string strName) if (strName == "SPORK_20_SEGWIT_ACTIVATION") return SPORK_20_SEGWIT_ACTIVATION; if (strName == "SPORK_21_SEGWIT_ON_COINBASE") return SPORK_21_SEGWIT_ON_COINBASE_DEFAULT; if (strName == "SPORK_22_ZEROCOIN_MAINTENANCE_MODE") return SPORK_22_ZEROCOIN_MAINTENANCE_MODE; + if (strName == "SPORK_23_NEW_BLOCKTIME_ENFORCEMENT") return SPORK_23_NEW_BLOCKTIME_ENFORCEMENT; + if (strName == "SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6") return SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6; return -1; } @@ -310,5 +314,7 @@ std::string CSporkManager::GetSporkNameByID(int id) if (id == SPORK_20_SEGWIT_ACTIVATION) return "SPORK_20_SEGWIT_ACTIVATION"; if (id == SPORK_21_SEGWIT_ON_COINBASE) return "SPORK_21_SEGWIT_ON_COINBASE"; if (id == SPORK_22_ZEROCOIN_MAINTENANCE_MODE) return "SPORK_22_ZEROCOIN_MAINTENANCE_MODE"; + if (id == SPORK_23_NEW_BLOCKTIME_ENFORCEMENT) return "SPORK_23_NEW_BLOCKTIME_ENFORCEMENT"; + if (id == SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6) return "SPORK_24_NEW_PROTOCOL_ENFORCEMENT_6"; return "Unknown"; } From 5069aebe4583b7bb7158daad9ea2e1d9ed80f37f Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 15 Aug 2020 22:32:36 -0400 Subject: [PATCH 14/14] Version 3.0.2.0 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 941a8f1..072664f 100755 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N) AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 3) define(_CLIENT_VERSION_MINOR, 0) -define(_CLIENT_VERSION_REVISION, 1) +define(_CLIENT_VERSION_REVISION, 2) define(_CLIENT_VERSION_BUILD, 0) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2020)