Skip to content

Commit f531445

Browse files
pinheadmzwillcl-ark
authored andcommitted
server: add circuit breaker to rpc network_status
1 parent 588da81 commit f531445

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/cli/network.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ def status(network: str):
122122
assert isinstance(result, list), "Result is not a list" # Make mypy happy
123123
for tank in result:
124124
lightning_status = ""
125+
circuitbreaker_status = ""
125126
if "lightning_status" in tank:
126127
lightning_status = f"\tLightning: {tank['lightning_status']}"
127-
print(f"Tank: {tank['tank_index']} \tBitcoin: {tank['bitcoin_status']}{lightning_status}")
128+
if "circuitbreaker_status" in tank:
129+
circuitbreaker_status = f"\tCircuit Breaker: {tank['circuitbreaker_status']}"
130+
print(f"Tank: {tank['tank_index']} \tBitcoin: {tank['bitcoin_status']}{lightning_status}{circuitbreaker_status}")
128131

129132

130133
@network.command()

src/warnet/lnnode.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def __str__(self):
2727
def status(self) -> RunningStatus:
2828
return self.warnet.container_interface.get_status(self.tank.index, ServiceType.LIGHTNING)
2929

30+
@property
31+
def cb_status(self) -> RunningStatus:
32+
if not self.cb:
33+
return None
34+
return self.warnet.container_interface.get_status(self.tank.index, ServiceType.CIRCUITBREAKER)
35+
3036
@exponential_backoff(max_retries=20, max_delay=300)
3137
@handle_json
3238
def lncli(self, cmd) -> dict:

src/warnet/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ def network_status(self, network: str = "warnet") -> list[dict]:
565565
status = {"tank_index": tank.index, "bitcoin_status": tank.status.name.lower()}
566566
if tank.lnnode is not None:
567567
status["lightning_status"] = tank.lnnode.status.name.lower()
568+
if tank.lnnode.cb is not None:
569+
status["circuitbreaker_status"] = tank.lnnode.cb_status.name.lower()
568570
stats.append(status)
569571
return stats
570572
except Exception as e:

test/test_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ def check_status():
175175
if lightning_status not in stats:
176176
stats[lightning_status] = 0
177177
stats[lightning_status] += 1
178+
if "circuitbreaker_status" in tank:
179+
stats["total"] += 1
180+
circuitbreaker_status = tank["circuitbreaker_status"]
181+
if circuitbreaker_status not in stats:
182+
stats[circuitbreaker_status] = 0
183+
stats[circuitbreaker_status] += 1
178184
print(f"Waiting for all tanks to reach '{target}': {stats}")
179185
# All tanks are running, proceed
180186
return target in stats and stats[target] == stats["total"]

0 commit comments

Comments
 (0)