lnwire: ensure we precisely encode the length for onion errors w/ chan updates
In this commit we fix a compatibility issue with other implementations. Before this commit, when writing out an onion error that includes a `ChannelUpdate` we would use the `MaxPayloadLength` to get the length to encode. However, a recent update has modified that to be the max `brontide` payload length as it's possible to pad out the message with optional fields we're unaware of. As a result, we would always write out a length of 65KB or so. This didn't effect our parser as we ignore the length and decode the channel update directly as we don't need the length to do that. However, other implementations depended on the length rather than just reading the channel update, meaning that they weren't able to decode our onion errors that had channel updates. In this commit we fix that by introducing a new `writeOnionErrorChanUpdate` which will write out the precise length instead of using the max payload size. Fixes #2450.
This commit is contained in:
2 files changed
+69
-30
No files matched your search
@@ -131,3 +131,38 @@ func TestChannelUpdateCompatabilityParsing(t *testing.T) {
|
||||
t.Fatalf("mismatched channel updates: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWriteOnionErrorChanUpdate tests that we write an exact size for the
|
||||
// channel update in order to be more compliant with the parsers of other
|
||||
// implementations.
|
||||
func TestWriteOnionErrorChanUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// First, we'll write out the raw channel update so we can obtain the
|
||||
// raw serialized length.
|
||||
var b bytes.Buffer
|
||||
update := testChannelUpdate
|
||||
if err := update.Encode(&b, 0); err != nil {
|
||||
t.Fatalf("unable to write update: %v", err)
|
||||
}
|
||||
trueUpdateLength := b.Len()
|
||||
|
||||
// Next, we'll use the function to encode the update as we would in a
|
||||
// onion error message.
|
||||
var errorBuf bytes.Buffer
|
||||
err := writeOnionErrorChanUpdate(&errorBuf, &update, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to encode onion error: %v", err)
|
||||
}
|
||||
|
||||
// Finally, read the length encoded and ensure that it matches the raw
|
||||
// length.
|
||||
var encodedLen uint16
|
||||
if err := ReadElement(&errorBuf, &encodedLen); err != nil {
|
||||
t.Fatalf("unable to read len: %v", err)
|
||||
}
|
||||
if uint16(trueUpdateLength) != encodedLen {
|
||||
t.Fatalf("wrong length written: expected %v, got %v",
|
||||
trueUpdateLength, encodedLen)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user