Skip to content

Commit 2cad5db

Browse files
sipaMarcoFalke
authored andcommitted
Align constant names for maximum compact block / blocktxn depth
Github-Pull: bitcoin#8637 Rebased-From: 3ac6de0
1 parent 3d23a0e commit 2cad5db

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

qa/rpc-tests/p2p-compactblocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,9 @@ def test_getblocktxn_handler(self, node, test_node, version):
635635

636636
def test_compactblocks_not_at_tip(self, node, test_node):
637637
# Test that requesting old compactblocks doesn't work.
638-
MAX_CMPCTBLOCK_DEPTH = 6
638+
MAX_CMPCTBLOCK_DEPTH = 5
639639
new_blocks = []
640-
for i in range(MAX_CMPCTBLOCK_DEPTH):
640+
for i in range(MAX_CMPCTBLOCK_DEPTH + 1):
641641
test_node.clear_block_announcement()
642642
new_blocks.append(node.generate(1)[0])
643643
wait_until(test_node.received_block_announcement, timeout=30)

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,7 +4855,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
48554855
// and we don't feel like constructing the object for them, so
48564856
// instead we respond with the full, non-compact block.
48574857
bool fPeerWantsWitness = State(pfrom->GetId())->fWantsCmpctWitness;
4858-
if (CanDirectFetch(Params().GetConsensus()) && mi->second->nHeight >= chainActive.Height() - 5) {
4858+
if (CanDirectFetch(consensusParams) && mi->second->nHeight >= chainActive.Height() - MAX_CMPCTBLOCK_DEPTH) {
48594859
CBlockHeaderAndShortTxIDs cmpctblock(block, fPeerWantsWitness);
48604860
pfrom->PushMessageWithFlag(fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::CMPCTBLOCK, cmpctblock);
48614861
} else
@@ -5401,8 +5401,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
54015401
return true;
54025402
}
54035403

5404-
if (it->second->nHeight < chainActive.Height() - 10) {
5405-
LogPrint("net", "Peer %d sent us a getblocktxn for a block > 10 deep", pfrom->id);
5404+
if (it->second->nHeight < chainActive.Height() - MAX_BLOCKTXN_DEPTH) {
5405+
LogPrint("net", "Peer %d sent us a getblocktxn for a block > %i deep", pfrom->id, MAX_BLOCKTXN_DEPTH);
54065406
return true;
54075407
}
54085408

src/main.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
8989
/** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends
9090
* less than this number, we reached its tip. Changing this value is a protocol upgrade. */
9191
static const unsigned int MAX_HEADERS_RESULTS = 2000;
92+
/** Maximum depth of blocks we're willing to serve as compact blocks to peers
93+
* when requested. For older blocks, a regular BLOCK response will be sent. */
94+
static const int MAX_CMPCTBLOCK_DEPTH = 5;
95+
/** Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. */
96+
static const int MAX_BLOCKTXN_DEPTH = 10;
9297
/** Size of the "block download window": how far ahead of our current height do we fetch?
9398
* Larger windows tolerate larger download speed differences between peer, but increase the potential
9499
* degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning

0 commit comments

Comments
 (0)