Created
March 12, 2019 19:38
-
-
Save pseudozach/00097d5509c7b7022f22610cf6625f7e to your computer and use it in GitHub Desktop.
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 | |
def getlndchannels(chanstofix): | |
cmd = subprocess.Popen(r'"C:\Users\pseudozach\AppData\Local\Node Launcher\lnd\lnd-windows-amd64-v0.5.2-beta\lncli.exe" listchannels', shell=True, stdout=subprocess.PIPE) | |
chanlist = [] | |
listindex = 0 | |
for line in cmd.stdout: | |
if b"active" in line: | |
#line starts | |
gotline = True | |
if b"remote_pubkey" in line: | |
#print("remote_pubkey::" + str(line)) | |
rpubkey = str(line).split('"remote_pubkey": "')[1].split('",')[0] | |
if b"chan_id" in line and gotline: | |
#print("lndchannels::" + str(line)) | |
chanid = str(line).split('"chan_id": "')[1].split('",')[0] | |
#print("index:: " + str(listindex) + ", " + chanid) | |
chanlist.append([chanid, rpubkey]) | |
#chanlist[listindex][1] = rpubkey | |
if b"private" in line: | |
#line ends | |
gotline = False | |
listindex = listindex + 1 | |
#print("chanlist::") | |
#print(chanlist) | |
for chantofix in chanstofix: | |
#print("finding channel:: " + str(chantofix)) | |
for channel in chanlist: | |
#print("comparing chantofix with channel0::" + str(chantofix[0]) + ", " + channel[0]) | |
if str(chantofix[0]) == str(channel[0]): | |
print("found it::") | |
print(str(channel[1])) | |
print("Liquidity Amount::" + chantofix[1]) | |
print("Date:: " + chantofix[2]) | |
print("") | |
def lnd_to_cl_scid(s): | |
block = s >> 40 | |
tx = s >> 16 & 0xFFFFFF | |
output = s & 0xFFFF | |
return (block, tx, output) | |
def cl_to_lnd_scid(s): | |
s = [int(i) for i in s.split(':')] | |
return (s[0] << 40) | (s[1] << 16) | s[2] | |
def checklogs(): | |
print("checking logs for failed htlc forwards...") | |
f = open("c:/Users/pseudozach/AppData/Local/Lnd/logs/bitcoin/mainnet/lnd.log", "r") | |
searchlines = f.readlines() | |
f.close() | |
failedchanids = [] | |
for i, line in enumerate(searchlines): | |
if "unhandled error while forwarding htlc packet over htlcswitch: unable to find appropriate channel link insufficient capacity" in line: | |
for l in searchlines[i:i+3]: | |
if "unhandled error while forwarding htlc packet over htlcswitch: unable to find appropriate channel link insufficient capacity" in l: | |
#print(l) | |
#print("splitting::") | |
channellink = l.split('ChannelLink(')[1].split(")")[0] | |
#print channellink | |
lndchanid = cl_to_lnd_scid(channellink) | |
#print "lndchanid::" | |
#print lndchanid | |
amount = l.split('need ')[1].split(" mSAT")[0] | |
datetime = l.split(' [ERR]')[0] | |
element = [lndchanid, amount, datetime] | |
failedchanids.append(element) | |
#print("found failed forwards::" + str(len(failedchanids))) | |
#for j, failedchan in enumerate(failedchanids): | |
return failedchanids | |
def main(): | |
print("starting channel checker by pseudozach...") | |
chanstofix = checklogs() | |
getlndchannels(chanstofix) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment