-
-
Save cdecker/7cc2a53ece9aa56618321c7850244c81 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
@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