From 662d01733df6c7995acaf463d0e09b0f988182f9 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Wed, 11 Feb 2015 21:05:09 -0700 Subject: [PATCH] added spork for resolving forks --- configure.ac | 2 +- src/clientversion.h | 2 +- src/main.cpp | 19 +++++++++++++------ src/main.h | 3 +++ src/spork.cpp | 19 +++++++++++++++---- src/spork.h | 7 +++++-- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 3b0fb5cd3..62d4713d9 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 11) define(_CLIENT_VERSION_REVISION, 1) -define(_CLIENT_VERSION_BUILD, 21) +define(_CLIENT_VERSION_BUILD, 22) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2015) AC_INIT([Darkcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@darkcoin.io],[darkcoin]) diff --git a/src/clientversion.h b/src/clientversion.h index 9da6bccd0..89c544a46 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -12,7 +12,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 11 #define CLIENT_VERSION_REVISION 1 -#define CLIENT_VERSION_BUILD 21 +#define CLIENT_VERSION_BUILD 22 diff --git a/src/main.cpp b/src/main.cpp index a0785c7f0..3e052f963 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2473,6 +2473,19 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew) { return true; } +bool DisconnectBlocksAndReprocess(int blocks) +{ + LOCK(cs_main); + + CValidationState state; + + LogPrintf("DisconnectBlocksAndReprocess: Got command to replay %d blocks", blocks); + for(int i = 0; i <= blocks; i++) + DisconnectTip(state); + + return true; +} + /* DisconnectBlockAndInputs @@ -3187,12 +3200,6 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl // Ask this guy to fill in what we're missing PushGetBlocks(pfrom, chainActive.Tip(), GetOrphanRoot(hash)); - - // Move backwards to tigger reprocessing both chains - if(fLargeWorkForkFound || fLargeWorkInvalidChainFound || IsSporkActive(SPORK_4_RECONVERGE)){ - CValidationState state; - DisconnectTip(state); - } } return true; } diff --git a/src/main.h b/src/main.h index 411b0d38a..27bbea817 100644 --- a/src/main.h +++ b/src/main.h @@ -613,6 +613,9 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex /** Find a conflicting transcation in a block and disconnect all up to that point **/ bool DisconnectBlockAndInputs(CValidationState &state, CTransaction txLock); +// reprocess a number of blocks to try and get on the correct chain again +bool DisconnectBlocksAndReprocess(int blocks); + // Apply the effects of this block (with given index) on the UTXO set represented by coins bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false); diff --git a/src/spork.cpp b/src/spork.cpp index 06dafa851..7dfd43327 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -10,6 +10,7 @@ #include "base58.h" #include "protocol.h" #include "spork.h" +#include "main.h" #include using namespace std; @@ -57,6 +58,8 @@ void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) mapSporksActive[spork.nSporkID] = spork; sporkManager.Relay(spork); + //does a task if needed + ExecuteSpork(spork.nSporkID, spork.nValue); } if (strCommand == "getsporks") { @@ -81,8 +84,8 @@ bool IsSporkActive(int nSporkID) if(nSporkID == SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT) r = SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT_DEFAULT; if(nSporkID == SPORK_2_INSTANTX) r = SPORK_2_INSTANTX_DEFAULT; if(nSporkID == SPORK_3_INSTANTX_BLOCK_FILTERING) r = SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT; - if(nSporkID == SPORK_4_RECONVERGE) r = SPORK_4_RECONVERGE_DEFAULT; if(nSporkID == SPORK_5_MAX_VALUE) r = SPORK_5_MAX_VALUE_DEFAULT; + if(nSporkID == SPORK_6_REPLAY_BLOCKS) r = SPORK_6_REPLAY_BLOCKS_DEFAULT; if(r == 0) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID); } @@ -102,8 +105,8 @@ int GetSporkValue(int nSporkID) if(nSporkID == SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT) r = SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT_DEFAULT; if(nSporkID == SPORK_2_INSTANTX) r = SPORK_2_INSTANTX_DEFAULT; if(nSporkID == SPORK_3_INSTANTX_BLOCK_FILTERING) r = SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT; - if(nSporkID == SPORK_4_RECONVERGE) r = SPORK_4_RECONVERGE_DEFAULT; if(nSporkID == SPORK_5_MAX_VALUE) r = SPORK_5_MAX_VALUE_DEFAULT; + if(nSporkID == SPORK_6_REPLAY_BLOCKS) r = SPORK_6_REPLAY_BLOCKS_DEFAULT; if(r == 0) LogPrintf("GetSpork::Unknown Spork %d\n", nSporkID); } @@ -111,6 +114,14 @@ int GetSporkValue(int nSporkID) return r; } +void ExecuteSpork(int nSporkID, int nValue) +{ + //replay and process blocks (to sync to the longest chain after disabling sporks) + if(nSporkID == SPORK_6_REPLAY_BLOCKS){ + DisconnectBlocksAndReprocess(nValue); + } +} + bool CSporkManager::CheckSignature(CSporkMessage& spork) { @@ -206,8 +217,8 @@ int CSporkManager::GetSporkIDByName(std::string strName) if(strName == "SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT") return SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT; if(strName == "SPORK_2_INSTANTX") return SPORK_2_INSTANTX; if(strName == "SPORK_3_INSTANTX_BLOCK_FILTERING") return SPORK_3_INSTANTX_BLOCK_FILTERING; - if(strName == "SPORK_4_RECONVERGE") return SPORK_4_RECONVERGE; if(strName == "SPORK_5_MAX_VALUE") return SPORK_5_MAX_VALUE; + if(strName == "SPORK_6_REPLAY_BLOCKS") return SPORK_6_REPLAY_BLOCKS; return -1; } @@ -217,8 +228,8 @@ std::string CSporkManager::GetSporkNameByID(int id) if(id == SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT) return "SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT"; if(id == SPORK_2_INSTANTX) return "SPORK_2_INSTANTX"; if(id == SPORK_3_INSTANTX_BLOCK_FILTERING) return "SPORK_3_INSTANTX_BLOCK_FILTERING"; - if(id == SPORK_4_RECONVERGE) return "SPORK_4_RECONVERGE"; if(id == SPORK_5_MAX_VALUE) return "SPORK_5_MAX_VALUE"; + if(id == SPORK_6_REPLAY_BLOCKS) return "SPORK_6_REPLAY_BLOCKS"; return "Unknown"; } \ No newline at end of file diff --git a/src/spork.h b/src/spork.h index 7c991560e..2467f2434 100644 --- a/src/spork.h +++ b/src/spork.h @@ -22,14 +22,16 @@ using namespace boost; #define SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT 10000 #define SPORK_2_INSTANTX 10001 #define SPORK_3_INSTANTX_BLOCK_FILTERING 10002 -#define SPORK_4_RECONVERGE 10003 +#define SPORK_4_NOTUSED 10003 #define SPORK_5_MAX_VALUE 10004 +#define SPORK_6_REPLAY_BLOCKS 10005 #define SPORK_1_MASTERNODE_PAYMENTS_ENFORCEMENT_DEFAULT 1424217600 //2015-2-18 #define SPORK_2_INSTANTX_DEFAULT 978307200 //2001-1-1 #define SPORK_3_INSTANTX_BLOCK_FILTERING_DEFAULT 1424217600 //2015-2-18 -#define SPORK_4_RECONVERGE_DEFAULT 4070908800 //2099-1-1 +#define SPORK_4_RECONVERGE_DEFAULT 1420070400 //2047-1-1 #define SPORK_5_MAX_VALUE_DEFAULT 1000 //1000 DRK +#define SPORK_6_REPLAY_BLOCKS_DEFAULT 0 class CSporkMessage; class CSporkManager; @@ -52,6 +54,7 @@ extern CSporkManager sporkManager; void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); int GetSporkValue(int nSporkID); bool IsSporkActive(int nSporkID); +void ExecuteSpork(int nSporkID, int nValue); // // Spork Class