diff --git a/src/consensus/activation.cpp b/src/consensus/activation.cpp index 06f5614610..e6c6ddb43a 100644 --- a/src/consensus/activation.cpp +++ b/src/consensus/activation.cpp @@ -1,59 +1,70 @@ // Copyright (c) 2018 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include static bool IsUAHFenabled(const Config &config, int nHeight) { return nHeight >= config.GetChainParams().GetConsensus().uahfHeight; } bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev) { if (pindexPrev == nullptr) { return false; } return IsUAHFenabled(config, pindexPrev->nHeight); } static bool IsDAAEnabled(const Config &config, int nHeight) { return nHeight >= config.GetChainParams().GetConsensus().daaHeight; } bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev) { if (pindexPrev == nullptr) { return false; } return IsDAAEnabled(config, pindexPrev->nHeight); } bool IsMagneticAnomalyEnabled(const Config &config, int32_t nHeight) { return nHeight >= config.GetChainParams().GetConsensus().magneticAnomalyHeight; } bool IsMagneticAnomalyEnabled(const Config &config, const CBlockIndex *pindexPrev) { if (pindexPrev == nullptr) { return false; } return IsMagneticAnomalyEnabled(config, pindexPrev->nHeight); } bool IsGreatWallEnabled(const Config &config, const CBlockIndex *pindexPrev) { if (pindexPrev == nullptr) { return false; } return pindexPrev->GetMedianTimePast() >= gArgs.GetArg( "-greatwallactivationtime", config.GetChainParams().GetConsensus().greatWallActivationTime); } + +bool IsGravitonEnabled(const Config &config, const CBlockIndex *pindexPrev) { + if (pindexPrev == nullptr) { + return false; + } + + return pindexPrev->GetMedianTimePast() >= + gArgs.GetArg( + "-gravitonactivationtime", + config.GetChainParams().GetConsensus().gravitonActivationTime); +} diff --git a/src/consensus/activation.h b/src/consensus/activation.h index c79ebbd02f..dd62f423ba 100644 --- a/src/consensus/activation.h +++ b/src/consensus/activation.h @@ -1,28 +1,31 @@ // Copyright (c) 2018 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_CONSENSUS_ACTIVATION_H #define BITCOIN_CONSENSUS_ACTIVATION_H #include class CBlockIndex; class Config; /** Check if UAHF has activated. */ bool IsUAHFenabled(const Config &config, const CBlockIndex *pindexPrev); /** Check if DAA HF has activated. */ bool IsDAAEnabled(const Config &config, const CBlockIndex *pindexPrev); /** Check if Nov 15, 2018 HF has activated using block height. */ bool IsMagneticAnomalyEnabled(const Config &config, int32_t nHeight); /** Check if Nov 15, 2018 HF has activated using previous block index. */ bool IsMagneticAnomalyEnabled(const Config &config, const CBlockIndex *pindexPrev); /** Check if May 15th, 2019 protocol upgrade has activated. */ bool IsGreatWallEnabled(const Config &config, const CBlockIndex *pindexPrev); +/** Check if Nov 15th, 2019 protocol upgrade has activated. */ +bool IsGravitonEnabled(const Config &config, const CBlockIndex *pindexPrev); + #endif // BITCOIN_CONSENSUS_ACTIVATION_H diff --git a/src/test/activation_tests.cpp b/src/test/activation_tests.cpp index 964e026e9f..e49bd90314 100644 --- a/src/test/activation_tests.cpp +++ b/src/test/activation_tests.cpp @@ -1,50 +1,74 @@ // Copyright (c) 2019 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include BOOST_FIXTURE_TEST_SUITE(activation_tests, BasicTestingSetup) static void SetMTP(std::array &blocks, int64_t mtp) { size_t len = blocks.size(); for (size_t i = 0; i < len; ++i) { blocks[i].nTime = mtp + (i - (len / 2)); } assert(blocks.back().GetMedianTimePast() == mtp); } BOOST_AUTO_TEST_CASE(isgreatwallenabled) { DummyConfig config; CBlockIndex prev; const auto activation = config.GetChainParams().GetConsensus().greatWallActivationTime; BOOST_CHECK(!IsGreatWallEnabled(config, nullptr)); std::array blocks; for (size_t i = 1; i < blocks.size(); ++i) { blocks[i].pprev = &blocks[i - 1]; } SetMTP(blocks, activation - 1); BOOST_CHECK(!IsGreatWallEnabled(config, &blocks.back())); SetMTP(blocks, activation); BOOST_CHECK(IsGreatWallEnabled(config, &blocks.back())); SetMTP(blocks, activation + 1); BOOST_CHECK(IsGreatWallEnabled(config, &blocks.back())); } +BOOST_AUTO_TEST_CASE(isgravitonenabled) { + DummyConfig config; + CBlockIndex prev; + + const auto activation = + config.GetChainParams().GetConsensus().gravitonActivationTime; + + BOOST_CHECK(!IsGravitonEnabled(config, nullptr)); + + std::array blocks; + for (size_t i = 1; i < blocks.size(); ++i) { + blocks[i].pprev = &blocks[i - 1]; + } + + SetMTP(blocks, activation - 1); + BOOST_CHECK(!IsGravitonEnabled(config, &blocks.back())); + + SetMTP(blocks, activation); + BOOST_CHECK(IsGravitonEnabled(config, &blocks.back())); + + SetMTP(blocks, activation + 1); + BOOST_CHECK(IsGravitonEnabled(config, &blocks.back())); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/test/lint/check-doc.py b/test/lint/check-doc.py index a4b8cdb0da..b85f69719b 100755 --- a/test/lint/check-doc.py +++ b/test/lint/check-doc.py @@ -1,89 +1,91 @@ #!/usr/bin/env python3 # Copyright (c) 2015-2016 The Bitcoin Core developers # Copyright (c) 2019 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. ''' This checks if all command line args are documented. Return value is 0 to indicate no error. Author: @MarcoFalke ''' from subprocess import check_output from pprint import PrettyPrinter import glob import re TOP_LEVEL = 'git rev-parse --show-toplevel' FOLDER_SRC = '/src/**/' FOLDER_TEST = '/src/**/test/' EXTENSIONS = ["*.c", "*.h", "*.cpp", "*.cc", "*.hpp"] REGEX_ARG = '(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\(\s*"(-[^"]+)"' REGEX_DOC = 'HelpMessageOpt\(\s*"(-[^"=]+?)(?:=|")' # list unsupported, deprecated and duplicate args as they need no documentation SET_DOC_OPTIONAL = set(['-benchmark', '-blockminsize', '-dbcrashratio', '-debugnet', '-forcecompactdb', + # TODO remove after the Nov 2019 upgrade + '-gravitonactivationtime', # TODO remove after the may 2019 fork '-greatwallactivationtime', '-h', '-help', '-parkdeepreorg', '-promiscuousmempoolflags', '-replayprotectionactivationtime', '-rpcssl', '-socks', '-tor', '-whitelistalwaysrelay']) # list false positive unknows arguments SET_FALSE_POSITIVE_UNKNOWNS = set(['-nodebug', '-zmqpubhashblock', '-zmqpubhashtx', '-zmqpubrawblock', '-zmqpubrawtx']) def main(): top_level = check_output(TOP_LEVEL, shell=True).decode().strip() source_files = [] test_files = [] for extension in EXTENSIONS: source_files += glob.glob(top_level + FOLDER_SRC + extension, recursive=True) test_files += glob.glob(top_level + FOLDER_TEST + extension, recursive=True) files = set(source_files) - set(test_files) args_used = set() args_docd = set() for file in files: with open(file, 'r') as f: content = f.read() args_used |= set(re.findall(re.compile(REGEX_ARG), content)) args_docd |= set(re.findall(re.compile(REGEX_DOC), content)) args_used |= SET_FALSE_POSITIVE_UNKNOWNS args_need_doc = args_used - args_docd - SET_DOC_OPTIONAL args_unknown = args_docd - args_used pp = PrettyPrinter() print("Args used : {}".format(len(args_used))) print("Args documented : {}".format(len(args_docd))) print("Args undocumented: {} ({} don't need documentation)".format( len(args_need_doc), len(SET_DOC_OPTIONAL))) pp.pprint(args_need_doc) print("Args unknown : {}".format(len(args_unknown))) pp.pprint(args_unknown) if __name__ == "__main__": main()