Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

managend pickhardt_pay verbosity with two optional arguments #17 #21

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
File renamed without changes.
27 changes: 13 additions & 14 deletions examples/basicexample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
from pickhardtpayments.OracleLightningNetwork import OracleLightningNetwork
from pickhardtpayments.SyncSimulatedPaymentSession import SyncSimulatedPaymentSession


#we first need to import the chanenl graph from c-lightning jsondump
#you can get your own data set via:
# we first need to import the chanenl graph from c-lightning jsondump
# you can get your own data set via:
# $: lightning-cli listchannels > listchannels20220412.json
# alternatively you can go to https://ln.rene-pickhardt.de to find a data dump
channel_graph = ChannelGraph("listchannels20220412.json")

uncertainty_network = UncertaintyNetwork(channel_graph)
oracle_lightning_network = OracleLightningNetwork(channel_graph)
#we create ourselves a payment session which in this case operates by sending out the onions
#sequentially
payment_session = SyncSimulatedPaymentSession(oracle_lightning_network,
uncertainty_network,
prune_network=False)
# we create ourselves a payment session which in this case operates by sending out the onions
# sequentially
payment_session = SyncSimulatedPaymentSession(oracle_lightning_network,
uncertainty_network,
prune_network=False)

#we need to make sure we forget all learnt information on the Uncertainty Nework
# we need to make sure we forget all learnt information on the Uncertainty Nework
payment_session.forget_information()

#we run the simulation of pickhardt payments and track all the results
# we run the simulation of pickhardt payments and track all the results

#Rene Pickhardt's public node key
# Rene Pickhardt's public node key
RENE = "03efccf2c383d7bf340da9a3f02e2c23104a0e4fe8ac1a880c8e2dc92fbdacd9df"
#Carsten Otto's public node key
# Carsten Otto's public node key
C_OTTO = "027ce055380348d7812d2ae7745701c9f93e70c1adeb2657f053f91df4f2843c71"
tested_amount = 10_000_000 #10 million sats
tested_amount = 10_000_000 # 10 million sats

payment_session.pickhardt_pay(RENE,C_OTTO, tested_amount,mu=0,base=0)
payment_session.pickhardt_pay(RENE, C_OTTO, tested_amount, mu=0, base=0, round_verbosity=True, summary=True)
10 changes: 7 additions & 3 deletions pickhardtpayments/OracleChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ def __init__(self, channel: Channel, actual_liquidity: int = None):
self._actual_liquidity = random.randint(0, self.capacity)

def __str__(self):
return super().__str__()+" actual Liquidity: {}".format(self.actual_liquidity)
return super().__str__() + " actual Liquidity: {}".format(self.actual_liquidity)

@property
def actual_liquidity(self):
"""
Tells us the actual liquidity according to the oracle.

This is usful for experiments but must of course not be used in routing and is also
not a vailable if mainnet remote channels are being used.
This is useful for experiments but must of course not be used in routing and is also
not available if mainnet remote channels are being used.
"""
return self._actual_liquidity

@actual_liquidity.setter
def actual_liquidity(self, amt: int):
self._actual_liquidity = amt

def can_forward(self, amt: int):
"""
check if the oracle channel can forward a certain amount
Expand Down
27 changes: 23 additions & 4 deletions pickhardtpayments/OracleLightningNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, channel_graph: ChannelGraph):
for src, dest, short_channel_id, channel in channel_graph.network.edges(data="channel", keys=True):
oracle_channel = None

# If Channel in oposite direction already exists with liquidity information match the channel
# If Channel in opposite direction already exists with liquidity information match the channel
if self._network.has_edge(dest, src):
if short_channel_id in self._network[dest][src]:
capacity = channel.capacity
Expand All @@ -39,10 +39,10 @@ def send_onion(self, path, amt):
oracle_channel = self.get_channel(
channel.src, channel.dest, channel.short_channel_id)
success_of_probe = oracle_channel.can_forward(
channel.in_flight+amt)
channel.in_flight + amt)
# print(channel,amt,success_of_probe)
channel.update_knowledge(amt, success_of_probe)
if success_of_probe == False:
if not success_of_probe:
return False, channel
return True, None

Expand All @@ -55,7 +55,7 @@ def theoretical_maximum_payable_amount(self, source: str, destination: str, base
"""
test_network = nx.DiGraph()
for src, dest, channel in self.network.edges(data="channel"):
#liqudity = 0
# liquidity = 0
# for channel in channels:
if channel.base_fee > base_fee:
continue
Expand All @@ -71,3 +71,22 @@ def theoretical_maximum_payable_amount(self, source: str, destination: str, base

mincut, _ = nx.minimum_cut(test_network, source, destination)
return mincut

def settle_payment(self, path: OracleChannel, payment_amount: int):
"""
receives a dictionary with channels and payment amounts and adjusts the balances of the channels along the path.

settle_payment should only be called after all send_onions for a payment terminated successfully!
# TODO testing
"""
for channel in path:
settlement_channel = self.get_channel(channel.src, channel.dest, channel.short_channel_id)
return_settlement_channel = self.get_channel(channel.dest, channel.src, channel.short_channel_id)
if settlement_channel.actual_liquidity > payment_amount:
# decrease channel balance in sending channel by amount
settlement_channel.actual_liquidity = settlement_channel.actual_liquidity - payment_amount
# increase channel balance in the other direction by amount
return_settlement_channel.actual_liquidity = return_settlement_channel.actual_liquidity + payment_amount
else:
raise Exception("""Channel liquidity on Channel {} is lower than payment amount.
\nPayment cannot settle.""".format(channel.short_channel_id))
Loading