Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show All 16 Lines | |||||
#include <consensus/consensus.h> | #include <consensus/consensus.h> | ||||
#include <consensus/merkle.h> | #include <consensus/merkle.h> | ||||
#include <consensus/tx_verify.h> | #include <consensus/tx_verify.h> | ||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <flatfile.h> | #include <flatfile.h> | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <index/txindex.h> | #include <index/txindex.h> | ||||
#include <minerfund.h> | |||||
#include <policy/fees.h> | #include <policy/fees.h> | ||||
#include <policy/mempool.h> | #include <policy/mempool.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <pow.h> | #include <pow.h> | ||||
#include <primitives/block.h> | #include <primitives/block.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <reverse_iterator.h> | #include <reverse_iterator.h> | ||||
Show All 17 Lines | |||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <boost/thread.hpp> // boost::this_thread::interruption_point() (mingw) | #include <boost/thread.hpp> // boost::this_thread::interruption_point() (mingw) | ||||
#include <atomic> | #include <atomic> | ||||
#include <future> | #include <future> | ||||
#include <sstream> | #include <sstream> | ||||
#include <thread> | #include <thread> | ||||
#include <core_io.h> // For debugging | |||||
#include <key_io.h> // For debugging | |||||
#define MICRO 0.000001 | #define MICRO 0.000001 | ||||
#define MILLI 0.001 | #define MILLI 0.001 | ||||
class ConnectTrace; | class ConnectTrace; | ||||
/** | /** | ||||
* CChainState stores and provides an API to update our local knowledge of the | * CChainState stores and provides an API to update our local knowledge of the | ||||
* current best chain and header tree. | * current best chain and header tree. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 1,963 Lines • ▼ Show 20 Lines | bool CChainState::ConnectBlock(const CBlock &block, CValidationState &state, | ||||
if (block.vtx[0]->GetValueOut() > blockReward) { | if (block.vtx[0]->GetValueOut() > blockReward) { | ||||
return state.DoS(100, | return state.DoS(100, | ||||
error("ConnectBlock(): coinbase pays too much " | error("ConnectBlock(): coinbase pays too much " | ||||
"(actual=%d vs limit=%d)", | "(actual=%d vs limit=%d)", | ||||
block.vtx[0]->GetValueOut(), blockReward), | block.vtx[0]->GetValueOut(), blockReward), | ||||
REJECT_INVALID, "bad-cb-amount"); | REJECT_INVALID, "bad-cb-amount"); | ||||
} | } | ||||
const std::vector<CTxDestination> whitelist = | |||||
GetMinerFundWhitelist(consensusParams, pindex->pprev); | |||||
if (!whitelist.empty()) { | |||||
const Amount required = blockReward / MINER_FUND_RATIO; | |||||
for (auto &o : block.vtx[0]->vout) { | |||||
if (o.nValue < required) { | |||||
// This output doesn't qualify because its amount is too low. | |||||
continue; | |||||
} | |||||
CTxDestination address; | |||||
if (!ExtractDestination(o.scriptPubKey, address)) { | |||||
// Cannot decode address. | |||||
continue; | |||||
} | |||||
if (std::find(whitelist.begin(), whitelist.end(), address) != | |||||
whitelist.end()) { | |||||
goto MinerFundSuccess; | |||||
} | |||||
} | |||||
// We did not find an output that match the miner fund requirements. | |||||
return state.DoS(100, false, REJECT_INVALID, "bad-cb-minerfund"); | |||||
} | |||||
MinerFundSuccess: | |||||
if (!control.Wait()) { | if (!control.Wait()) { | ||||
return state.DoS(100, false, REJECT_INVALID, "blk-bad-inputs", false, | return state.DoS(100, false, REJECT_INVALID, "blk-bad-inputs", false, | ||||
"parallel script check failed"); | "parallel script check failed"); | ||||
} | } | ||||
int64_t nTime4 = GetTimeMicros(); | int64_t nTime4 = GetTimeMicros(); | ||||
nTimeVerify += nTime4 - nTime2; | nTimeVerify += nTime4 - nTime2; | ||||
LogPrint( | LogPrint( | ||||
▲ Show 20 Lines • Show All 3,592 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
CBlockFileInfo *GetBlockFileInfo(size_t n) { | CBlockFileInfo *GetBlockFileInfo(size_t n) { | ||||
LOCK(cs_LastBlockFile); | LOCK(cs_LastBlockFile); | ||||
return &vinfoBlockFile.at(n); | return &vinfoBlockFile.at(n); | ||||
} | } | ||||
static ThresholdState VersionBitsStateImpl(const Consensus::Params ¶ms, | |||||
Consensus::DeploymentPos pos, | |||||
const CBlockIndex *pindex) | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) { | |||||
return VersionBitsState(pindex, params, pos, versionbitscache); | |||||
} | |||||
ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, | ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, | ||||
Consensus::DeploymentPos pos) { | Consensus::DeploymentPos pos) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return VersionBitsState(chainActive.Tip(), params, pos, versionbitscache); | return VersionBitsStateImpl(params, pos, chainActive.Tip()); | ||||
} | |||||
ThresholdState VersionBitsBlockState(const Consensus::Params ¶ms, | |||||
Consensus::DeploymentPos pos, | |||||
const CBlockIndex *pindex) { | |||||
LOCK(cs_main); | |||||
return VersionBitsStateImpl(params, pos, pindex); | |||||
} | } | ||||
BIP9Stats VersionBitsTipStatistics(const Consensus::Params ¶ms, | BIP9Stats VersionBitsTipStatistics(const Consensus::Params ¶ms, | ||||
Consensus::DeploymentPos pos) { | Consensus::DeploymentPos pos) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return VersionBitsStatistics(chainActive.Tip(), params, pos); | return VersionBitsStatistics(chainActive.Tip(), params, pos); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |