Add reconstruction debug logging

This commit is contained in:
Matt Corallo 2016-06-08 15:43:50 -07:00
parent 2f34a2e476
commit 56ba516727
2 changed files with 16 additions and 1 deletions

View File

@ -11,6 +11,7 @@
#include "streams.h"
#include "txmempool.h"
#include "main.h"
#include "util.h"
#include <unordered_map>
@ -72,6 +73,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
}
txn_available[lastprefilledindex] = std::make_shared<CTransaction>(cmpctblock.prefilledtxn[i].tx);
}
prefilled_count = cmpctblock.prefilledtxn.size();
// Calculate map of txids -> positions and check mempool to see what we have (or dont)
// Because well-formed cmpctblock messages will have a (relatively) uniform distribution
@ -103,11 +105,15 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
if (!have_txn[idit->second]) {
txn_available[idit->second] = it->GetSharedTx();
have_txn[idit->second] = true;
mempool_count++;
} else {
// If we find two mempool txn that match the short id, just request it.
// This should be rare enough that the extra bandwidth doesn't matter,
// but eating a round-trip due to FillBlock failure would be annoying
txn_available[idit->second].reset();
if (txn_available[idit->second]) {
txn_available[idit->second].reset();
mempool_count--;
}
}
}
// Though ideally we'd continue scanning for the two-txn-match-shortid case,
@ -117,6 +123,8 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
break;
}
LogPrint("cmpctblock", "Initialized PartiallyDownloadedBlock for block %s using a cmpctblock of size %lu\n", cmpctblock.header.GetHash().ToString(), cmpctblock.GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION));
return READ_STATUS_OK;
}
@ -154,5 +162,11 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
return READ_STATUS_INVALID;
}
LogPrint("cmpctblock", "Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool and %lu txn requested\n", header.GetHash().ToString(), prefilled_count, mempool_count, vtx_missing.size());
if (vtx_missing.size() < 5) {
for(const CTransaction& tx : vtx_missing)
LogPrint("cmpctblock", "Reconstructed block %s required tx %s\n", header.GetHash().ToString(), tx.GetHash().ToString());
}
return READ_STATUS_OK;
}

View File

@ -192,6 +192,7 @@ public:
class PartiallyDownloadedBlock {
protected:
std::vector<std::shared_ptr<const CTransaction> > txn_available;
size_t prefilled_count = 0, mempool_count = 0;
CTxMemPool* pool;
public:
CBlockHeader header;