Skip to content

Commit

Permalink
WIP feature_fedpeg with bitcoind
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Sep 24, 2018
1 parent 1920d84 commit 1aeed4b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
74 changes: 57 additions & 17 deletions qa/rpc-tests/feature_fedpeg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

from decimal import Decimal
import os
import json
import time

Expand All @@ -10,6 +11,7 @@
connect_nodes_bi,
rpc_auth_pair,
rpc_port,
p2p_port,
start_node,
start_nodes,
stop_node,
Expand Down Expand Up @@ -47,27 +49,61 @@ def __init__(self):
self.setup_clean_chain = True
self.num_nodes = 4

def add_options(self, parser):
parser.add_option("--parent_binpath", dest="parent_binpath", default="",
help="Use a different binary for launching nodes")
parser.add_option("--parent_bitcoin", dest="parent_bitcoin", default=False, action="store_true",
help="Parent nodes are Bitcoin")

def start_node(self, idx):
is_parent = idx < 2
binary = self.options.parent_binpath if is_parent and self.options.parent_binpath != "" else None
chain = "sidechain" if not is_parent else "regtest" if self.options.parent_bitcoin else "parent"
return start_node(idx, self.options.tmpdir, self.extra_args[idx], binary=binary, chain=chain)

def setup_network(self, split=False):
if self.options.parent_bitcoin and self.options.parent_binpath == "":
raise "Can't run with --parent_bitcoin without specifying --parent_binpath"

# Parent chain args
self.extra_args = [[
# '-printtoconsole',
'-validatepegin=0',
'-anyonecanspendaremine',
'-initialfreecoins=2100000000000000',
]] * 2

self.nodes = start_nodes(2, self.options.tmpdir, self.extra_args[:2], chain='parent')
self.nodes = []
self.extra_args = []
for n in range(2):
if self.options.parent_bitcoin:
rpc_u, rpc_p = rpc_auth_pair(n)
self.extra_args.append([
"-regtest=1",
"-port="+str(p2p_port(n)),
"-rpcuser="+rpc_u,
"-rpcpassword="+rpc_p,
"-rpcport="+str(rpc_port(n)),
"-testnet=0",
"-txindex=1",
"-addresstype=legacy", # To make sure bitcoind gives back p2pkh no matter version
"-connect=localhost:"+str(p2p_port((n+1)%2)),
"-listen=1",
#"-debug"
])
else:
self.extra_args.append([
# '-printtoconsole',
'-validatepegin=0',
'-anyonecanspendaremine',
'-initialfreecoins=2100000000000000',
])
self.nodes.append(self.start_node(n))

connect_nodes_bi(self.nodes, 0, 1)
self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
print('parentgenesisblockhash', self.parentgenesisblockhash)
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']
if not self.options.parent_bitcoin:
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']

# Sidechain args
parent_chain_signblockscript = '51'
for n in range(2):
rpc_u, rpc_p = rpc_auth_pair(n)
self.extra_args.append([
args = [
# '-printtoconsole',
'-parentgenesisblockhash=%s' % self.parentgenesisblockhash,
'-validatepegin=1',
Expand All @@ -78,12 +114,16 @@ def setup_network(self, split=False):
'-mainchainrpcport=%s' % rpc_port(n),
'-mainchainrpcuser=%s' % rpc_u,
'-mainchainrpcpassword=%s' % rpc_p,
'-parentpubkeyprefix=235',
'-parentscriptprefix=75',
'-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript,
'-con_parent_pegged_asset=%s' % parent_pegged_asset,
])
self.nodes.append(start_node(n + 2, self.options.tmpdir, self.extra_args[n + 2], chain='sidechain'))
]
if not self.options.parent_bitcoin:
args.extend([
'-parentpubkeyprefix=235',
'-parentscriptprefix=75',
'-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript,
'-con_parent_pegged_asset=%s' % parent_pegged_asset,
])
self.extra_args.append(args)
self.nodes.append(self.start_node(2 + n))

connect_nodes_bi(self.nodes, 2, 3)
self.is_network_split = True
Expand Down Expand Up @@ -281,7 +321,7 @@ def run_test(self):
assert(sidechain.getblockcount() != sidechain2.getblockcount())

print("Restarting parent2")
self.nodes[1] = start_node(1, self.options.tmpdir, self.extra_args[1], chain='parent')
self.nodes[1] = self.start_node(1)
parent2 = self.nodes[1]
connect_nodes_bi(self.nodes, 0, 1)
time.sleep(5)
Expand Down
4 changes: 3 additions & 1 deletion qa/rpc-tests/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
datadir = os.path.join(dirname, "node"+str(i))
if binary is None:
binary = os.getenv("ELEMENTSD", "elementsd")
args = [ binary, '-chain='+chain, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
if chain != "regtest": #TODO(stevenroose) remove if unnecessary or when bitcoind has -chain
args.append("-chain="+chain)
if extra_args is not None: args.extend(extra_args)
bitcoind_processes[i] = subprocess.Popen(args)
if os.getenv("PYTHON_DEBUG", ""):
Expand Down

0 comments on commit 1aeed4b

Please sign in to comment.