Skip to content

Commit c117d9e

Browse files
committed
Support for error messages and a few more rejection reasons
1 parent 14e7ffc commit c117d9e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
18481848
// an overestimation, as most will delete an existing entry or
18491849
// overwrite one. Still, use a conservative safety factor of 2.
18501850
if (!CheckDiskSpace(100 * 2 * 2 * pcoinsTip->GetCacheSize()))
1851-
return state.Error();
1851+
return state.Error("out of disk space");
18521852
FlushBlockFile();
18531853
pblocktree->Sync();
18541854
if (!pcoinsTip->Flush())
@@ -1924,7 +1924,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos
19241924
// Check for duplicate
19251925
uint256 hash = block.GetHash();
19261926
if (mapBlockIndex.count(hash))
1927-
return state.Invalid(error("AddToBlockIndex() : %s already exists", hash.ToString()));
1927+
return state.Invalid(error("AddToBlockIndex() : %s already exists", hash.ToString()), 0, "duplicate");
19281928

19291929
// Construct new block index object
19301930
CBlockIndex* pindexNew = new CBlockIndex(block);
@@ -2014,7 +2014,7 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd
20142014
}
20152015
}
20162016
else
2017-
return state.Error();
2017+
return state.Error("out of disk space");
20182018
}
20192019
}
20202020

@@ -2060,7 +2060,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
20602060
}
20612061
}
20622062
else
2063-
return state.Error();
2063+
return state.Error("out of disk space");
20642064
}
20652065

20662066
return true;
@@ -2138,15 +2138,15 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
21382138
// Check for duplicate
21392139
uint256 hash = block.GetHash();
21402140
if (mapBlockIndex.count(hash))
2141-
return state.Invalid(error("AcceptBlock() : block already in mapBlockIndex"));
2141+
return state.Invalid(error("AcceptBlock() : block already in mapBlockIndex"), 0, "duplicate");
21422142

21432143
// Get prev block index
21442144
CBlockIndex* pindexPrev = NULL;
21452145
int nHeight = 0;
21462146
if (hash != Params().HashGenesisBlock()) {
21472147
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
21482148
if (mi == mapBlockIndex.end())
2149-
return state.DoS(10, error("AcceptBlock() : prev block not found"));
2149+
return state.DoS(10, error("AcceptBlock() : prev block not found"), 0, "bad-prevblk");
21502150
pindexPrev = (*mi).second;
21512151
nHeight = pindexPrev->nHeight+1;
21522152

@@ -2269,9 +2269,9 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
22692269
// Check for duplicate
22702270
uint256 hash = pblock->GetHash();
22712271
if (mapBlockIndex.count(hash))
2272-
return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()));
2272+
return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()), 0, "duplicate");
22732273
if (mapOrphanBlocks.count(hash))
2274-
return state.Invalid(error("ProcessBlock() : already have block (orphan) %s", hash.ToString()));
2274+
return state.Invalid(error("ProcessBlock() : already have block (orphan) %s", hash.ToString()), 0, "duplicate");
22752275

22762276
// Preliminary checks
22772277
if (!CheckBlock(*pblock, state))

src/main.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,15 @@ class CValidationState {
950950
unsigned char _chRejectCode=0, std::string _strRejectReason="") {
951951
return DoS(0, ret, _chRejectCode, _strRejectReason);
952952
}
953-
bool Error() {
953+
bool Error(std::string strRejectReasonIn="") {
954+
if (mode == MODE_VALID)
955+
strRejectReason = strRejectReasonIn;
954956
mode = MODE_ERROR;
955957
return false;
956958
}
957959
bool Abort(const std::string &msg) {
958960
AbortNode(msg);
959-
return Error();
961+
return Error(msg);
960962
}
961963
bool IsValid() {
962964
return mode == MODE_VALID;

0 commit comments

Comments
 (0)