Skip to content

Commit

Permalink
update some exceptions and assertions
Browse files Browse the repository at this point in the history
update some exceptions and assertions
  • Loading branch information
Greg Griffith committed Jul 6, 2017
1 parent f6f02b7 commit 0906265
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 76 deletions.
8 changes: 1 addition & 7 deletions eccoin-qt.pro
Expand Up @@ -172,7 +172,7 @@ contains(USE_O3, 1) {
QMAKE_CFLAGS += -msse2
}

QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector
QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector


# Input
Expand All @@ -192,7 +192,6 @@ HEADERS += \
src/init.h \
src/key.h \
src/keystore.h \
src/limitedmap.h \
src/main.h \
src/messages.h \
src/miner.h \
Expand Down Expand Up @@ -242,9 +241,6 @@ HEADERS += \
src/util/utilexceptions.h \
src/amount.h \
src/network/subnet.h \
src/crypto/hmac_sha256.h \
src/crypto/sha256.h \
src/crypto/common.h \
src/crypto_endian.h \
src/byteswap.h \
src/noui.h \
Expand Down Expand Up @@ -280,8 +276,6 @@ SOURCES += \
src/random.cpp \
src/util/utilexceptions.cpp \
src/network/subnet.cpp \
src/crypto/hmac_sha256.cpp \
src/crypto/sha256.cpp \
src/rpc/rpcnet.cpp \
src/rpc/rpcwallet.cpp \
src/daemon.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/block.cpp
Expand Up @@ -790,7 +790,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos, const u
}
else
{
LogPrintf("Previous hash could not be found in block index, asserting false \n"); /// currently failing here
LogPrintf("Previous hash could not be found in block index, asserting false. this should never happen \n");
assert(false);
}

Expand Down
2 changes: 0 additions & 2 deletions src/init.cpp
Expand Up @@ -310,7 +310,6 @@ void Shutdown()
fTaken = true;
}
}
static bool fExit;
if (fFirstThread)
{
fShutdown = true;
Expand All @@ -327,7 +326,6 @@ void Shutdown()
ecc_threads.add_thread(exitTimeout);
MilliSleep(50);
LogPrintf("ECCoin exited\n\n");
fExit = true;
// ensure non-UI client gets exited here, but let ECCoin-Qt reach 'return 0;' in bitcoin.cpp
exit(0);
}
Expand Down
17 changes: 0 additions & 17 deletions src/messages.cpp
Expand Up @@ -167,22 +167,6 @@ struct CNodeState {
}
};


void NotifyHeaderTip() {
bool fInitialBlockDownload = false;
static CBlockIndex* pindexHeaderOld = NULL;
CBlockIndex* pindexHeader = NULL;
{
LOCK(cs_main);
pindexHeader = pindexBestHeader;

if (pindexHeader != pindexHeaderOld) {
fInitialBlockDownload = IsInitialBlockDownload();
pindexHeaderOld = pindexHeader;
}
}
}

/** Map maintaining per-node state. Requires cs_main. */
std::map<NodeId, CNodeState> mapNodeState;

Expand Down Expand Up @@ -429,7 +413,6 @@ bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, CValidatio
}
}
}
NotifyHeaderTip();
return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/messages.h
Expand Up @@ -15,7 +15,6 @@

extern unsigned char pchMessageStart[4];

void NotifyHeaderTip();
bool AlreadyHave(CTxDB& txdb, const CInv& inv);
bool ProcessMessages(CNode* pfrom);
bool SendMessages(CNode* pto, bool fSendTrickle);
Expand Down
6 changes: 5 additions & 1 deletion src/network/node.h
Expand Up @@ -334,7 +334,11 @@ class CNode
uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());
unsigned int nChecksum = 0;
memcpy(&nChecksum, &hash, sizeof(nChecksum));
assert(nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
if((nMessageStart - nHeaderStart >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum)) == false)
{
throw("checksum offset + checksum was too large, aborting message \n");
}

memcpy((char*)&vSend[nHeaderStart] + CMessageHeader::CHECKSUM_OFFSET, &nChecksum, sizeof(nChecksum));

if (fDebug) {
Expand Down
1 change: 0 additions & 1 deletion src/rpc/bitcoinrpc.cpp
Expand Up @@ -251,7 +251,6 @@ static const CRPCCommand vRPCCommands[] =
{ "getpeerinfo", &getpeerinfo, true, false },
{ "getdifficulty", &getdifficulty, true, false },
{ "getinfo", &getinfo, true, false },
{ "getsubsidy", &getsubsidy, true, false },
{ "getmininginfo", &getmininginfo, true, false },
{ "getstakinginfo", &getstakinginfo, true, false },
{ "getnewaddress", &getnewaddress, true, false },
Expand Down
1 change: 0 additions & 1 deletion src/rpc/bitcoinrpc.h
Expand Up @@ -165,7 +165,6 @@ extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fH
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getsubsidy(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getstakinginfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp);
Expand Down
26 changes: 2 additions & 24 deletions src/rpc/rpcmining.cpp
Expand Up @@ -16,28 +16,6 @@ using namespace std;

extern unsigned int nStakeTargetSpacing;

Value getsubsidy(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"getsubsidy [nTarget]\n"
"Returns proof-of-work subsidy value for the specified value of target.");

unsigned int nBits = 0;

if (params.size() != 0)
{
CBigNum bnTarget(uint256(params[0].get_str()));
nBits = bnTarget.GetCompact();
}
else
{
nBits = GetNextTargetRequired(pindexBest, false);
}

return (uint64_t)GetProofOfWorkReward(pindexBest->nHeight, 0, pindexBest->pprev);
}

Value getmininginfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
Expand All @@ -57,7 +35,7 @@ Value getmininginfo(const Array& params, bool fHelp)
diff.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
obj.push_back(Pair("difficulty", diff));

obj.push_back(Pair("blockvalue", (uint64_t)GetProofOfWorkReward(pindexBest->nHeight, 0, pindexBest->pprev)));
obj.push_back(Pair("blockvalue", (uint64_t)0));
obj.push_back(Pair("netmhashps", GetPoWMHashPS()));
obj.push_back(Pair("netstakeweight", GetPoSKernelPS()));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
Expand Down Expand Up @@ -446,7 +424,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
uint256 txHash = tx.GetHash();
setTxIndex[txHash] = i++;

if (i == 1 && tx.IsCoinBase() || tx.IsCoinStake())
if ((i == 1 && tx.IsCoinBase()) || tx.IsCoinStake())
continue;

Object entry;
Expand Down
17 changes: 1 addition & 16 deletions src/util/util.cpp
Expand Up @@ -439,6 +439,7 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg)
catch(...){
LogPrintf("exception when trying to get %s from mapMultiArgs \n", strArg.c_str());
}
return std::vector<std::string>();
}

bool ArgsManager::IsArgSet(const std::string& strArg)
Expand Down Expand Up @@ -524,22 +525,6 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message
std::string("\n\n");
}

static std::string FormatException(const std::exception* pex, const char* pszThread)
{
#ifdef WIN32
char pszModule[MAX_PATH] = "";
GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));
#else
const char* pszModule = "bitcoin";
#endif
if (pex)
return strprintf(
"EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex).name(), pex->what(), pszModule, pszThread);
else
return strprintf(
"UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
}

fs::path GetDefaultDataDir()
{
// Windows < Vista: C:\Documents and Settings\Username\Application Data\eccoin
Expand Down
6 changes: 3 additions & 3 deletions src/util/utilexceptions.cpp
Expand Up @@ -2,7 +2,7 @@
#include "util.h"


std::string FormatException(std::exception* pex, const char* pszThread)
std::string FormatException(const std::exception* pex, const char* pszThread)
{
#ifdef WIN32
char pszModule[MAX_PATH] = "";
Expand All @@ -19,7 +19,7 @@ std::string FormatException(std::exception* pex, const char* pszThread)
}


void PrintException(std::exception* pex, const char* pszThread)
void PrintException(const std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
LogPrintf("\n\n************************\n%s\n", message.c_str());
Expand All @@ -28,7 +28,7 @@ void PrintException(std::exception* pex, const char* pszThread)
throw;
}

void PrintExceptionContinue(std::exception* pex, const char* pszThread)
void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
LogPrintf("\n\n************************\n%s\n", message.c_str());
Expand Down
4 changes: 2 additions & 2 deletions src/util/utilexceptions.h
Expand Up @@ -3,7 +3,7 @@

#include <exception>

void PrintException(std::exception* pex, const char* pszThread);
void PrintExceptionContinue(std::exception* pex, const char* pszThread);
void PrintException(const std::exception *pex, const char* pszThread);
void PrintExceptionContinue(const std::exception *pex, const char* pszThread);

#endif // UTILEXCEPTIONS_H

0 comments on commit 0906265

Please sign in to comment.