Skip to content

Commit

Permalink
Increase default free relay for pegins, test that pegging is accepted…
Browse files Browse the repository at this point in the history
… to other node's mempool
  • Loading branch information
instagibbs committed Jul 14, 2017
1 parent e40a289 commit a5a81a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
50 changes: 46 additions & 4 deletions qa/rpc-tests/pegging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@
bitcoin_pass=''.join(random.choice('0123456789ABCDEF') for i in range(10))
sidechain_datadir="/tmp/"+''.join(random.choice('0123456789ABCDEF') for i in range(5))
sidechain_pass=''.join(random.choice('0123456789ABCDEF') for i in range(10))
sidechain2_datadir="/tmp/"+''.join(random.choice('0123456789ABCDEF') for i in range(5))
sidechain2_pass=''.join(random.choice('0123456789ABCDEF') for i in range(10))

bitcoin_port = 8000 + os.getpid()%999
sidechain_port = bitcoin_port + 1
sidechain2_port = bitcoin_port + 2
sidechain1_p2p_port = bitcoin_port + 3
sidechain2_p2p_port = bitcoin_port + 4

os.makedirs(bitcoin_datadir)
os.makedirs(sidechain_datadir)
os.makedirs(sidechain2_datadir)

with open(os.path.join(bitcoin_datadir, "bitcoin.conf"), 'w') as f:
f.write("regtest=1\n")
Expand All @@ -46,7 +52,6 @@
f.write("rpcpassword="+sidechain_pass+"\n")
f.write("rpcport="+str(sidechain_port)+"\n")
f.write("discover=0\n")
f.write("listen=0\n")
f.write("testnet=0\n")
f.write("txindex=1\n")
f.write("fedpegscript="+fedpeg_pubkey+"\n")
Expand All @@ -57,23 +62,49 @@
f.write("mainchainrpcpassword="+bitcoin_pass+"\n")
f.write("validatepegin=1\n")
f.write("validatepegout=0\n")
f.write("listen=0\n")
f.write("port="+str(sidechain1_p2p_port)+"\n")
f.write("connect=localhost:"+str(sidechain2_p2p_port)+"\n")
f.write("listen=1\n")

with open(os.path.join(sidechain2_datadir, "elements.conf"), 'w') as f:
f.write("regtest=1\n")
f.write("rpcuser=sidechainrpc2\n")
f.write("rpcpassword="+sidechain2_pass+"\n")
f.write("rpcport="+str(sidechain2_port)+"\n")
f.write("discover=0\n")
f.write("testnet=0\n")
f.write("txindex=1\n")
f.write("fedpegscript="+fedpeg_pubkey+"\n")
f.write("daemon=1\n")
f.write("mainchainrpchost=127.0.0.1\n")
f.write("mainchainrpcport="+str(bitcoin_port)+"\n")
f.write("mainchainrpcuser=bitcoinrpc\n")
f.write("mainchainrpcpassword="+bitcoin_pass+"\n")
f.write("validatepegin=1\n")
f.write("validatepegout=0\n")
f.write("port="+str(sidechain2_p2p_port)+"\n")
f.write("connect=localhost:"+str(sidechain1_p2p_port)+"\n")
f.write("listen=1\n")

try:

# Start daemons
print("Starting daemons at "+bitcoin_datadir+" and "+sidechain_datadir)
print("Starting daemons at "+bitcoin_datadir+", "+sidechain_datadir+" and "+sidechain2_datadir)
bitcoindstart = sys.argv[1]+"/bitcoind -datadir="+bitcoin_datadir
subprocess.Popen(bitcoindstart.split(), stdout=subprocess.PIPE)

sidechainstart = sys.argv[2]+"/elementsd -datadir="+sidechain_datadir
subprocess.Popen(sidechainstart.split(), stdout=subprocess.PIPE)

sidechain2start = sys.argv[2]+"/elementsd -datadir="+sidechain2_datadir
subprocess.Popen(sidechain2start.split(), stdout=subprocess.PIPE)

print("Daemons started")
time.sleep(2)

bitcoin = AuthServiceProxy("http://bitcoinrpc:"+bitcoin_pass+"@127.0.0.1:"+str(bitcoin_port))
sidechain = AuthServiceProxy("http://sidechainrpc:"+sidechain_pass+"@127.0.0.1:"+str(sidechain_port))
sidechain2 = AuthServiceProxy("http://sidechainrpc2:"+sidechain2_pass+"@127.0.0.1:"+str(sidechain2_port))
print("Daemons started, making blocks to get funds")

bitcoin.generate(101)
Expand All @@ -100,10 +131,21 @@
except JSONRPCException:
pass

timeout = 20
# Should succeed via wallet lookup for address match
pegtxid = sidechain.claimpegin(raw, proof)
while len(sidechain.getrawmempool()) != len(sidechain2.getrawmempool()):
time.sleep(1)
timeout -= 1
if timeout == 0:
raise Exception("Peg-in has failed to propagate.")
sidechain2.generate(1)
while sidechain.getblockcount() != sidechain2.getblockcount():
time.sleep(1)
timeout -= 1
if timeout == 0:
raise Exception("Blocks are not propagating.")

sidechain.generate(1)

tx = sidechain.gettransaction(pegtxid)

Expand Down
2 changes: 1 addition & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
/** Additional block download timeout per parallel downloading peer (i.e. 5 min) */
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;

static const unsigned int DEFAULT_LIMITFREERELAY = 0;
static const unsigned int DEFAULT_LIMITFREERELAY = 15;
static const bool DEFAULT_RELAYPRIORITY = true;
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
/** Maximum age of our tip in seconds for us to be considered current for fee estimation */
Expand Down

0 comments on commit a5a81a5

Please sign in to comment.