Skip to content

Commit

Permalink
Revert "Introduction of AttemptClass and PaymentClass (Issue renepick…
Browse files Browse the repository at this point in the history
…hardt#20) (renepickhardt#24)"

This reverts commit cd46871.
  • Loading branch information
adamritter committed Aug 5, 2022
1 parent bba8254 commit e149e6b
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 588 deletions.
11 changes: 0 additions & 11 deletions .gitignore

This file was deleted.

28 changes: 0 additions & 28 deletions CHANGELOG.md

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion examples/basicexample.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
C_OTTO = "027ce055380348d7812d2ae7745701c9f93e70c1adeb2657f053f91df4f2843c71"
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)
136 changes: 0 additions & 136 deletions pickhardtpayments/Attempt.py

This file was deleted.

4 changes: 2 additions & 2 deletions pickhardtpayments/Channel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ChannelFields:
class ChannelFields():
"""
These are the values describing public data about channels that is either available
via gossip or via the Bitcoin Blockchain. Their format is taken from the core lighting
Expand All @@ -21,7 +21,7 @@ class ChannelFields:
SHORT_CHANNEL_ID = 'short_channel_id'


class Channel:
class Channel():
"""
Stores the public available information of a channel.
Expand Down
4 changes: 2 additions & 2 deletions pickhardtpayments/ChannelGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .Channel import Channel


class ChannelGraph:
class ChannelGraph():
"""
Represents the public information about the Lightning Network that we see from Gossip and the
Bitcoin Blockchain.
Expand All @@ -15,7 +15,7 @@ class ChannelGraph:

def _get_channel_json(self, filename: str):
"""
extracts the dictionary from the file that contains lightning-cli listchannels json string
extracts the dictionary from the file that contains lightnig-cli listchannels json string
"""
f = open(filename)
return json.load(f)["channels"]
Expand Down
18 changes: 5 additions & 13 deletions pickhardtpayments/OracleChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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):
Expand All @@ -30,23 +30,15 @@ def actual_liquidity(self):
return self._actual_liquidity

@actual_liquidity.setter
def actual_liquidity(self, amt: int):
"""Sets the liquidity of a channel in the Oracle Network
:param amt: amount to be assigned to channel liquidity
:type amt: int
"""
if 0 <= amt <= self.capacity:
self._actual_liquidity = amt
else:
raise ValueError(f"Liquidity for channel {self.short_channel_id} cannot be set. Amount {amt} is negative or higher than capacity")

def actual_liquidity(self,amt):
self._actual_liquidity = amt


def can_forward(self, amt: int):
"""
check if the oracle channel can forward a certain amount
"""
if amt <= self.actual_liquidity:
return True
else:
return False
return False
34 changes: 4 additions & 30 deletions pickhardtpayments/OracleLightningNetwork.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from .ChannelGraph import ChannelGraph
from .OracleChannel import OracleChannel
import networkx as nx
Expand All @@ -15,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 opposite direction already exists with liquidity information match the channel
# If Channel in oposite 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 @@ -37,18 +35,14 @@ def network(self):
return self._network

def send_onion(self, path, amt):
"""
:rtype: object
"""
for channel in path:
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 not success_of_probe:
if success_of_probe == False:
return False, channel
return True, None

Expand All @@ -61,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"):
# liquidity = 0
#liqudity = 0
# for channel in channels:
if channel.base_fee > base_fee:
continue
Expand All @@ -77,23 +71,3 @@ 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: List[OracleChannel], payment_amount: int):
"""
receives a List of channels and payment amount 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))
return 0
Loading

0 comments on commit e149e6b

Please sign in to comment.