From 403444cfe12ab2d7357c2a2b8b1a3be4307e0b3c Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Thu, 9 Mar 2023 22:34:19 +0100 Subject: [PATCH] fix: add Wait event to allow to slow down lnptototest There is some case where lnprototest send the message too fast, well lnprototest is always too fast but in most case, we simulate the `time.sleep` inside the ExpectedMsg that iterates for a while till the message is not received. This is no longer true if lnprototest sends a message and the next steps is not the ExpectedMsg or equal but a message that required that the message sent to lnprototest is already processed, like in the `FundChannel(...)` case. So this commit is introducing a new Event `Wait` that will allow us to wait some time before processing the next message. This is needed when you send the connection event, and then you send the fundchannel message. It is possible endup in a concurrency problem when the node is waiting to finish the connection, but receive the next message, just because lnprototest it too fast. All this to said that this is an hack (but an hack with docs :) ) Link: https://github.com/rustyrussell/lnprototest/issues/74 Signed-off-by: Vincenzo Palazzo --- lnprototest/clightning/clightning.py | 9 ++++++++- tests/test_bolt2-01-open_channel.py | 4 ---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lnprototest/clightning/clightning.py b/lnprototest/clightning/clightning.py index e2a3047..2c90b0d 100644 --- a/lnprototest/clightning/clightning.py +++ b/lnprototest/clightning/clightning.py @@ -15,6 +15,7 @@ import shutil import logging import socket +import time from contextlib import closing from datetime import date @@ -214,7 +215,7 @@ def restart(self) -> None: self.bitcoind.restart() self.start(also_bitcoind=False) - def connect(self, event: Event, connprivkey: str) -> None: + def connect(self, _: Event, connprivkey: str) -> None: self.add_conn(CLightningConn(connprivkey, self.lightning_port)) def getblockheight(self) -> int: @@ -318,6 +319,12 @@ def _done(fut: Any) -> None: self.is_fundchannel_kill = False self.cleanup_callbacks.remove(self.kill_fundchannel) + # FIXME core lightning has a race condition + # when the core lightning node will go to fund the channel + # but it will go to to connect with the node before + # This required some more analysis from core lightning side + time.sleep(1) + fut = self.executor.submit( _fundchannel, self, conn, amount, feerate, expect_fail ) diff --git a/tests/test_bolt2-01-open_channel.py b/tests/test_bolt2-01-open_channel.py index 71ebfce..8617904 100644 --- a/tests/test_bolt2-01-open_channel.py +++ b/tests/test_bolt2-01-open_channel.py @@ -1,5 +1,4 @@ # Variations on open_channel, accepter + opener perspectives -import pytest from lnprototest import ( TryAll, Block, @@ -168,9 +167,6 @@ def test_open_channel_from_accepter_side(runner: Runner) -> None: run_runner(runner, merge_events_sequences(connections_events, test_events)) -@pytest.mark.skip( - reason="skip this test because the when we try to connect to lnprototest the connection fails" -) def test_open_channel_opener_side(runner: Runner) -> None: local_funding_privkey = "20" local_keyset = gen_random_keyset(int(local_funding_privkey))