Skip to content

Commit

Permalink
fix policy retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Otto committed Jan 5, 2019
1 parent fc07308 commit a990883
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ def get_routes(self, pub_key, amount, num_routes):
response = self.stub.QueryRoutes(request)
return response.routes

def get_policy(self, channel_id, target_pubkey):
def get_policy(self, channel_id, source_pubkey):
# node1_policy contains the fee base and rate for payments from node1 to node2
for edge in self.get_edges():
if edge.channel_id == channel_id:
if edge.node1_pub == target_pubkey:
if edge.node1_pub == source_pubkey:
result = edge.node1_policy
else:
result = edge.node2_policy
Expand Down
17 changes: 8 additions & 9 deletions route_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,36 @@ def create_new_hop(self, amount_msat, channel, expiry):

def update_amounts(self, hops):
additional_fees = 0
hop_out_chan_id = self.rebalance_channel.chan_id
hop_out_channel_id = self.rebalance_channel.chan_id
for hop in reversed(hops):
amount_to_forward_msat = hop.amt_to_forward_msat + additional_fees
hop.amt_to_forward_msat = amount_to_forward_msat
hop.amt_to_forward = amount_to_forward_msat // 1000

fee_msat_before = hop.fee_msat
new_fee_msat = self.get_fee_msat(amount_to_forward_msat, hop_out_chan_id, hop.pub_key)
new_fee_msat = self.get_fee_msat(amount_to_forward_msat, hop_out_channel_id, hop.pub_key)
hop.fee_msat = new_fee_msat
hop.fee = new_fee_msat // 1000
additional_fees += new_fee_msat - fee_msat_before
hop_out_chan_id = hop.chan_id
hop_out_channel_id = hop.chan_id

def get_expiry_delta_last_hop(self):
return self.payment.cltv_expiry

def update_expiry(self, hops, total_time_lock):
hop_out_chan_id = self.rebalance_channel.chan_id
hop_out_channel_id = self.rebalance_channel.chan_id
for hop in reversed(hops):
hop.expiry = total_time_lock

target_pubkey = hop.pub_key
policy = self.lnd.get_policy(hop_out_chan_id, target_pubkey)
hop_out_chan_id = hop.chan_id
policy = self.lnd.get_policy(hop_out_channel_id, hop.pub_key)

time_lock_delta = policy.time_lock_delta
total_time_lock += time_lock_delta
hop_out_channel_id = hop.chan_id
return total_time_lock

def get_fee_msat(self, amount_msat, channel_id, target_pubkey):
policy = self.lnd.get_policy(channel_id, target_pubkey)
def get_fee_msat(self, amount_msat, channel_id, source_pubkey):
policy = self.lnd.get_policy(channel_id, source_pubkey)
fee_base_msat = self.get_fee_base_msat(policy)
fee_rate_milli_msat = int(policy.fee_rate_milli_msat)
return fee_base_msat + fee_rate_milli_msat * amount_msat // 1000000
Expand Down

0 comments on commit a990883

Please sign in to comment.