From ca3680246ebcb59101041a73dc6075b36f8539c5 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 24 Jun 2021 15:00:52 +0930 Subject: [PATCH] pyln.proto: fix handling of subtypes in TLVs. This was revealed by using lnprototest on channel_types. Signed-off-by: Rusty Russell --- contrib/pyln-proto/pyln/proto/message/message.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/pyln-proto/pyln/proto/message/message.py b/contrib/pyln-proto/pyln/proto/message/message.py index fea95cb56..461d16332 100644 --- a/contrib/pyln-proto/pyln/proto/message/message.py +++ b/contrib/pyln-proto/pyln/proto/message/message.py @@ -305,8 +305,8 @@ other types. Since 'msgtype' is almost identical, it inherits from this too. raise ValueError("Missing field {} {}".format(f.name, otherfields)) val = None - if self.name in otherfields: - otherfields = otherfields[self.name] + if type(f.fieldtype) is SubtypeType: + otherfields = otherfields[f.name] f.fieldtype.write(io_out, val, otherfields) def read(self, io_in: BufferedIOBase, otherfields: Dict[str, Any]) -> Optional[Dict[str, Any]]: @@ -554,7 +554,7 @@ tlvdata,reply_channel_range_tlvs,timestamps_tlv,encoding_type,u8, for typenum, writefunc, val in ordered: buf = BytesIO() - writefunc(cast(BufferedIOBase, buf), val, otherfields) + writefunc(cast(BufferedIOBase, buf), val, val) BigSizeType.write(io_out, typenum) BigSizeType.write(io_out, len(buf.getvalue())) io_out.write(buf.getvalue())