Skip to content

Commit 859bf79

Browse files
committed
Add CommitSigBatch codec
While we send `commit_sig` messages individually on the wire, we need a codec for the batch object when using the cluster mode, when peer connection actors live on remote machines.
1 parent a014211 commit 859bf79

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/wire/protocol/LightningMessageCodecs.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ object LightningMessageCodecs {
278278
("htlcSignatures" | listofsignatures) ::
279279
("tlvStream" | CommitSigTlv.commitSigTlvCodec)).as[CommitSig]
280280

281+
// This isn't a "real" lightning codec, as we send each commit_sig individually to our peers.
282+
// But it's necessary to send CommitSigBatch objects to front machines when the cluster mode is used.
283+
val commitSigBatchCodec: Codec[CommitSigBatch] = listOfN(uint16, lengthDelimited(commitSigCodec)).xmap(sigs => CommitSigBatch(sigs.toSeq), batch => batch.messages.toList)
284+
281285
val revokeAndAckCodec: Codec[RevokeAndAck] = (
282286
("channelId" | bytes32) ::
283287
("perCommitmentSecret" | privateKey) ::
@@ -567,7 +571,7 @@ object LightningMessageCodecs {
567571
//
568572
.typecase(39409, recommendedFeeratesCodec)
569573
//
570-
574+
.typecase(53011, commitSigBatchCodec)
571575
//
572576

573577
//

eclair-core/src/test/scala/fr/acinq/eclair/wire/protocol/LightningMessageCodecsSpec.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import fr.acinq.eclair._
2727
import fr.acinq.eclair.blockchain.fee.FeeratePerKw
2828
import fr.acinq.eclair.channel.ChannelSpendSignature.{IndividualSignature, PartialSignatureWithNonce}
2929
import fr.acinq.eclair.channel.ChannelTypes.SimpleTaprootChannelsPhoenix
30-
import fr.acinq.eclair.channel.{ChannelFlags, ChannelTypes}
30+
import fr.acinq.eclair.channel.{ChannelFlags, ChannelSpendSignature, ChannelTypes}
3131
import fr.acinq.eclair.json.JsonSerializers
3232
import fr.acinq.eclair.reputation.Reputation
3333
import fr.acinq.eclair.router.Announcements
@@ -696,6 +696,18 @@ class LightningMessageCodecsSpec extends AnyFunSuite {
696696
}
697697
}
698698

699+
test("encode/decode commit_sig batch") {
700+
val channelId = randomBytes32()
701+
val batch = CommitSigBatch(Seq(
702+
CommitSig(channelId, ChannelSpendSignature.IndividualSignature(randomBytes64()), Nil, batchSize = 3),
703+
CommitSig(channelId, ChannelSpendSignature.IndividualSignature(randomBytes64()), Nil, batchSize = 3),
704+
CommitSig(channelId, ChannelSpendSignature.IndividualSignature(randomBytes64()), Nil, batchSize = 3),
705+
))
706+
val encoded = lightningMessageCodec.encode(batch).require
707+
val decoded = lightningMessageCodec.decode(encoded).require.value
708+
assert(decoded == batch)
709+
}
710+
699711
test("unknown messages") {
700712
// Non-standard tag number so this message can only be handled by a codec with a fallback
701713
val unknown = UnknownMessage(tag = 47282, data = ByteVector32.Zeroes.bytes)

0 commit comments

Comments
 (0)