Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test lbrycrdd crashes
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