Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251headers_message.headers.append(CBlockHeader(block_289f))252headers_message.headers.append(CBlockHeader(block_290f))253headers_message.headers.append(CBlockHeader(block_291))254headers_message.headers.append(CBlockHeader(block_292))255test_node.send_and_ping(headers_message)257tip_entry_found = False258for x in self.nodes[0].getchaintips():259if x['hash'] == block_292.hash_hex:260assert_equal(x['status'], "headers-only")261tip_entry_found = True262assert tip_entry_found263assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].getblock, block_292.hash_hex)265test_node.send_without_ping(msg_block(block_289f))266test_node.send_and_ping(msg_block(block_290f))268self.nodes[0].getblock(block_289f.hash_hex)269self.nodes[0].getblock(block_290f.hash_hex)271test_node.send_without_ping(msg_block(block_291))273# At this point we've sent an obviously-bogus block, wait for full processing274# and assume disconnection275test_node.wait_for_disconnect()277self.nodes[0].disconnect_p2ps()278test_node = self.nodes[0].add_p2p_connection(P2PInterface())280# We should have failed reorg and switched back to 290 (but have block 291)281assert_equal(self.nodes[0].getblockcount(), 290)282assert_equal(self.nodes[0].getbestblockhash(), all_blocks[286].hash_hex)283assert_equal(self.nodes[0].getblock(block_291.hash_hex)["confirmations"], -1)285# Now send a new header on the invalid chain, indicating we're forked off, and expect to get disconnected286block_293 = create_block(block_292.hash_int, height=293, ntime=block_292.nTime+1)287block_293.solve()288headers_message = msg_headers()289headers_message.headers.append(CBlockHeader(block_293))290test_node.send_without_ping(headers_message)291test_node.wait_for_disconnect()293# 9. Connect node1 to node0 and ensure it is able to sync294self.connect_nodes(0, 1)295self.sync_blocks([self.nodes[0], self.nodes[1]])296self.log.info("Successfully synced nodes 1 and 0")298if __name__ == '__main__':299AcceptBlockTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.