Skip to content

Commit

Permalink
pyln.proto.message: fix handling of missing optional fields.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rustyrussell committed Jun 12, 2020
1 parent e0d3174 commit 5dbec8f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contrib/pyln-proto/pyln/proto/message/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ def read(namespace: MessageNamespace, io_in: BufferedIOBase) -> Optional['Messag
fields[f.name] = f.fieldtype.read(io_in, fields)
if fields[f.name] is None:
# optional fields are OK to be missing at end!
if f.option is not None:
break
raise ValueError('{}: truncated at field {}'
.format(mtype, f.name))

Expand Down Expand Up @@ -641,6 +643,9 @@ def write(self, io_out: BufferedIOBase) -> None:
if f.name in self.fields:
val = self.fields[f.name]
else:
# If this isn't present, and it's marked optional, don't write.
if f.option is not None:
return
val = None
f.fieldtype.write(io_out, val, self.fields)

Expand Down

0 comments on commit 5dbec8f

Please sign in to comment.