From e14a28cce0967110327f758066c11922af94aa5e Mon Sep 17 00:00:00 2001 From: Tranz5 Date: Fri, 7 Jul 2017 23:23:24 -0400 Subject: [PATCH] Proof of Work Limits From Block 5.6m PoW will only be accepted after a Stake block, or 10 minutes with no block From Block 6.0m PoW will only be accepted after 10 mins with no block Bump to version 1.5.3.0 and update Proto Version, will send alerts Bump back down the DB version , as LevelDB1.9 "should" work fine as a drop in with LevelDB 1.7 --- HoboNickels-qt.pro | 2 +- src/checkpoints.cpp | 5 +++-- src/checkpoints.h | 1 + src/clientversion.h | 4 ++-- src/main.cpp | 16 ++++++++++++++-- src/main.h | 13 ++++++++++++- src/rpcmining.cpp | 35 +++++++++++++++++++++++++++++++++++ src/version.h | 4 ++-- 8 files changed, 70 insertions(+), 10 deletions(-) diff --git a/HoboNickels-qt.pro b/HoboNickels-qt.pro index 57a9ef8..46694c5 100644 --- a/HoboNickels-qt.pro +++ b/HoboNickels-qt.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = HoboNickels-qt -VERSION = 1.5.2.5 +VERSION = 1.5.3.0 QT += core gui network INCLUDEPATH += src src/json src/qt DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN __NO_SYSTEM_INCLUDES diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index bc9e2c0..575d5d5 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -215,7 +215,6 @@ namespace Checkpoints // Check against synchronized checkpoint bool CheckSync(const uint256& hashBlock, const CBlockIndex* pindexPrev) { - if (fTestNet) return true; // Testnet has no checkpoints int nHeight = pindexPrev->nHeight + 1; LOCK(cs_hashSyncCheckpoint); @@ -369,7 +368,9 @@ namespace Checkpoints } // sync-checkpoint master key + const std::string CSyncCheckpoint::strMasterPubKey = "04bdd7aa319f16d2682afab4d0d807141be59caac0291802ba7467f0288eaf54db9d144f8c78231d61746bb7b5f1ef70f92c62d4b18c5488ab39118e38460304dd"; +const std::string CSyncCheckpoint::strMasterPubKeyTestNet = "04d22e393d8500b017d0d3df9ef961321df12748bbd39a9f18b4cc47002717ad4d2f0ba87d1d81b83fff61472fad51ce11677b55b4f0861b4272ca3c6b001f8b1e"; std::string CSyncCheckpoint::strMasterPrivKey = ""; @@ -377,7 +378,7 @@ std::string CSyncCheckpoint::strMasterPrivKey = ""; bool CSyncCheckpoint::CheckSignature() { CKey key; - if (!key.SetPubKey(ParseHex(CSyncCheckpoint::strMasterPubKey))) + if (!key.SetPubKey(ParseHex((fTestNet ? CSyncCheckpoint::strMasterPubKeyTestNet : CSyncCheckpoint::strMasterPubKey)))) return error("CSyncCheckpoint::CheckSignature() : SetPubKey failed"); if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig)) return error("CSyncCheckpoint::CheckSignature() : verify signature failed"); diff --git a/src/checkpoints.h b/src/checkpoints.h index da6d871..ee11a11 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -100,6 +100,7 @@ class CSyncCheckpoint : public CUnsignedSyncCheckpoint { public: static const std::string strMasterPubKey; + static const std::string strMasterPubKeyTestNet; static std::string strMasterPrivKey; std::vector vchMsg; diff --git a/src/clientversion.h b/src/clientversion.h index 6ca1329..928ea36 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -8,8 +8,8 @@ // These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it #define CLIENT_VERSION_MAJOR 1 #define CLIENT_VERSION_MINOR 5 -#define CLIENT_VERSION_REVISION 2 -#define CLIENT_VERSION_BUILD 5 +#define CLIENT_VERSION_REVISION 3 +#define CLIENT_VERSION_BUILD 0 // Set to true for release, false for prerelease or test build #define CLIENT_VERSION_IS_RELEASE true diff --git a/src/main.cpp b/src/main.cpp index 697a85c..157d57e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2359,6 +2359,18 @@ bool CBlock::AcceptBlock() CBlockIndex* pindexPrev = (*mi).second; int nHeight = pindexPrev->nHeight+1; + // Code to effectivly turn off PoW, except for emergency need. + if (IsProofOfWork() && nHeight > (fTestNet ? POW_STOP_HEIGHT_TESTNET : POW_STOP_HEIGHT) + && (GetBlockTime() - FutureDrift(pindexPrev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT))) + return DoS(10, error("AcceptBlock() : PoW is only allowed after 10 mins of no block found")); + + // Code to prevent flash mining. + if (IsProofOfWork() && nHeight > (fTestNet ? POW_LIMIT_HEIGHT_TESTNET : POW_LIMIT_HEIGHT) && pindexPrev->IsProofOfWork()) + { + if (GetBlockTime() - FutureDrift(pindexPrev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT)) + return DoS(10, error("AcceptBlock() : PoW must come afer PoS only or after 10 mins")); + } + // Check proof-of-work or proof-of-stake if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake())) return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake")); @@ -2909,11 +2921,11 @@ bool LoadBlockIndex(bool fAllowNew) { CTxDB txdb; string strPubKey = ""; - if (!txdb.ReadCheckpointPubKey(strPubKey) || strPubKey != CSyncCheckpoint::strMasterPubKey) + if (!txdb.ReadCheckpointPubKey(strPubKey) || strPubKey != (fTestNet ? CSyncCheckpoint::strMasterPubKeyTestNet : CSyncCheckpoint::strMasterPubKey)) { // write checkpoint master key to db txdb.TxnBegin(); - if (!txdb.WriteCheckpointPubKey(CSyncCheckpoint::strMasterPubKey)) + if (!txdb.WriteCheckpointPubKey((fTestNet ? CSyncCheckpoint::strMasterPubKeyTestNet : CSyncCheckpoint::strMasterPubKey))) return error("LoadBlockIndex() : failed to write new checkpoint master key to db"); if (!txdb.TxnCommit()) return error("LoadBlockIndex() : failed to commit new checkpoint master key to db"); diff --git a/src/main.h b/src/main.h index 4e2255c..09c2465 100644 --- a/src/main.h +++ b/src/main.h @@ -67,7 +67,18 @@ static const unsigned int POS_REWARD_SWITCH_TIME = 1378684800; // 9 SEP 2013 00: static const unsigned int POS_REWARD_FIX_TIME = 1383177600; // 31 OCT 2013 00:00:00 static const unsigned int POS_REWARD_FIX_TIME2 = 1383606000; // 04 Nov 2013 23:00:00 static const unsigned int VERSION1_5_SWITCH_TIME = 1421489410; // Sat, 17 Jan 2015 10:10:10 GMT -static const unsigned int VERSION1_5_SWITCH_BLOCK = 1600000; // Block 1.6 million, approx same time +static const int VERSION1_5_SWITCH_BLOCK = 1600000; // Block 1.6 million, approx same time + +static const int POW_LIMIT_HEIGHT_TESTNET = 4500; // Limit Flash PoW Mining TestNet. +static const int POW_STOP_HEIGHT_TESTNET = 4600; // Limit PoW Mining TestNet +static const int64_t POW_TIME_LIMIT_TESTNET = 60; // Time for PoW to wait to find block TestNet + +static const int POW_LIMIT_HEIGHT = 5600000 ; // Limit Flash PoW Mining. +static const int POW_STOP_HEIGHT = 6000000; // Limit PoW Mining. +static const int64_t POW_TIME_LIMIT = 60 * 10; // Time for PoW to wait to find block + + + inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index f0afc7c..092ed0e 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -73,6 +73,17 @@ Value getworkex(CWallet* pWallet, const Array& params, bool fHelp) if (IsInitialBlockDownload()) throw JSONRPCError(-10, "HoboNickels is downloading blocks..."); + // Code to effectivly turn off PoW, except for emergency need. + if (pindexBest->nHeight >= (fTestNet ? POW_STOP_HEIGHT_TESTNET : POW_STOP_HEIGHT) + && (GetAdjustedTime() - FutureDrift(pindexBest->pprev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT))) + throw JSONRPCError(RPC_MISC_ERROR, "PoW is only allowed after 10 mins of no block found"); + + // Code to prevent flash mining. + if (pindexBest->IsProofOfWork() && pindexBest->nHeight >= (fTestNet ? POW_LIMIT_HEIGHT_TESTNET : POW_LIMIT_HEIGHT)) + { + if (GetAdjustedTime() - FutureDrift(pindexBest->pprev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT)) + throw JSONRPCError(RPC_MISC_ERROR, "PoW must wait for PoS block or 10 min with no block"); + } typedef map > mapNewBlock_t; static mapNewBlock_t mapNewBlock; static vector vNewBlock; @@ -207,6 +218,18 @@ Value getwork(CWallet* pWallet, const Array& params, bool fHelp) if (IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "HoboNickels is downloading blocks..."); + // Code to effectivly turn off PoW, except for emergency need. + if (pindexBest->nHeight >= (fTestNet ? POW_STOP_HEIGHT_TESTNET : POW_STOP_HEIGHT) + && (GetAdjustedTime() - FutureDrift(pindexBest->pprev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT))) + throw JSONRPCError(RPC_MISC_ERROR, "PoW is only allowed after 10 mins of no block found"); + + // Code to prevent flash mining. + if (pindexBest->IsProofOfWork() && pindexBest->nHeight >= (fTestNet ? POW_LIMIT_HEIGHT_TESTNET : POW_LIMIT_HEIGHT)) + { + if (GetAdjustedTime() - FutureDrift(pindexBest->pprev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT)) + throw JSONRPCError(RPC_MISC_ERROR, "PoW must wait for PoS block or 10 min with no block"); + } + typedef map > mapNewBlock_t; static mapNewBlock_t mapNewBlock; // FIXME: thread safety static vector vNewBlock; @@ -352,6 +375,18 @@ Value getblocktemplate(CWallet* pWallet, const Array& params, bool fHelp) if (IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "HoboNickels is downloading blocks..."); + // Code to effectivly turn off PoW, except for emergency need. + if (pindexBest->nHeight >= (fTestNet ? POW_STOP_HEIGHT_TESTNET : POW_STOP_HEIGHT ) + && (GetAdjustedTime() - FutureDrift(pindexBest->pprev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT))) + throw JSONRPCError(RPC_MISC_ERROR, "PoW is only allowed after 10 mins of no block found"); + + // Code to prevent flash mining. + if (pindexBest->IsProofOfWork() && pindexBest->nHeight >= (fTestNet ? POW_LIMIT_HEIGHT_TESTNET : POW_LIMIT_HEIGHT)) + { + if (GetAdjustedTime() - FutureDrift(pindexBest->pprev->GetBlockTime()) < (fTestNet ? POW_TIME_LIMIT_TESTNET : POW_TIME_LIMIT)) + throw JSONRPCError(RPC_MISC_ERROR, "PoW must wait for PoS block or 10 min with no block"); + } + static CReserveKey reservekey(pWallet); // Update block diff --git a/src/version.h b/src/version.h index 8563247..a35d518 100644 --- a/src/version.h +++ b/src/version.h @@ -22,10 +22,10 @@ extern const std::string CLIENT_BUILD; extern const std::string CLIENT_DATE; // database version -static const int DATABASE_VERSION = 70600; +static const int DATABASE_VERSION = 70501; // network protocol versioning -static const int PROTOCOL_VERSION = 70007; +static const int PROTOCOL_VERSION = 70008; // intial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209;