More agressively filter compact block requests

Unit test adaptations by Pieter Wuille.
pull/8637/head
Matt Corallo 9 years ago committed by Pieter Wuille
parent 02a337defd
commit fe998e962d

@ -591,7 +591,7 @@ class CompactBlocksTest(BitcoinTestFramework):
def test_getblocktxn_handler(self, node, test_node, version): def test_getblocktxn_handler(self, node, test_node, version):
# bitcoind won't respond for blocks whose height is more than 15 blocks # bitcoind won't respond for blocks whose height is more than 15 blocks
# deep. # deep.
MAX_GETBLOCKTXN_DEPTH = 15 MAX_GETBLOCKTXN_DEPTH = 10
chain_height = node.getblockcount() chain_height = node.getblockcount()
current_height = chain_height current_height = chain_height
while (current_height >= chain_height - MAX_GETBLOCKTXN_DEPTH): while (current_height >= chain_height - MAX_GETBLOCKTXN_DEPTH):
@ -632,7 +632,7 @@ class CompactBlocksTest(BitcoinTestFramework):
def test_compactblocks_not_at_tip(self, node, test_node): def test_compactblocks_not_at_tip(self, node, test_node):
# Test that requesting old compactblocks doesn't work. # Test that requesting old compactblocks doesn't work.
MAX_CMPCTBLOCK_DEPTH = 11 MAX_CMPCTBLOCK_DEPTH = 6
new_blocks = [] new_blocks = []
for i in range(MAX_CMPCTBLOCK_DEPTH): for i in range(MAX_CMPCTBLOCK_DEPTH):
test_node.clear_block_announcement() test_node.clear_block_announcement()

@ -4878,7 +4878,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
// and we don't feel like constructing the object for them, so // and we don't feel like constructing the object for them, so
// instead we respond with the full, non-compact block. // instead we respond with the full, non-compact block.
bool fPeerWantsWitness = State(pfrom->GetId())->fWantsCmpctWitness; bool fPeerWantsWitness = State(pfrom->GetId())->fWantsCmpctWitness;
if (mi->second->nHeight >= chainActive.Height() - 10) { if (CanDirectFetch(Params().GetConsensus()) && mi->second->nHeight >= chainActive.Height() - 5) {
CBlockHeaderAndShortTxIDs cmpctblock(block, fPeerWantsWitness); CBlockHeaderAndShortTxIDs cmpctblock(block, fPeerWantsWitness);
pfrom->PushMessageWithFlag(fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::CMPCTBLOCK, cmpctblock); pfrom->PushMessageWithFlag(fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS, NetMsgType::CMPCTBLOCK, cmpctblock);
} else } else
@ -5405,8 +5405,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return true; return true;
} }
if (it->second->nHeight < chainActive.Height() - 15) { if (it->second->nHeight < chainActive.Height() - 10) {
LogPrint("net", "Peer %d sent us a getblocktxn for a block > 15 deep", pfrom->id); LogPrint("net", "Peer %d sent us a getblocktxn for a block > 10 deep", pfrom->id);
return true; return true;
} }

Loading…
Cancel
Save