mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Support for error messages and a few more rejection reasons
This commit is contained in:
parent
14e7ffcc64
commit
c117d9e93a
2 changed files with 12 additions and 10 deletions
16
src/main.cpp
16
src/main.cpp
|
@ -1848,7 +1848,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
|
||||||
// an overestimation, as most will delete an existing entry or
|
// an overestimation, as most will delete an existing entry or
|
||||||
// overwrite one. Still, use a conservative safety factor of 2.
|
// overwrite one. Still, use a conservative safety factor of 2.
|
||||||
if (!CheckDiskSpace(100 * 2 * 2 * pcoinsTip->GetCacheSize()))
|
if (!CheckDiskSpace(100 * 2 * 2 * pcoinsTip->GetCacheSize()))
|
||||||
return state.Error();
|
return state.Error("out of disk space");
|
||||||
FlushBlockFile();
|
FlushBlockFile();
|
||||||
pblocktree->Sync();
|
pblocktree->Sync();
|
||||||
if (!pcoinsTip->Flush())
|
if (!pcoinsTip->Flush())
|
||||||
|
@ -1924,7 +1924,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos
|
||||||
// Check for duplicate
|
// Check for duplicate
|
||||||
uint256 hash = block.GetHash();
|
uint256 hash = block.GetHash();
|
||||||
if (mapBlockIndex.count(hash))
|
if (mapBlockIndex.count(hash))
|
||||||
return state.Invalid(error("AddToBlockIndex() : %s already exists", hash.ToString()));
|
return state.Invalid(error("AddToBlockIndex() : %s already exists", hash.ToString()), 0, "duplicate");
|
||||||
|
|
||||||
// Construct new block index object
|
// Construct new block index object
|
||||||
CBlockIndex* pindexNew = new CBlockIndex(block);
|
CBlockIndex* pindexNew = new CBlockIndex(block);
|
||||||
|
@ -2014,7 +2014,7 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return state.Error();
|
return state.Error("out of disk space");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2060,7 +2060,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return state.Error();
|
return state.Error("out of disk space");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -2138,7 +2138,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
|
||||||
// Check for duplicate
|
// Check for duplicate
|
||||||
uint256 hash = block.GetHash();
|
uint256 hash = block.GetHash();
|
||||||
if (mapBlockIndex.count(hash))
|
if (mapBlockIndex.count(hash))
|
||||||
return state.Invalid(error("AcceptBlock() : block already in mapBlockIndex"));
|
return state.Invalid(error("AcceptBlock() : block already in mapBlockIndex"), 0, "duplicate");
|
||||||
|
|
||||||
// Get prev block index
|
// Get prev block index
|
||||||
CBlockIndex* pindexPrev = NULL;
|
CBlockIndex* pindexPrev = NULL;
|
||||||
|
@ -2146,7 +2146,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
|
||||||
if (hash != Params().HashGenesisBlock()) {
|
if (hash != Params().HashGenesisBlock()) {
|
||||||
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
|
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
|
||||||
if (mi == mapBlockIndex.end())
|
if (mi == mapBlockIndex.end())
|
||||||
return state.DoS(10, error("AcceptBlock() : prev block not found"));
|
return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk");
|
||||||
pindexPrev = (*mi).second;
|
pindexPrev = (*mi).second;
|
||||||
nHeight = pindexPrev->nHeight+1;
|
nHeight = pindexPrev->nHeight+1;
|
||||||
|
|
||||||
|
@ -2269,9 +2269,9 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
|
||||||
// Check for duplicate
|
// Check for duplicate
|
||||||
uint256 hash = pblock->GetHash();
|
uint256 hash = pblock->GetHash();
|
||||||
if (mapBlockIndex.count(hash))
|
if (mapBlockIndex.count(hash))
|
||||||
return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()));
|
return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()), 0, "duplicate");
|
||||||
if (mapOrphanBlocks.count(hash))
|
if (mapOrphanBlocks.count(hash))
|
||||||
return state.Invalid(error("ProcessBlock() : already have block (orphan) %s", hash.ToString()));
|
return state.Invalid(error("ProcessBlock() : already have block (orphan) %s", hash.ToString()), 0, "duplicate");
|
||||||
|
|
||||||
// Preliminary checks
|
// Preliminary checks
|
||||||
if (!CheckBlock(*pblock, state))
|
if (!CheckBlock(*pblock, state))
|
||||||
|
|
|
@ -950,13 +950,15 @@ public:
|
||||||
unsigned char _chRejectCode=0, std::string _strRejectReason="") {
|
unsigned char _chRejectCode=0, std::string _strRejectReason="") {
|
||||||
return DoS(0, ret, _chRejectCode, _strRejectReason);
|
return DoS(0, ret, _chRejectCode, _strRejectReason);
|
||||||
}
|
}
|
||||||
bool Error() {
|
bool Error(std::string strRejectReasonIn="") {
|
||||||
|
if (mode == MODE_VALID)
|
||||||
|
strRejectReason = strRejectReasonIn;
|
||||||
mode = MODE_ERROR;
|
mode = MODE_ERROR;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool Abort(const std::string &msg) {
|
bool Abort(const std::string &msg) {
|
||||||
AbortNode(msg);
|
AbortNode(msg);
|
||||||
return Error();
|
return Error(msg);
|
||||||
}
|
}
|
||||||
bool IsValid() {
|
bool IsValid() {
|
||||||
return mode == MODE_VALID;
|
return mode == MODE_VALID;
|
||||||
|
|
Loading…
Add table
Reference in a new issue