From 1c06aa98c63fff02679d446588fad06ae8cd706f Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 7 Apr 2013 03:40:33 +0200 Subject: [PATCH] Always print full hashes (tx, block, inv) --- src/main.cpp | 58 ++++++++++++++++++++++++------------------------ src/main.h | 23 ++++++++----------- src/protocol.cpp | 7 +----- src/wallet.cpp | 6 ++--- src/wallet.h | 2 +- src/walletdb.cpp | 2 +- 6 files changed, 44 insertions(+), 54 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7f408c4d..ddf7797f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -297,7 +297,7 @@ bool AddOrphanTx(const CDataStream& vMsg) // at most 500 megabytes of orphans: if (pvMsg->size() > 5000) { - printf("ignoring large orphan tx (size: %"PRIszu", hash: %s)\n", pvMsg->size(), hash.ToString().substr(0,10).c_str()); + printf("ignoring large orphan tx (size: %"PRIszu", hash: %s)\n", pvMsg->size(), hash.ToString().c_str()); delete pvMsg; return false; } @@ -306,7 +306,7 @@ bool AddOrphanTx(const CDataStream& vMsg) BOOST_FOREACH(const CTxIn& txin, tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(make_pair(hash, pvMsg)); - printf("stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString().substr(0,10).c_str(), + printf("stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString().c_str(), mapOrphanTransactions.size()); return true; } @@ -770,7 +770,7 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fCheckIn // This is done last to help prevent CPU exhaustion denial-of-service attacks. if (!tx.CheckInputs(state, view, true, SCRIPT_VERIFY_P2SH)) { - return error("CTxMemPool::accept() : ConnectInputs failed %s", hash.ToString().substr(0,10).c_str()); + return error("CTxMemPool::accept() : ConnectInputs failed %s", hash.ToString().c_str()); } } @@ -792,7 +792,7 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fCheckIn SyncWithWallets(hash, tx, NULL, true); printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n", - hash.ToString().substr(0,10).c_str(), + hash.ToString().c_str(), mapTx.size()); return true; } @@ -1198,11 +1198,11 @@ void static InvalidChainFound(CBlockIndex* pindexNew) uiInterface.NotifyBlocksChanged(); } printf("InvalidChainFound: invalid block=%s height=%d work=%s date=%s\n", - BlockHashStr(pindexNew->GetBlockHash()).c_str(), pindexNew->nHeight, + pindexNew->GetBlockHash().ToString().c_str(), pindexNew->nHeight, pindexNew->bnChainWork.ToString().c_str(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexNew->GetBlockTime()).c_str()); printf("InvalidChainFound: current best=%s height=%d work=%s date=%s\n", - BlockHashStr(hashBestChain).c_str(), nBestHeight, bnBestChainWork.ToString().c_str(), + hashBestChain.ToString().c_str(), nBestHeight, bnBestChainWork.ToString().c_str(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexBest->GetBlockTime()).c_str()); if (pindexBest && bnBestInvalidWork > bnBestChainWork + pindexBest->GetBlockWork() * 6) printf("InvalidChainFound: Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n"); @@ -1366,7 +1366,7 @@ bool CTransaction::HaveInputs(CCoinsViewCache &inputs) const bool CScriptCheck::operator()() const { const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; if (!VerifyScript(scriptSig, scriptPubKey, *ptxTo, nIn, nFlags, nHashType)) - return error("CScriptCheck() : %s VerifySignature failed", ptxTo->GetHash().ToString().substr(0,10).c_str()); + return error("CScriptCheck() : %s VerifySignature failed", ptxTo->GetHash().ToString().c_str()); return true; } @@ -1385,7 +1385,7 @@ bool CTransaction::CheckInputs(CValidationState &state, CCoinsViewCache &inputs, // This doesn't trigger the DoS code on purpose; if it did, it would make it easier // for an attacker to attempt to split the network. if (!HaveInputs(inputs)) - return state.Invalid(error("CheckInputs() : %s inputs unavailable", GetHash().ToString().substr(0,10).c_str())); + return state.Invalid(error("CheckInputs() : %s inputs unavailable", GetHash().ToString().c_str())); // While checking, GetBestBlock() refers to the parent block. // This is also true for mempool checks. @@ -1411,12 +1411,12 @@ bool CTransaction::CheckInputs(CValidationState &state, CCoinsViewCache &inputs, } if (nValueIn < GetValueOut()) - return state.DoS(100, error("CheckInputs() : %s value in < value out", GetHash().ToString().substr(0,10).c_str())); + return state.DoS(100, error("CheckInputs() : %s value in < value out", GetHash().ToString().c_str())); // Tally transaction fees int64 nTxFee = nValueIn - GetValueOut(); if (nTxFee < 0) - return state.DoS(100, error("CheckInputs() : %s nTxFee < 0", GetHash().ToString().substr(0,10).c_str())); + return state.DoS(100, error("CheckInputs() : %s nTxFee < 0", GetHash().ToString().c_str())); nFees += nTxFee; if (!MoneyRange(nFees)) return state.DoS(100, error("CheckInputs() : nFees out of range")); @@ -1750,8 +1750,8 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) reverse(vConnect.begin(), vConnect.end()); if (vDisconnect.size() > 0) { - printf("REORGANIZE: Disconnect %"PRIszu" blocks; %s..%s\n", vDisconnect.size(), BlockHashStr(pfork->GetBlockHash()).c_str(), BlockHashStr(pindexBest->GetBlockHash()).c_str()); - printf("REORGANIZE: Connect %"PRIszu" blocks; %s..%s\n", vConnect.size(), BlockHashStr(pfork->GetBlockHash()).c_str(), BlockHashStr(pindexNew->GetBlockHash()).c_str()); + printf("REORGANIZE: Disconnect %"PRIszu" blocks; %s..\n", vDisconnect.size(), pfork->GetBlockHash().ToString().c_str()); + printf("REORGANIZE: Connect %"PRIszu" blocks; ..%s\n", vConnect.size(), pindexNew->GetBlockHash().ToString().c_str()); } // Disconnect shorter branch @@ -1762,7 +1762,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) return state.Abort(_("Failed to read block")); int64 nStart = GetTimeMicros(); if (!block.DisconnectBlock(state, pindex, view)) - return error("SetBestBlock() : DisconnectBlock %s failed", BlockHashStr(pindex->GetBlockHash()).c_str()); + return error("SetBestBlock() : DisconnectBlock %s failed", pindex->GetBlockHash().ToString().c_str()); if (fBenchmark) printf("- Disconnect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); @@ -1786,7 +1786,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) InvalidChainFound(pindexNew); InvalidBlockFound(pindex); } - return error("SetBestBlock() : ConnectBlock %s failed", BlockHashStr(pindex->GetBlockHash()).c_str()); + return error("SetBestBlock() : ConnectBlock %s failed", pindex->GetBlockHash().ToString().c_str()); } if (fBenchmark) printf("- Connect: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); @@ -1862,7 +1862,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew) nTimeBestReceived = GetTime(); nTransactionsUpdated++; printf("SetBestChain: new best=%s height=%d work=%s tx=%lu date=%s progress=%f\n", - BlockHashStr(hashBestChain).c_str(), nBestHeight, bnBestChainWork.ToString().c_str(), (unsigned long)pindexNew->nChainTx, + hashBestChain.ToString().c_str(), nBestHeight, bnBestChainWork.ToString().c_str(), (unsigned long)pindexNew->nChainTx, DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexBest->GetBlockTime()).c_str(), Checkpoints::GuessVerificationProgress(pindexBest)); @@ -1901,7 +1901,7 @@ bool CBlock::AddToBlockIndex(CValidationState &state, const CDiskBlockPos &pos) // Check for duplicate uint256 hash = GetHash(); if (mapBlockIndex.count(hash)) - return state.Invalid(error("AddToBlockIndex() : %s already exists", BlockHashStr(hash).c_str())); + return state.Invalid(error("AddToBlockIndex() : %s already exists", hash.ToString().c_str())); // Construct new block index object CBlockIndex* pindexNew = new CBlockIndex(*this); @@ -2222,9 +2222,9 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl // Check for duplicate uint256 hash = pblock->GetHash(); if (mapBlockIndex.count(hash)) - return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, BlockHashStr(hash).c_str())); + return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString().c_str())); if (mapOrphanBlocks.count(hash)) - return state.Invalid(error("ProcessBlock() : already have block (orphan) %s", BlockHashStr(hash).c_str())); + return state.Invalid(error("ProcessBlock() : already have block (orphan) %s", hash.ToString().c_str())); // Preliminary checks if (!pblock->CheckBlock(state)) @@ -2253,7 +2253,7 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl // If we don't already have its previous block, shunt it off to holding area until we get it if (pblock->hashPrevBlock != 0 && !mapBlockIndex.count(pblock->hashPrevBlock)) { - printf("ProcessBlock: ORPHAN BLOCK, prev=%s\n", BlockHashStr(pblock->hashPrevBlock).c_str()); + printf("ProcessBlock: ORPHAN BLOCK, prev=%s\n", pblock->hashPrevBlock.ToString().c_str()); // Accept orphans as long as there is a node to request its parents from if (pfrom) { @@ -2589,7 +2589,7 @@ bool static LoadBlockIndexDB() pindex = pindexPrev; } printf("LoadBlockIndexDB(): hashBestChain=%s height=%d date=%s\n", - BlockHashStr(hashBestChain).c_str(), nBestHeight, + hashBestChain.ToString().c_str(), nBestHeight, DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexBest->GetBlockTime()).c_str()); return true; @@ -3426,12 +3426,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (pindex) pindex = pindex->pnext; int nLimit = 500; - printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), BlockHashStr(hashStop).c_str(), nLimit); + printf("getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str(), nLimit); for (; pindex; pindex = pindex->pnext) { if (pindex->GetBlockHash() == hashStop) { - printf(" getblocks stopping at %d %s\n", pindex->nHeight, BlockHashStr(pindex->GetBlockHash()).c_str()); + printf(" getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); break; } pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash())); @@ -3439,7 +3439,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { // When this block is requested, we'll send an inv that'll make them // getblocks the next batch of inventory. - printf(" getblocks stopping at limit %d %s\n", pindex->nHeight, BlockHashStr(pindex->GetBlockHash()).c_str()); + printf(" getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); pfrom->hashContinue = pindex->GetBlockHash(); break; } @@ -3473,7 +3473,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end vector vHeaders; int nLimit = 2000; - printf("getheaders %d to %s\n", (pindex ? pindex->nHeight : -1), BlockHashStr(hashStop).c_str()); + printf("getheaders %d to %s\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().c_str()); for (; pindex; pindex = pindex->pnext) { vHeaders.push_back(pindex->GetBlockHeader()); @@ -3522,7 +3522,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (tx.AcceptToMemoryPool(stateDummy, true, true, &fMissingInputs2)) { - printf(" accepted orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); + printf(" accepted orphan tx %s\n", inv.hash.ToString().c_str()); RelayTransaction(tx, inv.hash, vMsg); mapAlreadyAskedFor.erase(inv); vWorkQueue.push_back(inv.hash); @@ -3532,7 +3532,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) { // invalid or too-little-fee orphan vEraseQueue.push_back(inv.hash); - printf(" removed orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str()); + printf(" removed orphan tx %s\n", inv.hash.ToString().c_str()); } } } @@ -3560,7 +3560,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) CBlock block; vRecv >> block; - printf("received block %s\n", BlockHashStr(block.GetHash()).c_str()); + printf("received block %s\n", block.GetHash().ToString().c_str()); // block.print(); CInv inv(MSG_BLOCK, block.GetHash()); @@ -4107,9 +4107,9 @@ public: void print() const { printf("COrphan(hash=%s, dPriority=%.1f, dFeePerKb=%.1f)\n", - ptx->GetHash().ToString().substr(0,10).c_str(), dPriority, dFeePerKb); + ptx->GetHash().ToString().c_str(), dPriority, dFeePerKb); BOOST_FOREACH(uint256 hash, setDependsOn) - printf(" setDependsOn %s\n", hash.ToString().substr(0,10).c_str()); + printf(" setDependsOn %s\n", hash.ToString().c_str()); } }; diff --git a/src/main.h b/src/main.h index c6bd77d3..83d98638 100644 --- a/src/main.h +++ b/src/main.h @@ -195,11 +195,6 @@ bool AbortNode(const std::string &msg); -static inline std::string BlockHashStr(const uint256& hash) -{ - return hash.ToString(); -} - bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut); struct CDiskBlockPos @@ -301,7 +296,7 @@ public: std::string ToString() const { - return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n); + return strprintf("COutPoint(%s, %u)", hash.ToString().c_str(), n); } void print() const @@ -635,7 +630,7 @@ public: { std::string str; str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%"PRIszu", vout.size=%"PRIszu", nLockTime=%u)\n", - GetHash().ToString().substr(0,10).c_str(), + GetHash().ToString().c_str(), nVersion, vin.size(), vout.size(), @@ -1472,10 +1467,10 @@ public: void print() const { printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n", - BlockHashStr(GetHash()).c_str(), + GetHash().ToString().c_str(), nVersion, - BlockHashStr(hashPrevBlock).c_str(), - hashMerkleRoot.ToString().substr(0,10).c_str(), + hashPrevBlock.ToString().c_str(), + hashMerkleRoot.ToString().c_str(), nTime, nBits, nNonce, vtx.size()); for (unsigned int i = 0; i < vtx.size(); i++) @@ -1485,7 +1480,7 @@ public: } printf(" vMerkleTree: "); for (unsigned int i = 0; i < vMerkleTree.size(); i++) - printf("%s ", vMerkleTree[i].ToString().substr(0,10).c_str()); + printf("%s ", vMerkleTree[i].ToString().c_str()); printf("\n"); } @@ -1785,8 +1780,8 @@ public: { return strprintf("CBlockIndex(pprev=%p, pnext=%p, nHeight=%d, merkle=%s, hashBlock=%s)", pprev, pnext, nHeight, - hashMerkleRoot.ToString().substr(0,10).c_str(), - BlockHashStr(GetBlockHash()).c_str()); + hashMerkleRoot.ToString().c_str(), + GetBlockHash().ToString().c_str()); } void print() const @@ -1867,7 +1862,7 @@ public: str += CBlockIndex::ToString(); str += strprintf("\n hashBlock=%s, hashPrev=%s)", GetBlockHash().ToString().c_str(), - BlockHashStr(hashPrev).c_str()); + hashPrev.ToString().c_str()); return str; } diff --git a/src/protocol.cpp b/src/protocol.cpp index 7b42f527..88bbe49a 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -142,12 +142,7 @@ const char* CInv::GetCommand() const std::string CInv::ToString() const { - if (type == MSG_BLOCK) - return strprintf("%s %s", GetCommand(), BlockHashStr(hash).c_str()); - if (type == MSG_TX) - return strprintf("%s %s", GetCommand(), hash.ToString().substr(0,10).c_str()); - - return strprintf("%s %s", GetCommand(), hash.ToString().substr(0,20).c_str()); + return strprintf("%s %s", GetCommand(), hash.ToString().c_str()); } void CInv::print() const diff --git a/src/wallet.cpp b/src/wallet.cpp index 5761b008..e150a503 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -420,7 +420,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) } else printf("AddToWallet() : found %s in block %s not in index\n", - wtxIn.GetHash().ToString().substr(0,10).c_str(), + wtxIn.GetHash().ToString().c_str(), wtxIn.hashBlock.ToString().c_str()); } } @@ -449,7 +449,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) } //// debug print - printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().substr(0,10).c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); + printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); // Write to disk if (fInsertedNew || fUpdated) @@ -845,7 +845,7 @@ void CWalletTx::RelayWalletTransaction() { if (GetDepthInMainChain() == 0) { uint256 hash = GetHash(); - printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str()); + printf("Relaying wtx %s\n", hash.ToString().c_str()); RelayTransaction((CTransaction)*this, hash); } } diff --git a/src/wallet.h b/src/wallet.h index e750bfd8..2e007557 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -704,7 +704,7 @@ public: std::string ToString() const { - return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString().substr(0,10).c_str(), i, nDepth, FormatMoney(tx->vout[i].nValue).c_str()); + return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString().c_str(), i, nDepth, FormatMoney(tx->vout[i].nValue).c_str()); } void print() const diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 841553ea..81a21443 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -240,7 +240,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, //printf(" %12"PRI64d" %s %s %s\n", // wtx.vout[0].nValue, // DateTimeStrFormat("%Y-%m-%d %H:%M:%S", wtx.GetBlockTime()).c_str(), - // wtx.hashBlock.ToString().substr(0,20).c_str(), + // wtx.hashBlock.ToString().c_str(), // wtx.mapValue["message"].c_str()); } else if (strType == "acentry")