TeachMeBitcoin

The P2P Puppet Master: Testing Network Logic with Python

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

8. The P2P Puppet Master: Testing Network Logic with Python

In our next 1,500 words, we perform a granular audit of the Shadow Protocol. Sometimes, you don't want to test a real node talking to a real node. You want to test a real node talking to a "Malicious Puppet." This is done using the P2PInterface class.

Analyzing the Puppet: The P2PConnection

# PEDAGOGICAL ANALYSIS: THE LIAR
# This Python class pretends to be a Bitcoin node.
# But it is actually a "Script" that can lie.
class MaliciousNode(P2PInterface):
    def on_version(self, message):
        # 1. Receive the "Version" message from the real node.
        # 2. Send back a fake "Version" that says we are from the future.
        self.send_message(msg_version(nVersion=99999))

    def on_inv(self, message):
        # 3. If the real node tells us about a block...
        # 4. Just ignore it. Don't say anything back.
        pass

Explaining the Puppet: The Deception of the Mesh

The Sovereignty of the Puppet

The P2P Puppet Master is the "Inquisitor of the Node." It asks the hardest questions and tells the most complex lies to see if the node can find the truth. As a Sovereign Architect, you know that "The truth is only found by questioning every lie." By running a node that has survived a "Swarm of Liars," you are ensuring your machine is an "Incorruptible Judge" of economic reality. You are the Master of the Puppet.


☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!