aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-03-11 17:36:21 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2014-04-25 00:33:13 +0200
commitf457347053029d6a0248036a1ffeb7127108fd6d (patch)
treeba7f669bed780bf241f58e03c3e523ef51123f24 /src
parent4765b8c11679aeb76efd9ce907a5c17661d4b018 (diff)
Split up CheckBlock in a block and header version
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp26
-rw-r--r--src/main.h1
2 files changed, 18 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7a6d4b39de..66800cc224 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2288,16 +2288,8 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
}
-bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot)
+bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW)
{
- // These are checks that are independent of context
- // that can be verified before saving an orphan block.
-
- // Size limits
- if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
- return state.DoS(100, error("CheckBlock() : size limits failed"),
- REJECT_INVALID, "bad-blk-length");
-
// Check proof of work matches claimed amount
if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits))
return state.DoS(50, error("CheckBlock() : proof of work failed"),
@@ -2308,6 +2300,22 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
return state.Invalid(error("CheckBlock() : block timestamp too far in the future"),
REJECT_INVALID, "time-too-new");
+ return true;
+}
+
+bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot)
+{
+ // These are checks that are independent of context
+ // that can be verified before saving an orphan block.
+
+ if (!CheckBlockHeader(block, state, fCheckPOW))
+ return false;
+
+ // Size limits
+ if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
+ return state.DoS(100, error("CheckBlock() : size limits failed"),
+ REJECT_INVALID, "bad-blk-length");
+
// First transaction must be coinbase, the rest must not be
if (block.vtx.empty() || !block.vtx[0].IsCoinBase())
return state.DoS(100, error("CheckBlock() : first tx is not coinbase"),
diff --git a/src/main.h b/src/main.h
index aff20d0379..8e3f1d95ce 100644
--- a/src/main.h
+++ b/src/main.h
@@ -603,6 +603,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos& pos);
// Context-independent validity checks
+bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
// Store block on disk