Skip to content

Commit 5dbec8f

Browse files
committed
pyln.proto.message: fix handling of missing optional fields.
If they don't exist, that's OK. These will eventually be going away from the spec, but there are still some in gossip messages for now. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e0d3174 commit 5dbec8f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

contrib/pyln-proto/pyln/proto/message/message.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ def read(namespace: MessageNamespace, io_in: BufferedIOBase) -> Optional['Messag
591591
fields[f.name] = f.fieldtype.read(io_in, fields)
592592
if fields[f.name] is None:
593593
# optional fields are OK to be missing at end!
594+
if f.option is not None:
595+
break
594596
raise ValueError('{}: truncated at field {}'
595597
.format(mtype, f.name))
596598

@@ -641,6 +643,9 @@ def write(self, io_out: BufferedIOBase) -> None:
641643
if f.name in self.fields:
642644
val = self.fields[f.name]
643645
else:
646+
# If this isn't present, and it's marked optional, don't write.
647+
if f.option is not None:
648+
return
644649
val = None
645650
f.fieldtype.write(io_out, val, self.fields)
646651

0 commit comments

Comments
 (0)