Bitcoin Forum
May 23, 2024, 11:52:36 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Getting node 1 to mine a block, send it to node 2,and check node2 received it.  (Read 78 times)
decent1984 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
July 31, 2021, 11:16:35 PM
 #1

Hi There,

I am trying to write the code for the above requirement within the `example_test.py` in the functional test directory,
This is the code I have written:

Code:
 def run_test(self):
        """Main test logic"""

        # Create P2P connections will wait for a verack to make sure the connection is fully up
        peer_messaging = self.nodes[0].add_p2p_connection(BaseNode())

        # Generating a block on one of the nodes will get us out of IBD
        blocks = [int(self.nodes[0].generate(nblocks=1)[0], 16)]
        self.sync_all(self.nodes[0:2])

       
        self.log.info("Starting test!")

        # Getting node 1 to mine another block,
        self.log.info("Getting node 1 to generate a block")
        self.nodes[1].generate(1)
        # Send the generated block to node 2
        self.log.info("Sending the generated block from node 1 to node 2")
        self.sync_blocks()
        # Check that node 2 received it.
        self.log.info("Testing if node 2 has received the block from node 1")
        assert_equal(self.nodes[1].getbestblockhash(), self.nodes[2].getbestblockhash())

        self.log.info("Ending Test")

Now, How can I test if it is actually happening [Getting node 1 to mine a block, send it to node 2,and check node2 received it.] or if I am just imagining all these things?

Thanks again
Noob.
pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10579



View Profile
August 01, 2021, 05:13:13 AM
 #2

You should only test your own code and behavior not what others do, meaning in this scenario you test that the connection is instantiated correctly, messages are constructed and sent correctly and things like that and you don't care if the other node received these messages or not.

But if you want to know I remember some full node clients sent back the inv message with the hash of the new block they just received and that could be an indication. You could also send them a getdata message requesting the block and see if they have it or not.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
NotATether
Legendary
*
Offline Offline

Activity: 1610
Merit: 6756


bitcoincleanup.com / bitmixlist.org


View Profile WWW
August 01, 2021, 06:45:48 PM
 #3

Use this function p2port():

Code:
def p2p_port(n):
    assert n <= MAX_NODES
    return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)

to calculate the port number used by the bitcoind node number (the host is always 'localhost' and the node numbers increment from 0), then call getblockhash() on both nodes using curl or some other network client to see if two blocks were really generated.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!