Skip to content

Commit

Permalink
Merge branch 'rustyrussell:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycho-Pirate authored Nov 22, 2024
2 parents d72a87b + c9e78d9 commit b1cc3eb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 60 deletions.
12 changes: 7 additions & 5 deletions docker/Dockerfile.clightning
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ RUN apt-get -qq update && \
wget \
gettext \
xsltproc \
zlib1g-dev && \
zlib1g-dev \
jq && \
rm -rf /var/lib/apt/lists/*

ENV LANGUAGE=en_US.UTF-8
Expand All @@ -58,10 +59,11 @@ RUN pip3 install -U pip && \
RUN git config --global user.name "John Doe" && \
git config --global user.email johndoe@example.com && \
git clone https://github.com/ElementsProject/lightning.git && \
cd lightning && \
pip3 install mako && \
./configure && \
make -j$(nproc)
# FIXME: cln 24.05 is the last version that works with the current lnprototest.
cd lightning && git checkout v24.05 && \
pip3 install mako --break-system-packages && pip3 install grpcio-tools --break-system-packages && \
./configure && \
make -j$(nproc)

RUN mkdir lnprototest

Expand Down
2 changes: 1 addition & 1 deletion lnprototest/clightning/clightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def start(self, also_bitcoind: bool = True) -> None:
"--network=regtest",
"--bitcoin-rpcuser=rpcuser",
"--bitcoin-rpcpassword=rpcpass",
f"--bitcoin-rpcconnect=localhost:{self.bitcoind.port}",
f"--bitcoin-rpcconnect=127.0.0.1:{self.bitcoind.port}",
"--log-level=debug",
"--log-file=log",
"--htlc-maximum-msat=2000sat",
Expand Down
19 changes: 12 additions & 7 deletions lnprototest/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,23 +566,28 @@ def action(self, runner: "Runner") -> bool:


class ExpectDisconnect(PerConnEvent):
"""This is considerer an hack, because the protocol
is not specifing what fail the connection means, so in
some case a node close the connection without any message
or in a local env the connection got close before sending
out the msg, so this event is the simplest way to work around
this current issue."""
"""
This is considered a hack because the protocol does not specify what failing the connection means.
In some cases, a node closes the connection without any message, or in a local environment, the
connection may close before sending out the message. This event is the simplest way to work around
this current issue.
"""

def __init__(self, connprivkey: Optional[str] = None):
super().__init__(connprivkey)

def action(self, runner: "Runner") -> bool:
super().action(runner)
if runner._is_dummy():
return True
msg = runner.check_error(self, self.find_conn(runner))
logging.info(f"expecting disconnection: `{msg}`")
# in this case of the dummy runner we return a `Dummy error`
# but in this case we wan receive an None value
# because the connected got close before
return msg is None or runner._is_dummy()
if msg is None:
return True
raise EventError(self, "Peer did not disconnect")


class CheckEq(Event):
Expand Down
53 changes: 23 additions & 30 deletions tests/test_bolt1-01-init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#! /usr/bin/env python3
# Variations on init exchange.
# Spec: MUST respond to known feature bits as specified in [BOLT #9](09-features.md).
"""
Variation of init exchange.
Spec: MUST respond to known feature bits as specified in [BOLT #9](09-features.md).
"""
import functools

from typing import List, Any
Expand Down Expand Up @@ -88,7 +90,24 @@ def test_echo_init(runner: Runner, namespaceoverride: Any) -> None:
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# You should always handle us echoing your own features back!
ExpectMsg("init"),
Msg("init", globalfeatures=rcvd(), features=rcvd()),
]

run_runner(runner, test)


def test_echo_init_after_disconnect(runner: Runner, namespaceoverride: Any) -> None:
# We override default namespace since we only need BOLT1
namespaceoverride(pyln.spec.bolt1.namespace)
test = [
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
Disconnect(),
Connect(connprivkey="02"),
# You should always handle us echoing your own features back!
ExpectMsg("init"),
Expand All @@ -105,8 +124,6 @@ def test_init_check_received_msg(runner: Runner, namespaceoverride: Any) -> None
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# Even if we don't send anything, it should send init.
ExpectMsg("init", if_match=no_gf13),
Expand All @@ -121,8 +138,6 @@ def test_init_invalid_globalfeatures(runner: Runner, namespaceoverride: Any) ->
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
ExpectMsg("init", if_match=no_gf13),
# BOLT #1:
Expand All @@ -140,8 +155,6 @@ def test_init_is_first_msg(runner: Runner, namespaceoverride: Any) -> None:
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# Minimal possible init message.
# BOLT #1:
Expand All @@ -160,8 +173,6 @@ def test_init_check_free_featurebits(runner: Runner, namespaceoverride: Any) ->
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
ExpectMsg("init", if_match=functools.partial(no_feature, [98, 99])),
# BOLT #1:
Expand All @@ -183,8 +194,6 @@ def test_init_fail_connection_if_receive_an_even_unknown_featurebits(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# BOLT #1:
# The receiving node: ...
Expand All @@ -206,8 +215,6 @@ def test_init_fail_connection_if_receive_an_even_unknown_globalfeaturebits(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# init msg with unknown even global bit (98): you will error
ExpectMsg("init"),
Expand All @@ -226,8 +233,6 @@ def test_init_fail_ask_for_option_data_loss_protect(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# If you don't support `option_data_loss_protect`, you will be ok if
# we ask for it.
Expand All @@ -251,8 +256,6 @@ def test_init_advertize_option_data_loss_protect(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# If you support `option_data_loss_protect`, you will advertize it odd.
Sequence(
Expand All @@ -272,8 +275,6 @@ def test_init_required_option_data_loss_protect(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# If you require `option_data_loss_protect`, you will advertize it even.
Sequence(
Expand All @@ -293,8 +294,6 @@ def test_init_reject_option_data_loss_protect_if_not_supported(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# If you don't support `option_anchor_outputs`, you will error if
# we require it.
Expand All @@ -319,8 +318,6 @@ def test_init_advertize_option_anchor_outputs(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# If you support `option_anchor_outputs`, you will advertize it odd.
Sequence(
Expand All @@ -340,8 +337,6 @@ def test_init_required_option_anchor_outputs(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# If you require `option_anchor_outputs`, you will advertize it even.
Sequence(
Expand All @@ -361,8 +356,6 @@ def test_init_advertize_option_static_remotekey(
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# optionally disconnect that first one
TryAll([], Disconnect()),
Connect(connprivkey="02"),
# BOLT-a12da24dd0102c170365124782b46d9710950ac1 #9:
# | Bits | Name | ... | Dependencies
Expand Down
44 changes: 27 additions & 17 deletions tests/test_bolt1-02-unknown-messages.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#! /usr/bin/env python3
# Init exchange, with unknown messages
#
import pyln.spec.bolt1

from typing import Any

from lnprototest import TryAll, Connect, ExpectMsg, Msg, RawMsg, Runner
from lnprototest.event import ExpectDisconnect
import pyln.spec.bolt1
from typing import Any
from lnprototest.utils import run_runner


def test_unknowns(runner: Runner, namespaceoverride: Any) -> None:
Expand All @@ -15,20 +17,28 @@ def test_unknowns(runner: Runner, namespaceoverride: Any) -> None:
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
TryAll(
[],
# BOLT #1:
# A receiving node:
# - upon receiving a message of _odd_, unknown type:
# - MUST ignore the received message.
[RawMsg(bytes.fromhex("270F"))],
# BOLT #1:
# A receiving node:...
# - upon receiving a message of _even_, unknown type:
# - MUST close the connection.
# - MAY fail the channels.
[RawMsg(bytes.fromhex("2710")), ExpectDisconnect()],
),
# BOLT #1:
# A receiving node:
# - upon receiving a message of _odd_, unknown type:
# - MUST ignore the received message.
RawMsg(bytes.fromhex("270F")),
]
run_runner(runner, test)


runner.run(test)
def test_unknowns_even_message(runner: Runner, namespaceoverride: Any) -> None:
# We override default namespace since we only need BOLT1
namespaceoverride(pyln.spec.bolt1.namespace)
test = [
Connect(connprivkey="03"),
ExpectMsg("init"),
Msg("init", globalfeatures="", features=""),
# BOLT #1:
# A receiving node:...
# - upon receiving a message of _even_, unknown type:
# - MUST close the connection.
# - MAY fail the channels.
RawMsg(bytes.fromhex("2710")),
ExpectDisconnect(),
]
run_runner(runner, test)

0 comments on commit b1cc3eb

Please sign in to comment.