Skip to content

Commit

Permalink
proposals: allow proposals to add a new TLV field.
Browse files Browse the repository at this point in the history
We refuse to merge same-named TLVs across namespaces, so we want to
create a new namespace from the merged TLVs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 24, 2021
1 parent 97d225d commit 5330378
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lnprototest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .structure import Sequence, OneOf, AnyOrder, TryAll
from .runner import Runner, Conn, remote_revocation_basepoint, remote_payment_basepoint, remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_per_commitment_point, remote_per_commitment_secret, remote_funding_pubkey, remote_funding_privkey
from .dummyrunner import DummyRunner
from .namespace import peer_message_namespace, namespace, assign_namespace
from .namespace import peer_message_namespace, namespace, assign_namespace, make_namespace
from .bitfield import bitfield, has_bit, bitfield_len
from .signature import SigType, Sig
from .keyset import KeySet
Expand Down Expand Up @@ -65,6 +65,7 @@
"peer_message_namespace",
"namespace",
"assign_namespace",
"make_namespace",
"bitfield",
"has_bit",
"bitfield_len",
Expand Down
17 changes: 11 additions & 6 deletions lnprototest/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
import pyln.spec.bolt7
from pyln.proto.message import MessageNamespace
from .signature import SigType
from typing import List


def peer_message_namespace() -> MessageNamespace:
"""Namespace containing all the peer messages"""
def make_namespace(csv: List[str]) -> MessageNamespace:
"""Load a namespace, replacing signature type"""
ns = MessageNamespace()
# We replace the fundamental signature type with our custom type,
# then we load in all the csv files so they use it.
ns.fundamentaltypes['signature'] = SigType()

ns.load_csv(pyln.spec.bolt1.csv
+ pyln.spec.bolt2.csv
+ pyln.spec.bolt7.csv)
ns.load_csv(csv)
return ns


def peer_message_namespace() -> MessageNamespace:
"""Namespace containing all the peer messages"""
return make_namespace(pyln.spec.bolt1.csv
+ pyln.spec.bolt2.csv
+ pyln.spec.bolt7.csv)


def namespace() -> MessageNamespace:
return event_namespace

Expand Down
10 changes: 9 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import pytest
import importlib
import lnprototest
import pyln.spec.bolt1
import pyln.spec.bolt2
import pyln.spec.bolt7
from pyln.proto.message import MessageNamespace
from typing import Any, Callable, Generator, List

Expand Down Expand Up @@ -33,7 +36,12 @@ def with_proposal(pytestconfig: Any) -> Generator[Callable[[List[str]], None], N
"""Use this to add additional messages to the namespace
Useful for testing proposed (but not yet merged) spec mods"""
def _setter(proposal_csv: List[str]) -> None:
lnprototest.assign_namespace(lnprototest.namespace() + MessageNamespace(proposal_csv))
# We merge *csv*, because then you can add tlv entries; merging
# namespaces with duplicate TLVs complains of a clash.
lnprototest.assign_namespace(lnprototest.make_namespace(pyln.spec.bolt1.csv
+ pyln.spec.bolt2.csv
+ pyln.spec.bolt7.csv
+ proposal_csv))

yield _setter

Expand Down

0 comments on commit 5330378

Please sign in to comment.