Browse Source

Merge pull request #2778 from jgarzik/rpc-verifydb

RPC: add 'verifychain' to verify chain database at runtime
miguelfreitas
Jeff Garzik 12 years ago
parent
commit
4be2aba302
  1. 3
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 3
      src/init.cpp
  4. 7
      src/main.cpp
  5. 2
      src/main.h
  6. 16
      src/rpcblockchain.cpp

3
src/bitcoinrpc.cpp

@ -254,6 +254,7 @@ static const CRPCCommand vRPCCommands[] =
{ "gettxout", &gettxout, true, false }, { "gettxout", &gettxout, true, false },
{ "lockunspent", &lockunspent, false, false }, { "lockunspent", &lockunspent, false, false },
{ "listlockunspent", &listlockunspent, false, false }, { "listlockunspent", &listlockunspent, false, false },
{ "verifychain", &verifychain, true, false },
}; };
CRPCTable::CRPCTable() CRPCTable::CRPCTable()
@ -1194,6 +1195,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "lockunspent" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "lockunspent" && n > 0) ConvertTo<bool>(params[0]);
if (strMethod == "lockunspent" && n > 1) ConvertTo<Array>(params[1]); if (strMethod == "lockunspent" && n > 1) ConvertTo<Array>(params[1]);
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]); if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]);
return params; return params;
} }

1
src/bitcoinrpc.h

@ -205,5 +205,6 @@ extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fH
extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp);
#endif #endif

3
src/init.cpp

@ -763,7 +763,8 @@ bool AppInit2(boost::thread_group& threadGroup)
} }
uiInterface.InitMessage(_("Verifying blocks...")); uiInterface.InitMessage(_("Verifying blocks..."));
if (!VerifyDB()) { if (!VerifyDB(GetArg("-checklevel", 3),
GetArg( "-checkblocks", 288))) {
strLoadError = _("Corrupted block database detected"); strLoadError = _("Corrupted block database detected");
break; break;
} }

7
src/main.cpp

@ -2686,14 +2686,13 @@ bool static LoadBlockIndexDB()
return true; return true;
} }
bool VerifyDB() { bool VerifyDB(int nCheckLevel, int nCheckDepth)
{
if (pindexBest == NULL || pindexBest->pprev == NULL) if (pindexBest == NULL || pindexBest->pprev == NULL)
return true; return true;
// Verify blocks in the best chain // Verify blocks in the best chain
int nCheckLevel = GetArg("-checklevel", 3); if (nCheckDepth <= 0)
int nCheckDepth = GetArg( "-checkblocks", 288);
if (nCheckDepth == 0)
nCheckDepth = 1000000000; // suffices until the year 19000 nCheckDepth = 1000000000; // suffices until the year 19000
if (nCheckDepth > nBestHeight) if (nCheckDepth > nBestHeight)
nCheckDepth = nBestHeight; nCheckDepth = nBestHeight;

2
src/main.h

@ -146,7 +146,7 @@ bool LoadBlockIndex();
/** Unload database information */ /** Unload database information */
void UnloadBlockIndex(); void UnloadBlockIndex();
/** Verify consistency of the block and coin databases */ /** Verify consistency of the block and coin databases */
bool VerifyDB(); bool VerifyDB(int nCheckLevel, int nCheckDepth);
/** Print the loaded block tree */ /** Print the loaded block tree */
void PrintBlockTree(); void PrintBlockTree();
/** Find a block by height in the currently-connected chain */ /** Find a block by height in the currently-connected chain */

16
src/rpcblockchain.cpp

@ -243,4 +243,20 @@ Value gettxout(const Array& params, bool fHelp)
return ret; return ret;
} }
Value verifychain(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
"verifychain [check level] [num blocks]\n"
"Verifies blockchain database.");
int nCheckLevel = GetArg("-checklevel", 3);
int nCheckDepth = GetArg("-checkblocks", 288);
if (params.size() > 0)
nCheckLevel = params[0].get_int();
if (params.size() > 1)
nCheckDepth = params[1].get_int();
return VerifyDB(nCheckLevel, nCheckDepth);
}

Loading…
Cancel
Save