Skip to content

Commit

Permalink
fix: add Wait event to allow to slow down lnptototest
Browse files Browse the repository at this point in the history
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: #74
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Mar 12, 2023
1 parent 3e6bc6e commit 403444c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lnprototest/clightning/clightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import shutil
import logging
import socket
import time

from contextlib import closing
from datetime import date
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
)
Expand Down
4 changes: 0 additions & 4 deletions tests/test_bolt2-01-open_channel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Variations on open_channel, accepter + opener perspectives
import pytest
from lnprototest import (
TryAll,
Block,
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 403444c

Please sign in to comment.