Skip to content

Commit fe998e9

Browse files
TheBlueMattsipa
authored andcommitted
More agressively filter compact block requests
Unit test adaptations by Pieter Wuille.
1 parent 02a337d commit fe998e9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

qa/rpc-tests/p2p-compactblocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def test_incorrect_blocktxn_response(self, node, test_node, version):
591591
def test_getblocktxn_handler(self, node, test_node, version):
592592
# bitcoind won't respond for blocks whose height is more than 15 blocks
593593
# deep.
594-
MAX_GETBLOCKTXN_DEPTH = 15
594+
MAX_GETBLOCKTXN_DEPTH = 10
595595
chain_height = node.getblockcount()
596596
current_height = chain_height
597597
while (current_height >= chain_height - MAX_GETBLOCKTXN_DEPTH):
@@ -632,7 +632,7 @@ def test_getblocktxn_handler(self, node, test_node, version):
632632

633633
def test_compactblocks_not_at_tip(self, node, test_node):
634634
# Test that requesting old compactblocks doesn't work.
635-
MAX_CMPCTBLOCK_DEPTH = 11
635+
MAX_CMPCTBLOCK_DEPTH = 6
636636
new_blocks = []
637637
for i in range(MAX_CMPCTBLOCK_DEPTH):
638638
test_node.clear_block_announcement()

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,7 +4878,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
48784878
// and we don't feel like constructing the object for them, so
48794879
// instead we respond with the full, non-compact block.
48804880
bool fPeerWantsWitness = State(pfrom->GetId())->fWantsCmpctWitness;
4881-
if (mi->second->nHeight >= chainActive.Height() - 10) {
4881+
if (CanDirectFetch(Params().GetConsensus()) && mi->second->nHeight >= chainActive.Height() - 5) {
48824882
CBlockHeaderAndShortTxIDs cmpctblock(block, fPeerWantsWitness);
48834883
pfrom->PushMessageWithFlag(fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::CMPCTBLOCK, cmpctblock);
48844884
} else
@@ -5405,8 +5405,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
54055405
return true;
54065406
}
54075407

5408-
if (it->second->nHeight < chainActive.Height() - 15) {
5409-
LogPrint("net", "Peer %d sent us a getblocktxn for a block > 15 deep", pfrom->id);
5408+
if (it->second->nHeight < chainActive.Height() - 10) {
5409+
LogPrint("net", "Peer %d sent us a getblocktxn for a block > 10 deep", pfrom->id);
54105410
return true;
54115411
}
54125412

0 commit comments

Comments
 (0)