Skip to content

Commit 8286762

Browse files
committed
Clarify batch unit test
This happens over a single connection with a given peer: we clarify that we use distinct channels, but they are not with different peers.
1 parent d7e8405 commit 8286762

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

eclair-core/src/test/scala/fr/acinq/eclair/io/PeerConnectionSpec.scala

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -353,67 +353,73 @@ class PeerConnectionSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike wi
353353
import f._
354354
connect(nodeParams, remoteNodeId, switchboard, router, connection, transport, peerConnection, peer)
355355

356-
// The channel with A has a pending splice.
357-
val channelIdA = randomBytes32()
358-
val commitSigA1 = CommitSig(channelIdA, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(2)))
359-
val commitSigA2 = CommitSig(channelIdA, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(2)))
360-
// The channel with B has 2 pending splices.
361-
val channelIdB = randomBytes32()
362-
val commitSigB1 = CommitSig(channelIdB, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3)))
363-
val commitSigB2 = CommitSig(channelIdB, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3)))
364-
val commitSigB3 = CommitSig(channelIdB, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3)))
365-
// The channel with C doesn't have any pending splice.
366-
val channelIdC = randomBytes32()
367-
val commitSigC1 = CommitSig(channelIdC, randomBytes64(), Nil)
368-
// The channel with D doesn't have any pending splice, but the batch TLV is (incorrectly) set.
369-
val channelIdD = randomBytes32()
370-
val commitSigD1 = CommitSig(channelIdD, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(1)))
356+
// The first channel has a pending splice.
357+
val channelId1 = randomBytes32()
358+
val commitSigs1 = Seq(
359+
CommitSig(channelId1, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(2))),
360+
CommitSig(channelId1, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(2))),
361+
)
362+
// A second channel has 2 pending splices.
363+
val channelId2 = randomBytes32()
364+
val commitSigs2 = Seq(
365+
CommitSig(channelId2, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3))),
366+
CommitSig(channelId2, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3))),
367+
CommitSig(channelId2, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3))),
368+
)
369+
// Another channel doesn't have any pending splice.
370+
val channelId3 = randomBytes32()
371+
val commitSig3 = CommitSig(channelId3, randomBytes64(), Nil)
372+
// Another channel doesn't have any pending splice, but the batch TLV is (incorrectly) set.
373+
val channelId4 = randomBytes32()
374+
val commitSig4 = CommitSig(channelId4, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(1)))
371375

372376
// Older peers may not correctly group these messages on the wire: unrelated messages may be interleaved.
373-
// We start by receiving a partial batch from A and B.
374-
transport.send(peerConnection, commitSigA1)
375-
transport.expectMsg(TransportHandler.ReadAck(commitSigA1))
376-
transport.send(peerConnection, commitSigB1)
377-
transport.expectMsg(TransportHandler.ReadAck(commitSigB1))
378-
transport.send(peerConnection, commitSigB2)
379-
transport.expectMsg(TransportHandler.ReadAck(commitSigB2))
377+
// We start by receiving a partial batch from the first two channels.
378+
transport.send(peerConnection, commitSigs1(0))
379+
transport.expectMsg(TransportHandler.ReadAck(commitSigs1(0)))
380+
transport.send(peerConnection, commitSigs2(0))
381+
transport.expectMsg(TransportHandler.ReadAck(commitSigs2(0)))
382+
transport.send(peerConnection, commitSigs2(1))
383+
transport.expectMsg(TransportHandler.ReadAck(commitSigs2(1)))
380384
peer.expectNoMessage(100 millis)
381-
// We then receive individual commit_sig messages from C and D.
382-
transport.send(peerConnection, commitSigC1)
383-
transport.expectMsg(TransportHandler.ReadAck(commitSigC1))
384-
peer.expectMsg(commitSigC1)
385-
transport.send(peerConnection, commitSigD1)
386-
transport.expectMsg(TransportHandler.ReadAck(commitSigD1))
387-
peer.expectMsg(commitSigD1)
388-
// Finally, we receive the end of A and B's batches.
389-
transport.send(peerConnection, commitSigA2)
390-
transport.expectMsg(TransportHandler.ReadAck(commitSigA2))
391-
peer.expectMsg(CommitSigBatch(commitSigA1 :: commitSigA2 :: Nil))
392-
transport.send(peerConnection, commitSigB3)
393-
transport.expectMsg(TransportHandler.ReadAck(commitSigB3))
394-
peer.expectMsg(CommitSigBatch(commitSigB1 :: commitSigB2 :: commitSigB3 :: Nil))
385+
// We then receive individual commit_sig messages from the last two channels.
386+
transport.send(peerConnection, commitSig3)
387+
transport.expectMsg(TransportHandler.ReadAck(commitSig3))
388+
peer.expectMsg(commitSig3)
389+
transport.send(peerConnection, commitSig4)
390+
transport.expectMsg(TransportHandler.ReadAck(commitSig4))
391+
peer.expectMsg(commitSig4)
392+
// Finally, we receive the end of the first two channels' batches.
393+
transport.send(peerConnection, commitSigs1(1))
394+
transport.expectMsg(TransportHandler.ReadAck(commitSigs1(1)))
395+
peer.expectMsg(CommitSigBatch(commitSigs1))
396+
transport.send(peerConnection, commitSigs2(2))
397+
transport.expectMsg(TransportHandler.ReadAck(commitSigs2(2)))
398+
peer.expectMsg(CommitSigBatch(commitSigs2))
395399
peer.expectNoMessage(100 millis)
396400

397-
// We then receive another batch of messages from A with unrelated channel messages in-between.
398-
val commitSigA3 = CommitSig(channelIdA, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3)))
399-
val commitSigA4 = CommitSig(channelIdA, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3)))
400-
val spliceLockedA = SpliceLocked(channelIdA, randomTxId())
401-
val commitSigA5 = CommitSig(channelIdA, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3)))
402-
transport.send(peerConnection, commitSigA3)
403-
transport.expectMsg(TransportHandler.ReadAck(commitSigA3))
404-
transport.send(peerConnection, commitSigA4)
405-
transport.expectMsg(TransportHandler.ReadAck(commitSigA4))
406-
transport.send(peerConnection, spliceLockedA)
407-
transport.expectMsg(TransportHandler.ReadAck(spliceLockedA))
408-
peer.expectMsg(spliceLockedA)
401+
// We then receive another batch of messages from the first channel with unrelated channel messages in-between.
402+
val commitSigs5 = Seq(
403+
CommitSig(channelId1, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3))),
404+
CommitSig(channelId1, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3))),
405+
CommitSig(channelId1, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(3))),
406+
)
407+
val spliceLocked = SpliceLocked(channelId1, randomTxId())
408+
transport.send(peerConnection, commitSigs5(0))
409+
transport.expectMsg(TransportHandler.ReadAck(commitSigs5(0)))
410+
transport.send(peerConnection, commitSigs5(1))
411+
transport.expectMsg(TransportHandler.ReadAck(commitSigs5(1)))
412+
transport.send(peerConnection, spliceLocked)
413+
transport.expectMsg(TransportHandler.ReadAck(spliceLocked))
414+
peer.expectMsg(spliceLocked)
409415
peer.expectNoMessage(100 millis)
410-
transport.send(peerConnection, commitSigA5)
411-
transport.expectMsg(TransportHandler.ReadAck(commitSigA5))
412-
peer.expectMsg(CommitSigBatch(commitSigA3 :: commitSigA4 :: commitSigA5 :: Nil))
416+
transport.send(peerConnection, commitSigs5(2))
417+
transport.expectMsg(TransportHandler.ReadAck(commitSigs5(2)))
418+
peer.expectMsg(CommitSigBatch(commitSigs5))
413419
peer.expectNoMessage(100 millis)
414420

415421
// We receive a batch that exceeds our threshold: we process them individually.
416-
val invalidCommitSigs = (0 until 30).map(_ => CommitSig(channelIdB, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(30))))
422+
val invalidCommitSigs = (0 until 30).map(_ => CommitSig(channelId2, randomBytes64(), Nil, TlvStream(CommitSigTlv.BatchTlv(30))))
417423
invalidCommitSigs.foreach(commitSig => {
418424
transport.send(peerConnection, commitSig)
419425
transport.expectMsg(TransportHandler.ReadAck(commitSig))

0 commit comments

Comments
 (0)