Browse Source

Rename ProcessBlock to ProcessNewBlock to indicate change of behaviour, and document it

0.10
Luke Dashjr 10 years ago
parent
commit
1bea2bbddc
  1. 14
      src/main.cpp
  2. 12
      src/main.h
  3. 4
      src/miner.cpp
  4. 2
      src/rpcmining.cpp
  5. 2
      src/test/miner_tests.cpp

14
src/main.cpp

@ -2524,7 +2524,7 @@ void CBlockIndex::BuildSkip() @@ -2524,7 +2524,7 @@ void CBlockIndex::BuildSkip()
pskip = pprev->GetAncestor(GetSkipHeight(nHeight));
}
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp)
bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp)
{
// Preliminary checks
bool checked = CheckBlock(*pblock, state);
@ -2533,7 +2533,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl @@ -2533,7 +2533,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
LOCK(cs_main);
MarkBlockAsReceived(pblock->GetHash());
if (!checked) {
return error("ProcessBlock() : CheckBlock FAILED");
return error("%s : CheckBlock FAILED", __func__);
}
// Store to disk
@ -2543,11 +2543,11 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl @@ -2543,11 +2543,11 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
mapBlockSource[pindex->GetBlockHash()] = pfrom->GetId();
}
if (!ret)
return error("ProcessBlock() : AcceptBlock FAILED");
return error("%s : AcceptBlock FAILED", __func__);
}
if (!ActivateBestChain(state, pblock))
return error("ProcessBlock() : ActivateBestChain failed");
return error("%s : ActivateBestChain failed", __func__);
return true;
}
@ -3145,7 +3145,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) @@ -3145,7 +3145,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
// process in case the block isn't known yet
if (mapBlockIndex.count(hash) == 0) {
CValidationState state;
if (ProcessBlock(state, NULL, &block, dbp))
if (ProcessNewBlock(state, NULL, &block, dbp))
nLoaded++;
if (state.IsError())
break;
@ -3165,7 +3165,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) @@ -3165,7 +3165,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
head.ToString());
CValidationState dummy;
if (ProcessBlock(dummy, NULL, &block, &it->second))
if (ProcessNewBlock(dummy, NULL, &block, &it->second))
{
nLoaded++;
queue.push_back(block.GetHash());
@ -3943,7 +3943,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, @@ -3943,7 +3943,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pfrom->AddInventoryKnown(inv);
CValidationState state;
ProcessBlock(state, pfrom, &block);
ProcessNewBlock(state, pfrom, &block);
int nDoS;
if (state.IsInvalid(nDoS)) {
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),

12
src/main.h

@ -148,8 +148,16 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals); @@ -148,8 +148,16 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals);
/** Unregister a network node */
void UnregisterNodeSignals(CNodeSignals& nodeSignals);
/** Process an incoming block */
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL);
/** Process an incoming block. This only returns after the best known valid
block is made active. Note that it does not, however, guarantee that the
specific block passed to it has been checked for validity!
@param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state iff pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface - this will have its BlockChecked method called whenever *any* block completes validation.
@param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid.
@param[in] pblock The block we want to process.
@param[out] dbp If pblock is stored to disk (or already there), this will be set to its location.
@return True if state.IsValid()
*/
bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL);
/** Check whether enough disk space is available for an incoming block */
bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
/** Open a block file (blk?????.dat) */

4
src/miner.cpp

@ -425,8 +425,8 @@ bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) @@ -425,8 +425,8 @@ bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
// Process this block the same as if we had received it from another node
CValidationState state;
if (!ProcessBlock(state, NULL, pblock))
return error("BitcoinMiner : ProcessBlock, block not accepted");
if (!ProcessNewBlock(state, NULL, pblock))
return error("BitcoinMiner : ProcessNewBlock, block not accepted");
return true;
}

2
src/rpcmining.cpp

@ -578,7 +578,7 @@ Value submitblock(const Array& params, bool fHelp) @@ -578,7 +578,7 @@ Value submitblock(const Array& params, bool fHelp)
CValidationState state;
submitblock_StateCatcher sc(pblock.GetHash());
RegisterValidationInterface(&sc);
bool fAccepted = ProcessBlock(state, NULL, &pblock);
bool fAccepted = ProcessNewBlock(state, NULL, &pblock);
UnregisterValidationInterface(&sc);
if (fAccepted)
{

2
src/test/miner_tests.cpp

@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
pblock->nNonce = blockinfo[i].nonce;
CValidationState state;
BOOST_CHECK(ProcessBlock(state, NULL, pblock));
BOOST_CHECK(ProcessNewBlock(state, NULL, pblock));
BOOST_CHECK(state.IsValid());
pblock->hashPrevBlock = pblock->GetHash();
}

Loading…
Cancel
Save