lnwire: convert the delivery addr in [Open+Accept]Channel to a TLV type in ExtraData

In this commit, we convert the delivery address in the open and accept
channel methods to be a TLV type. This works as an "empty" delivery
address is encoded using a two zero bytes (uint16 length zero), and a
tlv type of 0 is encoded in the same manner (byte for type, byte for
zero length). This change allows us to easily extend these messages in
the future, in a uniform manner.

When decoding the message we snip the bytes from the read TLV data.
Similarly, when encoding we concatenate the TLV record for the shutdown
script with the rest of the TLV data.
This commit is contained in:
Johan T. Halseth committed 2021-02-24 17:40:08 +01:00
1 parent 9a6bb19770
commit 6842c0ba8c
6 files changed
+227 -40

No files matched your search

+17
View File
@@ -376,6 +376,15 @@ func TestLightningWireProtocol(t *testing.T) {
req.UpfrontShutdownScript = []byte{}
}
// 1/2 chance how having more TLV data after the
// shutdown script.
if r.Intn(2) == 0 {
// TLV type 1 of length 2.
req.ExtraData = []byte{1, 2, 0xff, 0xff}
} else {
req.ExtraData = []byte{}
}
v[0] = reflect.ValueOf(req)
},
MsgAcceptChannel: func(v []reflect.Value, r *rand.Rand) {
@@ -436,6 +445,14 @@ func TestLightningWireProtocol(t *testing.T) {
} else {
req.UpfrontShutdownScript = []byte{}
}
// 1/2 chance how having more TLV data after the
// shutdown script.
if r.Intn(2) == 0 {
// TLV type 1 of length 2.
req.ExtraData = []byte{1, 2, 0xff, 0xff}
} else {
req.ExtraData = []byte{}
}
v[0] = reflect.ValueOf(req)
},