Skip to content

Instantly share code, notes, and snippets.

@cdecker
Created September 14, 2019 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdecker/7cc2a53ece9aa56618321c7850244c81 to your computer and use it in GitHub Desktop.
Save cdecker/7cc2a53ece9aa56618321c7850244c81 to your computer and use it in GitHub Desktop.
@plugin.method('traceroute')
def traceroute(plugin, node_id, **kwargs):
traceroute = {
'destination': node_id,
'started_at': str(datetime.now()),
'probes': [],
}
try:
traceroute['route'] = plugin.rpc.getroute(
traceroute['destination'],
msatoshi=10000,
riskfactor=1,
)['route']
traceroute['payment_hash'] = ''.join(random.choice(string.hexdigits) for _ in range(64))
except RpcError:
traceroute['failcode'] = -1
return traceroute
# For each prefix length, shorten the route and attempt the payment
for l in range(1, len(traceroute['route'])):
probe = {
'route': traceroute['route'][:l],
'payment_hash': ''.join(random.choice(string.hexdigits) for _ in range(64)),
'started_at': str(datetime.now()),
}
probe['destination'] = probe['route'][-1]['id']
plugin.rpc.sendpay(probe['route'], probe['payment_hash'])
try:
plugin.rpc.waitsendpay(probe['payment_hash'], timeout=timeout)
raise ValueError("The recipient guessed the preimage? Cryptography is broken!!!")
except RpcError as e:
probe['finished_at'] = str(datetime.now())
probe['error'] = e.error['data']
probe['failcode'] = e.error['data']['failcode']
traceroute['probes'].append(probe_route(probe, timeout=30))
return traceroute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment