mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-13 11:35:20 +01:00
net_processing: make all Misbehaving increments = 100
This removes the need to actually track misbehavior score (see further commit), because any Misbehaving node will immediately hit the discouragement threshold.
This commit is contained in:
parent
5120ab1478
commit
6457c31197
7 changed files with 28 additions and 23 deletions
|
@ -1949,8 +1949,7 @@ bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
|
|||
return true;
|
||||
// Conflicting (but not necessarily invalid) data or different policy:
|
||||
case BlockValidationResult::BLOCK_MISSING_PREV:
|
||||
// TODO: Handle this much more gracefully (10 DoS points is super arbitrary)
|
||||
if (peer) Misbehaving(*peer, 10, message);
|
||||
if (peer) Misbehaving(*peer, 100, message);
|
||||
return true;
|
||||
case BlockValidationResult::BLOCK_RECENT_CONSENSUS_CHANGE:
|
||||
case BlockValidationResult::BLOCK_TIME_FUTURE:
|
||||
|
@ -2690,7 +2689,7 @@ bool PeerManagerImpl::CheckHeadersPoW(const std::vector<CBlockHeader>& headers,
|
|||
|
||||
// Are these headers connected to each other?
|
||||
if (!CheckHeadersAreContinuous(headers)) {
|
||||
Misbehaving(peer, 20, "non-continuous headers sequence");
|
||||
Misbehaving(peer, 100, "non-continuous headers sequence");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -4107,7 +4106,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
if (vAddr.size() > MAX_ADDR_TO_SEND)
|
||||
{
|
||||
Misbehaving(*peer, 20, strprintf("%s message size = %u", msg_type, vAddr.size()));
|
||||
Misbehaving(*peer, 100, strprintf("%s message size = %u", msg_type, vAddr.size()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -4189,7 +4188,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
vRecv >> vInv;
|
||||
if (vInv.size() > MAX_INV_SZ)
|
||||
{
|
||||
Misbehaving(*peer, 20, strprintf("inv message size = %u", vInv.size()));
|
||||
Misbehaving(*peer, 100, strprintf("inv message size = %u", vInv.size()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -4281,7 +4280,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
vRecv >> vInv;
|
||||
if (vInv.size() > MAX_INV_SZ)
|
||||
{
|
||||
Misbehaving(*peer, 20, strprintf("getdata message size = %u", vInv.size()));
|
||||
Misbehaving(*peer, 100, strprintf("getdata message size = %u", vInv.size()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -4966,7 +4965,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
// Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks.
|
||||
unsigned int nCount = ReadCompactSize(vRecv);
|
||||
if (nCount > MAX_HEADERS_RESULTS) {
|
||||
Misbehaving(*peer, 20, strprintf("headers message size = %u", nCount));
|
||||
Misbehaving(*peer, 100, strprintf("headers message size = %u", nCount));
|
||||
return;
|
||||
}
|
||||
headers.resize(nCount);
|
||||
|
|
|
@ -350,7 +350,6 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
|||
peerLogic->InitializeNode(*nodes[1], NODE_NETWORK);
|
||||
nodes[1]->fSuccessfullyConnected = true;
|
||||
connman->AddTestNode(*nodes[1]);
|
||||
peerLogic->UnitTestMisbehaving(nodes[1]->GetId(), DISCOURAGEMENT_THRESHOLD - 1);
|
||||
BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
|
||||
// [0] is still discouraged/disconnected.
|
||||
BOOST_CHECK(banman->IsDiscouraged(addr[0]));
|
||||
|
@ -358,7 +357,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
|||
// [1] is not discouraged/disconnected yet.
|
||||
BOOST_CHECK(!banman->IsDiscouraged(addr[1]));
|
||||
BOOST_CHECK(!nodes[1]->fDisconnect);
|
||||
peerLogic->UnitTestMisbehaving(nodes[1]->GetId(), 1); // [1] reaches discouragement threshold
|
||||
peerLogic->UnitTestMisbehaving(nodes[1]->GetId(), DISCOURAGEMENT_THRESHOLD); // [1] reaches discouragement threshold
|
||||
BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
|
||||
// Expect both [0] and [1] to be discouraged/disconnected now.
|
||||
BOOST_CHECK(banman->IsDiscouraged(addr[0]));
|
||||
|
|
|
@ -142,7 +142,8 @@ class AddrTest(BitcoinTestFramework):
|
|||
|
||||
msg = self.setup_addr_msg(1010)
|
||||
with self.nodes[0].assert_debug_log(['addr message size = 1010']):
|
||||
addr_source.send_and_ping(msg)
|
||||
addr_source.send_message(msg)
|
||||
addr_source.wait_for_disconnect()
|
||||
|
||||
self.nodes[0].disconnect_p2ps()
|
||||
|
||||
|
|
|
@ -86,11 +86,6 @@ class AddrTest(BitcoinTestFramework):
|
|||
addr_source = self.nodes[0].add_p2p_connection(P2PInterface())
|
||||
msg = msg_addrv2()
|
||||
|
||||
self.log.info('Send too-large addrv2 message')
|
||||
msg.addrs = ADDRS * 101
|
||||
with self.nodes[0].assert_debug_log(['addrv2 message size = 1010']):
|
||||
addr_source.send_and_ping(msg)
|
||||
|
||||
self.log.info('Check that addrv2 message content is relayed and added to addrman')
|
||||
addr_receiver = self.nodes[0].add_p2p_connection(AddrReceiver())
|
||||
msg.addrs = ADDRS
|
||||
|
@ -106,6 +101,13 @@ class AddrTest(BitcoinTestFramework):
|
|||
assert addr_receiver.addrv2_received_and_checked
|
||||
assert_equal(len(self.nodes[0].getnodeaddresses(count=0, network="i2p")), 0)
|
||||
|
||||
self.log.info('Send too-large addrv2 message')
|
||||
msg.addrs = ADDRS * 101
|
||||
with self.nodes[0].assert_debug_log(['addrv2 message size = 1010']):
|
||||
addr_source.send_message(msg)
|
||||
addr_source.wait_for_disconnect()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
AddrTest().main()
|
||||
|
|
|
@ -261,7 +261,9 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
|||
msg_type = msg.msgtype.decode('ascii')
|
||||
self.log.info("Test {} message of size {} is logged as misbehaving".format(msg_type, size))
|
||||
with self.nodes[0].assert_debug_log(['Misbehaving', '{} message size = {}'.format(msg_type, size)]):
|
||||
self.nodes[0].add_p2p_connection(P2PInterface()).send_and_ping(msg)
|
||||
conn = self.nodes[0].add_p2p_connection(P2PInterface())
|
||||
conn.send_message(msg)
|
||||
conn.wait_for_disconnect()
|
||||
self.nodes[0].disconnect_p2ps()
|
||||
|
||||
def test_oversized_inv_msg(self):
|
||||
|
@ -322,7 +324,8 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
|||
# delete arbitrary block header somewhere in the middle to break link
|
||||
del block_headers[random.randrange(1, len(block_headers)-1)]
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=MISBEHAVING_NONCONTINUOUS_HEADERS_MSGS):
|
||||
peer.send_and_ping(msg_headers(block_headers))
|
||||
peer.send_message(msg_headers(block_headers))
|
||||
peer.wait_for_disconnect()
|
||||
self.nodes[0].disconnect_p2ps()
|
||||
|
||||
def test_resource_exhaustion(self):
|
||||
|
|
|
@ -104,11 +104,10 @@ class MutatedBlocksTest(BitcoinTestFramework):
|
|||
block_missing_prev.hashPrevBlock = 123
|
||||
block_missing_prev.solve()
|
||||
|
||||
# Attacker gets a DoS score of 10, not immediately disconnected, so we do it 10 times to get to 100
|
||||
for _ in range(10):
|
||||
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["AcceptBlock FAILED (prev-blk-not-found)"]):
|
||||
attacker.send_message(msg_block(block_missing_prev))
|
||||
# Check that non-connecting block causes disconnect
|
||||
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["AcceptBlock FAILED (prev-blk-not-found)"]):
|
||||
attacker.send_message(msg_block(block_missing_prev))
|
||||
attacker.wait_for_disconnect(timeout=5)
|
||||
|
||||
|
||||
|
|
|
@ -170,9 +170,11 @@ class AcceptBlockTest(BitcoinTestFramework):
|
|||
tip = next_block
|
||||
|
||||
# Now send the block at height 5 and check that it wasn't accepted (missing header)
|
||||
test_node.send_and_ping(msg_block(all_blocks[1]))
|
||||
test_node.send_message(msg_block(all_blocks[1]))
|
||||
test_node.wait_for_disconnect()
|
||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblock, all_blocks[1].hash)
|
||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblockheader, all_blocks[1].hash)
|
||||
test_node = self.nodes[0].add_p2p_connection(P2PInterface())
|
||||
|
||||
# The block at height 5 should be accepted if we provide the missing header, though
|
||||
headers_message = msg_headers()
|
||||
|
|
Loading…
Add table
Reference in a new issue