Skip to content

Commit 297677e

Browse files
committed
Improved update after channel policy changes
1 parent c3f088c commit 297677e

6 files changed

+49
-15
lines changed

auto_policy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def __init__(self):
3333

3434
def update(self):
3535
sc = SystemConfiguration()
36+
sc.channel_info_update_needed = True
3637
for c in lightning_channel.Channels.channel_index:
3738
channel = lightning_channel.Channels.channel_index[c][0]
38-
x = channel.remote_pubkey
3939
if channel.channel_type == "open_channel":
4040
if channel.remote_balance == 0:
4141
balance_ratio = 100000.0

channel_graph_widget.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#
1515

1616
from PyQt5 import QtCore, QtWidgets, QtGui
17+
from config.config import SystemConfiguration
1718
from instruction import CenterNode, CenterNodeInstruction, ChannelGraphPicture, Node, NodeInstruction
1819
from lightning import lightning_node, lightning_channel
1920

@@ -50,7 +51,7 @@ def update(self):
5051
pen = QtGui.QPen(colour, self.pen_width)
5152

5253
instruction = CenterNodeInstruction(center_node, pen)
53-
ChannelGraphPicture._instructions.append(instruction)
54+
ChannelGraphPicture.instructions.append(instruction)
5455

5556
# draw the nodes and channels connect to the center node
5657
for c in lightning_channel.Channels.channel_index:
@@ -61,22 +62,26 @@ def update(self):
6162
pen = QtGui.QPen(colour, self.pen_width)
6263
node = Node(channel.remote_node_alias)
6364
instruction = NodeInstruction(node, pen, channel.chan_id)
64-
ChannelGraphPicture._instructions.append(instruction)
65-
if ChannelGraphPicture._instructions[1]:
66-
self.channel_info_widget.update(ChannelGraphPicture._instructions[1].chan_id)
65+
ChannelGraphPicture.instructions.append(instruction)
66+
if ChannelGraphPicture.instructions[1]:
67+
self.channel_info_widget.update(ChannelGraphPicture.instructions[1].chan_id)
6768
self._stop_repaint = False
6869

6970
def paintEvent(self, event):
7071
qp = QtGui.QPainter(self)
71-
for instruction in ChannelGraphPicture._instructions:
72+
for instruction in ChannelGraphPicture.instructions:
7273
instruction.paint(self, qp)
7374

7475
def mousePressEvent(self, event):
75-
for i in ChannelGraphPicture._instructions:
76+
sc = SystemConfiguration()
77+
temp_update_needed = sc.channel_info_update_needed
78+
sc.channel_info_update_needed = False
79+
for i in ChannelGraphPicture.instructions:
7680
if isinstance(i, NodeInstruction):
7781
try:
7882
if i.get_window_position().contains(event.pos()):
7983
self.channel_info_widget.update(i.chan_id)
8084
break
8185
except AttributeError:
82-
pass
86+
sc.channel_info_update_needed = temp_update_needed
87+
sc.channel_info_update_needed = temp_update_needed

channel_info_widget.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,16 @@ def __init__(self, channel_id=0):
505505
# in order for the channel list to access this object
506506
# to update info
507507

508-
def update(self, channel_id, cold_update=False):
508+
self.timer = QtCore.QTimer()
509+
self.timer.timeout.connect(lambda: self.update(self.channel_id))
510+
self.timer.start(1000 * 60 * 5) # update once 5 minutes
511+
512+
def update(self, channel_id):
513+
sc = SystemConfiguration()
509514
self.channel_id = channel_id
510-
if cold_update:
515+
if sc.channel_info_update_needed:
511516
lightning_channel.Channels.read_channels()
517+
sc.channel_info_update_needed = False
512518

513519
self.forwarding_events = FwdingEvents()
514520
channel = lightning_channel.Channels.channel_index[channel_id][0]
@@ -563,7 +569,9 @@ def reconnect_channel(self, event):
563569
try:
564570
channel = lightning_channel.Channels.channel_index[self.channel_id][0]
565571
channel.reconnect()
566-
self.update(self.channel_id, cold_update=True)
572+
sc = SystemConfiguration()
573+
sc.channel_info_update_needed = True
574+
self.update(self.channel_id)
567575
if self.active_label.text() == 'INACTIVE':
568576
mb = QtWidgets.QMessageBox()
569577
mb.about(self, "Reconnect error", "Unable to reconnect with node. Try again later")
@@ -596,4 +604,6 @@ def set_channel_policy(self):
596604
base_fee_msat=self.base_fee_msat,
597605
fee_rate=self.fee_rate,
598606
time_lock_delta=self.time_lock_delta)
599-
self.update(self.channel_id, cold_update=True)
607+
sc = SystemConfiguration()
608+
sc.channel_info_update_needed = True
609+
self.update(self.channel_id)

config/conductor.conf

+9
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ default_fee_rate = 0.000001
1313
default_time_lock_delta = 144
1414

1515
[POLICY]
16+
# if local balance divided by remote balance >= policy1_perc
17+
# in the case below if the local balance is at least 4 times
18+
# larger than the remote balance of a channel, policy 1 will be set (no fees)
1619
policy1_perc = 4
1720
policy1_base_fee = 0
1821
policy1_fee_rate = 0.000001
1922

23+
#elsif local balance divided by remote balance >= policy2_perc
24+
# in the case below if the local balance is between 4 times smaller and 4 times larger
25+
# policy 2 will be set (2500 msat)
2026
policy2_perc = 0.25
2127
policy2_base_fee = 2500
2228
policy2_fee_rate = 0.000001
2329

30+
#else
31+
# in all other cases policy three will be used (5000 msat)
32+
# so if if the local balance is more than 4 times smaller in this case
2433
policy3_perc = 0
2534
policy3_base_fee = 5000
2635
policy3_fee_rate = 0.000001

config/config.py

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(self):
4343
self._policy2 = None
4444
self._policy3 = None
4545

46+
self._channel_info_update_needed = False
47+
4648
@property
4749
def admin_macaroon_directory(self):
4850
return self._admin_macaroon_directory
@@ -131,6 +133,14 @@ def policy3(self):
131133
def policy3(self, value):
132134
self._policy3 = value
133135

136+
@property
137+
def channel_info_update_needed(self):
138+
return self._channel_info_update_needed
139+
140+
@channel_info_update_needed.setter
141+
def channel_info_update_needed(self, value):
142+
self._channel_info_update_needed = value
143+
134144
def read_config(self):
135145
if not os.path.isfile('./config/conductor.conf'):
136146
raise FileNotFoundError

instruction.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ def reset(self):
226226

227227

228228
class ChannelGraphPicture(object):
229-
_instructions = []
229+
instructions = []
230230

231231
@staticmethod
232232
def reset():
233-
for instruction in ChannelGraphPicture._instructions:
233+
for instruction in ChannelGraphPicture.instructions:
234234
instruction.reset()
235235
Node.reset()
236-
ChannelGraphPicture._instructions = []
236+
ChannelGraphPicture.instructions = []
237237

238238

239239
class Node(object):

0 commit comments

Comments
 (0)