fix: lndrest nodemanager get_channel (flaky ci decoy) (#2877)

This commit is contained in:
dni ⚡
2025-01-09 17:04:32 +01:00
committed by GitHub
parent 6f3d0edfbd
commit 7e27b2c6f0
2 changed files with 18 additions and 6 deletions

View File

@ -220,10 +220,21 @@ class LndRestNode(Node):
async def get_channel(self, channel_id: str) -> Optional[NodeChannel]: async def get_channel(self, channel_id: str) -> Optional[NodeChannel]:
channel_info = await self.get(f"/v1/graph/edge/{channel_id}") channel_info = await self.get(f"/v1/graph/edge/{channel_id}")
peer_id = channel_info["node2_pub"] info = await self.get("/v1/getinfo")
if info["identity_pubkey"] == channel_info["node1_pub"]:
my_node_key = "node1"
peer_node_key = "node2"
else:
my_node_key = "node2"
peer_node_key = "node1"
peer_id = channel_info[f"{peer_node_key}_pub"]
peer_b64 = _encode_urlsafe_bytes(peer_id) peer_b64 = _encode_urlsafe_bytes(peer_id)
channels = await self.get(f"/v1/channels?peer={peer_b64}") channels = await self.get(f"/v1/channels?peer={peer_b64}")
if "error" in channel_info and "error" in channels: if "error" in channel_info and "error" in channels:
logger.debug("LND get_channel", channels)
return None
if len(channels["channels"]) == 0:
logger.debug(f"LND get_channel no channels founds with id {peer_b64}")
return None return None
for channel in channels["channels"]: for channel in channels["channels"]:
if channel["chan_id"] == channel_id: if channel["chan_id"] == channel_id:
@ -238,8 +249,12 @@ class LndRestNode(Node):
if channel["active"] if channel["active"]
else ChannelState.INACTIVE else ChannelState.INACTIVE
), ),
fee_ppm=channel_info["node1_policy"]["fee_rate_milli_msat"], fee_ppm=channel_info[f"{my_node_key}_policy"][
fee_base_msat=channel_info["node1_policy"]["fee_base_msat"], "fee_rate_milli_msat"
],
fee_base_msat=channel_info[f"{my_node_key}_policy"][
"fee_base_msat"
],
point=_parse_channel_point(channel["channel_point"]), point=_parse_channel_point(channel["channel_point"]),
balance=ChannelBalance( balance=ChannelBalance(
local_msat=msat(channel["local_balance"]), local_msat=msat(channel["local_balance"]),

View File

@ -106,14 +106,12 @@ async def test_get_channel(node_client):
response = await node_client.get("/node/api/v1/channels") response = await node_client.get("/node/api/v1/channels")
assert response.status_code == 200 assert response.status_code == 200
channels = parse_obj_as(list[NodeChannel], response.json()) channels = parse_obj_as(list[NodeChannel], response.json())
ch = random.choice( ch = random.choice(
[channel for channel in channels if channel.state == ChannelState.ACTIVE] [channel for channel in channels if channel.state == ChannelState.ACTIVE]
) )
assert ch, "No active channel found" assert ch, "No active channel found"
assert ch.point, "No channel point found" assert ch.point, "No channel point found"
await asyncio.sleep(3)
response = await node_client.get(f"/node/api/v1/channels/{ch.id}") response = await node_client.get(f"/node/api/v1/channels/{ch.id}")
assert response.status_code == 200 assert response.status_code == 200
@ -140,7 +138,6 @@ async def test_set_channel_fees(node_client):
) )
assert response.status_code == 200 assert response.status_code == 200
await asyncio.sleep(3)
response = await node_client.get(f"/node/api/v1/channels/{ch.id}") response = await node_client.get(f"/node/api/v1/channels/{ch.id}")
assert response.status_code == 200 assert response.status_code == 200
channel = parse_obj_as(NodeChannel, response.json()) channel = parse_obj_as(NodeChannel, response.json())