From f8e5c5d56ed85679feb963d0a914905c49a972cc Mon Sep 17 00:00:00 2001 From: Nathan Marley Date: Wed, 18 Apr 2018 04:50:26 -0700 Subject: [PATCH] Simplify spork defaults by using a map (#2037) --- src/spork.cpp | 47 +++++++++++++++++++---------------------------- src/spork.h | 11 +---------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/spork.cpp b/src/spork.cpp index 817b7560f0..35ae5aa5b4 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -16,6 +16,17 @@ CSporkManager sporkManager; std::map mapSporks; +std::map mapSporkDefaults = { + {SPORK_2_INSTANTSEND_ENABLED, 0}, // ON + {SPORK_3_INSTANTSEND_BLOCK_FILTERING, 0}, // ON + {SPORK_5_INSTANTSEND_MAX_VALUE, 1000}, // 1000 Dash + {SPORK_6_NEW_SIGS, 4070908800ULL}, // OFF + {SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT, 4070908800ULL}, // OFF + {SPORK_9_SUPERBLOCKS_ENABLED, 4070908800ULL}, // OFF + {SPORK_10_MASTERNODE_PAY_UPDATED_NODES, 4070908800ULL}, // OFF + {SPORK_12_RECONSIDER_BLOCKS, 0}, // 0 BLOCKS + {SPORK_14_REQUIRE_SENTINEL_FLAG, 4070908800ULL}, // OFF +}; void CSporkManager::ProcessSpork(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman) { @@ -124,22 +135,11 @@ bool CSporkManager::IsSporkActive(int nSporkID) if(mapSporksActive.count(nSporkID)){ r = mapSporksActive[nSporkID].nValue; + } else if (mapSporkDefaults.count(nSporkID)) { + r = mapSporkDefaults[nSporkID]; } else { - switch (nSporkID) { - case SPORK_2_INSTANTSEND_ENABLED: r = SPORK_2_INSTANTSEND_ENABLED_DEFAULT; break; - case SPORK_3_INSTANTSEND_BLOCK_FILTERING: r = SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT; break; - case SPORK_5_INSTANTSEND_MAX_VALUE: r = SPORK_5_INSTANTSEND_MAX_VALUE_DEFAULT; break; - case SPORK_6_NEW_SIGS: r = SPORK_6_NEW_SIGS_DEFAULT; break; - case SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT: r = SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT; break; - case SPORK_9_SUPERBLOCKS_ENABLED: r = SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT; break; - case SPORK_10_MASTERNODE_PAY_UPDATED_NODES: r = SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT; break; - case SPORK_12_RECONSIDER_BLOCKS: r = SPORK_12_RECONSIDER_BLOCKS_DEFAULT; break; - case SPORK_14_REQUIRE_SENTINEL_FLAG: r = SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT; break; - default: - LogPrint("spork", "CSporkManager::IsSporkActive -- Unknown Spork ID %d\n", nSporkID); - r = 4070908800ULL; // 2099-1-1 i.e. off by default - break; - } + LogPrint("spork", "CSporkManager::IsSporkActive -- Unknown Spork ID %d\n", nSporkID); + r = 4070908800ULL; // 2099-1-1 i.e. off by default } return r < GetAdjustedTime(); @@ -151,21 +151,12 @@ int64_t CSporkManager::GetSporkValue(int nSporkID) if (mapSporksActive.count(nSporkID)) return mapSporksActive[nSporkID].nValue; - switch (nSporkID) { - case SPORK_2_INSTANTSEND_ENABLED: return SPORK_2_INSTANTSEND_ENABLED_DEFAULT; - case SPORK_3_INSTANTSEND_BLOCK_FILTERING: return SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT; - case SPORK_5_INSTANTSEND_MAX_VALUE: return SPORK_5_INSTANTSEND_MAX_VALUE_DEFAULT; - case SPORK_6_NEW_SIGS: return SPORK_6_NEW_SIGS_DEFAULT; - case SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT: return SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT; - case SPORK_9_SUPERBLOCKS_ENABLED: return SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT; - case SPORK_10_MASTERNODE_PAY_UPDATED_NODES: return SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT; - case SPORK_12_RECONSIDER_BLOCKS: return SPORK_12_RECONSIDER_BLOCKS_DEFAULT; - case SPORK_14_REQUIRE_SENTINEL_FLAG: return SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT; - default: - LogPrint("spork", "CSporkManager::GetSporkValue -- Unknown Spork ID %d\n", nSporkID); - return -1; + if (mapSporkDefaults.count(nSporkID)) { + return mapSporkDefaults[nSporkID]; } + LogPrint("spork", "CSporkManager::GetSporkValue -- Unknown Spork ID %d\n", nSporkID); + return -1; } int CSporkManager::GetSporkIDByName(const std::string& strName) diff --git a/src/spork.h b/src/spork.h index a7bae20294..036dd46a15 100644 --- a/src/spork.h +++ b/src/spork.h @@ -30,16 +30,7 @@ static const int SPORK_10_MASTERNODE_PAY_UPDATED_NODES = 10009; static const int SPORK_12_RECONSIDER_BLOCKS = 10011; static const int SPORK_14_REQUIRE_SENTINEL_FLAG = 10013; -static const int64_t SPORK_2_INSTANTSEND_ENABLED_DEFAULT = 0; // ON -static const int64_t SPORK_3_INSTANTSEND_BLOCK_FILTERING_DEFAULT = 0; // ON -static const int64_t SPORK_5_INSTANTSEND_MAX_VALUE_DEFAULT = 1000; // 1000 DASH -static const int64_t SPORK_6_NEW_SIGS_DEFAULT = 4070908800ULL;// OFF -static const int64_t SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT_DEFAULT = 4070908800ULL;// OFF -static const int64_t SPORK_9_SUPERBLOCKS_ENABLED_DEFAULT = 4070908800ULL;// OFF -static const int64_t SPORK_10_MASTERNODE_PAY_UPDATED_NODES_DEFAULT = 4070908800ULL;// OFF -static const int64_t SPORK_12_RECONSIDER_BLOCKS_DEFAULT = 0; // 0 BLOCKS -static const int64_t SPORK_14_REQUIRE_SENTINEL_FLAG_DEFAULT = 4070908800ULL;// OFF - +extern std::map mapSporkDefaults; extern std::map mapSporks; extern CSporkManager sporkManager;