Created
July 9, 2018 00:34
-
-
Save kaykurokawa/9b8b493d5b54858aab08636a93955621 to your computer and use it in GitHub Desktop.
test lbrycrdd crashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import json | |
from bitcoinrpc.authproxy import AuthServiceProxy | |
import time | |
lbrycrd_rpc_user = 'test' | |
lbrycrd_rpc_pw = 'test' | |
lbrycrd_rpc_ip = '127.0.0.1' | |
lbrycrd_rpc_port = '9245' | |
def run_command(cmd): | |
"""given shell command, returns communication tuple of stdout and stderr""" | |
p=subprocess.Popen(cmd, shell=True) | |
#return p.communicate() | |
def restart(lbrycrd): | |
run_command('pkill lbrycrdd') | |
time.sleep(10) | |
run_command('src/lbrycrdd -rpcuser=test -rpcpassword=test') | |
time.sleep(1) | |
# wait for startup | |
while 1: | |
try: | |
#lbrycrd.__conn.close() | |
lbrycrd = AuthServiceProxy("http://{}:{}@{}:{}".format(lbrycrd_rpc_user, lbrycrd_rpc_pw, | |
lbrycrd_rpc_ip, lbrycrd_rpc_port)) | |
out = lbrycrd.getblockchaininfo() | |
except Exception as e: | |
print('waiting:{} {}'.format(e, type(e))) | |
time.sleep(2) | |
continue | |
else: | |
return lbrycrd | |
break | |
lbrycrd = AuthServiceProxy("http://{}:{}@{}:{}".format(lbrycrd_rpc_user, lbrycrd_rpc_pw, | |
lbrycrd_rpc_ip, lbrycrd_rpc_port)) | |
invalidated_blocks = [] | |
from_height = 359760 | |
DEC_BLOCKS = 500 | |
for i in range(0, DEC_BLOCKS): | |
# invalidate block | |
height = from_height - i | |
print("height:{}".format(height)) | |
block_hash = lbrycrd.getblockhash(height) | |
invalidated_blocks.append(block_hash) | |
out = lbrycrd.invalidateblock(block_hash) | |
print("invalidated {}:{}".format(block_hash,out)) | |
lbrycrd=restart(lbrycrd) | |
# reconsider block and invalidate it again, should not crash when we do this | |
lbrycrd.reconsiderblock(block_hash) | |
lbrycrd.getblockchaininfo() #test to see if this command works | |
lbrycrd.invalidateblock(block_hash) | |
for b in reversed(invalidated_blocks): | |
print('reconsider :{}'.format(b)) | |
lbrycrd.reconsiderblock(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment