diff --git a/src/blockvalidity.h b/src/blockvalidity.h new file mode 100644 --- /dev/null +++ b/src/blockvalidity.h @@ -0,0 +1,50 @@ +// 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_BLOCKVALIDITY_H +#define BITCOIN_BLOCKVALIDITY_H + +#include + +enum class BlockValidity : uint32_t { + /** + * Unused. + */ + UNKNOWN = 0, + + /** + * Parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, + * timestamp not in future. + */ + HEADER = 1, + + /** + * All parent headers found, difficulty matches, timestamp >= median + * previous, checkpoint. Implies all parents are also at least TREE. + */ + TREE = 2, + + /** + * Only first tx is coinbase, 2 <= coinbase input script length <= 100, + * transactions valid, no duplicate txids, sigops, size, merkle root. + * Implies all parents are at least TREE but not necessarily TRANSACTIONS. + * When all parent blocks also have TRANSACTIONS, CBlockIndex::nChainTx will + * be set. + */ + TRANSACTIONS = 3, + + /** + * Outputs do not overspend inputs, no double spends, coinbase output ok, no + * immature coinbase spends, BIP30. + * Implies all parents are also at least CHAIN. + */ + CHAIN = 4, + + /** + * Scripts & signatures ok. Implies all parents are also at least SCRIPTS. + */ + SCRIPTS = 5, +}; + +#endif diff --git a/src/chain.h b/src/chain.h --- a/src/chain.h +++ b/src/chain.h @@ -7,7 +7,9 @@ #define BITCOIN_CHAIN_H #include "arith_uint256.h" +#include "blockvalidity.h" #include "consensus/params.h" +#include "diskblockpos.h" #include "pow.h" #include "primitives/block.h" #include "tinyformat.h" @@ -30,84 +32,6 @@ */ static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME; -struct CDiskBlockPos { - int nFile; - unsigned int nPos; - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(VARINT(nFile)); - READWRITE(VARINT(nPos)); - } - - CDiskBlockPos() { SetNull(); } - - CDiskBlockPos(int nFileIn, unsigned int nPosIn) { - nFile = nFileIn; - nPos = nPosIn; - } - - friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) { - return (a.nFile == b.nFile && a.nPos == b.nPos); - } - - friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) { - return !(a == b); - } - - void SetNull() { - nFile = -1; - nPos = 0; - } - bool IsNull() const { return (nFile == -1); } - - std::string ToString() const { - return strprintf("CBlockDiskPos(nFile=%i, nPos=%i)", nFile, nPos); - } -}; - -enum class BlockValidity : uint32_t { - /** - * Unused. - */ - UNKNOWN = 0, - - /** - * Parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, - * timestamp not in future. - */ - HEADER = 1, - - /** - * All parent headers found, difficulty matches, timestamp >= median - * previous, checkpoint. Implies all parents are also at least TREE. - */ - TREE = 2, - - /** - * Only first tx is coinbase, 2 <= coinbase input script length <= 100, - * transactions valid, no duplicate txids, sigops, size, merkle root. - * Implies all parents are at least TREE but not necessarily TRANSACTIONS. - * When all parent blocks also have TRANSACTIONS, CBlockIndex::nChainTx will - * be set. - */ - TRANSACTIONS = 3, - - /** - * Outputs do not overspend inputs, no double spends, coinbase output ok, no - * immature coinbase spends, BIP30. - * Implies all parents are also at least CHAIN. - */ - CHAIN = 4, - - /** - * Scripts & signatures ok. Implies all parents are also at least SCRIPTS. - */ - SCRIPTS = 5, -}; - struct BlockStatus { private: uint32_t status; diff --git a/src/diskblockpos.h b/src/diskblockpos.h new file mode 100644 --- /dev/null +++ b/src/diskblockpos.h @@ -0,0 +1,50 @@ +// Copyright (c) 2018 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_DISKBLOCKPOS_H +#define BITCOIN_DISKBLOCKPOS_H + +#include "serialize.h" + +#include + +struct CDiskBlockPos { + int nFile; + unsigned int nPos; + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream &s, Operation ser_action) { + READWRITE(VARINT(nFile)); + READWRITE(VARINT(nPos)); + } + + CDiskBlockPos() { SetNull(); } + + CDiskBlockPos(int nFileIn, unsigned int nPosIn) { + nFile = nFileIn; + nPos = nPosIn; + } + + friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) { + return (a.nFile == b.nFile && a.nPos == b.nPos); + } + + friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) { + return !(a == b); + } + + void SetNull() { + nFile = -1; + nPos = 0; + } + bool IsNull() const { return (nFile == -1); } + + std::string ToString() const { + return strprintf("CBlockDiskPos(nFile=%i, nPos=%i)", nFile, nPos); + } +}; + +#endif // BITCOIN_DISKBLOCKPOS_H diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -17,6 +17,7 @@ #include "compat/sanity.h" #include "config.h" #include "consensus/validation.h" +#include "diskblockpos.h" #include "fs.h" #include "httprpc.h" #include "httpserver.h" diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -8,6 +8,7 @@ #include "addrman.h" #include "arith_uint256.h" #include "blockencodings.h" +#include "blockvalidity.h" #include "chainparams.h" #include "config.h" #include "consensus/validation.h" diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -5,6 +5,7 @@ #include "rpc/mining.h" #include "amount.h" +#include "blockvalidity.h" #include "chain.h" #include "chainparams.h" #include "config.h" diff --git a/src/test/blockindex_tests.cpp b/src/test/blockindex_tests.cpp --- a/src/test/blockindex_tests.cpp +++ b/src/test/blockindex_tests.cpp @@ -2,7 +2,9 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "blockvalidity.h" #include "chain.h" +#include "diskblockpos.h" #include "uint256.h" #include "test/test_bitcoin.h" diff --git a/src/test/blockstatus_tests.cpp b/src/test/blockstatus_tests.cpp --- a/src/test/blockstatus_tests.cpp +++ b/src/test/blockstatus_tests.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "blockvalidity.h" #include "chain.h" #include "test/test_bitcoin.h" diff --git a/src/txdb.h b/src/txdb.h --- a/src/txdb.h +++ b/src/txdb.h @@ -6,10 +6,11 @@ #ifndef BITCOIN_TXDB_H #define BITCOIN_TXDB_H -#include "chain.h" #include "blockfileinfo.h" +#include "chain.h" #include "coins.h" #include "dbwrapper.h" +#include "diskblockpos.h" #include #include diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -12,10 +12,11 @@ #endif #include "amount.h" -#include "chain.h" #include "blockfileinfo.h" +#include "chain.h" #include "coins.h" #include "consensus/consensus.h" +#include "diskblockpos.h" #include "fs.h" #include "protocol.h" // For CMessageHeader::MessageMagic #include "script/script_error.h" diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -8,6 +8,7 @@ #include "arith_uint256.h" #include "blockindexworkcomparator.h" +#include "blockvalidity.h" #include "chainparams.h" #include "checkpoints.h" #include "checkqueue.h" @@ -606,10 +607,10 @@ // . Defaults to the pre-defined timestamp when not set. static bool IsReplayProtectionEnabled(const Config &config, int64_t nMedianTimePast) { - return nMedianTimePast >= gArgs.GetArg("-replayprotectionactivationtime", - config.GetChainParams() - .GetConsensus() - .greatWallActivationTime); + return nMedianTimePast >= + gArgs.GetArg( + "-replayprotectionactivationtime", + config.GetChainParams().GetConsensus().greatWallActivationTime); } static bool IsReplayProtectionEnabled(const Config &config,