@@ -39,33 +39,41 @@ def add_options(self, parser):
3939 def setup_network (self , split = False ):
4040 if self .options .parent_bitcoin and self .options .parent_binpath == "" :
4141 raise Exception ("Can't run with --parent_bitcoin without specifying --parent_binpath" )
42-
4342 self .nodes = []
4443 self .extra_args = []
4544 # Parent chain args
4645 for n in range (2 ):
46+ # We want to test the rpc cookie method so we force the use of a
47+ # dummy conf file to avoid loading rpcuser/rpcpassword lines
48+ use_cookie_auth = n == 1
49+ rpc_u , rpc_p = rpc_auth_pair (n )
4750 if self .options .parent_bitcoin :
4851 self .parent_chain = 'regtest'
49- rpc_u , rpc_p = rpc_auth_pair (n )
5052 self .extra_args .append ([
53+ "-conf=dummy" ,
5154 "-printtoconsole=0" ,
52- "-port=" + str (p2p_port (n )),
53- "-rpcuser=" + rpc_u ,
54- "-rpcpassword=" + rpc_p ,
55- "-rpcport=" + str (rpc_port (n )),
5655 "-addresstype=legacy" , # To make sure bitcoind gives back p2pkh no matter version
5756 "-deprecatedrpc=validateaddress" ,
57+ "-port=" + str (p2p_port (n )),
58+ "-rpcport=" + str (rpc_port (n ))
5859 ])
5960 else :
6061 self .parent_chain = 'parent'
6162 self .extra_args .append ([
63+ "-conf=dummy" ,
6264 "-printtoconsole=0" ,
6365 '-validatepegin=0' ,
6466 '-anyonecanspendaremine' ,
6567 '-initialfreecoins=2100000000000000' ,
68+ "-port=" + str (p2p_port (n )),
69+ "-rpcport=" + str (rpc_port (n ))
6670 ])
71+ # Only first parent uses name/password, the 2nd uses cookie auth
72+ if not use_cookie_auth :
73+ self .extra_args [n ].extend (["-rpcuser=" + rpc_u , "-rpcpassword=" + rpc_p ])
74+
6775 self .binary = self .options .parent_binpath if self .options .parent_binpath != "" else None
68- self .nodes .append (start_node (n , self .options .tmpdir , self .extra_args [n ], binary = self .binary , chain = self .parent_chain ))
76+ self .nodes .append (start_node (n , self .options .tmpdir , self .extra_args [n ], binary = self .binary , chain = self .parent_chain , cookie_auth = use_cookie_auth ))
6977
7078 connect_nodes_bi (self .nodes , 0 , 1 )
7179 self .parentgenesisblockhash = self .nodes [0 ].getblockhash (0 )
@@ -77,6 +85,7 @@ def setup_network(self, split=False):
7785 self .fedpeg_script = "512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
7886 parent_chain_signblockscript = '51'
7987 for n in range (2 ):
88+ used_cookie_auth = n == 1
8089 rpc_u , rpc_p = rpc_auth_pair (n )
8190 args = [
8291 "-printtoconsole=0" ,
@@ -88,8 +97,6 @@ def setup_network(self, split=False):
8897 '-peginconfirmationdepth=10' ,
8998 '-mainchainrpchost=127.0.0.1' ,
9099 '-mainchainrpcport=%s' % rpc_port (n ),
91- '-mainchainrpcuser=%s' % rpc_u ,
92- '-mainchainrpcpassword=%s' % rpc_p ,
93100 ]
94101 if not self .options .parent_bitcoin :
95102 args .extend ([
@@ -98,9 +105,21 @@ def setup_network(self, split=False):
98105 '-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript ,
99106 '-con_parent_pegged_asset=%s' % parent_pegged_asset ,
100107 ])
108+
109+ if used_cookie_auth :
110+ # Need to specify where to find parent cookie file
111+ datadir = os .path .join (self .options .tmpdir , "node" + str (n ))
112+ args .append ('-mainchainrpccookiefile=' + datadir + "/" + self .parent_chain + "/.cookie" )
113+ else :
114+ args .extend ([
115+ '-mainchainrpcuser=%s' % rpc_u ,
116+ '-mainchainrpcpassword=%s' % rpc_p ,
117+ ])
118+
101119 self .extra_args .append (args )
102120 self .nodes .append (start_node (n + 2 , self .options .tmpdir , self .extra_args [n + 2 ], chain = 'sidechain' ))
103121
122+ # We only connect the same-chain nodes, so sync_all works correctly
104123 connect_nodes_bi (self .nodes , 2 , 3 )
105124 self .is_network_split = True
106125 self .sync_all ()
@@ -297,7 +316,7 @@ def run_test(self):
297316 assert (sidechain .getblockcount () != sidechain2 .getblockcount ())
298317
299318 print ("Restarting parent2" )
300- self .nodes [1 ] = start_node (1 , self .options .tmpdir , self .extra_args [1 ], binary = self .binary , chain = self .parent_chain )
319+ self .nodes [1 ] = start_node (1 , self .options .tmpdir , self .extra_args [1 ], binary = self .binary , chain = self .parent_chain , cookie_auth = True )
301320 parent2 = self .nodes [1 ]
302321 connect_nodes_bi (self .nodes , 0 , 1 )
303322 time .sleep (5 )
0 commit comments