Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,571 Lines • ▼ Show 20 Lines | static bool FindUndoPos(CValidationState &state, int nFile, FlatFilePos &pos, | ||||
unsigned int nAddSize); | unsigned int nAddSize); | ||||
static bool WriteUndoDataForBlock(const CBlockUndo &blockundo, | static bool WriteUndoDataForBlock(const CBlockUndo &blockundo, | ||||
CValidationState &state, CBlockIndex *pindex, | CValidationState &state, CBlockIndex *pindex, | ||||
const CChainParams &chainparams) { | const CChainParams &chainparams) { | ||||
// Write undo information to disk | // Write undo information to disk | ||||
if (pindex->GetUndoPos().IsNull()) { | if (pindex->GetUndoPos().IsNull()) { | ||||
FlatFilePos _pos; | FlatFilePos _pos; | ||||
if (!FindUndoPos( | if (!FindUndoPos(state, pindex->nFile, _pos, | ||||
state, pindex->nFile, _pos, | ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) { | ||||
::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40)) { | |||||
return error("ConnectBlock(): FindUndoPos failed"); | return error("ConnectBlock(): FindUndoPos failed"); | ||||
} | } | ||||
if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), | if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), | ||||
chainparams.DiskMagic())) { | chainparams.DiskMagic())) { | ||||
return AbortNode(state, "Failed to write undo data"); | return AbortNode(state, "Failed to write undo data"); | ||||
} | } | ||||
// update nUndoPos in block index | // update nUndoPos in block index | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | bool CChainState::ConnectBlock(const CBlock &block, CValidationState &state, | ||||
std::vector<int> prevheights; | std::vector<int> prevheights; | ||||
Amount nFees = Amount::zero(); | Amount nFees = Amount::zero(); | ||||
int nInputs = 0; | int nInputs = 0; | ||||
// Sigops counting. We need to do it again because of P2SH. | // Sigops counting. We need to do it again because of P2SH. | ||||
uint64_t nSigOpsCount = 0; | uint64_t nSigOpsCount = 0; | ||||
const uint64_t currentBlockSize = | const uint64_t currentBlockSize = | ||||
::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); | ::GetSerializeSize(block, PROTOCOL_VERSION); | ||||
const uint64_t nMaxSigOpsCount = GetMaxBlockSigOpsCount(currentBlockSize); | const uint64_t nMaxSigOpsCount = GetMaxBlockSigOpsCount(currentBlockSize); | ||||
blockundo.vtxundo.reserve(block.vtx.size() - 1); | blockundo.vtxundo.reserve(block.vtx.size() - 1); | ||||
for (const auto &ptx : block.vtx) { | for (const auto &ptx : block.vtx) { | ||||
const CTransaction &tx = *ptx; | const CTransaction &tx = *ptx; | ||||
nInputs += tx.vin.size(); | nInputs += tx.vin.size(); | ||||
▲ Show 20 Lines • Show All 1,664 Lines • ▼ Show 20 Lines | bool CheckBlock(const CBlock &block, CValidationState &state, | ||||
auto nMaxBlockSize = validationOptions.getExcessiveBlockSize(); | auto nMaxBlockSize = validationOptions.getExcessiveBlockSize(); | ||||
// Bail early if there is no way this block is of reasonable size. | // Bail early if there is no way this block is of reasonable size. | ||||
if ((block.vtx.size() * MIN_TRANSACTION_SIZE) > nMaxBlockSize) { | if ((block.vtx.size() * MIN_TRANSACTION_SIZE) > nMaxBlockSize) { | ||||
return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, | return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, | ||||
"size limits failed"); | "size limits failed"); | ||||
} | } | ||||
auto currentBlockSize = | auto currentBlockSize = ::GetSerializeSize(block, PROTOCOL_VERSION); | ||||
::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); | |||||
if (currentBlockSize > nMaxBlockSize) { | if (currentBlockSize > nMaxBlockSize) { | ||||
return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, | return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, | ||||
"size limits failed"); | "size limits failed"); | ||||
} | } | ||||
// And a valid coinbase. | // And a valid coinbase. | ||||
if (!CheckCoinbase(*block.vtx[0], state)) { | if (!CheckCoinbase(*block.vtx[0], state)) { | ||||
return state.Invalid(false, state.GetRejectCode(), | return state.Invalid(false, state.GetRejectCode(), | ||||
▲ Show 20 Lines • Show All 390 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Store block on disk. If dbp is non-nullptr, the file is known to already | * Store block on disk. If dbp is non-nullptr, the file is known to already | ||||
* reside on disk. | * reside on disk. | ||||
*/ | */ | ||||
static FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight, | static FlatFilePos SaveBlockToDisk(const CBlock &block, int nHeight, | ||||
const CChainParams &chainparams, | const CChainParams &chainparams, | ||||
const FlatFilePos *dbp) { | const FlatFilePos *dbp) { | ||||
unsigned int nBlockSize = | unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION); | ||||
::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); | |||||
FlatFilePos blockPos; | FlatFilePos blockPos; | ||||
if (dbp != nullptr) { | if (dbp != nullptr) { | ||||
blockPos = *dbp; | blockPos = *dbp; | ||||
} | } | ||||
if (!FindBlockPos(blockPos, nBlockSize + 8, nHeight, block.GetBlockTime(), | if (!FindBlockPos(blockPos, nBlockSize + 8, nHeight, block.GetBlockTime(), | ||||
dbp != nullptr)) { | dbp != nullptr)) { | ||||
error("%s: FindBlockPos failed", __func__); | error("%s: FindBlockPos failed", __func__); | ||||
return FlatFilePos(); | return FlatFilePos(); | ||||
▲ Show 20 Lines • Show All 1,827 Lines • Show Last 20 Lines |