Skip to content

Commit

Permalink
Fix remote upfront script codec (#1991)
Browse files Browse the repository at this point in the history
The script wasn't length-delimited.
Fortunately this feature was disabled by default.
Since no-one reported the issue, we can probably just do this simple fix.
  • Loading branch information
t-bast authored Oct 6, 2021
1 parent 0621ccf commit bb5e6df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private[channel] object ChannelCodecs3 {
("delayedPaymentBasepoint" | publicKey) ::
("htlcBasepoint" | publicKey) ::
("features" | combinedFeaturesCodec) ::
("shutdownScript" | optional(bool8, bytes))).as[RemoteParams]
("shutdownScript" | optional(bool8, lengthDelimited(bytes)))).as[RemoteParams]

def setCodec[T](codec: Codec[T]): Codec[Set[T]] = listOfN(uint16, codec).xmap(_.toSet, _.toList)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class ChannelCodecs3Spec extends AnyFunSuite {
assert(remoteParamsCodec.decodeValue(remoteParamsCodec.encode(remoteParams).require).require === remoteParams)
val remoteParams1 = remoteParams.copy(shutdownScript = Some(ByteVector.fromValidHex("deadbeef")))
assert(remoteParamsCodec.decodeValue(remoteParamsCodec.encode(remoteParams1).require).require === remoteParams1)

val dataWithoutRemoteShutdownScript = normal.copy(commitments = normal.commitments.copy(remoteParams = remoteParams))
assert(DATA_NORMAL_Codec.decode(DATA_NORMAL_Codec.encode(dataWithoutRemoteShutdownScript).require).require.value === dataWithoutRemoteShutdownScript)

val dataWithRemoteShutdownScript = normal.copy(commitments = normal.commitments.copy(remoteParams = remoteParams1))
assert(DATA_NORMAL_Codec.decode(DATA_NORMAL_Codec.encode(dataWithRemoteShutdownScript).require).require.value === dataWithRemoteShutdownScript)
}

test("backward compatibility DATA_NORMAL_COMPAT_02_Codec") {
Expand Down

0 comments on commit bb5e6df

Please sign in to comment.