From aaefbe2e9e87b0e9c9c0ade4e6f974a498e4b811 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 12 Jun 2020 13:24:56 +0930 Subject: [PATCH] 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 --- contrib/pyln-proto/pyln/proto/message/message.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/pyln-proto/pyln/proto/message/message.py b/contrib/pyln-proto/pyln/proto/message/message.py index 2f498e7ef..1b8d8f37f 100644 --- a/contrib/pyln-proto/pyln/proto/message/message.py +++ b/contrib/pyln-proto/pyln/proto/message/message.py @@ -591,6 +591,8 @@ Returns None on EOF 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)) @@ -641,6 +643,9 @@ Must not have missing fields. 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)