mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 02:33:07 +02: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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user