Skip to content

Commit 56ba516

Browse files
committed
Add reconstruction debug logging
1 parent 2f34a2e commit 56ba516

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/blockencodings.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "streams.h"
1212
#include "txmempool.h"
1313
#include "main.h"
14+
#include "util.h"
1415

1516
#include <unordered_map>
1617

@@ -72,6 +73,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
7273
}
7374
txn_available[lastprefilledindex] = std::make_shared<CTransaction>(cmpctblock.prefilledtxn[i].tx);
7475
}
76+
prefilled_count = cmpctblock.prefilledtxn.size();
7577

7678
// Calculate map of txids -> positions and check mempool to see what we have (or dont)
7779
// Because well-formed cmpctblock messages will have a (relatively) uniform distribution
@@ -103,11 +105,15 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
103105
if (!have_txn[idit->second]) {
104106
txn_available[idit->second] = it->GetSharedTx();
105107
have_txn[idit->second] = true;
108+
mempool_count++;
106109
} else {
107110
// If we find two mempool txn that match the short id, just request it.
108111
// This should be rare enough that the extra bandwidth doesn't matter,
109112
// but eating a round-trip due to FillBlock failure would be annoying
110-
txn_available[idit->second].reset();
113+
if (txn_available[idit->second]) {
114+
txn_available[idit->second].reset();
115+
mempool_count--;
116+
}
111117
}
112118
}
113119
// Though ideally we'd continue scanning for the two-txn-match-shortid case,
@@ -117,6 +123,8 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
117123
break;
118124
}
119125

126+
LogPrint("cmpctblock", "Initialized PartiallyDownloadedBlock for block %s using a cmpctblock of size %lu\n", cmpctblock.header.GetHash().ToString(), cmpctblock.GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION));
127+
120128
return READ_STATUS_OK;
121129
}
122130

@@ -154,5 +162,11 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
154162
return READ_STATUS_INVALID;
155163
}
156164

165+
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());
166+
if (vtx_missing.size() < 5) {
167+
for(const CTransaction& tx : vtx_missing)
168+
LogPrint("cmpctblock", "Reconstructed block %s required tx %s\n", header.GetHash().ToString(), tx.GetHash().ToString());
169+
}
170+
157171
return READ_STATUS_OK;
158172
}

src/blockencodings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class CBlockHeaderAndShortTxIDs {
192192
class PartiallyDownloadedBlock {
193193
protected:
194194
std::vector<std::shared_ptr<const CTransaction> > txn_available;
195+
size_t prefilled_count = 0, mempool_count = 0;
195196
CTxMemPool* pool;
196197
public:
197198
CBlockHeader header;

0 commit comments

Comments
 (0)