Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct reorg issue in the ln helper function #107

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/Dockerfile.clightning
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ RUN git config --global user.name "John Doe" && \
cd lightning && \
poetry config virtualenvs.create false && \
poetry install && \
./configure --enable-developer && \
./configure && \
make -j$(nproc)

RUN mkdir lnprototest
Expand Down
9 changes: 6 additions & 3 deletions lnprototest/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def action(self, runner: "Runner") -> bool:
raise EventError(
self, "Got msg banned by {}: {}".format(e, binmsg.hex())
)
logging.debug(f"raw msg {binmsg}")
logging.debug(f"raw msg {''.join('%02x' % b for b in binmsg)}")
# Might be completely unknown to namespace.
try:
msg = Message.read(namespace(), io.BytesIO(binmsg))
Expand Down Expand Up @@ -378,7 +378,7 @@ class Block(Event):

def __init__(
self,
blockheight: int,
blockheight: Union[int, Callable],
number: Union[int, Callable] = 1,
txs: List[ResolvableStr] = [],
):
Expand All @@ -389,6 +389,10 @@ def __init__(

def action(self, runner: "Runner") -> bool:
super().action(runner)

if isinstance(self.blockheight, Callable):
self.blockheight = self.resolve_arg(None, runner, self.blockheight)

# Oops, did they ask us to produce a block with no predecessor?
if runner.getblockheight() + 1 < self.blockheight:
raise SpecFileError(
Expand All @@ -397,7 +401,6 @@ def action(self, runner: "Runner") -> bool:
self.blockheight, runner.getblockheight()
),
)

# Throw away blocks we're replacing.
if runner.getblockheight() >= self.blockheight:
runner.trim_blocks(self.blockheight - 1)
Expand Down
13 changes: 8 additions & 5 deletions lnprototest/utils/ln_spec_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def open_and_announce_channel_helper(
),
# Mine it and get it deep enough to confirm channel.
Block(
blockheight=103,
blockheight=block_height,
number=stash_field_from_event(
"accept_channel", field_name="minimum_depth", dummy_val=3
),
Expand All @@ -216,9 +216,12 @@ def open_and_announce_channel_helper(
second_per_commitment_point=local_keyset.per_commit_point(1),
),
# wait confirmations
Block(blockheight=103, number=6),
# BOLT 2:
#
# Once both nodes have exchanged channel_ready (and optionally announcement_signatures),
# the channel can be used to make payments via Hashed Time Locked Contracts.
# FIXME: Uh! do you know why this sucks, because lnprototest is lazy evaluated.
# This is huggly, and we should change it at some point but this now works.
Block(
blockheight=lambda runner, event, _: block_height
+ runner.get_stash(event, "accept_channel").fields["minimum_depth"],
number=6,
),
]
4 changes: 4 additions & 0 deletions tests/test_bolt2-01-open_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def test_open_channel_opener_side_wrong_announcement_signatures(runner: Runner)
dummy_sign = "138c93afb2013c39f959e70a163c3d6d8128cf72f8ae143f87b9d1fd6bb0ad30321116b9c58d69fca9fb33c214f681b664e53d5640abc2fdb972dc62a5571053"
short_channel_id = opts["short_channel_id"]
test_events = [
# BOLT 2:
#
# - Once both nodes have exchanged channel_ready (and optionally announcement_signatures),
# the channel can be used to make payments via Hashed Time Locked Contracts.
ExpectMsg(
"announcement_signatures",
channel_id=channel_id(),
Expand Down